Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ supported as exact pairs; on the 0.x line they are independent. See the

## Unreleased (next release)

- Reference-typed UDT fields keep their type when initialized or reassigned
with `na`, including array defaults. Drawing handles cross user-function
and tuple boundaries by value, and `label(na)` produces a missing label
handle. Polyline locals, arrays, fields and delete methods retain opaque
handles and argument evaluation while rendering remains a visual no-op.

- 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.
The paired engine reports a typed timezone error identifying the failed bar.
Expand Down
6 changes: 6 additions & 0 deletions docs/reference/support-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ lowering. Structural mutation, collection reassignment/escape, history and
pair-binder iteration retain PF-E5086 pending TV evidence/provenance support;
declaration tails yielding collections as callable/selection values are refused.
`polyline.all` retains PF-E5085 until the engine has a Polyline handle/arena.
Polyline locals, array elements and UDT fields retain opaque typed handles;
default construction and bare `na` use a missing handle, and copies retain
its identity. `polyline.new` and functional or method-form `delete` keep the
existing visual-only rendering contract, while evaluating their arguments
once in parameter order. Opaque ID allocation joins script reset and rollback
state. This does not supply the live arena required by `polyline.all`.
`var`/`varip` aliases retain PF-E5086 until a TradingView capture establishes
their lifetime semantics. Whether a later creation in the same bar is visible
through the alias is not yet measured against TradingView.
Expand Down
9 changes: 8 additions & 1 deletion pineforge_codegen/analyzer/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from ..errors import Phase
from ..limits import iter_ast_nodes
from ..matrix_overloads import matrix_sum_has_rhs
from ..reference_casts import na_reference_cast_kind
from ..symbols import (
PineType,
TypeSpec,
Expand All @@ -59,7 +60,9 @@
# Drawing-objects-as-data type names (spec §4.1). Defined locally — the
# analyzer must not import from ``codegen`` (codegen imports analyzer, so the
# reverse would be a cycle). Mirrors codegen.tables.DRAWING_TYPE_TO_CPP keys.
_DRAWING_TYPE_NAMES = frozenset({"line", "box", "label", "linefill", "chart.point"})
_DRAWING_TYPE_NAMES = frozenset({
"line", "box", "label", "linefill", "chart.point", "polyline",
})
_DRAWING_NS = frozenset({"line", "box", "label", "linefill"})
_DIRECT_ARRAY_VALUE_PRODUCERS = frozenset({
"from",
Expand Down Expand Up @@ -588,6 +591,10 @@ def direct_user_udt_ctor_name(node: ASTNode) -> str | None:
return typed_receiver_spec
# Drawing-objects-as-data return typing: *.new / *.copy -> handle of
# the self-type; linefill.get_line* -> line; chart.point.* -> point.
if cast_kind := na_reference_cast_kind(value):
return TypeSpec.udt(cast_kind)
if ns == "polyline" and func == "new":
return TypeSpec.udt("polyline")
if ns in _DRAWING_NS:
if func in ("new", "copy"):
return TypeSpec.udt(ns)
Expand Down
43 changes: 22 additions & 21 deletions pineforge_codegen/codegen/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from ..errors import CompileError, Diagnostic, Level, Phase, SourceLocation
from ..limits import TimeBudget, iter_ast_nodes, syntax_children
from ..matrix_overloads import matrix_sum_has_rhs
from ..reference_casts import na_reference_cast_kind
from . import graph_journal
from .capacities import CapacityPolicy, validate_capacity_options
from ..session_reads import emitted_session_reads
Expand Down Expand Up @@ -1110,19 +1111,18 @@ def func_var_storage(owner: str, raw_name: str) -> str:
# ``_active_var_remap`` while emitting the owning block's statements.
self._block_var_renames: dict[int, dict[str, str]] = getattr(ctx, "block_var_renames", {}) or {}
self._udt_field_type_specs: dict[str, dict[str, TypeSpec]] = getattr(ctx, "udt_field_type_specs", {}) or {}
# Map UDT struct name -> set of field names that were dropped from the
# emitted C++ struct because they had drawing-only types (label, line,
# box, linefill, polyline, table, chart.point). Populated eagerly
# Map UDT struct name -> visual-only table fields omitted from the
# emitted record. Populated eagerly
# here from ``self._udt_defs`` so downstream visitors (visit_expr /
# visit_stmt) can consult it before ``generate()`` runs. The struct
# emission loop later asserts/syncs against this same map. Used to
# rewrite or strip downstream references to those fields so the
# generated C++ never references a member that doesn't exist on the
# emitted struct. See: pineforge-codegen issue #10.
# Drawing-objects-as-data: line/box/label/linefill/chart.point are now
# REAL data (un-dropped from UDT structs). Only table/polyline stay
# dropped (no C++ representation). See drawing-objects-as-data.md §4.2.
_DRAWING_TYPES_INIT = {"table", "polyline"}
# REAL data (un-dropped from UDT structs). Polyline retains an opaque
# handle while its geometry remains visual-only. Only table is dropped.
_DRAWING_TYPES_INIT = {"table"}
self._udt_omitted_fields: dict[str, set[str]] = {}
for _type_name, _fields in self._udt_defs.items():
_omitted = set()
Expand Down Expand Up @@ -1198,14 +1198,14 @@ def func_var_storage(owner: str, raw_name: str) -> str:
self._map_vars.add(_name)
elif _spec.kind == "udt" and _spec.name:
self._udt_var_types.setdefault(_name, _spec.name)
# Table / polyline variables and params have NO C++ representation
# Table variables and params have NO C++ representation
# (SKIP_VAR_TYPES). A *method* call on such a receiver
# (``panel.cell(...)``, ``dash.merge_cells(...)``) is a visual no-op
# that must be dropped — but unlike the namespace form
# (``table.cell(...)``) the receiver is a bare var/param the
# namespace-based skip cannot see. Collect those names so
# ``_is_skip_expr`` can drop their method calls.
_SKIP_DECL_TYPES = set(SKIP_VAR_TYPES) | {"polyline"}
_SKIP_DECL_TYPES = set(SKIP_VAR_TYPES)
self._visual_drop_vars: set[str] = set()
for _node in self._walk_ast(self.ctx.ast):
if isinstance(_node, VarDecl):
Expand Down Expand Up @@ -1359,7 +1359,10 @@ def func_var_storage(owner: str, raw_name: str) -> str:
# Drawing-objects-as-data: gate all new emission (drawing.hpp include +
# the per-type arenas) on this flag so non-drawing strategies stay
# byte-identical. Caps come from the strategy() header max_*_count.
self._uses_drawing = self._detect_drawing_usage()
self._uses_polyline = self._detect_drawing_usage({"polyline"})
self._uses_drawing = self._detect_drawing_usage(
set(DRAWING_TYPE_TO_CPP) - {"polyline"},
)
self._drawing_caps = self._compute_drawing_caps() if self._uses_drawing else {}

# Pine history directives retain their existing global-maximum rule.
Expand Down Expand Up @@ -1451,14 +1454,7 @@ def _is_default_drawing_initializer(self, node) -> bool:
"""Whether a drawing RHS is the constant missing handle."""
return (
self._is_na_expr(node)
or (
isinstance(node, FuncCall)
and isinstance(node.callee, Identifier)
and node.callee.name in ("line", "box")
and len(node.args) == 1
and not node.kwargs
and self._is_na_expr(node.args[0])
)
or na_reference_cast_kind(node) is not None
)

def _is_runtime_scalar_var_initializer(
Expand Down Expand Up @@ -6155,6 +6151,8 @@ def _generate_cpp(self) -> str:
lines.append(" DrawingArena<BoxRec> _pf_boxes_{_PF_DRAWING_UNBOUNDED};")
lines.append(" DrawingArena<LabelRec> _pf_labels_{_PF_DRAWING_UNBOUNDED};")
lines.append(" DrawingArena<LinefillRec> _pf_linefills_{_PF_DRAWING_UNBOUNDED};")
if self._uses_polyline:
lines.append(" uint64_t _pf_polyline_next_id_ = 0;")

# 8e. The copies an array or a matrix variable's executions left
# (pineforge_codegen/collection_history.py).
Expand Down Expand Up @@ -6564,13 +6562,17 @@ def _is_skip_expr(self, node) -> bool:
if self._is_chart_point_callee(node.callee):
return False
func_name, namespace = self._resolve_callee(node.callee)
if namespace == "polyline" and func_name in {"new", "delete"}:
# The geometry is visual-only; its handle and argument
# evaluations must still flow through declarations and calls.
return False
if namespace is None and func_name in SKIP_FUNC_NAMES:
return True
if namespace in SKIP_NAMESPACES:
return True
if namespace in SKIP_VAR_TYPES:
return True
# Method call on a table/polyline-typed receiver var/param
# Method call on a table-typed receiver var/param
# (``panel.cell(...)``). These types have no C++ representation, so
# the call is a visual no-op — drop it (mirrors the namespace form).
if namespace in self._visual_drop_vars:
Expand All @@ -6586,9 +6588,8 @@ def _is_skip_expr(self, node) -> bool:

def _is_omitted_udt_field(self, node) -> bool:
"""True when ``node`` is a ``MemberAccess`` on a UDT variable and the
member name was dropped from the emitted struct because it had a
drawing-only type (label, line, box, linefill, polyline, table,
chart.point). Callers use this to rewrite reads and strip writes so
member name was dropped from the emitted struct because it had the
visual-only table type. Callers rewrite reads and strip writes so
the generated C++ never references a non-existent struct member.
See: pineforge-codegen issue #10.
"""
Expand Down
Loading