Skip to content

+Enums#187

Merged
0xGeorgii merged 3 commits intomainfrom
179-enum-support
Apr 1, 2026
Merged

+Enums#187
0xGeorgii merged 3 commits intomainfrom
179-enum-support

Conversation

@0xGeorgii
Copy link
Copy Markdown
Contributor

Closes #179

@0xGeorgii 0xGeorgii self-assigned this Apr 1, 2026
@0xGeorgii 0xGeorgii added inf2wasm Inference to WASM converting codegen Bytecode emitting labels Apr 1, 2026
@0xGeorgii 0xGeorgii requested a review from Copilot April 1, 2026 04:37
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 86.04651% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
core/type-checker/src/typed_context.rs 27.27% 8 Missing ⚠️
core/wasm-codegen/src/compiler.rs 91.17% 3 Missing ⚠️
core/analysis/src/walker.rs 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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) via TypedContext::lookup_enum, store variants in declaration order, and add negative/positive enum operator tests.
  • WASM codegen: lower TypeMemberAccess for 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 .inf sources and expected .wasm/.wat outputs, 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_fields still treats arrays of enums as “compound” when the enum appears as TypeInfoKind::Custom inside the array element type (because is_compound_type returns true for all Custom(_)). 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., thread ctx into is_compound_type, or explicitly treat Custom(name) as scalar when lookup_enum(name).is_some() while recursing through Array).
                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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@0xGeorgii 0xGeorgii merged commit 838e34a into main Apr 1, 2026
10 checks passed
@0xGeorgii 0xGeorgii deleted the 179-enum-support branch April 1, 2026 06:31
@0xGeorgii 0xGeorgii restored the 179-enum-support branch April 1, 2026 06:34
@0xGeorgii 0xGeorgii deleted the 179-enum-support branch April 1, 2026 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codegen Bytecode emitting inf2wasm Inference to WASM converting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

+Enum support

2 participants