Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
85b9100
Resolve empty timeframe arguments to the chart period
luisleo526 Nov 14, 2026
6e90b5a
Integrate empty timeframe handling with current main
luisleo526 Nov 14, 2026
6453949
Preserve timeframe arguments and generated-name safety
luisleo526 Nov 14, 2026
cd3b13f
Update anchor test expectations for conditional timeframe calls
luisleo526 Nov 14, 2026
909baaf
Preserve reference types across fields and calls
luisleo526 Nov 14, 2026
9120d20
Combine reference-type support with current main
luisleo526 Nov 14, 2026
cb93e2d
Handle emitters without function metadata
luisleo526 Nov 14, 2026
96297f9
Retain structured value types across user function calls
luisleo526 Nov 14, 2026
9237e1b
Check compound values through native execution
luisleo526 Nov 14, 2026
2a8071d
Combine structured type support with current main
luisleo526 Nov 14, 2026
e004cbf
Bound type inference within expression queries
luisleo526 Nov 14, 2026
8802058
Validate timeframe argument types
luisleo526 Nov 14, 2026
7a28a29
Register the timeframe argument diagnostic
luisleo526 Nov 15, 2026
209b3dc
Refresh test reporting and timestamp controls
luisleo526 Nov 15, 2026
31f2d50
Refresh test reporting and timestamp controls
luisleo526 Nov 15, 2026
49cab86
Refresh test reporting and timestamp controls
luisleo526 Nov 15, 2026
c04553d
Disambiguate diagnostic templates by argument kinds
luisleo526 Nov 15, 2026
f2f6ec8
Validate timeframe arguments using semantic types
luisleo526 Nov 15, 2026
b2db977
fix(codegen): allocate function clone names against authored members
luisleo526 Nov 15, 2026
c9bb034
Use the generated timeframe type diagnostic presentation
luisleo526 Nov 15, 2026
5beedda
Locate helper argument expectations inside the builtin call
luisleo526 Nov 15, 2026
bd8a3c6
Resolve registered argument types and report their source starts
luisleo526 Nov 15, 2026
4da8042
fix(codegen): separate composed helper and lexical storage names
luisleo526 Nov 15, 2026
95e5924
Preserve sizing string values across expressions and host settings
luisleo526 Nov 15, 2026
149cb9b
Exercise v5 receiver shadowing through an imported library
luisleo526 Nov 15, 2026
95b26d8
Preserve integer risk type boundary codes
luisleo526 Nov 15, 2026
6e9d119
Strengthen sizing regression and reserve generated name
luisleo526 Nov 15, 2026
d9a643e
Lower computed risk type arms at numeric boundary
luisleo526 Nov 15, 2026
57d0db6
Convert sizing selection arms at host boundaries
luisleo526 Nov 15, 2026
6c1ff4f
fix(codegen): preserve established typed method names
luisleo526 Nov 15, 2026
a0afaa8
Assert the risk type conversion for reassigned sizing variables (#394)
luisleo526 Nov 15, 2026
db8b39a
Combine the empty timeframe and reference type fixes
luisleo526 Nov 15, 2026
ed1eb67
Combine with the generated name collision fix
luisleo526 Nov 15, 2026
45b8662
Preserve unresolved script selection history
luisleo526 Nov 15, 2026
43ec287
Combine corrected timeframe and compound type inference
luisleo526 Nov 15, 2026
40a9877
Combine the compound value type fix with the stacked fixes (#391)
luisleo526 Nov 15, 2026
cbe9f2b
fix(codegen): compile qualified declarations and request helper forms
luisleo526 Nov 15, 2026
6fa5d2b
Merge main into the compound value type fix (#391)
luisleo526 Nov 15, 2026
c2569a2
Combine the qualified declaration and request helper fix (#372) with …
luisleo526 Nov 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ supported as exact pairs; on the 0.x line they are independent. See the
declarations in sibling blocks also retain distinct storage when a script
uses their generated spelling. Declarations, calls and history storage use
the same allocated identities. Regenerate C++ and relink affected strategies.
- Persistent declarations accept a type qualifier after `var` or `varip`.
Lower-timeframe requests return independently typed arrays for inline and
helper-returned tuple payloads.
- Complete nested indentation levels can combine tabs and spaces. Requested
`na`/`nz` helper parameters retain their bindings beside time operations;
global tuple declarations and their member histories share one requested
sample. Uncalled forwarding helpers no longer allocate unresolved TA buffers
for their unreachable call variants (#372).

- A zone name the engine rejects now makes calendar-form `timestamp()` stop the
run at its first evaluation, instead of silently calculating a UTC value.
Expand All @@ -67,6 +75,12 @@ supported as exact pairs; on the 0.x line they are independent. See the
bytes: the timezone macro block and newly reserved names remain.
Regenerate C++ and relink affected strategies.

- User functions retain array, object and string result types through branch
returns and history clones. Untyped arguments retain collection element
types through nested calls and tuple bindings, and reassigned matrix locals
keep their initializer's matrix type. (#391)
- Deeply nested user-function calls share type-inference work within each
expression query, including when a return type remains unresolved.
- `array.sort_indices` returns integer indices, accepts typed `array<int>`
results and honors ascending/default or descending order in namespace and
method calls, including named arguments. Numeric `na` values sort last in
Expand Down
24 changes: 24 additions & 0 deletions docs/reference/support-contracts.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
## Support contracts

Persistent typed declarations parse their storage prefix separately from their
qualifier: `var const float`, `varip const int`, and the corresponding `simple`
and `series` forms retain both annotations and their existing initialization.

`request.security_lower_tf` tuple payloads, written inline or returned by a
helper, produce one array per element. Each intrabar evaluates the tuple once
before distributing values to the independently typed arrays; clearing the
request clears every array together. Tuple-bound arrays retain collection
metadata in global and callable scopes.

A global tuple declaration read by `request.security` is sampled once in the
requested evaluator, in declaration order. Scalar and history reads share that
sample, including stateful helper results. Member history commits on completed
requested bars even when a lazy payload does not read the member on that bar.
Helper parameter bindings remain active through `na`/`nz` builtin emission in
both evaluator modes. These rules supersede the older tuple refusal limitations
described in the historical helper row below.

Complete mixed tab/space nested block prefixes use four columns per tab plus
the spaces. Previously accepted incomplete mixed prefixes, skipped first-body
widths and pending logical-line continuations retain their earlier handling
pending additional TradingView observations; they are not newly refused as part
of the nested-block correction.

Builtin `array.slice` on a resolved typed array in the script, a function or
method parameter, or a callable-local array opens the view gate and lowers the
script's array storage to typed handles:
Expand Down
213 changes: 190 additions & 23 deletions pineforge_codegen/analyzer/base.py

Large diffs are not rendered by default.

81 changes: 65 additions & 16 deletions pineforge_codegen/analyzer/call_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,9 +1001,8 @@ def _handle_request_security_lower_tf(self, node: FuncCall) -> PineType:
the codegen knows to emit a ``std::vector<T>`` accumulator that
gets cleared on sub-bar 0 and pushed-to per sub-bar.

UDT / color / string element types are deliberately rejected here
with a precise diagnostic; the runtime path only knows how to
accumulate ``double`` / ``int`` / ``bool``."""
Scalar calls retain their existing numeric/bool arrays. Tuple calls
carry each primitive element's type to its own array accumulator."""
param_names = ["symbol", "timeframe", "expression",
"ignore_invalid_symbol", "currency",
"ignore_invalid_timeframe", "calc_bars_count"]
Expand Down Expand Up @@ -1033,13 +1032,6 @@ def _handle_request_security_lower_tf(self, node: FuncCall) -> PineType:
node.loc,
)

if isinstance(expr_node, TupleLiteral):
self._error(
"request.security_lower_tf does not support tuple expressions yet. "
"Issue separate request.security_lower_tf calls for each series.",
node.loc,
)

for arg in node.args:
if arg is not None and arg is not expr_node:
self._visit(arg)
Expand All @@ -1054,20 +1046,45 @@ def _handle_request_security_lower_tf(self, node: FuncCall) -> PineType:
ta_end = len(self._ta_call_sites)
security_ta_range = (ta_start, ta_end) if ta_end > ta_start else None

tuple_types = self._tuple_element_types_by_node.get(id(expr_node), ())
if (isinstance(expr_node, FuncCall)
and isinstance(expr_node.callee, Identifier)
and self._func_returns_tuple.get(expr_node.callee.name, False)):
tuple_types = self._func_tuple_element_types.get(expr_node.callee.name, ())
if PineType.UNKNOWN in tuple_types:
tuple_types = self._security_callsite_tuple_types(
expr_node.callee.name, expr_node, tuple_types,
)
elif (isinstance(expr_node, FuncCall)
and isinstance(expr_node.callee, MemberAccess)
and isinstance(expr_node.callee.object, Identifier)
and expr_node.callee.object.name == "ta"):
count = TA_TUPLE_ELEMENT_COUNTS.get(expr_node.callee.member, 0)
if count:
tuple_types = tuple_types or (PineType.FLOAT,) * count

# Cache the resolved element type on the call node so the
# ``_type_spec_from_expr`` pass can map ``request.security_lower_tf``
# to ``array<T>`` without re-visiting the expression (which would
# double-allocate TA call sites for expressions like ``ta.ema``).
cached_anns = getattr(node, "annotations", None) or {}
cached_anns["lower_tf_element_pine_type"] = expr_pine_type
if tuple_types:
cached_anns["lower_tf_tuple_element_types"] = tuple_types
self._security_tuple_shapes[id(node)] = len(tuple_types)
node.annotations = cached_anns

if expr_pine_type not in (PineType.FLOAT, PineType.INT, PineType.BOOL,
PineType.NA, PineType.UNKNOWN):
element_types = tuple_types or (expr_pine_type,)
supported = {PineType.FLOAT, PineType.INT, PineType.BOOL,
PineType.NA, PineType.UNKNOWN}
if tuple_types:
supported |= {PineType.STRING, PineType.COLOR}
unsupported = next((item for item in element_types if item not in supported), None)
if unsupported is not None:
element_label = {
PineType.STRING: "string",
PineType.COLOR: "color",
}.get(expr_pine_type, str(expr_pine_type))
}.get(unsupported, str(unsupported))
self._error(
"request.security_lower_tf element type '" + element_label
+ "' is not yet supported. Supported element types: float, int, bool. "
Expand All @@ -1085,8 +1102,9 @@ def _handle_request_security_lower_tf(self, node: FuncCall) -> PineType:
sec_id=sec_id,
timeframe=context["timeframe"] if context is not None else tf_node,
expression=expr_node,
returns_tuple=False,
tuple_size=0,
returns_tuple=bool(tuple_types),
tuple_size=len(tuple_types),
tuple_element_types=tuple(tuple_types),
gaps=None,
lookahead=None,
ta_range=security_ta_range,
Expand Down Expand Up @@ -1924,6 +1942,7 @@ def _handle_user_func_call(self, func_name: str, node: FuncCall) -> PineType:
for i in range(len(param_specs)):
if param_specs[i] is None and i < len(arg_specs):
param_specs[i] = arg_specs[i]
self._callable_bound_param_specs_by_node[id(node)] = tuple(param_specs)
self._record_deferred_param_call_edge(
node,
func_name,
Expand Down Expand Up @@ -2171,13 +2190,43 @@ def _handle_user_func_call(self, func_name: str, node: FuncCall) -> PineType:
# scalar fallbacks. Propagate the concrete specs through the exact
# definition-time call edges and infer returns in post-order before
# codegen snapshots the FuncInfo table.
self._propagate_deferred_map_callable_specs(
self._propagate_deferred_callable_specs(
func_name,
{
name: spec
for name, spec in zip(func_def.params, param_specs)
},
)
value_specs = [*param_specs, fi.return_type_spec]
exact_return = (
self._callable_value_return_spec(
func_def, dict(zip(func_def.params, param_specs)),
)
if any(
spec is not None
and (spec.kind != "primitive" or spec.name == "string")
for spec in value_specs
)
else None
)
if exact_return is not None and (
exact_return.kind != "primitive" or exact_return.name == "string"
):
self._callable_bound_return_specs_by_node[id(node)] = exact_return
self._callable_return_specs_by_profile[
(func_name, tuple(param_specs))
] = exact_return
if (fi.return_type_spec is None
or fi.return_type_spec.kind == "primitive"):
fi.return_type_spec = exact_return
self._func_return_type_specs[func_name] = exact_return
if exact_return.kind == "primitive":
return_type = self._primitive_pine_type_from_spec(exact_return)
fi.return_type = return_type
self._func_return_types[func_name] = return_type
elif exact_return.kind == "udt":
fi.udt_return_type = exact_return.name
self._func_udt_return_types[func_name] = exact_return.name

if return_type == PineType.NA:
self._na_return_callables[id(node)] = func_def
Expand Down
6 changes: 6 additions & 0 deletions pineforge_codegen/analyzer/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ class AnalyzerContext:
# helper called with both ``bar_index`` and ``close``).
func_callsite_param_types: dict = field(default_factory=dict)
func_callsite_return_types: dict = field(default_factory=dict)
# Exact argument/return value types retain collection element types, object
# identities and strings independently of the coarse primitive profiles.
func_callsite_param_specs: dict = field(default_factory=dict)
func_callsite_return_specs: dict = field(default_factory=dict)
func_value_call_edges: dict = field(default_factory=dict)
func_value_return_specs: dict = field(default_factory=dict)
# Declaration-time parameter specs, before any call-site inference fills
# untyped slots on the legacy FuncInfo record. Codegen uses this to apply
# variant overrides only to genuinely untyped parameters.
Expand Down
Loading
Loading