Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Interpreter issues with func.bind #36

Closed
titzer opened this issue Sep 3, 2020 · 3 comments
Closed

Interpreter issues with func.bind #36

titzer opened this issue Sep 3, 2020 · 3 comments

Comments

@titzer
Copy link
Contributor

titzer commented Sep 3, 2020

Related to #11 and #27.

Because there is no type annotation for type of the incoming function argument to func.bind, the runtime representation of a function must include the signature of the function in order for the interpreter to compute how many stack arguments are bound. It must also annotate the new closure with the signature for future func.bind instructions.

It gets hairier with subtyping. Here, the interpreter must compute the new signature from the signature of the incoming function, since it may differ from the signature specified in the immediate (i.e. be a subtype), and then store that signature on the newly bound closure, since that amounts to RTT that might be used when storing the function into a table.

@rossberg
Copy link
Member

Doesn't a function need to contain its signature anyway? How else would you implement call_indirect -- or in the future, casts on functions?

@titzer
Copy link
Contributor Author

titzer commented Sep 17, 2020

For call_indirect, each table entry stores a signature id (call tag). Only table.set needs to look at a funcref value's signature in order to derive a signature id. For unbound functions, this can be computed from the code pointer of the function alone (up until we have type imports, in which case, it can be computed from the code pointer and the instance). For bound functions, the closure object can contain the number of bound arguments, thus the signature can be computed lazily from the function pointer and the closure object.

Related to #27, this is another example of statically derivable information becoming dynamic information.

I think it would be better to add an additional u32 immediate to func.bind which is the number of arguments bound. Even better would be a bitmask of which arguments are bound so that programs could do more than just left-to-right binding.

@rossberg
Copy link
Member

Func.bind has been dropped from the proposal.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants