Skip to content

Method codegen#178

Merged
0xGeorgii merged 17 commits intomainfrom
162-method-codegen
Mar 23, 2026
Merged

Method codegen#178
0xGeorgii merged 17 commits intomainfrom
162-method-codegen

Conversation

@0xGeorgii
Copy link
Copy Markdown
Contributor

Closes #162

…gnments and expressions

- Added tests to ensure that assigning from functions returning structs is rejected.
- Updated existing tests to check for error messages related to compound-returning function calls.
- Introduced new tests for standalone expressions and method calls that return structs.
- Added tests for methods and associated functions returning primitives to confirm they are allowed in standalone contexts.
- Created new test cases for struct methods that mutate self, ensuring value semantics are maintained.
- Added code generation tests for methods across multiple structs and self-mutating methods in WebAssembly.
- Updated method names in WASM and WAT files to follow a consistent naming convention (e.g., changed `Point__get_x` to `Point.get_x`).
- Introduced new structs and methods for handling arrays and i64 fields:
  - Added `Pair` struct with methods to convert to an array and retrieve individual fields.
  - Added `BigPair` struct with methods to get individual i64 fields and calculate their sum.
  - Added `Vec3` struct with methods to retrieve individual fields and calculate their sum.
- Created corresponding test functions for the new structs and methods to ensure functionality.
- Updated binary files for the changes made to the WASM modules.
@0xGeorgii 0xGeorgii self-assigned this Mar 22, 2026
@0xGeorgii 0xGeorgii added inf2wasm Inference to WASM converting codegen Bytecode emitting labels Mar 22, 2026
@0xGeorgii 0xGeorgii requested a review from Copilot March 22, 2026 12:44
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 WebAssembly codegen support for methods, including self parameter handling, instance method call lowering (instance.method()), and associated function lowering (Type::new()), along with updated type-checker restrictions/tests for compound-return call positions.

Changes:

  • Extend WASM codegen traversal to index and compile both top-level functions and struct methods using mangled names (TypeName.method).
  • Implement lowering for instance method calls and associated functions, including mut self copy-on-entry semantics.
  • Add/update codegen fixtures and Rust tests for method codegen + tighten type-checker diagnostics around compound-return calls in unsupported positions.

Reviewed changes

Copilot reviewed 33 out of 42 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
core/wasm-codegen/src/lib.rs Two-stage traversal: register indices for functions+methods, then compile bodies with method context.
core/wasm-codegen/src/compiler.rs Core implementation for method name mangling, callee resolution, instance/associated call lowering, and self handling.
core/wasm-codegen/src/errors.rs Adjust internal error docs after method/sret lowering changes.
core/type-checker/src/type_checker.rs Enforce compound-return call placement rules across assignment/expr/arg/member-access/method-chain cases.
core/type-checker/src/errors.rs Rename/expand error variants for compound-return call restrictions + add method-chain/assignment-specific errors.
core/type-checker/src/typed_context.rs Add TypedContext::lookup_method() + MethodMetadata for downstream consumers.
core/type-checker/src/lib.rs Re-export MethodMetadata.
core/type-checker/docs/errors.md Rename error doc section to CompoundReturnCallInExpressionPosition.
core/type-checker/README.md Update documentation to reflect new compound-return error naming/behavior.
core/analysis/README.md Update references to renamed compound-return restriction error.
tests/src/type_checker/struct_tests.rs Add type-checker tests for method-call chaining and compound-return restrictions with structs.
tests/src/type_checker/array_tests.rs Update assignment-rejection test to assert the new compound-return assignment error message.
tests/src/codegen/wasm/validation.rs Add validation tests for mangled method names, self lowering, and frame-copy expectations + helper extraction.
tests/src/codegen/wasm/base.rs Add full fixture+equivalence+execution tests for method/associated calls, mutable self, sret returns, arrays, i64 fields, etc.
tests/test_data/codegen/wasm/base/method_instance/method_instance.inf New method instance-call fixture source.
tests/test_data/codegen/wasm/base/method_instance/method_instance.wat Expected WAT for method_instance.
tests/test_data/codegen/wasm/base/method_instance/method_instance.wasm Expected WASM for method_instance.
tests/test_data/codegen/wasm/base/method_assoc/method_assoc.inf New associated-function fixture source.
tests/test_data/codegen/wasm/base/method_assoc/method_assoc.wat Expected WAT for method_assoc.
tests/test_data/codegen/wasm/base/method_assoc/method_assoc.wasm Expected WASM for method_assoc.
tests/test_data/codegen/wasm/base/method_return_struct/method_return_struct.inf New struct-returning method fixture source.
tests/test_data/codegen/wasm/base/method_return_struct/method_return_struct.wat Expected WAT for method_return_struct.
tests/test_data/codegen/wasm/base/method_return_struct/method_return_struct.wasm Expected WASM for method_return_struct.
tests/test_data/codegen/wasm/base/method_self_mutate/method_self_mutate.inf New mut self semantics fixture source.
tests/test_data/codegen/wasm/base/method_self_mutate/method_self_mutate.wat Expected WAT for method_self_mutate.
tests/test_data/codegen/wasm/base/method_self_mutate/method_self_mutate.wasm Expected WASM for method_self_mutate.
tests/test_data/codegen/wasm/base/method_multi_struct/method_multi_struct.inf New multi-struct (same method names) fixture source.
tests/test_data/codegen/wasm/base/method_multi_struct/method_multi_struct.wat Expected WAT for method_multi_struct.
tests/test_data/codegen/wasm/base/method_multi_struct/method_multi_struct.wasm Expected WASM for method_multi_struct.
tests/test_data/codegen/wasm/base/method_cross_call/method_cross_call.inf New cross-calls (method↔method / method↔fn) fixture source.
tests/test_data/codegen/wasm/base/method_cross_call/method_cross_call.wat Expected WAT for method_cross_call.
tests/test_data/codegen/wasm/base/method_cross_call/method_cross_call.wasm Expected WASM for method_cross_call.
tests/test_data/codegen/wasm/base/method_array_return/method_array_return.inf New method returning array fixture source.
tests/test_data/codegen/wasm/base/method_array_return/method_array_return.wat Expected WAT for method_array_return.
tests/test_data/codegen/wasm/base/method_array_return/method_array_return.wasm Expected WASM for method_array_return.
tests/test_data/codegen/wasm/base/method_i64_fields/method_i64_fields.inf New i64 field access via methods fixture source.
tests/test_data/codegen/wasm/base/method_i64_fields/method_i64_fields.wat Expected WAT for method_i64_fields.
tests/test_data/codegen/wasm/base/method_i64_fields/method_i64_fields.wasm Expected WASM for method_i64_fields.
tests/test_data/codegen/wasm/base/method_three_fields/method_three_fields.inf New 3-field struct method access fixture source.
tests/test_data/codegen/wasm/base/method_three_fields/method_three_fields.wat Expected WAT for method_three_fields.
tests/test_data/codegen/wasm/base/method_three_fields/method_three_fields.wasm Expected WASM for method_three_fields.
Cargo.toml Bump tree-sitter-inference dependency version.

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

Comment thread core/wasm-codegen/src/compiler.rs Outdated
Comment thread tests/src/codegen/wasm/validation.rs Outdated
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 33 out of 42 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.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 22, 2026

Codecov Report

❌ Patch coverage is 84.45006% with 123 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
core/wasm-codegen/src/compiler.rs 76.82% 111 Missing ⚠️
core/type-checker/src/type_checker.rs 87.83% 9 Missing ⚠️
core/type-checker/src/errors.rs 84.21% 3 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

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


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

Comment thread core/wasm-codegen/src/compiler.rs Outdated
Comment thread core/wasm-codegen/src/compiler.rs
Comment thread tests/src/utils.rs
…alls

- Updated README.md to reflect the increase in error variants from 47 to 50.
- Added new tests for distinguishing instance methods from associated functions in the type checker.
- Implemented error handling for compound-returning method calls in expression positions.
- Enhanced WASM code generation to support associated function calls and instance methods.
- Introduced a new documentation file detailing type-checker-guarded panics to improve understanding of panic sites in the codebase.
- Improved error messages and documentation throughout the type checker and codegen modules.
@0xGeorgii 0xGeorgii merged commit 9061ef9 into main Mar 23, 2026
6 checks passed
@0xGeorgii 0xGeorgii deleted the 162-method-codegen branch March 23, 2026 04:35
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.

Method codegen

2 participants