Skip to content

feat[next]: Direct subscripting of variable-length tuples - #2838

Draft
tehrengruber wants to merge 4 commits into
sf_n_tracer_supportfrom
vararg_subscript
Draft

feat[next]: Direct subscripting of variable-length tuples#2838
tehrengruber wants to merge 4 commits into
sf_n_tracer_supportfrom
vararg_subscript

Conversation

@tehrengruber

@tehrengruber tehrengruber commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Allow indexing variable-length tuple parameters directly, e.g.

@gtx.field_operator
def testee(tracers: tuple[IFloatField, ...], factor: float) -> tuple[IFloatField, IFloatField]:
    return tracers[0] * factor, tracers[1] * factor

The subscript type deduction accepts any literal index on a VarArgType and yields the element type; lowering and tests (test_tuple_vararg) included.

Extracted from #2833 pending a decision on whether we want this at all.

Stacked on-top of: #2833

Concern (why this is likely to be skipped): subscripting a variable-length tuple is arguably an anti-pattern — the field operator cannot be fully verified/type checked at definition time, since the tuple length is only known at call/compile time. An out-of-range index therefore only surfaces late, in unroll_map_tuple, instead of as a frontend diagnostic at the subscript.


Disclaimer: This PR and its description were written largely with the help of AI. Code was not reviewed yet.

@tehrengruber
tehrengruber changed the base branch from sf_n_tracer_support to main August 27, 2026 16:24
@tehrengruber
tehrengruber changed the base branch from main to sf_n_tracer_support August 27, 2026 16:24
The GTIR 'concat_where' type synthesizer derives the result dims via
'type_info.promote(tb, fb)', which asserted that the promoted dtypes are
'ScalarType'. A local field carries a 'ListType' dtype at the GTIR
level, so any 'concat_where' with a local-field branch failed with a
bare 'AssertionError' during type inference -- and it did so even though
both branches have the identical dtype, since the assertion is on the
dtype's kind, not on the operands differing.

Let 'promote' handle 'ListType' the same way it handles 'ScalarType':
both promote only between equal types, so the two cases collapse into a
single check. The docstring records that a 'ListType' only ever reaches
'promote' from the ITIR level, because the frontend represents the same
concept as a field with a local dimension in 'dims' and a scalar dtype.

The combination was previously untested ('test_concat_where.py' had no
local-dimension coverage), so the latent assert never fired in CI.
@tehrengruber
tehrengruber changed the base branch from sf_n_tracer_support to main August 27, 2026 20:02
@tehrengruber
tehrengruber changed the base branch from main to sf_n_tracer_support August 27, 2026 20:02
Allow indexing 'tuple[Field, ...]' parameters directly, e.g.
'tracers[0] * factor': the subscript type deduction accepts any literal
index on a 'ts.VarArgType' and yields the element type. Extracted from
#2833 pending a decision; likely to be skipped, since the field operator
cannot be fully type checked at definition time (the tuple length is only
known at call/compile time, so an out-of-range index only surfaces late,
in 'unroll_map_tuple').
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant