Source File
escape.go
Belonging Package
internal/abi
// Copyright 2024 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package abiimport// NoEscape hides the pointer p from escape analysis, preventing it// from escaping to the heap. It compiles down to nothing.//// WARNING: This is very subtle to use correctly. The caller must// ensure that it's truly safe for p to not escape to the heap by// maintaining runtime pointer invariants (for example, that globals// and the heap may not generally point into a stack).////go:nosplit//go:nocheckptrfunc ( unsafe.Pointer) unsafe.Pointer {:= uintptr()return unsafe.Pointer( ^ 0)}var alwaysFalse boolvar escapeSink any// Escape forces any pointers in x to escape to the heap.func [ any]( ) {if alwaysFalse {escapeSink =}return}// EscapeNonString forces v to be on the heap, if v contains a// non-string pointer.//// This is used in hash/maphash.Comparable. We cannot hash pointers// to local variables on stack, as their addresses might change on// stack growth. Strings are okay as the hash depends on only the// content, not the pointer.//// This is essentially//// if hasNonStringPointers(T) { Escape(v) }//// Implemented as a compiler intrinsic.func [ any]( ) { panic("intrinsic") }// EscapeToResultNonString models a data flow edge from v to the result,// if v contains a non-string pointer. If v contains only string pointers,// it returns a copy of v, but is not modeled as a data flow edge// from the escape analysis's perspective.//// This is used in unique.clone, to model the data flow edge on the// value with strings excluded, because strings are cloned (by// content).//// TODO: probably we should define this as a intrinsic and EscapeNonString// could just be "heap = EscapeToResultNonString(v)". This way we can model// an edge to the result but not necessarily heap.func [ any]( ) {EscapeNonString()return *(*)(NoEscape(unsafe.Pointer(&)))}
![]() |
The pages are generated with Golds v0.7.9-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |