stubs

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package stubs is the method-signature "shape" catalog (S1..S16) that lets interpreted methods satisfy native stdlib interfaces (fmt.Stringer, json.Marshaler, sort.Interface, io.Reader, ...) at the reflect boundary.

Each shape has a generated stub pool (pool_s*.go) and a hand-written handler dispatcher (registry_s*.go). The Attach* wrappers resolve a method's shape to a free stub slot PC, then delegate rtype synthesis to runtype.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FillMethods

func FillMethods(res *runtype.Reservation, methods []Method) error

FillMethods installs methods into a reserved rtype in place (the reserve/fill path), resolving each method's stub slot first.

func SlotsUsedS1

func SlotsUsedS1() uint32

SlotsUsedS1 reports how many S1 stub slots have been consumed. Exported for tests that verify idempotency at the interp layer.

func SlotsUsedS2

func SlotsUsedS2() uint32

SlotsUsedS2 reports how many S2 stub slots have been consumed.

func SlotsUsedS3

func SlotsUsedS3() uint32

SlotsUsedS3 reports how many S3 stub slots have been consumed.

func SlotsUsedS4

func SlotsUsedS4() uint32

SlotsUsedS4 reports how many S4 stub slots have been consumed.

func SlotsUsedS5

func SlotsUsedS5() uint32

SlotsUsedS5 reports how many S5 stub slots have been consumed.

func SlotsUsedS6

func SlotsUsedS6() uint32

SlotsUsedS6 reports how many S6 stub slots have been consumed.

func SlotsUsedS7

func SlotsUsedS7() uint32

SlotsUsedS7 reports how many S7 stub slots have been consumed.

func SlotsUsedS8

func SlotsUsedS8() uint32

SlotsUsedS8 reports how many S8 stub slots have been consumed.

func SlotsUsedS9

func SlotsUsedS9() uint32

SlotsUsedS9 reports how many S9 stub slots have been consumed.

func SlotsUsedS10

func SlotsUsedS10() uint32

SlotsUsedS10 reports how many S10 stub slots have been consumed.

func SlotsUsedS11

func SlotsUsedS11() uint32

SlotsUsedS11 reports how many S11 stub slots have been consumed.

func SlotsUsedS12

func SlotsUsedS12() uint32

SlotsUsedS12 reports how many S12 stub slots have been consumed.

func SlotsUsedS13

func SlotsUsedS13() uint32

SlotsUsedS13 reports how many S13 stub slots have been consumed.

func SlotsUsedS14

func SlotsUsedS14() uint32

SlotsUsedS14 reports how many S14 stub slots have been consumed.

func SlotsUsedS15

func SlotsUsedS15() uint32

SlotsUsedS15 reports how many S15 stub slots have been consumed.

func SlotsUsedS16

func SlotsUsedS16() uint32

SlotsUsedS16 reports how many S16 stub slots have been consumed.

func SlotsUsedS17

func SlotsUsedS17() uint32

SlotsUsedS17 reports how many S17 stub slots have been consumed.

func SlotsUsedS18

func SlotsUsedS18() uint32

SlotsUsedS18 reports how many S18 stub slots have been consumed.

func SlotsUsedS19

func SlotsUsedS19() uint32

SlotsUsedS19 reports how many S19 stub slots have been consumed.

func SlotsUsedS20

func SlotsUsedS20() uint32

SlotsUsedS20 reports how many S20 stub slots have been consumed.

func SlotsUsedS21

func SlotsUsedS21() uint32

SlotsUsedS21 reports how many S21 stub slots have been consumed.

func SlotsUsedS22

func SlotsUsedS22() uint32

SlotsUsedS22 reports how many S22 stub slots have been consumed.

func SlotsUsedS23

func SlotsUsedS23() uint32

SlotsUsedS23 reports how many S23 stub slots have been consumed.

func SlotsUsedS24

func SlotsUsedS24() uint32

SlotsUsedS24 reports how many S24 stub slots have been consumed.

func SlotsUsedS25

func SlotsUsedS25() uint32

SlotsUsedS25 reports how many S25 stub slots have been consumed.

func SlotsUsedS26

func SlotsUsedS26() uint32

SlotsUsedS26 reports how many S26 stub slots have been consumed.

func SlotsUsedS27

func SlotsUsedS27() uint32

SlotsUsedS27 reports how many S27 stub slots have been consumed.

func SlotsUsedS28

func SlotsUsedS28() uint32

SlotsUsedS28 reports how many S28 stub slots have been consumed.

func SlotsUsedS29

func SlotsUsedS29() uint32

SlotsUsedS29 reports how many S29 stub slots have been consumed.

func SlotsUsedS30

func SlotsUsedS30() uint32

SlotsUsedS30 reports how many S30 stub slots have been consumed.

func SlotsUsedS31

func SlotsUsedS31() uint32

SlotsUsedS31 reports how many S31 stub slots have been consumed.

Types

type HandlerS1

type HandlerS1 = func(recv unsafe.Pointer) string

HandlerS1 is the per-method callback for shape S1: func(*T) string. recv is the receiver pointer per Go's iface-dispatch convention. For non-direct kinds it points at the boxed value; for direct-iface kinds it IS the value reinterpreted as a pointer.

type HandlerS2

type HandlerS2 = func(recv unsafe.Pointer) ([]byte, error)

HandlerS2 is the per-method callback for shape S2: func(*T) ([]byte, error). Covers MarshalJSON, MarshalBinary, MarshalText.

type HandlerS3

type HandlerS3 = func(recv unsafe.Pointer, data []byte) error

HandlerS3 is the per-method callback for shape S3: func(*T, []byte) error. Covers UnmarshalJSON, UnmarshalBinary, UnmarshalText.

type HandlerS4

type HandlerS4 = func(recv unsafe.Pointer, target error) bool

HandlerS4 is the per-method callback for shape S4: func(*T, error) bool. Covers errors.Is dispatch: (T).Is(target error) bool.

type HandlerS5

type HandlerS5 = func(recv unsafe.Pointer, target any) bool

HandlerS5 is the per-method callback for shape S5: func(*T, any) bool. Covers errors.As dispatch: (T).As(target any) bool, where target is a non-nil pointer the method writes through.

type HandlerS6

type HandlerS6 = func(recv unsafe.Pointer) error

HandlerS6 is the per-method callback for shape S6: func(*T) error. Covers single-error unwrap: (T).Unwrap() error.

type HandlerS7

type HandlerS7 = func(recv unsafe.Pointer) []error

HandlerS7 is the per-method callback for shape S7: func(*T) []error. Covers multi-error unwrap: (T).Unwrap() []error.

type HandlerS8

type HandlerS8 = func(recv unsafe.Pointer) int

HandlerS8 is the per-method callback for shape S8: func(*T) int. Covers sort.Interface.Len.

type HandlerS9

type HandlerS9 = func(recv unsafe.Pointer, i, j int) bool

HandlerS9 is the per-method callback for shape S9: func(*T, int, int) bool. Covers sort.Interface.Less.

type HandlerS10

type HandlerS10 = func(recv unsafe.Pointer, i, j int)

HandlerS10 is the per-method callback for shape S10: func(*T, int, int). Covers sort.Interface.Swap (no result).

type HandlerS11

type HandlerS11 = func(recv unsafe.Pointer, x any)

HandlerS11 is the per-method callback for shape S11: func(*T, any). Covers heap.Interface.Push (no result).

type HandlerS12

type HandlerS12 = func(recv unsafe.Pointer) any

HandlerS12 is the per-method callback for shape S12: func(*T) any. Covers heap.Interface.Pop.

type HandlerS13

type HandlerS13 = func(recv unsafe.Pointer, p []byte) (int, error)

HandlerS13 is the per-method callback for shape S13: func(*T, []byte) (int, error). Covers io.Reader.Read and io.Writer.Write.

type HandlerS14

type HandlerS14 = func(recv unsafe.Pointer, st fmt.State, verb rune)

HandlerS14 is the per-method callback for shape S14: func(*T, fmt.State, rune). Covers fmt.Formatter.Format (no result).

type HandlerS15

type HandlerS15 = func(recv unsafe.Pointer, e *xml.Encoder, start xml.StartElement) error

HandlerS15 is the per-method callback for shape S15: func(*T, *xml.Encoder, xml.StartElement) error. Covers xml.Marshaler.MarshalXML.

type HandlerS16

type HandlerS16 = func(recv unsafe.Pointer, d *xml.Decoder, start xml.StartElement) error

HandlerS16 is the per-method callback for shape S16: func(*T, *xml.Decoder, xml.StartElement) error. Covers xml.Unmarshaler.UnmarshalXML.

type HandlerS17

type HandlerS17 = func(recv unsafe.Pointer) (int, bool)

HandlerS17 is the per-method callback for shape S17: func(*T) (int, bool). Covers fmt.State.Width and fmt.State.Precision.

type HandlerS18

type HandlerS18 = func(recv unsafe.Pointer, c int) bool

HandlerS18 is the per-method callback for shape S18: func(*T, int) bool. Covers fmt.State.Flag.

type HandlerS19

type HandlerS19 = func(recv unsafe.Pointer, st fmt.ScanState, verb rune) error

HandlerS19 is the per-method callback for shape S19: func(*T, fmt.ScanState, rune) error. Covers fmt.Scanner.Scan.

type HandlerS20

type HandlerS20 = func(recv unsafe.Pointer, value string) error

HandlerS20 is the per-method callback for shape S20: func(*T, string) error. Covers flag.Value.Set.

type HandlerS21

type HandlerS21 = func(recv unsafe.Pointer) bool

HandlerS21 is the per-method callback for shape S21: func(*T) bool. Covers flag.boolFlag.IsBoolFlag.

type HandlerS22

type HandlerS22 = func(recv unsafe.Pointer) int64

HandlerS22 is the per-method callback for shape S22: func(*T) int64. Covers fs.FileInfo.Size.

type HandlerS23

type HandlerS23 = func(recv unsafe.Pointer) fs.FileMode

HandlerS23 is the per-method callback for shape S23: func(*T) fs.FileMode. Covers fs.FileInfo.Mode and fs.DirEntry.Type.

type HandlerS24

type HandlerS24 = func(recv unsafe.Pointer) time.Time

HandlerS24 is the per-method callback for shape S24: func(*T) time.Time. Covers fs.FileInfo.ModTime.

type HandlerS25

type HandlerS25 = func(recv unsafe.Pointer) (fs.FileInfo, error)

HandlerS25 is the per-method callback for shape S25: func(*T) (fs.FileInfo, error). Covers fs.DirEntry.Info and fs.File.Stat.

type HandlerS26

type HandlerS26 = func(recv unsafe.Pointer, name string) (fs.File, error)

HandlerS26 is the per-method callback for shape S26: func(*T, string) (fs.File, error). Covers fs.FS.Open.

type HandlerS27

type HandlerS27 = func(recv unsafe.Pointer, name string) (fs.FileInfo, error)

HandlerS27 is the per-method callback for shape S27: func(*T, string) (fs.FileInfo, error). Covers fs.StatFS.Stat.

type HandlerS28

type HandlerS28 = func(recv unsafe.Pointer, dir string) (fs.FS, error)

HandlerS28 is the per-method callback for shape S28: func(*T, string) (fs.FS, error). Covers fs.SubFS.Sub.

type HandlerS29

type HandlerS29 = func(recv unsafe.Pointer, pattern string) ([]string, error)

HandlerS29 is the per-method callback for shape S29: func(*T, string) ([]string, error). Covers fs.GlobFS.Glob.

type HandlerS30

type HandlerS30 = func(recv unsafe.Pointer, name string) ([]fs.DirEntry, error)

HandlerS30 is the per-method callback for shape S30: func(*T, string) ([]fs.DirEntry, error). Covers fs.ReadDirFS.ReadDir.

type HandlerS31

type HandlerS31 = func(recv unsafe.Pointer, name string) ([]byte, error)

HandlerS31 is the per-method callback for shape S31: func(*T, string) ([]byte, error). Covers fs.ReadFileFS.ReadFile.

type Method

type Method struct {
	Name     string
	Exported bool
	Sig      reflect.Type
	Shape    Shape
	Handler  any
}

Method describes one method to install on a synthesized type. Shape selects which stub pool the slot comes from; Handler must be the matching HandlerS* function type for the Shape (default ShapeS1 expects HandlerS1).

type Shape

type Shape uint8

Shape identifies a method-signature shape. Each shape has its own stub pool, handler type, and dispatcher. New shapes can be added without touching existing shapes.

const (
	// ShapeS1 is func() string.
	// Covers fmt.Stringer.String, error.Error, fmt.GoStringer.GoString,
	// flag.Value.String.
	ShapeS1 Shape = 0

	// ShapeS2 is func() ([]byte, error).
	// Covers json.Marshaler.MarshalJSON, encoding.BinaryMarshaler,
	// encoding.TextMarshaler, xml.Marshaler.MarshalXML (almost; subset).
	ShapeS2 Shape = 1

	// ShapeS3 is func([]byte) error.
	// Covers json.Unmarshaler.UnmarshalJSON, encoding.BinaryUnmarshaler,
	// encoding.TextUnmarshaler.
	ShapeS3 Shape = 2

	// ShapeS4 is func(error) bool.
	// Covers the errors-tree predicate errors.Is dispatches: (T).Is(error) bool.
	ShapeS4 Shape = 3

	// ShapeS5 is func(any) bool.
	// Covers errors.As dispatch: (T).As(any) bool.
	ShapeS5 Shape = 4

	// ShapeS6 is func() error.
	// Covers single-error unwrap: (T).Unwrap() error.
	ShapeS6 Shape = 5

	// ShapeS7 is func() []error.
	// Covers multi-error unwrap: (T).Unwrap() []error.
	ShapeS7 Shape = 6

	// ShapeS8 is func() int.
	// Covers sort.Interface.Len.
	ShapeS8 Shape = 7

	// ShapeS9 is func(int, int) bool.
	// Covers sort.Interface.Less.
	ShapeS9 Shape = 8

	// ShapeS10 is func(int, int).
	// Covers sort.Interface.Swap.
	ShapeS10 Shape = 9

	// ShapeS11 is func(any).
	// Covers heap.Interface.Push.
	ShapeS11 Shape = 10

	// ShapeS12 is func() any.
	// Covers heap.Interface.Pop.
	ShapeS12 Shape = 11

	// ShapeS13 is func([]byte) (int, error).
	// Covers io.Reader.Read and io.Writer.Write.
	ShapeS13 Shape = 12

	// ShapeS14 is func(fmt.State, rune).
	// Covers fmt.Formatter.Format.
	ShapeS14 Shape = 13

	// ShapeS15 is func(*xml.Encoder, xml.StartElement) error.
	// Covers xml.Marshaler.MarshalXML.
	ShapeS15 Shape = 14

	// ShapeS16 is func(*xml.Decoder, xml.StartElement) error.
	// Covers xml.Unmarshaler.UnmarshalXML.
	ShapeS16 Shape = 15

	// ShapeS17 is func() (int, bool).
	// Covers fmt.State.Width and fmt.State.Precision.
	ShapeS17 Shape = 16

	// ShapeS18 is func(int) bool.
	// Covers fmt.State.Flag.
	ShapeS18 Shape = 17

	// ShapeS19 is func(fmt.ScanState, rune) error.
	// Covers fmt.Scanner.Scan.
	ShapeS19 Shape = 18

	// ShapeS20 is func(string) error.
	// Covers flag.Value.Set.
	ShapeS20 Shape = 19

	// ShapeS21 is func() bool.
	// Covers flag.boolFlag.IsBoolFlag.
	ShapeS21 Shape = 20

	// ShapeS22 is func() int64. Covers fs.FileInfo.Size.
	ShapeS22 Shape = 21
	// ShapeS23 is func() fs.FileMode. Covers fs.FileInfo.Mode and fs.DirEntry.Type.
	ShapeS23 Shape = 22
	// ShapeS24 is func() time.Time. Covers fs.FileInfo.ModTime.
	ShapeS24 Shape = 23
	// ShapeS25 is func() (fs.FileInfo, error). Covers fs.DirEntry.Info and fs.File.Stat.
	ShapeS25 Shape = 24
	// ShapeS26 is func(string) (fs.File, error). Covers fs.FS.Open.
	ShapeS26 Shape = 25
	// ShapeS27 is func(string) (fs.FileInfo, error). Covers fs.StatFS.Stat.
	ShapeS27 Shape = 26
	// ShapeS28 is func(string) (fs.FS, error). Covers fs.SubFS.Sub.
	ShapeS28 Shape = 27
	// ShapeS29 is func(string) ([]string, error). Covers fs.GlobFS.Glob.
	ShapeS29 Shape = 28
	// ShapeS30 is func(string) ([]fs.DirEntry, error). Covers fs.ReadDirFS.ReadDir.
	ShapeS30 Shape = 29
	// ShapeS31 is func(string) ([]byte, error). Covers fs.ReadFileFS.ReadFile.
	ShapeS31 Shape = 30
)

Jump to

Keyboard shortcuts

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