flat codegen: data-carrying (tagged-union) enums + value-producing match
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 14
- Forks
- 2
- Avg merge
- 12h 42m
- Merged PRs (30d)
- 61
Description
Follow-up to hiraditya/Vx.1#227 (which landed payload-free C-like enums: construction + statement-form match now lower through the flat path).
What still declines.
- Data-carrying variants —
Option<i32>::Some(42), anyenum E { V(T) }. The AST codegen models these as an!llvm.struct<(i32, payload)>(tag + payload), built withllvm.mlir.undef+insertvalue; a match binds the payload viaextractvalue(src/codegen/lower/expr.rs::EnumVariantExpr,lower/mod.rs::generate_match_chain). The flat path treats every enum inenum_variants(payload-free only) as a barei32and declines the rest. - Value-producing
match— amatchin tail/expression position whose arms yield a value (e.g.Option::unwrap'sSome => v/None => assert). The flatlower_matchis statement-only. - Payload bindings / non-enum patterns —
Pattern::EnumVariant(.., Some(payloads)),Pattern::Literal,Pattern::Identifier.
Concrete corpus case: tests/backend/pass/option_unwrap.vx (Option<i32>::Some + .unwrap() + Vec<Option<i32>>), which also needs generic Option + Vec/stdlib methods.
Approach. Model a data-carrying enum as an aggregate (the flat path already has struct alloca/GEP/field load-store from hiraditya/Vx.1#199/#215): construct via field stores (tag at offset 0, payload after), and extend lower_match to (a) load the tag from the aggregate for the compare and (b) bind a payload pattern via a field load into the arm scope. Add a value-producing match form (each arm stores its result into a slot, like the value-if in hiraditya/Vx.1#201). Overlaps generic-enum monomorphization (Option<T>).
Acceptance. An Option<i32> construct + match/unwrap program lowers through the flat path with JIT parity vs --legacy-codegen; full-corpus parity holds.
Part of the flat-codegen convergence (#200/#201).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/codegen/lower/expr.rs::EnumVariantExpr and lower/mod.rs::generate_match_chain/lower_match, then inspect the existing flat-path struct alloca/GEP and field load-store support. Use tests/backend/pass/option_unwrap.vx as the concrete case and compare against --legacy-codegen. Done means the Option construction, match/unwrap, and full corpus achieve flat-path JIT parity.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100