Skip to content

feat: add names arena and thread 'names lifetime through IR#42

Merged
iljakuklic merged 6 commits intodevelfrom
name-arena
Apr 6, 2026
Merged

feat: add names arena and thread 'names lifetime through IR#42
iljakuklic merged 6 commits intodevelfrom
name-arena

Conversation

@iljakuklic
Copy link
Copy Markdown
Owner

Introduces a dedicated names_arena: Bump that owns all identifier strings for the lifetime of the pipeline. Only lexer::Lexer calls alloc_str; every downstream layer (parser, checker, staging) reuses the existing &Name references without re-allocating.

To express this, AST and core IR types gain a separate 'n lifetime parameter for name references, distinct from the structural allocation lifetime 'a. The elaboration bound changes from 'src: 'core to 'n: 'core, which lets ast_arena be dropped before core_arena in the pipeline, as intended.

Introduces a dedicated `names_arena: Bump` that owns all identifier
strings for the lifetime of the pipeline.  Only `lexer::Lexer` calls
`alloc_str`; every downstream layer (parser, checker, staging) reuses
the existing `&Name` references without re-allocating.

To express this, AST and core IR types gain a separate `'n` lifetime
parameter for name references, distinct from the structural allocation
lifetime `'a`.  The elaboration bound changes from `'src: 'core` to
`'n: 'core`, which lets `ast_arena` be dropped before `core_arena`
in the pipeline, as intended.

Closes #28

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@iljakuklic iljakuklic self-assigned this Apr 6, 2026
iljakuklic and others added 4 commits April 6, 2026 08:23
- `'n` → `'names` everywhere (names arena)
- `'a` → `'ast` in parser and checker function signatures (AST arena)
- `'a` → `'eval` for ObjVal/ObjArm in staging (eval arena)
- `'a` → `'names` for Token and Lexer (names arena)
- `'c` → `'core` in elaborate_sig (core arena)
- `'t` → `'a` in core::Arm and core::Function (normalise with other structs)

The `'a` parameter in core IR type definitions (Term, Pi, Lam, etc.)
remains `'a` as it is polymorphic over 'core/'eval/'out.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…arsing

Lexer<'src, 'names> separates the source text lifetime from the names
arena lifetime. The iterator now yields Token<'names>, making it clear
that produced tokens outlive the source string.

In the CLI pipeline, source is dropped immediately after parse_program
returns, since all identifier strings are interned in names_arena.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Copy link
Copy Markdown
Owner Author

@iljakuklic iljakuklic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two minor comments:

Copy link
Copy Markdown
Owner Author

@iljakuklic iljakuklic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in aff27f7: inlined param_name in both the Pi and Lam elaboration loops.

@iljakuklic iljakuklic merged commit 41e3cb5 into devel Apr 6, 2026
3 checks passed
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.

Allocate Names once in a long-lived arena from the lexer

1 participant