mark

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package mark provides markers for special compiler behavior

Index

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

func NoEscapeBytesString[T ~byte](s []T) string

NoEscapeBytesString is NoEscapeString but taking bytes as the argument.

func NoEscapePointer

func NoEscapePointer[T any](p *T) unsafe.Pointer

NoEscapePointer is NoEscape but returns unsafe.Pointer.

func NoEscapeSlice

func NoEscapeSlice[T any](p []T) []T

NoEscapeSlice is NoEscape for slices.

func NoEscapeSliceData

func NoEscapeSliceData[T any](p []T) *T

NoEscapeSliceData is NoEscapeSlice but returns the pointer to the underlay array.

func NoEscapeSliceDataPointer

func NoEscapeSliceDataPointer[T any](p []T) unsafe.Pointer

NoEscapeSliceDataPointer is NoEscapeSliceData but returns an unsafe.Pointer.

func NoEscapeString

func NoEscapeString[String ~string](s String) String

NoEscapeString is NoEscape for string.

func NoEscapeStringData

func NoEscapeStringData[String ~string](s String) *byte

NoEscapeStringData is NoEscapeString but returns the pointer to the underlay byte array.

func NoEscapeStringDataPointer

func NoEscapeStringDataPointer[String ~string](s String) unsafe.Pointer

NoEscapeStringDataPointer is NoEscapeStringData but returns an unsafe.Pointer.

func NoEscapeUnsafePointer

func NoEscapeUnsafePointer(p unsafe.Pointer) unsafe.Pointer

Types

type Align64

type Align64 = atomic.Align64

Align64 may be added to structs that must be 64-bit aligned.

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.

func (*NoCopy) Lock

func (*NoCopy) Lock()

Lock is a no-op used by -copylocks checker from `go vet`.

func (*NoCopy) Unlock

func (*NoCopy) Unlock()

type NotInHeap

type NotInHeap = sys.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)

Directories

Path Synopsis
internal
sys

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL