Skip to content

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

Draft
tehrengruber wants to merge 1 commit into
sf_n_tracer_supportfrom
vararg_subscript
Draft

feat[next]: Direct subscripting of variable-length tuples#2838
tehrengruber wants to merge 1 commit 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
@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