Skip to content

feat: tuples and unit values - #1

Merged
andogq merged 11 commits into
mainfrom
feat/tuples-and-unit
Jan 4, 2026
Merged

feat: tuples and unit values#1
andogq merged 11 commits into
mainfrom
feat/tuples-and-unit

Conversation

@andogq

@andogq andogq commented Jan 4, 2026

Copy link
Copy Markdown
Owner

Types

  • added Type::Tuple

  • added size_of to calculate size of a type

  • added offset_of to calculate offset of a field within a type

Lexer

  • added tok::Dot

CST

  • added Tuple<T>, which supports parsing tuple-like structures from tokens

    • surrounded by ()
    • contains zero or more T, separated by commas
    • if only one T, must be terminated with a trailing comma
  • added Expression::Tuple variant which contains Tuple<Expression>, to allow for tuple expressions ((1, true, 3))

  • added Expression::Field variant which contains an Expression, and a usize as the field key

  • added CstType to represent a wider range of types

    • CstType::Named(tok::Ident): named types (i8)
    • CstType::Tuple(Tuple<CstType>): tuple types ((i8, bool, i8))

AST

  • added AstType, which is similar to CstType

    • AstType::Named(StringId): named types
    • AstType::Tuple(Vec<AstTypeId>): tuple types
  • added Expression::Field

HIR

  • added Expression::Aggregate, which represents a collection of expressions

  • added Expression::Field

THIR

  • added Constraint::Aggregate and Solution::Tuple to the solver

  • added Constraint::Field and associated logic to the solver

  • added rules to solver to handle (Solution::Tuple, Solution::Type) and (Solution::Tuple, Solution::Tuple)

  • updated IncompatibleKind convention to use _____Solution(Solution) (eg ReferenceSolution) to indicate that a given solution did not fulfil some expectation (eg solution was expected to be a reference)

MIR

  • added RValue::Aggregate, lowered from thir::Expression::Aggregate

  • added Projection::Field

Codegen

  • change resolve_rvalue to store_rvalue, and provide a pointer to store the value into

  • lower RValue::Aggregate

  • lower Projection::Field

- created `cst::Tuple` and implemented parsing

- altered expression prefix parsing to look ahead when `(` is encountered

  - if `)` is encountered, parse as `cst::Tuple` (zero-item tuple)

  - try parse `cst::Expression` (both `cst::Tuple` and `cst::Parenthesis`)
    expect this next

  - if `)` is encountered, parse as `cst::Parenthesis` (parenthesised
    expression)

  - if `,` is encountered, parse as `cst::Tuple` (tuple expression with
    at least one field and a trailing comma)

- allow `cst::Parenthesis` to be parsed from pre-existing parts
@codecov-commenter

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

andogq added 10 commits January 4, 2026 15:22
- used in function signatures

- may represent a named type (`i8`) or a tuple type (`(i8, bool)`)

- `ast_gen` updated to enforce `CstType::Named` variant when lowering
- allows for different kinds of types to be used

  - `Ast::Named`: named types by `StringId` (`i8`)

  - `Ast::Tuple`: tuple of types (`(i8, bool)`)
- support lowering tuple expressions from `cst`
- represents a collection of expressions

- currently only used for `ast::Tuple`, but can be used in the future
  for array initialisation
- create `Type::Tuple`

- implement tuple solving in type solver

  - introduce `Aggregate` constraint (corresponds with a collection of
    expressions, such as a tuple instantiation)

  - introduce `Tuple` solution, which is similar to `Type::Tuple` except
    the values are `TypeVarId` (can be partially solved)

  - new rules:

    - `Solution::Tuple` and `Solution::Type`: values are zipped and
      merged, then `Solution::Type` is emitted

    - `Solution::Tuple` and `Solution::Tuple`: values are merged, and if
      all have solutions then `Solution::Type` is emitted, otherwise
      `Solution::Tuple` is emitted with merged values
- `Types`

  - add `size_of` to calculate the size in bytes of a type

  - add `offset_of` to calculate offset of a field in a type

- add `ty` field to `mir::Aggregate`

- change `resolve_rvalue` to `store_rvalue`, providing a pointer to
  write the value into

- implement codegen for `RValue::Aggregate`
- remove `cst::Unit`

- in `codegen`, when determining return type of function, use `void` if
  `()` would've been used
- add `tok::Dot` with highest precedence

- create `Field` nodes through CST/AST/HIR

- add `Constraint::Field` constraint, and update solver to process it

- add `Projection::Field` to `MIR`
@andogq
andogq marked this pull request as ready for review January 4, 2026 12:17
@andogq andogq changed the title Tuples and unit values feat: tuples and unit values Jan 4, 2026
@andogq
andogq merged commit b4b2ba0 into main Jan 4, 2026
3 checks passed
@andogq
andogq deleted the feat/tuples-and-unit branch January 4, 2026 12:23
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.

2 participants