transform: PtrToInt and IntToPtr do not escape #4889
Draft
+19
−8
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.
This hints compiler that constructs like
uintptr(unsafe.Pointer(&x))
do not escape. Handled byllvm.PtrToInt
case.(I've also added
llvm.IntToPtr
, for completeness, but I'm not sure what code matches it. Feel free to reject.)Disclaimer
This change may very well be completely wrong; can such constructs escape?
Hence a draft, merely a conversation starter.
Context
I2C implementations on RP2040 and NRF52 behave differently regarding allocation behavior.
NRF52 implementation escapes to heap while RP2040 does not.
The issue was tracked down to lines 52 and 61 of this file: https://github.com/tinygo-org/tinygo/blob/release/src/machine/machine_nrf528xx.go
Reproducer
And this does not escape at all
After this change both do not escape anymore.
Thanks @dgryski for pointing at
allocs.go