Skip to content

feat: add parametric tuple types#341

Merged
scarmuega merged 1 commit into
mainfrom
feat/tuples
Jun 11, 2026
Merged

feat: add parametric tuple types#341
scarmuega merged 1 commit into
mainfrom
feat/tuples

Conversation

@scarmuega

Copy link
Copy Markdown
Contributor

Summary

Adds parametric tuple types to the Tx3 language, mirroring List<T>/Map<K,V>.

  • Type: Tuple<T1, ..., Tn> (arity ≥ 2) — the type carries its element types and erases to a bare TIR Type::Tuple.
  • Literal: (e1, e2, ...) — two or more comma-separated expressions in parentheses. (e) is grouping and () is unit, so tuples start at two elements.
  • Access: 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/.1

A .<number> postfix is lexically indistinguishable from the asset literal separator policy.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

  • New tuple_end_to_end facade test (parse → analyze → lower → Expression::Tuple).
  • New examples/tuples.tx3 registered in the parse + lower snapshot harness.
  • Tuple field/literal/access threaded through examples/lang_tour.tx3 (snapshots regenerated).
  • Full tx3-lang suite: 184 + 4 passing.

Release ordering

Depends on tx3-lang/tir#3 (Type::Tuple + N-ary Expression::Tuple). Merge after that releases, and bump the tx3-tir dependency to the released version. Downstream: tx3-lsp, tx3-mcp (need this tx3-lang release); tx3-lift (needs the tir release).

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant