Repository navigation
A bound method given as a function type with more parameters is called through an adapter (wasm: 00object_func2) - #812
Merged
Conversation
…d through an adapter `call_func(user.sayHi, user)`, where `call_func` takes `(o: object) => void`: an object parameter first is taken as a `this` when function types are matched, so the cast went through as it was, and the call passed the method its `this` and every argument of the type - `sayHi(user, user)`. Natively the extra argument was ignored when the method took none, and read in the wrong place when it took some (`(o: object, x: number) => number` given `c.add`: `x` was `o`). wasm's call_indirect checks the signature and traps. The method and its `this` are known only at run time (read from a field), so the adapter keeps the bound method in a box, as a closure keeps its captures: the box and the adapter bound to it are two words, as a bound method is. The adapter calls the method with its `this` and the last arguments, as many as it takes. -mm=own does not take a bound method given as a function value yet, and keeps its own error. 00object_func2 now runs on wasm32 and wasm64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A bound method given as a function type with more parameters than the method takes is now called through an adapter. Before,
00object_func2trapped on wasm.What went wrong
call_func(user.sayHi, user), wherecall_functakes(o: object) => void:this, so the cast went through unchanged.thisplus every argument of the type:sayHi(user, user).c.addgiven as(o: object, x: number) => numbergotoas itsx.call_indirectchecks the signature and traps.The fix (
MLIRGenCast.cpp,boundMethodWiderTypeAdapter)thisare known only at run time, because they are read from a field. So the bound method goes into a box, the way a closure keeps its captures. The adapter is bound to that box, so the value is still two words, like a bound method.thisand the last arguments, as many as the method takes.thisand function separately, so rc keeps the receiver through the usual bound-method retain and release. A box holding an object literal'sthisdirectly crashed under rc.-mm=owndoesn't accept a bound method passed as a function value yet. It keeps its existing error, and no adapter is made.Tests
00bound_method_wider_callback:thisis used, not the argument;00object_func2is removed fromwasm_skips.txt.00object_func2and the new test.🤖 Generated with Claude Code