Conversation
|
Is this ready for review/merge? |
Not quite. Inheritance coming soon on top. Or should I raise inheritance separately? |
|
Yes, better keep the PRs small and merge them regularly. |
There was a problem hiding this comment.
Pull request overview
Adds WebAssembly backend support for instance/class methods on (non-inheriting) classes by lowering methods into standalone direct-call Wasm functions with an explicit receiver (this) parameter, plus a prescan that predeclares constructors/methods to support recursion and forward references.
Changes:
- Add prescan metadata registration for constructors and methods, and emit lowered method functions.
- Route constructor/method calls through direct
callto the lowered functions (instead of indirectcall_ref) where applicable. - Add/adjust Wasm golden tests for methods and for constructor calls in matching output.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| hkmc2/shared/src/test/mlscript/wasm/Methods.mls | New golden tests covering getters, nullary/callable methods, recursion, forward references, chaining, mutation, and error cases. |
| hkmc2/shared/src/test/mlscript/wasm/Matching.mls | Update golden WAT output to reflect direct constructor calls (call) rather than call_ref. |
| hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/WatBuilder.scala | Implement method/ctor metadata prescan, emit lowered method funcs, and add direct-call lowering for constructors/methods and related selection/assignment handling. |
| hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/Ctx.scala | Add MethodInfo/ConstructorInfo metadata storage and accessors in the Wasm codegen context. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
LPTK
left a comment
There was a problem hiding this comment.
The logic seems quite complicated, for what this achieves. But let's try to merge this soon anyway, as soon as you have fixed what I point out.
Derppening
left a comment
There was a problem hiding this comment.
Just a few preliminary comments for now. I will need to look into this in more detail.
|
This PR has been superseded by #456. |
This PR adds class-method support for non-inheriting classes by lowering instance methods to standalone direct-call wasm functions with an explicit
thisparameter, and a prescan that predeclares constructors and methods so self recursion, mutual recursion, later-method calls, and constructor calls to same or later classes work by construction.