Documentation
¶
Overview ¶
Package lower computes and applies the text edits that turn Go+ source into Go. Edits operate on original source bytes — the AST and type information decide where to edit, but bytes are the medium, so untouched regions (comments, formatting) pass through losslessly.
Index ¶
- Constants
- func Apply(src []byte, edits []Edit) ([]byte, error)
- type Edit
- func ClassEdits(f *syntax.File, c *syntax.ClassDecl) []Edit
- func Decl(f *syntax.File, gm *syntax.GenericMethod, funcName string, ...) []Edit
- func DelegateEdits(f *syntax.File, d *syntax.DelegateField) []Edit
- func EnumEdits(f *syntax.File, e *syntax.EnumDecl, spec *EnumSpec) []Edit
- func InstanceEdits(f *syntax.File, d *syntax.InstanceDecl) []Edit
- func MarkerInsert(f *syntax.File, gm *syntax.GenericMethod, marker string) Edit
- func QuantityEdits(f *syntax.File, q *syntax.QuantityParam) []Edit
- func RefinementEdits(f *syntax.File, d *syntax.RefinementDecl) []Edit
- type EnumSpec
- type EnumVariantSpec
- type FieldSpec
- type Hoister
- type TParam
- type TailError
Constants ¶
const ( // BareCarrierPrefix marks a pipeline segment awaiting member-vs- // function resolution: __gp_bare_Map(head, args…). BareCarrierPrefix = "__gp_bare_" // SegCarrierPrefix marks a direct-callee segment awaiting the flowing // type: __gp_seg1(head, callee, fixedArgs…) — the digit is the piped // value's insertion index among the final args. SegCarrierPrefix = "__gp_seg" // DotCarrier wraps a dot-segment's receiver: __gp_dot(head).Suffix… DotCarrier = "__gp_dot" // ComposeCarrier marks a one-track composition: __gp_comp(f, g, …). ComposeCarrier = "__gp_comp" // KleisliCarrierPrefix marks a mixed/railway composition with per-link // kinds encoded as letters: __gp_kcomp_kc(f, g, h). KleisliCarrierPrefix = "__gp_kcomp_" )
const PatternCarrier = "//goplus:pattern "
PatternCarrier is the comment prefix threading pattern structure through the resolution fixpoint. The resolver deletes each carrier as it expands the arm — the fixpoint's progress signal for matches.
const TailPrefix = "//goplus:tail"
TailPrefix marks a function declared with the Go+ `tail` modifier.
const ValCarrierPrefix = "__gp_val"
ValCarrierPrefix defers an expression-form temp's type to resolution: `__gp_v0 := __gp_val0()`.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Edit ¶
Edit replaces src[Start:End] with New. A zero-width edit (Start == End) is an insertion.
func ClassEdits ¶
ClassEdits lowers one class declaration.
func Decl ¶
Decl computes the edits lowering one generic method declaration to a package-level function declaration named funcName:
func (s Stack[T]) Map[U any](f func(T) U) Stack[U] { … }
→ func StackMap[T any, U any](s Stack[T], f func(T) U) Stack[U] { … }
The body is untouched: the receiver keeps its name, now as the first parameter.
func DelegateEdits ¶
func DelegateEdits(f *syntax.File, d *syntax.DelegateField) []Edit
DelegateEdits lowers one delegate field.
func EnumEdits ¶
EnumEdits lowers one enum declaration: a marker line above the decl and a single replacement of the `type X enum { … }` span with the sealed interface, variant structs, and marker methods.
func InstanceEdits ¶
func InstanceEdits(f *syntax.File, d *syntax.InstanceDecl) []Edit
InstanceEdits lowers one instance declaration.
func MarkerInsert ¶
MarkerInsert computes the edit inserting a marker comment line directly above a method's declaration (above its doc comment, if any).
func QuantityEdits ¶
func QuantityEdits(f *syntax.File, q *syntax.QuantityParam) []Edit
QuantityEdits strips one parameter's quantity prefix.
func RefinementEdits ¶ added in v0.22.0
func RefinementEdits(f *syntax.File, d *syntax.RefinementDecl) []Edit
RefinementEdits erases a refinement declaration to a Go alias while retaining its proof contract in a machine-readable marker.
type EnumSpec ¶
type EnumSpec struct {
Name string // enum (interface) type name
TParamsSrc string // full tparam list with constraints, e.g. "T any"; ""
TParamNames []string
MarkerName string // sealed marker method, e.g. "isOption"
EnumMarker string // "//goplus:enum Option[T any]"
Variants []EnumVariantSpec
FoldText string // derived Cases struct + Fold function (v0.6.0); "" = none
TraversalText string // derived Children/Universe/Transform (v0.11.0); "" = none
EqualText string // derived Equal/EqualWith/EqOverrides (v0.11.0); "" = none
ViewName string // erased GADT view helper; empty when every case head is spellable
ViewMethod string // sealed per-variant payload method
Transparent bool // concrete alias representation for one monomorphic variant
BoxPointer bool // //goplus:box pointer — markers on pointer receivers
}
EnumSpec is a fully-resolved enum ready to render: names assigned, GADT result types analyzed, field types substituted. Computed by gen.
type EnumVariantSpec ¶
type EnumVariantSpec struct {
GoplusName string // constructor name as written, e.g. "Some"
Doc string // variant doc comment, newline-terminated lines; "" = none
TypeName string // lowered struct name
TParamsSrc string // kept tparams with constraints; "" for ground variants
TParamNames []string // kept tparam names
MarkerArgs []string // sealed-method parameter types (result type args)
Fields []FieldSpec
ParamNames []string // original parameter names, aligned with Fields
Marker string // "//goplus:variant (Option[T]) Some(value T)"
ViewTag int // stable declaration-order discriminator
}
EnumVariantSpec is one variant ready to render.
type Hoister ¶
type Hoister struct {
// contains filtered or unexported fields
}
Hoister renders a file's pass-1 flow and expression-form lowerings.
func NewHoister ¶
NewHoister prepares pass-1 rendering; matchStmtCount seeds skeleton numbering past the statement matches.
type TParam ¶
TParam is a resolved receiver type parameter: its name as written on the receiver and its constraint (rendered in receiver-name terms).
type TailError ¶ added in v0.21.0
TailError describes an invalid use of the recur tail-call intrinsic.
func LowerTailCalls ¶ added in v0.21.0
LowerTailCalls lowers explicit recur(nextArgs...) tail statements to a labelled loop. It runs after the other Go+ source rewrites, so recur works uniformly inside authored Go control flow and lowered constructs such as match.