Repository navigation
fix[next]: named collections as program arguments - #3042
Conversation
FLATTEN_AS_FIELDOP_ARGS named the let variable binding a flattened tuple argument
__ct_flat_remapped_{i}, with a counter restarting at 0 on every application. Flattening a
nested tuple argument inside a let that survived the previous flattening rebound the same
name and captured the outer references.
A program body like domain={E: (d.edges.lb, d.edges.ub)} failed on every compiled backend
because ProgramLowering had no visit_Attribute.
|
🤖 Written by an agent on behalf of @havogt |
A subscript on a tuple program argument, e.g. d[1] as a field operator argument or d[0][1] as a domain bound, was typed as the whole tuple and nested subscripts were rejected, as program_ast.Subscript only modelled slicing an output field.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
⚙️ Agent run details
|
Reject non-literal, out-of-range, negative and bool tuple indices, integer indexing of dataclass collections and element access on closure variables with a DSLError, and look up named-collection attributes by key, so that fields named like attributes of the type spec (e.g. 'keys') resolve.
|
Note Advisory review by opencode 2.2.7 ( SummaryThis PR makes named collections / tuples usable as program arguments: Findings
Nits
Questions
|
…programs Subscripting a scalar or slicing a field passed as a field operator input got through type deduction and failed on an assert in lowering. Also resolve the NamedTuple/dataclass distinction for classes defined in a function, which pkgutil can not resolve by name.
Attribute access on an enum or FrozenNamespace closure variable in a program body is folded to a constant, as in field operators. It previously worked only in embedded execution.
…llow-up Keep only the index checks for tuple subscripts and the rejection of subscripted scalars here. Key-based attribute lookup, folding of enum attributes, rejecting dataclass indexing, closure-variable element access and sliced inputs move to a separate PR.
…wn PR This reverts commit 3969b84. The fix now lives on tehrengruber/collapse-tuple-remapped-arg-capture, which names the remapped arguments with unique_symbol instead of uids.
|
I pushed some changes on top of this PR to a separate branch (
The CollapseTuple naming fix is now its own PR. This still needs work:
|
…ices Named collections are accessed by field name, as in field operators. Negative tuple indices count from the end and are lowered to the non-negative position.
Field operators accepted t[-1] but passed the negative index to tuple_get, which the compiled backends do not handle for tuples that reach them.
…ograms Field operators accepted bool tuple indices and raised a bare IndexError for out-of-range ones. Both frontends now use one check: literal integers in [-n, n), bool rejected, with a DSLError otherwise.
…ction and lowering
Fixes for named collections and tuples passed as program arguments:
domain={E: (d.edges.lb, d.edges.ub)}) was not lowered:ProgramLoweringgets avisit_Attribute, lowering totuple_getas infoast_to_gtir.t[1],t[0][-1],t[1].lb) were typed as the whole tuple, and nested ones were rejected. They are now typed as the element and lowered totuple_get. Named collections can not be subscripted, as in field operators: their fields are accessed by name.[-n, n), sobooland out-of-range indices are aDSLErrorin both (field operators acceptedt[True]and raised a bareIndexErrorbefore).tuple_getunchanged in field operators, which the backends do not support. Both lowerings now pass the non-negative position.UnpackedAssignPasstyped the temporary of a tuple unpacking as the element instead of the tuple.