vx-lang / vx-lang/Vx

flat codegen: data-carrying (tagged-union) enums + value-producing match

Open
#233 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

codegen enhancement
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 variantsOption<i32>::Some(42), any enum E { V(T) }. The AST codegen models these as an !llvm.struct<(i32, payload)> (tag + payload), built with llvm.mlir.undef + insertvalue; a match binds the payload via extractvalue (src/codegen/lower/expr.rs::EnumVariantExpr, lower/mod.rs::generate_match_chain). The flat path treats every enum in enum_variants (payload-free only) as a bare i32 and declines the rest.
  • Value-producing match — a match in tail/expression position whose arms yield a value (e.g. Option::unwrap's Some => v / None => assert). The flat lower_match is statement-only.
  • Payload bindings / non-enum patternsPattern::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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.