Skip to content

support //go:noescape #4584

Closed
Closed
@dgryski

Description

@dgryski

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..)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions