cmd/compile: pass pointer-shaped receivers using context register #44827
TL;DR: We should look into passing pointer-shaped receivers using the context register.
Today, receiver parameters are effectively simply prepended to the parameter list. This was convenient when Go only had method expressions (i.e., expressions like
However, Go later added method values (i.e., expressions like
If we change the internal calling convention so that receiver arguments are passed using the context register too, then we'd be able to avoid generating method value wrappers. We'd instead need just a single simple, universal wrapper, which could be used by both the compiler and package reflect. (For methods with non-pointer-shaped receivers, we would wrap the interface-calling-convention wrapper for the method, which always uses a pointer-shaped receiver parameter.)
Another benefit (pointed out by @dr2chase) is this would free up an extra register for passing arguments to pointer-receiver methods.
The only downside I see at the moment is that method expressions for pointer-shaped receiver types (e.g.,
The text was updated successfully, but these errors were encountered:
There was a question about what the universal method value wrapper would look like. My idea was something like:
and then have a wrapper function like:
(AX can be replaced with any other register that better fits the regabi calling convention.)