Documentation
¶
Overview ¶
Package mark provides markers for special compiler behavior
Index ¶
- func NoEscape[T any](p *T) *T
- func NoEscapeBytesString[T ~byte](s []T) string
- func NoEscapePointer[T any](p *T) unsafe.Pointer
- func NoEscapeSlice[T any](p []T) []T
- func NoEscapeSliceData[T any](p []T) *T
- func NoEscapeSliceDataPointer[T any](p []T) unsafe.Pointer
- func NoEscapeString[String ~string](s String) String
- func NoEscapeStringData[String ~string](s String) *byte
- func NoEscapeStringDataPointer[String ~string](s String) unsafe.Pointer
- func NoEscapeUnsafePointer(p unsafe.Pointer) unsafe.Pointer
- type Align64
- type NoCompare
- type NoCopy
- type NotInHeap
- type SelfPointing
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NoEscape ¶
func NoEscape[T any](p *T) *T
NoEscape hides a pointer from escape analysis. USE CAREFULLY!
It is the identity function but escape analysis doesn't think the output depends on the input.
It is inlined and currently compiles down to zero instructions.
func NoEscapeBytesString ¶
NoEscapeBytesString is NoEscapeString but taking bytes as the argument.
func NoEscapePointer ¶
NoEscapePointer is NoEscape but returns unsafe.Pointer.
func NoEscapeSliceData ¶
func NoEscapeSliceData[T any](p []T) *T
NoEscapeSliceData is NoEscapeSlice but returns the pointer to the underlay array.
func NoEscapeSliceDataPointer ¶
NoEscapeSliceDataPointer is NoEscapeSliceData but returns an unsafe.Pointer.
func NoEscapeString ¶
func NoEscapeString[String ~string](s String) String
NoEscapeString is NoEscape for string.
func NoEscapeStringData ¶
NoEscapeStringData is NoEscapeString but returns the pointer to the underlay byte array.
func NoEscapeStringDataPointer ¶
NoEscapeStringDataPointer is NoEscapeStringData but returns an unsafe.Pointer.
Types ¶
type NoCompare ¶
type NoCompare [0]func()
NoCompare may be added to structs to disable generating code to compare the struct value.
type NoCopy ¶
type NoCopy struct{}
NoCopy may be added to structs which must not be copied after the first use.
See https://golang.org/issues/8005#issuecomment-190753527 for details.
Note that it must not be embedded, due to the Lock and Unlock methods.
type NotInHeap ¶
NotInHeap is a type must never be allocated from the GC'd heap or on the stack, and is called not-in-heap.
Other types can embed NotInHeap to make it not-in-heap. Specifically, pointers to these types must always fail the `runtime.inheap` check. The type may be used for global variables, or for objects in unmanaged memory (e.g., allocated with `sysAlloc`, `persistentalloc`, r`fixalloc`, or from a manually-managed span).
Specifically:
1. `new(T)`, `make([]T)`, `append([]T, ...)` and implicit heap allocation of T are disallowed. (Though implicit allocations are disallowed in the runtime anyway.)
2. A pointer to a regular type (other than `unsafe.Pointer`) cannot be converted to a pointer to a not-in-heap type, even if they have the same underlying type.
3. Any type that containing a not-in-heap type is itself considered as not-in-heap.
- Structs and arrays are not-in-heap if their elements are not-in-heap. - Maps and channels contains no-in-heap types are disallowed.
4. Write barriers on pointers to not-in-heap types can be omitted.
The last point is the real benefit of NotInHeap. The runtime uses it for low-level internal structures to avoid memory barriers in the scheduler and the memory allocator where they are illegal or simply inefficient. This mechanism is reasonably safe and does not compromise the readability of the runtime.
type SelfPointing ¶
type SelfPointing struct{}
SelfPointing marks a struct field as a pointer may pointing to data inside the same struct.
When using, add an extra field right before the pointer whose name MUST be "_" + <name of the pointed field>.
For example:
type T struct {
_storage mark.SelfPointing
buf []byte
_foo mark.SelfPointing
f *uint
foo uint
storage [1024]byte
}
T.buf is a slice whose first field is a pointer may be pointing at storage, which is:
unsafe.Pointer(unsafe.SliceData(T.buf)) == unsafe.Pointer(&storage)