Skip to content

support //go:noescape #4584

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

Closed
dgryski opened this issue Nov 6, 2024 · 1 comment
Closed

support //go:noescape #4584

dgryski opened this issue Nov 6, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@dgryski
Copy link
Member

dgryski commented Nov 6, 2024

So this patch

diff --git a/compiler/symbol.go b/compiler/symbol.go
index 9b9b1d10..5ef6924d 100644
--- a/compiler/symbol.go
+++ b/compiler/symbol.go
@@ -33,6 +33,7 @@ type functionInfo struct {
        exported      bool       // go:export, CGo
        interrupt     bool       // go:interrupt
        nobounds      bool       // go:nobounds
+       noescape      bool       // go:noescape
        variadic      bool       // go:variadic (CGo only)
        inline        inlineType // go:inline
 }
@@ -202,7 +203,7 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value)

        // External/exported functions may not retain pointer values.
        // https://golang.org/cmd/cgo/#hdr-Passing_pointers
-       if info.exported {
+       if info.exported || info.noescape {
                if c.archFamily() == "wasm32" && len(fn.Blocks) == 0 {
                        // We need to add the wasm-import-module and the wasm-import-name
                        // attributes.
@@ -394,6 +395,10 @@ func (c *compilerContext) parsePragmas(info *functionInfo, f *ssa.Function) {
                        if hasUnsafeImport(f.Pkg.Pkg) {
                                info.nobounds = true
                        }
+               case "//go:noescape":
+                       //if hasUnsafeImport(f.Pkg.Pkg) {
+                       info.noescape = true
+                       //              }
                case "//go:variadic":
                        // The //go:variadic pragma is emitted by the CGo preprocessing
                        // pass for C variadic functions. This includes both explicit

"should" add support for //go:noescape, but looking through the runtime I feel like I need to add those annotations all through the hashmap code in order to actually tag things as non-escaping. Looking through there still seem to be a lot of places our escape analysis needs help.

(btw, the commented out code in the patch to check for hasUnsafeImport was causing a segfault in the compiler; not sure why..)

@aykevl
Copy link
Member

aykevl commented Nov 19, 2024

I worked on this previously: #3887

@deadprogram deadprogram added enhancement New feature or request next-release Will be part of next release labels Dec 2, 2024
@deadprogram deadprogram removed the next-release Will be part of next release label Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants