Skip to content

+Memory structs#159

Merged
0xGeorgii merged 16 commits intomainfrom
149-memory-structs
Mar 16, 2026
Merged

+Memory structs#159
0xGeorgii merged 16 commits intomainfrom
149-memory-structs

Conversation

@0xGeorgii
Copy link
Copy Markdown
Contributor

No description provided.

@0xGeorgii 0xGeorgii self-assigned this Mar 16, 2026
@0xGeorgii 0xGeorgii added inf2wasm Inference to WASM converting codegen Bytecode emitting memory management Related to how memory is tracked and manipulated labels Mar 16, 2026
@0xGeorgii 0xGeorgii requested a review from Copilot March 16, 2026 11:27
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 89.46037% with 125 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
core/wasm-codegen/src/compiler.rs 84.51% 83 Missing ⚠️
core/type-checker/src/type_checker.rs 94.18% 20 Missing ⚠️
core/type-checker/src/symbol_table.rs 68.18% 14 Missing ⚠️
core/type-checker/src/errors.rs 90.47% 8 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 introduces memory-backed struct support across the type checker and the Wasm code generator, along with golden fixtures and execution/validation tests to cover struct literals, field access/assignment, parameter passing (copy semantics), and struct returns (sret).

Changes:

  • Add struct layout computation and struct-aware frame layout/copying in Wasm codegen (struct literals, member access read/write, struct params/returns/copies).
  • Extend the type checker with new struct-related validations (empty structs, struct literal field validation, unused self in methods), plus stricter mutability/shadowing checks.
  • Add new codegen/type-checker tests and expected .wasm/.wat fixtures for multiple struct scenarios.

Reviewed changes

Copilot reviewed 30 out of 36 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/test_data/codegen/wasm/base/struct_return/struct_return.wat New golden WAT for struct return (sret) scenarios.
tests/test_data/codegen/wasm/base/struct_return/struct_return.wasm New golden Wasm binary for struct return scenarios.
tests/test_data/codegen/wasm/base/struct_return/struct_return.inf New source fixture describing struct return tests.
tests/test_data/codegen/wasm/base/struct_params/struct_params.wat New golden WAT for struct parameters (copy-on-entry) scenarios.
tests/test_data/codegen/wasm/base/struct_params/struct_params.wasm New golden Wasm binary for struct parameter scenarios.
tests/test_data/codegen/wasm/base/struct_params/struct_params.inf New source fixture for struct parameter tests.
tests/test_data/codegen/wasm/base/struct_literal/struct_literal.wat New golden WAT for struct literal materialization.
tests/test_data/codegen/wasm/base/struct_literal/struct_literal.wasm New golden Wasm binary for struct literal tests.
tests/test_data/codegen/wasm/base/struct_literal/struct_literal.inf New source fixture for struct literal tests.
tests/test_data/codegen/wasm/base/struct_copy/struct_copy.wat New golden WAT for struct-to-struct copy semantics.
tests/test_data/codegen/wasm/base/struct_copy/struct_copy.wasm New golden Wasm binary for struct copy semantics.
tests/test_data/codegen/wasm/base/struct_copy/struct_copy.inf New source fixture for struct copy tests.
tests/test_data/codegen/wasm/base/struct_assign/struct_assign.wat New golden WAT for struct field assignment behavior.
tests/test_data/codegen/wasm/base/struct_assign/struct_assign.wasm New golden Wasm binary for struct assignment tests.
tests/test_data/codegen/wasm/base/struct_assign/struct_assign.inf New source fixture for struct assignment tests.
tests/test_data/codegen/wasm/base/struct_access/struct_access.wat New golden WAT for struct field access (reads).
tests/test_data/codegen/wasm/base/struct_access/struct_access.wasm New golden Wasm binary for struct access tests.
tests/test_data/codegen/wasm/base/struct_access/struct_access.inf New source fixture for struct access tests.
tests/src/type_checker/type_checker.rs Refactor shared try_type_check helper and update method tests to actually use self.
tests/src/type_checker/struct_tests.rs New type-checker tests for struct mutability, shadowing, and struct literal validation limitations.
tests/src/type_checker/mod.rs Register new struct_tests module.
tests/src/type_checker/coverage.rs Add coverage tests for bool/number mismatches and ordering comparisons.
tests/src/type_checker/array_tests.rs Update array method test to reference self in returned array.
tests/src/codegen/wasm/base.rs Add new Wasm codegen golden + execution tests and regeneration helpers for struct features.
core/wasm-codegen/src/memory.rs Add struct layout structs + compute_struct_field_layout + struct param copy emission; expose MEMORY_INDEX.
core/wasm-codegen/src/lib.rs Pass TypedContext into codegen’s function indexing to support struct return metadata.
core/wasm-codegen/src/compiler.rs Implement struct sret metadata, struct slots in frame layout, struct literal lowering, and member access read/write.
core/type-checker/src/typed_context.rs Add lookup_struct API for querying struct metadata by name.
core/type-checker/src/type_checker.rs Add/extend validations: empty struct error, unused self method rule, struct literal field checks, shadowing, and assignment mutability root-name extraction.
core/type-checker/src/symbol_table.rs Make StructInfo/StructFieldInfo public + preserve field order via Vec; add parent-scope variable lookup helper.
core/type-checker/src/lib.rs Re-export StructInfo/StructFieldInfo for downstream consumers (e.g., Wasm codegen).
core/type-checker/src/errors.rs Add new error variants (shadowing, struct literal as argument, unused self, empty struct, struct literal field diagnostics).
core/type-checker/docs/errors.md Update error catalog overview (currently incomplete vs added variants).
core/type-checker/docs/architecture.md Update docs for generalized assignment mutability extraction and add shadowing rationale/behavior.
core/ast/src/builder.rs Update struct literal field parsing to match new field names in the parse tree.
CHANGELOG.md Document new shadowing rule and struct-field assignment mutability requirement.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/type-checker/src/type_checker.rs
Comment thread core/wasm-codegen/src/compiler.rs
Comment thread core/type-checker/docs/errors.md Outdated
…st for struct return call in expression position
@0xGeorgii 0xGeorgii requested a review from Copilot March 16, 2026 11:48
@0xGeorgii 0xGeorgii linked an issue Mar 16, 2026 that may be closed by this pull request
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

Adds end-to-end support for “memory structs” (stack-allocated, pointer-backed structs) across the type checker and Wasm codegen, along with new golden test fixtures and runtime execution tests to validate behavior.

Changes:

  • Implement struct layout computation + stack frame allocation/copy semantics in Wasm codegen (struct literals, field read/write, struct params, struct returns via sret).
  • Extend the type checker with struct-specific validation rules (empty structs, struct literal field validation, “method never accesses self”, shadowing prohibition, assignment mutability via root-variable extraction).
  • Add/update extensive test data (.inf/.wat/.wasm) and Rust tests for both type-checking and Wasm execution.

Reviewed changes

Copilot reviewed 30 out of 36 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_data/codegen/wasm/base/struct_return/struct_return.wat New golden WAT for struct return (sret) cases
tests/test_data/codegen/wasm/base/struct_return/struct_return.wasm New golden WASM for struct return (sret) cases
tests/test_data/codegen/wasm/base/struct_return/struct_return.inf New source fixture for struct return scenarios
tests/test_data/codegen/wasm/base/struct_params/struct_params.wat New golden WAT for struct parameters (copy-on-entry)
tests/test_data/codegen/wasm/base/struct_params/struct_params.wasm New golden WASM for struct parameters
tests/test_data/codegen/wasm/base/struct_params/struct_params.inf New source fixture for struct parameters
tests/test_data/codegen/wasm/base/struct_literal/struct_literal.wat New golden WAT for struct literal construction
tests/test_data/codegen/wasm/base/struct_literal/struct_literal.wasm New golden WASM for struct literal construction
tests/test_data/codegen/wasm/base/struct_literal/struct_literal.inf New source fixture for struct literals
tests/test_data/codegen/wasm/base/struct_copy/struct_copy.wat New golden WAT for struct-to-struct copy semantics
tests/test_data/codegen/wasm/base/struct_copy/struct_copy.wasm New golden WASM for struct copy semantics
tests/test_data/codegen/wasm/base/struct_copy/struct_copy.inf New source fixture for struct copy semantics
tests/test_data/codegen/wasm/base/struct_assign/struct_assign.wat New golden WAT for field assignment/mutation
tests/test_data/codegen/wasm/base/struct_assign/struct_assign.wasm New golden WASM for field assignment/mutation
tests/test_data/codegen/wasm/base/struct_assign/struct_assign.inf New source fixture for field assignment/mutation
tests/test_data/codegen/wasm/base/struct_access/struct_access.wat New golden WAT for field reads
tests/test_data/codegen/wasm/base/struct_access/struct_access.wasm New golden WASM for field reads
tests/test_data/codegen/wasm/base/struct_access/struct_access.inf New source fixture for field read scenarios
tests/src/type_checker/type_checker.rs Refactor shared typecheck helper + add new struct-related tests
tests/src/type_checker/struct_tests.rs New dedicated struct mutability/shadowing/field-validation tests
tests/src/type_checker/mod.rs Register new struct_tests module
tests/src/type_checker/coverage.rs Add type mismatch coverage tests (notably bool ordering rejection)
tests/src/type_checker/array_tests.rs Update an array-return method test to actually use self
tests/src/codegen/wasm/base.rs Add struct codegen golden + execution tests and regen helpers
core/wasm-codegen/src/memory.rs Add struct layout/slot types + struct param copy emission
core/wasm-codegen/src/lib.rs Pass TypedContext into build_func_name_to_idx
core/wasm-codegen/src/compiler.rs Add struct sret metadata, struct literal lowering, member access read/write, struct copies
core/type-checker/src/typed_context.rs Expose lookup_struct for downstream consumers (e.g., codegen)
core/type-checker/src/type_checker.rs Add EmptyStruct/unused-self/shadowing rules; struct literal validation; assignment root-name extraction
core/type-checker/src/symbol_table.rs Make StructInfo/StructFieldInfo public; store struct fields in order; add parent-scope var lookup
core/type-checker/src/lib.rs Re-export StructInfo/StructFieldInfo
core/type-checker/src/errors.rs Add new error variants/messages for struct/shadowing/unused-self and struct literal validation
core/type-checker/docs/errors.md Update error catalog counts + document new errors
core/type-checker/docs/architecture.md Document generalized assignment mutability + shadowing rule
core/ast/src/builder.rs Update struct-literal field parsing to new node field names
CHANGELOG.md Document new mutability extraction, shadowing error, and struct-field assignment requirement

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/wasm-codegen/src/compiler.rs
Comment thread core/wasm-codegen/src/memory.rs
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

Adds first-class struct support (backed by linear memory) across the type checker and WASM codegen, along with extensive new golden files and runtime/validation tests for struct literals, field access/assignment, parameter passing (copy semantics), and struct returns via sret.

Changes:

  • Implement struct memory layout + frame-slot allocation and copy semantics in WASM codegen (struct literals, member read/write, struct params, struct returns via sret).
  • Extend type checker with struct literal validation (missing/unknown/duplicate fields), new validation rules (empty structs, unused self, shadowing), and updated mutability checks for assignments through member/idx access.
  • Add/expand tests and golden WASM/WAT fixtures for struct-related codegen and type-checking behavior.

Reviewed changes

Copilot reviewed 30 out of 36 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/test_data/codegen/wasm/base/struct_return/struct_return.wat New golden WAT for struct-return (sret) scenarios.
tests/test_data/codegen/wasm/base/struct_return/struct_return.wasm New golden WASM binary for struct-return tests.
tests/test_data/codegen/wasm/base/struct_return/struct_return.inf Source fixture for struct-return test cases.
tests/test_data/codegen/wasm/base/struct_params/struct_params.wat New golden WAT for struct parameter passing & copy-on-entry.
tests/test_data/codegen/wasm/base/struct_params/struct_params.wasm New golden WASM binary for struct param tests.
tests/test_data/codegen/wasm/base/struct_params/struct_params.inf Source fixture for struct param tests.
tests/test_data/codegen/wasm/base/struct_literal/struct_literal.wat New golden WAT for struct literal materialization.
tests/test_data/codegen/wasm/base/struct_literal/struct_literal.wasm New golden WASM binary for struct literal tests.
tests/test_data/codegen/wasm/base/struct_literal/struct_literal.inf Source fixture for struct literal tests.
tests/test_data/codegen/wasm/base/struct_copy/struct_copy.wat New golden WAT for struct-to-struct copy semantics.
tests/test_data/codegen/wasm/base/struct_copy/struct_copy.wasm New golden WASM binary for struct copy tests.
tests/test_data/codegen/wasm/base/struct_copy/struct_copy.inf Source fixture for struct copy tests.
tests/test_data/codegen/wasm/base/struct_assign/struct_assign.wat New golden WAT for struct field writes / assignment behavior.
tests/test_data/codegen/wasm/base/struct_assign/struct_assign.wasm New golden WASM binary for struct assignment tests.
tests/test_data/codegen/wasm/base/struct_assign/struct_assign.inf Source fixture for struct assignment tests.
tests/test_data/codegen/wasm/base/struct_access/struct_access.wat New golden WAT for struct field reads.
tests/test_data/codegen/wasm/base/struct_access/struct_access.wasm New golden WASM binary for struct access tests.
tests/test_data/codegen/wasm/base/struct_access/struct_access.inf Source fixture for struct access tests.
tests/src/type_checker/type_checker.rs Refactor shared try_type_check helper; update some struct method tests to actually use self.
tests/src/type_checker/struct_tests.rs New type-checker tests for struct mutability, shadowing, and struct literal field validation.
tests/src/type_checker/mod.rs Register new struct_tests module.
tests/src/type_checker/coverage.rs Add mismatch coverage tests (notably bool vs numeric and ordering comparisons).
tests/src/type_checker/array_tests.rs Update array method test to ensure self usage is exercised.
tests/src/codegen/wasm/base.rs Add struct-related codegen equivalence tests, execution tests, and regeneration helpers.
core/wasm-codegen/src/memory.rs Add struct field layout computation + struct frame slots + struct param copy helper.
core/wasm-codegen/src/lib.rs Pass TypedContext into function index build to support struct-return metadata.
core/wasm-codegen/src/compiler.rs Implement struct literals, member access read/write, struct copies, struct sret returns, and struct param handling.
core/type-checker/src/typed_context.rs Expose lookup_struct on TypedContext.
core/type-checker/src/type_checker.rs Add empty-struct + unused-self validations, struct literal validation, shadowing prohibition, and unified mutability checking.
core/type-checker/src/symbol_table.rs Make struct infos public/exportable; store struct fields in declaration order; add parent-scope lookup helper.
core/type-checker/src/lib.rs Re-export StructInfo/StructFieldInfo for codegen.
core/type-checker/src/errors.rs Add new error variants for shadowing, empty structs, unused self, and struct literal field issues.
core/type-checker/docs/errors.md Update documented error count and add shadowing error docs.
core/type-checker/docs/architecture.md Document generalized assignment mutability validation and shadowing rule.
core/ast/src/builder.rs Update struct literal CST field names used during AST building.
CHANGELOG.md Document new shadowing + struct mutability behavior and root-name extraction generalization.
Comments suppressed due to low confidence (1)

core/type-checker/src/type_checker.rs:756

  • The type checker now uses ArrayReturnCallInExpressionPosition for struct-returning (sret) functions too (matches Struct(_) | Custom(_)), but the error name/message are array-specific. This will produce confusing diagnostics for struct returns; consider generalizing the error wording/variant to cover both array and struct sret calls.
                    // Check for array return call in assignment position
                    if let Expr::FunctionCall { function, .. } = &ctx.arena()[right].kind {
                        let func_name = self.resolve_function_call_name(ctx.arena(), *function);
                        if let Some(ref fn_name) = func_name
                            && let Some(sig) = self.symbol_table.lookup_function(fn_name)
                            && matches!(sig.return_type.kind, TypeInfoKind::Array(_, _) | TypeInfoKind::Struct(_) | TypeInfoKind::Custom(_))
                        {
                            self.errors
                                .push(TypeCheckError::ArrayReturnCallInExpressionPosition {
                                    location: ctx.arena()[right].location,

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/type-checker/src/symbol_table.rs
Comment thread core/type-checker/src/type_checker.rs
Comment thread core/wasm-codegen/src/compiler.rs
…ed expression positions and corresponding tests
@0xGeorgii 0xGeorgii requested a review from Copilot March 16, 2026 12:56
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

Adds first-class support for struct values stored in linear memory for the WASM backend, along with type-checker validations and new codegen/type-check tests to cover struct literals, field access/assignment, struct params, struct returns (sret), and copy/value semantics.

Changes:

  • WASM codegen: introduce struct frame layout, struct param copy-on-entry, struct literals, member access read/write, struct sret returns, and struct-to-struct copies.
  • Type checker: add/extend rules for empty structs, unused self, variable shadowing prohibition, and compound literal placement/field validation; expose struct lookup via TypedContext.
  • Tests: add new golden wasm/wat fixtures and execution/validation tests for struct features; add dedicated type-checker struct tests and additional coverage cases.

Reviewed changes

Copilot reviewed 30 out of 36 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
core/wasm-codegen/src/memory.rs Adds struct layout computation and frame slot metadata; adds struct param copy emitter.
core/wasm-codegen/src/compiler.rs Implements struct literals, member access read/write, struct sret return handling, struct copy, and struct frame allocation.
core/wasm-codegen/src/lib.rs Passes TypedContext into function index building for struct return metadata.
core/type-checker/src/type_checker.rs Adds validations (empty struct, unused self, shadowing), compound literal restrictions, struct literal field checks, and struct-aware assignment mutability.
core/type-checker/src/symbol_table.rs Changes struct field storage to preserve declaration order and adds parent-scope lookup helper.
core/type-checker/src/typed_context.rs Exposes lookup_struct for codegen/type checker consumers.
core/type-checker/src/errors.rs Adds new error variants for struct/compound literal and new validation rules.
core/type-checker/docs/* Updates docs to reflect new validation rules and error count.
tests/src/codegen/wasm/base.rs Adds struct codegen golden tests + wasmtime execution tests and regeneration helpers.
tests/src/type_checker/type_checker.rs Refactors shared try_type_check helper + expands rule tests.
tests/src/type_checker/struct_tests.rs New test module for struct mutability, shadowing, and struct literal validation restrictions.
tests/src/type_checker/coverage.rs Adds additional type mismatch coverage tests.
tests/test_data/codegen/wasm/base/* New struct-related .inf, .wat, .wasm fixtures (literal/access/assign/params/return/copy).
core/ast/src/builder.rs Updates struct literal field parsing to match updated tree-sitter field names.
CHANGELOG.md Documents new mutability extraction behavior and shadowing rule.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/type-checker/src/type_checker.rs
Comment thread core/type-checker/src/type_checker.rs
…unction calls in unsupported expression positions
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 extends the compiler pipeline to support memory-backed structs end-to-end: the type checker now validates additional struct rules and restrictions, and the Wasm backend lowers structs via frame-allocated layouts with explicit loads/stores, including sret-style struct returns and copy-on-entry for struct parameters. It also adds substantial new Wasm codegen golden files and execution/validation tests covering struct literals, member access, field assignment, struct params, struct returns, and struct copying.

Changes:

  • Add struct-aware frame layout + struct field layout computation, plus Wasm lowering for struct literals, member access (read/write), struct param copies, and struct returns via sret.
  • Tighten type checking around structs/compound values (empty structs, unused self, field validation, shadowing prohibition, compound literal placement restrictions).
  • Add new test suites and golden Wasm/WAT/INF fixtures for struct scenarios (including execution tests via wasmtime).

Reviewed changes

Copilot reviewed 30 out of 36 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_data/codegen/wasm/base/struct_return/struct_return.wat New expected WAT for struct-return (sret) scenarios
tests/test_data/codegen/wasm/base/struct_return/struct_return.wasm New expected Wasm binary for struct-return tests
tests/test_data/codegen/wasm/base/struct_return/struct_return.inf New source fixture for struct-return tests
tests/test_data/codegen/wasm/base/struct_params/struct_params.wat New expected WAT for struct parameter passing/copy semantics
tests/test_data/codegen/wasm/base/struct_params/struct_params.wasm New expected Wasm binary for struct param tests
tests/test_data/codegen/wasm/base/struct_params/struct_params.inf New source fixture for struct param tests
tests/test_data/codegen/wasm/base/struct_literal/struct_literal.wat New expected WAT for struct literal lowering
tests/test_data/codegen/wasm/base/struct_literal/struct_literal.wasm New expected Wasm binary for struct literal tests
tests/test_data/codegen/wasm/base/struct_literal/struct_literal.inf New source fixture for struct literal tests
tests/test_data/codegen/wasm/base/struct_copy/struct_copy.wat New expected WAT for struct-to-struct copy (value semantics)
tests/test_data/codegen/wasm/base/struct_copy/struct_copy.wasm New expected Wasm binary for struct copy tests
tests/test_data/codegen/wasm/base/struct_copy/struct_copy.inf New source fixture for struct copy tests
tests/test_data/codegen/wasm/base/struct_assign/struct_assign.wat New expected WAT for struct field assignment tests
tests/test_data/codegen/wasm/base/struct_assign/struct_assign.wasm New expected Wasm binary for struct assignment tests
tests/test_data/codegen/wasm/base/struct_assign/struct_assign.inf New source fixture for struct assignment tests
tests/test_data/codegen/wasm/base/struct_access/struct_access.wat New expected WAT for struct member access reads
tests/test_data/codegen/wasm/base/struct_access/struct_access.wasm New expected Wasm binary for struct access tests
tests/test_data/codegen/wasm/base/struct_access/struct_access.inf New source fixture for struct access tests
tests/src/type_checker/type_checker.rs Refactors shared try_type_check helper + adds new rule tests (empty struct, unused self, etc.)
tests/src/type_checker/struct_tests.rs New dedicated struct-related type checker tests (mutability, shadowing, field validation, literal placement restrictions)
tests/src/type_checker/mod.rs Registers new struct_tests module
tests/src/type_checker/coverage.rs Adds mismatch/ordering-operator coverage tests
tests/src/type_checker/array_tests.rs Updates array method test to actually use self.x
tests/src/codegen/wasm/base.rs Adds extensive struct codegen tests (golden + inline validation + execution via wasmtime + regen helpers)
core/wasm-codegen/src/memory.rs Adds struct layout computation + struct slots in frame layout + struct param copy emission
core/wasm-codegen/src/lib.rs Passes TypedContext into function indexing to detect struct returns
core/wasm-codegen/src/compiler.rs Implements struct lowering (literals, member access read/write, struct copy init, struct sret returns/forwarding, struct slots in frame layout)
core/type-checker/src/typed_context.rs Exposes lookup_struct for downstream consumers (e.g., codegen)
core/type-checker/src/type_checker.rs Adds new validations (empty struct, unused self, compound literal placement, struct literal field validation, mutability root extraction, shadowing prohibition, comparison operand validation)
core/type-checker/src/symbol_table.rs Makes StructInfo/StructFieldInfo public + changes struct fields to ordered Vec + adds parent-scope variable lookup
core/type-checker/src/lib.rs Re-exports StructInfo and StructFieldInfo
core/type-checker/src/errors.rs Adds new error variants/messages for struct + shadowing + compound literal restrictions
core/type-checker/docs/errors.md Updates error catalog count and documents VariableShadowed
core/type-checker/docs/architecture.md Updates docs for mutability validation + shadowing prohibition
core/ast/src/builder.rs Updates struct literal field parsing to match new tree-sitter field names
CHANGELOG.md Documents new shadowing + mutability-root extraction behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/wasm-codegen/src/compiler.rs
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

Adds first-class “memory-backed structs” support across the type checker and WASM codegen pipeline, along with extensive new regression tests and golden WASM/WAT fixtures.

Changes:

  • Implement struct layout + stack frame allocation, struct param copy-on-entry, struct literals, member access read/write, struct copy, and struct sret returns in WASM codegen.
  • Extend the type checker with new struct-related validations (empty struct, unused self methods, struct literal field validation), compound-literal position rules, and variable shadowing prohibition.
  • Add new type-checker and wasm-codegen test suites plus corresponding .inf/.wat/.wasm fixtures for struct literal/access/assign/params/return/copy.

Reviewed changes

Copilot reviewed 30 out of 36 changed files in this pull request and generated no comments.

Show a summary per file
File Description
core/wasm-codegen/src/memory.rs Introduces struct slot/field layout and struct param copy helpers for linear-memory structs.
core/wasm-codegen/src/compiler.rs Adds struct-aware frame layout, literals, member access lowering, struct copy, and struct sret handling.
core/type-checker/src/type_checker.rs Adds new validation rules (empty struct, unused self, compound literal position, shadowing) and struct literal checking.
core/type-checker/src/symbol_table.rs / typed_context.rs Exposes struct metadata (StructInfo) to downstream phases and adjusts field storage/lookup.
tests/src/codegen/wasm/base.rs Adds new wasm codegen + execution tests for struct features and regeneration helpers.
tests/src/type_checker/* Adds a dedicated struct-focused type-checker test module and additional coverage tests.
tests/test_data/codegen/wasm/base/* Adds golden fixtures for struct scenarios (literal/access/assign/params/return/copy).
Comments suppressed due to low confidence (1)

core/type-checker/src/type_checker.rs:180

  • Struct fields are registered with TypeInfo::from_type_id (unresolved) and there’s no validation that their kinds are codegen-supported. Because compute_struct_field_layout() calls element_size() (which todo!s for Custom, Array, String, etc.), a struct like struct Rect { origin: Point; } can make WASM codegen panic as soon as Rect is used in a param/return/frame layout. Consider resolving field types with symbol_table.resolve_custom_type(...) during registration and emitting a dedicated error (or at least a hard validation) when a struct field type isn’t one of the currently supported primitive kinds (bool/number).
                    let field_infos: Vec<(String, TypeInfo, Visibility)> = fields
                        .iter()
                        .map(|f| {
                            (
                                arena[f.name].name.clone(),
                                TypeInfo::from_type_id(arena, f.ty),
                                Visibility::Private,
                            )
                        })
                        .collect();

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@0xGeorgii 0xGeorgii merged commit ab90d53 into main Mar 16, 2026
9 checks passed
@0xGeorgii 0xGeorgii deleted the 149-memory-structs branch March 16, 2026 23:24
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 memory management Related to how memory is tracked and manipulated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

+ Memory allocation: structs

2 participants