rewrite

package
v0.1.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package rewrite applies declarative Go injection templates to a package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindingShapes

func BindingShapes(pkg string, sources []Source, rule Rule) (map[string]Binding, error)

BindingShapes captures syntax identities, not type equivalence. Only the semantic package may certify these pairs after checking actual Go types.

func CanonicalSignature

func CanonicalSignature(importPath string, sources []Source, symbol string) (string, error)

CanonicalSignature resolves a native bridge target using the same normalized signature representation returned in Result.Links. Methods, generics, bodyless functions and compiler intrinsics are deliberately outside the bridge contract.

Types

type Binding

type Binding struct{ Template, Target string }
type Link struct {
	Symbol, Signature string
	Checked           bool
}

Link describes a native go:linkname declaration that needs link closure.

type Match

type Match struct {
	Rule, Target, Function string
	Order                  int
}

Match records an applied declaration or function injection.

type Result

type Result struct {
	Replacements map[string][]byte
	Additions    map[string][]byte
	Imports      []string
	Links        []Link
	Matches      []Match
}

Result contains only changed source files and newly added Go files. Additions with a main/ prefix must be routed to the application's main package.

func Declarations

func Declarations(importPath string, sources []Source, rules []Rule) (*Result, error)

Declarations prepares the actual target type environment before signatures are bound, without injecting function bodies or guessing type equivalence.

func Package

func Package(importPath string, sources []Source, rules []Rule) (result *Result, err error)

Package applies all selected rules atomically in memory. It never changes the input buffers or writes files. A selected rule that does not match is an error.

type Rule

type Rule struct {
	Path, Target, File, Provider, ID string
	Source                           []byte
	ImportNames                      map[string]string
	// Bindings is populated by Go type checking. Syntax pairs ensure workers
	// apply the proof to exactly the declarations which were checked.
	Bindings map[string]Binding
}

Rule is a selected template. Target names a package ("main" for the application entry); File optionally narrows a file target to one named source file within that package, and is empty for package-level targets whose declarations match anywhere in the package. Provider and ID distinguish independently distributed injection templates.

type Source

type Source struct {
	Path string
	Data []byte
	// ImportNames maps import paths to authoritative package names from go list.
	ImportNames map[string]string
}

Source is one selected, buildable Go source file in the target package.

Jump to

Keyboard shortcuts

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