Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR adds end-to-end support for simple (unit) enums, enabling enum variant access (Enum::Variant), enum values flowing through params/returns/locals, enum comparisons (==/!=), and treating enums as scalar i32 tags in WASM codegen. It also adds type-checker tests and WASM golden fixtures to cover the new behavior (closes #179).
Changes:
- Type checker: expose enum metadata (
EnumInfo) viaTypedContext::lookup_enum, store variants in declaration order, and add negative/positive enum operator tests. - WASM codegen: lower
TypeMemberAccessfor enum variants, treat enums as i32 in memory sizing/alignment and load/store selection, and support enums in uzumaki i32 emission. - Tests/fixtures: add multiple enum-focused
.infsources and expected.wasm/.watoutputs, plus new golden + execution tests.
Reviewed changes
Copilot reviewed 24 out of 32 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_data/codegen/wasm/base/if_else_compound_overlap/if_else_compound_overlap.wat | New expected WAT output for compound overlap scenario. |
| tests/test_data/codegen/wasm/base/if_else_compound_overlap/if_else_compound_overlap.wasm | New expected WASM binary for compound overlap scenario. |
| tests/test_data/codegen/wasm/base/enum_variant/enum_variant.wat | New expected WAT for returning enum variants (tags). |
| tests/test_data/codegen/wasm/base/enum_variant/enum_variant.wasm | New expected WASM for returning enum variants (tags). |
| tests/test_data/codegen/wasm/base/enum_variant/enum_variant.inf | New source fixture demonstrating enum variant construction/returns. |
| tests/test_data/codegen/wasm/base/enum_params/enum_params.wat | New expected WAT for passing enums as params and branching on tags. |
| tests/test_data/codegen/wasm/base/enum_params/enum_params.wasm | New expected WASM for passing enums as params and branching on tags. |
| tests/test_data/codegen/wasm/base/enum_params/enum_params.inf | New source fixture demonstrating enum params/returns. |
| tests/test_data/codegen/wasm/base/enum_multi/enum_multi.wat | New expected WAT for multiple enums in one module. |
| tests/test_data/codegen/wasm/base/enum_multi/enum_multi.wasm | New expected WASM for multiple enums in one module. |
| tests/test_data/codegen/wasm/base/enum_multi/enum_multi.inf | New source fixture demonstrating multiple enum definitions. |
| tests/test_data/codegen/wasm/base/enum_in_struct/enum_in_struct.wat | New expected WAT for enums inside struct fields. |
| tests/test_data/codegen/wasm/base/enum_in_struct/enum_in_struct.wasm | New expected WASM for enums inside struct fields. |
| tests/test_data/codegen/wasm/base/enum_in_struct/enum_in_struct.inf | New source fixture demonstrating struct fields of enum type. |
| tests/test_data/codegen/wasm/base/enum_compare/enum_compare.wat | New expected WAT for enum equality/inequality comparisons. |
| tests/test_data/codegen/wasm/base/enum_compare/enum_compare.wasm | New expected WASM for enum equality/inequality comparisons. |
| tests/test_data/codegen/wasm/base/enum_compare/enum_compare.inf | New source fixture demonstrating enum comparisons. |
| tests/test_data/codegen/wasm/base/enum_assign/enum_assign.wat | New expected WAT for enum assignment/reassignment. |
| tests/test_data/codegen/wasm/base/enum_assign/enum_assign.wasm | New expected WASM for enum assignment/reassignment. |
| tests/test_data/codegen/wasm/base/enum_assign/enum_assign.inf | New source fixture demonstrating enum reassignment and param assignment. |
| tests/test_data/codegen/wasm/base/enum_array/enum_array.wat | New expected WAT for arrays of enum tags in linear memory. |
| tests/test_data/codegen/wasm/base/enum_array/enum_array.wasm | New expected WASM for arrays of enum tags in linear memory. |
| tests/test_data/codegen/wasm/base/enum_array/enum_array.inf | New source fixture demonstrating [Color; N] usage. |
| tests/src/type_checker/features.rs | Adds enum operator acceptance/rejection tests (arithmetic/order/negation/bool-context). |
| tests/src/codegen/wasm/base.rs | Adds enum golden tests, execution tests, and regeneration helpers for new fixtures. |
| core/wasm-codegen/src/memory.rs | Treat enums as 4-byte scalars for sizing/alignment and load/store instruction selection; handle enums in struct layout. |
| core/wasm-codegen/src/compiler.rs | Lowers enum variant access (Enum::Variant) to i32 constants; treats enums as i32 for locals and uzumaki emission. |
| core/type-checker/src/typed_context.rs | Adds lookup_enum and a test-utils helper to register enums. |
| core/type-checker/src/symbol_table.rs | Changes EnumInfo to store variants in declaration order and adds variant_index. |
| core/type-checker/src/lib.rs | Re-exports EnumInfo publicly. |
| core/ast/src/builder.rs | Allows type_member_access_expression where literals are expected (e.g., const enum variants). |
| core/analysis/src/walker.rs | Updates compound-field detection to treat Custom enums as scalar in some cases. |
Comments suppressed due to low confidence (1)
core/analysis/src/walker.rs:181
has_compound_fieldsstill treats arrays of enums as “compound” when the enum appears asTypeInfoKind::Custominside the array element type (becauseis_compound_typereturnstruefor allCustom(_)). This can cause analysis rules A026/A027 to incorrectly reject structs that only contain scalar enum arrays (enums are i32 tags). Consider making the compound-type check enum-aware for arrays as well (e.g., threadctxintois_compound_type, or explicitly treatCustom(name)as scalar whenlookup_enum(name).is_some()while recursing throughArray).
s.fields.iter().any(|f| match &f.type_info.kind {
TypeInfoKind::Struct(_) => true,
TypeInfoKind::Custom(n) => ctx.lookup_enum(n).is_none(),
TypeInfoKind::Array(_, _) => {
is_compound_type(&f.type_info.kind)
|| array_nesting_depth(&f.type_info.kind) > 1
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… improving tag handling
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 24 out of 32 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Closes #179