-
Notifications
You must be signed in to change notification settings - Fork 913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compiler: Add go:noescape
pragma for variables
#3809
Comments
Seems like the real solution here is to be able to tag |
Unfortunately, that's not really safe. Some other code could (in theory) capture the value in the parameter. Instead, what is needed is to add this pragma to the implementation of that method call. So for example, in the machine package on the The LLVM attribute that corresponds to |
That would be ideal.
So does the compiler have knowledge of the underlying SPI/I2C type in a Unrelated: Testing out |
No. Basically, the compiler currently converts a method call to a type switch and direct call, like this pseudocode: func callTxMethod(itf any, w, r []byte) error {
switch itf := itf.(type) {
case *machine.SPI:
return machine.SPI.Tx(itf, w, r)
// other cases here
default:
runtime.nilPanic()
}
} If |
Linking a related PR for future reference: #3887 |
Having interface methods and function pointers being able to be tagged as |
I'd like to be able to mark variables as non-escaping for cases where I'm using well defined interfaces which guarantee their arguments don't escape like the
drivers.SPI
anddrivers.I2C
interfaces.Usage
In the below case we are sure that SPI implementation will not capture the buf slice. We tell the compiler that it's perfectly OK if buf is on the stack.
Incorrect usage
Example of where NOT to use
go:escape
. buf should certainly not stay on stack since it may be immediately be reused by the next function to be called afterUitoa
. This is just for demonstration, I don't expect the compiler to realize this is bad usage.The text was updated successfully, but these errors were encountered: