feat: add parametric tuple types#341
Merged
Merged
Conversation
Adds `Tuple<T1, ..., Tn>` (arity >= 2) as a parametric type, mirroring
List/Map: the type carries its element types and erases to a bare TIR
`Type::Tuple`. Covers the full pipeline — grammar, AST, parsing, analysis,
lowering — plus spec sections (§4.3/§4.4/§5.2/§5.9) and examples.
Surface syntax:
- Type: `Tuple<Int, Bytes>`
- Literal: `(e1, e2, ...)` (>= 2 elements; `(e)` is grouping, `()` is unit)
- Access: `t[i]` with an integer-literal index, resolving to that
position's element type
Element access uses bracket indexing rather than Rust-style `.0`/`.1`: a
`.<number>` postfix is lexically ambiguous with the `asset` literal
separator `policy.asset_name`, where the name can be a bare number or hex.
Adds an end-to-end facade test and a `tuples` example (parse + lower
snapshots), and threads a tuple field/literal/access through the language
tour.
Requires tx3-tir with `Type::Tuple` and the N-ary `Expression::Tuple`
(tx3-lang/tir#3). Bump the tx3-tir dependency once that releases.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds parametric tuple types to the Tx3 language, mirroring
List<T>/Map<K,V>.Tuple<T1, ..., Tn>(arity ≥ 2) — the type carries its element types and erases to a bare TIRType::Tuple.(e1, e2, ...)— two or more comma-separated expressions in parentheses.(e)is grouping and()is unit, so tuples start at two elements.t[i]— bracket indexing with an integer literal; the result is that position's element type. The index must be a literal (heterogeneous positions can't be typed under a runtime index); out-of-range is a compile error.Touches the full frontend pipeline (
tx3.pest,ast.rs,parsing.rs,analyzing.rs,lowering.rs), the spec (§4.3/§4.4/§5.2/§5.9), and adds tests + examples.Why bracket indexing, not
.0/.1A
.<number>postfix is lexically indistinguishable from theassetliteral separatorpolicy.asset_name, where the asset name can be a bare number or hex (asset X = 0xPOLICY.333;). No PEG trick disambiguates<expr>.<digits>, so tuples reuse the existing[i]index form.Tests & examples
tuple_end_to_endfacade test (parse → analyze → lower →Expression::Tuple).examples/tuples.tx3registered in the parse + lower snapshot harness.examples/lang_tour.tx3(snapshots regenerated).tx3-langsuite: 184 + 4 passing.Release ordering
Depends on tx3-lang/tir#3 (
Type::Tuple+ N-aryExpression::Tuple). Merge after that releases, and bump thetx3-tirdependency to the released version. Downstream:tx3-lsp,tx3-mcp(need thistx3-langrelease);tx3-lift(needs the tir release).🤖 Generated with Claude Code