ir

package
v0.38.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 52 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ir defines the intermediate representation used by Protocompile.

This package provides both the IR, and the lowering machinery for that IR. The IR is intended to provide a richer and easier to manipulate structure compared to a FileDescriptorProto. This structure is used for name resolution, type checking, tag number validation, and other semantic operations.

Index

Constants

View Source
const (
	// NullMaskName is the name of the generated field.
	NullMaskName = "_null"
	// NullMaskJSONName is its JSON name, as protoc derives it from
	// [NullMaskName].
	NullMaskJSONName = "Null"
	// NullMaskNumber is the field number protowire claims for the mask in
	// every message that gets one: the highest legal field number, which
	// hand-numbered fields almost never reach. It is fixed so that no
	// schema change can move the mask.
	NullMaskNumber int32 = 536870911
	// NullMaskTypeName is the mask's message type.
	NullMaskTypeName FullName = "google.protobuf.FieldMask"
	// NullMaskImport is the file that declares [NullMaskTypeName].
	NullMaskImport = "google/protobuf/field_mask.proto"
)

The `_null` mask (protocompile#248). PXF decoders record the paths of fields a document sets to null in a message's `_null` FieldMask, and encoders write those fields back as `field = null`; without the mask a null and an absent field are the same on the wire. With masks enabled, lowering adds the field to every message that has a field able to hold null, so a schema author does not have to declare it.

View Source
const DescriptorProtoPath = "google/protobuf/descriptor.proto"
View Source
const MaxNumericLiteralDigits = 4096

MaxNumericLiteralDigits is protowire's hardening limit on the digit count of a numeric literal and on the magnitude of pxf.Decimal.scale on the wire (protowire HARDENING.md, "Mandatory limits"; draft -01 § Mandatory Limits as amended by trendvidia/protowire#278). It is a decoder limit, and it binds the compiler through what the compiler emits: a binder renders a pxf.BigInt or pxf.Decimal default back into a PXF literal and refuses one past the cap, so a carrier beyond it is a schema no decoder accepts. It lives here, with the rest of the carrier semantics, rather than in the generic big-number helpers.

Variables

This section is empty.

Functions

func CanonicalizeFilePath

func CanonicalizeFilePath(path string) string

CanonicalizeFilePath puts a file path into canonical form.

This function is exported so that all code depending on this module can make sure paths are consistently canonicalized.

func DedupExportedSymbols

func DedupExportedSymbols(r *report.Report, files ...*File)

DedupExportedSymbols takes a report and the given *[File]s and checks for duplicate exported symbols based on FullName across the files.

Diagnostics are provided only for the highest level of duplication. For example, given the following files and content:

-- a1.proto --
syntax = "proto3";
package a;

message Foo {
 optional string bar = 1;
}

-- a2.proto --
syntax = "proto3";
package a;

message Foo {
 optional string bar = 1;
}

A diagnostic for the duplication of `a.Foo` would be surfaced, but it would be redundant to surface diagnostics for `a.Foo.bar`..

func DedupExtensions

func DedupExtensions(r *report.Report, files ...*File)

DedupExtensionTags takes a report and the given *[File]s and checks for duplicate tags for the same extendee. This ensures that a single tag is only used in a single extension across the given files.

func GetRef

func GetRef[T ~id.Node[T, *File, Raw], Raw any](base *File, r Ref[T]) T

Get vets the value that a reference refers to.

func NeedsNullMask added in v0.35.0

func NeedsNullMask(ty Type) bool

NeedsNullMask reports whether lowering with masks enabled adds a `_null` field to ty. It does not consult File.NullMasks; callers check the file first.

func OptionTargets

func OptionTargets() iter.Seq[OptionTarget]

OptionTargets returns an iterator over all of the possible valid targets, which excludes OptionTargetInvalid.

func TopoSort

func TopoSort(files []*File) iter.Seq[*File]

TopoSort sorts a graph of [File]s according to their dependency graph, in topological order. Files with no dependencies are yielded first.

Types

type Annotation

type Annotation id.Node[Annotation, *File, *rawAnnotation]

Annotation is an `annotation` declaration introduced by the Protowire Schema Extensions (PSE) grammar — see ast.DeclAnnotation.

Annotation declarations name a metadata attachment that use sites reference via `@name(args)` syntax (see ast.DeclAnnotationUse). They live in the file's exported symbol table under SymbolKindAnnotation so cross-file resolution works the same way it does for `message` and `service`.

This is Phase B1 scope: symbol registration only. Subsequent phases will add use-site name resolution, argument type-checking against the parameter signature, and FDP emission via the universal annotation carrier extension.

func (Annotation) AST

func (a Annotation) AST() ast.DeclAnnotation

AST returns the declaration for this annotation, if known.

func (Annotation) Annotations

func (a Annotation) Annotations() seq.Indexer[AnnotationUse]

Annotations returns the annotation use sites attached to this declaration (trailing form: `annotation foo @bar @baz;`). See Type.Annotations for the resolution model.

func (Annotation) FullName

func (a Annotation) FullName() FullName

FullName returns this annotation's fully-qualified name.

func (Annotation) InternedFullName

func (a Annotation) InternedFullName() intern.ID

InternedFullName returns the intern ID for Annotation.FullName.

func (Annotation) InternedName

func (a Annotation) InternedName() intern.ID

InternedName returns the intern ID for Annotation.FullName().Name().

func (Annotation) Name

func (a Annotation) Name() string

Name returns this annotation's declared name, i.e. the last component of its full name.

func (Annotation) Params

func (a Annotation) Params() seq.Indexer[AnnotationParam]

Params returns the parameters of this annotation declaration.

func (Annotation) ResolveEnumValueDefault

func (a Annotation) ResolveEnumValueDefault(path ast.Path) Member

ResolveEnumValueDefault resolves a qualified-identifier default expression of one of this annotation's parameters as an enum-value reference, relative to the declaration's own scope. Returns a zero Member when the name does not resolve to an enum value.

Like AnnotationUse.ResolveEnumValueArg, this resolution is quiet; the B3 defaults validator performs the same resolution with diagnostics.

type AnnotationArgBinding

type AnnotationArgBinding struct {
	Arg   ast.AnnotationUseArg
	Param AnnotationParam
}

AnnotationArgBinding pairs one use-site argument with the parameter of the resolved target Annotation that it binds.

Positional arguments bind parameters left to right; named arguments bind the parameter with the matching name. Param is zero when the argument does not bind anything — an excess positional argument or an unknown name — in which case the B3 validation pass has emitted a diagnostic.

type AnnotationEnumValue added in v0.36.0

type AnnotationEnumValue struct {
	Spelling string
	Value    Member
}

AnnotationEnumValue is one enum value reference in an expression- classified annotation argument (RFC-001 §5.4, §8.1): its canonical spelling and the enum value it resolved to.

type AnnotationFunctionCall

type AnnotationFunctionCall struct {
	// The resolved function declaration.
	Target Function
	// The call site's arity: its count of top-level commas plus one,
	// or zero for empty parentheses.
	Arity int
	// The call site's source span (the identifier through the closing
	// parenthesis), for diagnostics and source-map anchoring.
	Span source.Span
}

AnnotationFunctionCall is one function-call site extracted from an expression-classified annotation argument, per RFC-001 §8.1: a maximal qualified identifier immediately followed by `(...)` whose name resolves to a visible `function` declaration.

type AnnotationParam

type AnnotationParam id.Node[AnnotationParam, *File, *rawAnnotationParam]

AnnotationParam is a single parameter of an Annotation declaration — see ast.DeclAnnotationParam.

Parameters carry a name, a declared type, and an optional default expression. Phase B1 stores the AST link and the parameter name; type-resolution into [TypeAny] and default-value lowering land in later phases together with use-site type-checking.

func (AnnotationParam) AST

AST returns the declaration for this annotation parameter, if known.

func (AnnotationParam) Annotation

func (p AnnotationParam) Annotation() Annotation

Annotation returns the annotation declaration that this parameter belongs to.

func (AnnotationParam) Default

func (p AnnotationParam) Default() ast.ExprAny

Default returns the default-value expression syntactically attached to this parameter (e.g. the `"hi"` in `annotation foo(x: string = "hi")`). Returns a zero ast.ExprAny when the parameter has no default — callers should check `defaultExpr.IsZero()` before lowering.

The expression has been shape-checked by the parser's narrow annotation-argument legalize pass and type-checked by the resolution pass — see [validateAnnotationParamDefaults].

func (AnnotationParam) DefaultCalls added in v0.36.0

func (p AnnotationParam) DefaultCalls() []AnnotationFunctionCall

DefaultCalls is AnnotationUse.ExtractCalls for an `expression`-typed parameter's default, whose names resolve from the annotation declaration's scope.

func (AnnotationParam) DefaultEnumValues added in v0.36.0

func (p AnnotationParam) DefaultEnumValues() []AnnotationEnumValue

DefaultEnumValues is AnnotationUse.ExtractEnumValues for an `expression`-typed parameter's default, whose names resolve from the annotation declaration's scope.

func (AnnotationParam) DefaultSpan added in v0.36.0

func (p AnnotationParam) DefaultSpan() source.Span

DefaultSpan returns the source of an `expression`-typed parameter's captured default (RFC-001 §5.1), or zero.

func (AnnotationParam) HasDefault added in v0.36.0

func (p AnnotationParam) HasDefault() bool

HasDefault reports whether the parameter declares a default value. An `expression`-typed default that is an engine-expression fragment has a zero AnnotationParam.Default, so ask this instead.

func (AnnotationParam) InternedName

func (p AnnotationParam) InternedName() intern.ID

InternedName returns the intern ID for AnnotationParam.Name.

func (AnnotationParam) IsAny

func (p AnnotationParam) IsAny() bool

IsAny reports whether the parameter's declared type is the special PSE pseudo-type `any` (accepts any literal-shaped argument).

func (AnnotationParam) IsExpression

func (p AnnotationParam) IsExpression() bool

IsExpression reports whether the parameter's declared type is the special PSE pseudo-type `expression`: a rule in the RFC-001 §5.4 language, kept as source text and checked by the compiler for syntax, names, builtin arity and a visibly non-boolean result.

func (AnnotationParam) IsScalar

func (p AnnotationParam) IsScalar() bool

IsScalar reports whether the parameter's declared type resolved to a predeclared scalar (string, int32, etc.).

func (AnnotationParam) Name

func (p AnnotationParam) Name() string

Name returns this parameter's declared name.

func (AnnotationParam) Scalar

func (p AnnotationParam) Scalar() predeclared.Name

Scalar returns the predeclared scalar type for this parameter, or predeclared.Unknown when the parameter's type is not a scalar. Pair with AnnotationParam.IsScalar to disambiguate "type resolved to a non-scalar" from "predeclared.Unknown is the type".

func (AnnotationParam) TypeName

func (p AnnotationParam) TypeName() string

TypeName returns the literal text of the parameter's declared type, e.g. "string", "expression", or "myco.SomeMessage". Useful for diagnostics — see AnnotationParam.IsScalar, AnnotationParam.IsExpression, AnnotationParam.IsAny, and AnnotationParam.UserType for the resolved classification.

func (AnnotationParam) UserType

func (p AnnotationParam) UserType() Type

UserType returns the resolved Type when the parameter's declared type is a user-defined message or enum. Returns a zero Type for predeclared scalars, the `expression`/`any` pseudo- types, and unresolved references.

type AnnotationUse

type AnnotationUse id.Node[AnnotationUse, *File, *rawAnnotationUse]

AnnotationUse is a single `@name(args)` annotation use site — see ast.DeclAnnotationUse. Use sites are attached to a carrier declaration via that carrier's `Annotations()` accessor (e.g. Type.Annotations, Member.Annotations, Service.Annotations).

As of Phase B2, a use site carries its source AST link plus the resolved Annotation (or a zero Ref when name resolution failed — the diagnostic is emitted at resolve time). The argument list is not yet materialised into IR values: that pairs with the signature-aware type-check in Phase B3.

func (AnnotationUse) AST

AST returns the use-site syntax for this annotation use.

func (AnnotationUse) ArgBindings

func (u AnnotationUse) ArgBindings() []AnnotationArgBinding

ArgBindings pairs this use site's arguments with the target annotation's parameters, in argument source order.

Returns bindings with a zero Param for every argument when the use site's name did not resolve.

func (AnnotationUse) ExtractCalls

ExtractCalls scans an expression-classified argument's captured token range for function-call sites and resolves each against the visible `function` declarations, per RFC-001 §8.1.

Extraction is complete with respect to declared functions: every maximal `qualifiedIdent (` occurrence whose name resolves (relative to the use site's scope) is returned, including calls nested inside other calls' argument lists. Names that do not resolve are not returned; they must be RFC-001 §5.4 builtins, and validateExpressionLanguage diagnoses those that are not.

Resolution is quiet; arity verification against the declaration is the B3 validation pass's job.

func (AnnotationUse) ExtractEnumValues added in v0.36.0

func (u AnnotationUse) ExtractEnumValues(arg ast.AnnotationUseArg) []AnnotationEnumValue

ExtractEnumValues returns the enum value references in an expression-classified argument, once per distinct spelling in source order, each resolved from the use site's scope as an enum-typed argument is. References that do not resolve are left out; the expression-language check diagnoses them. A capture that does not parse has none.

func (AnnotationUse) MessageLiteralArg

func (u AnnotationUse) MessageLiteralArg(arg ast.AnnotationUseArg) MessageValue

MessageLiteralArg returns the evaluated message value for a message-literal argument, recorded by the B3 validation pass. Returns a zero MessageValue when the argument is not a message literal or its evaluation failed.

func (AnnotationUse) MessageLiteralElem added in v0.22.0

func (u AnnotationUse) MessageLiteralElem(elem ast.ExprAny) MessageValue

MessageLiteralElem returns the evaluated message value for a typed message-literal list element, recorded by the B3 validation pass. Returns a zero MessageValue when the element is not a message literal or its evaluation failed.

func (AnnotationUse) ResolveEnumValueArg

func (u AnnotationUse) ResolveEnumValueArg(path ast.Path) Member

ResolveEnumValueArg resolves a qualified-identifier argument as an enum-value reference, relative to this use site's lexical scope. Returns a zero Member when the name does not resolve to an enum value.

This resolution is quiet: no diagnostics are emitted. The B3 validation pass performs the same resolution with diagnostics; this accessor exists so descriptor production can recover the resolved value without re-running validation.

func (AnnotationUse) Target

func (u AnnotationUse) Target() Annotation

Target returns the Annotation this use site resolves to. Returns a zero Annotation when name resolution failed (in which case the resolve pass already emitted a diagnostic).

func (AnnotationUse) TargetRef

func (u AnnotationUse) TargetRef() Ref[Symbol]

TargetRef returns the raw Ref for the resolved target symbol. Useful for callers that want to detect resolution failures (zero ref) without going through the Annotation accessor.

type ArgLiteralKind added in v0.31.0

type ArgLiteralKind int

ArgLiteralKind is the type an annotation argument carries on its own, before any target is considered.

const (
	// ArgLiteralNone is a shape this rule does not decide: an enum
	// reference, a message literal, a list.
	ArgLiteralNone  ArgLiteralKind = iota
	ArgLiteralInt                  // A number written without a point or an exponent.
	ArgLiteralFloat                // A number written with either.
	ArgLiteralString
	ArgLiteralBool
)

func ArgLiteralKindOf added in v0.31.0

func ArgLiteralKindOf(tok token.Token) ArgLiteralKind

ArgLiteralKindOf classifies a scalar literal token by how it is WRITTEN, which is what RFC-001 means by the argument carrying its own typing. Boolean arguments are identifier paths rather than literal tokens, so callers classify those themselves.

token.NumberToken.IsFloat is the spelling test: a `.` or an exponent makes a float. It did not count a positive exponent until #191, which is why this briefly needed a second predicate of its own.

func (ArgLiteralKind) String added in v0.31.0

func (k ArgLiteralKind) String() string

String names the literal's own type as an author wrote it.

type ArgMember added in v0.31.0

type ArgMember int

ArgMember names the AnnotationArg oneof member a converted argument lands in.

const (
	ArgMemberNone ArgMember = iota
	ArgMemberInt
	ArgMemberDouble
	ArgMemberBool
	ArgMemberString
	ArgMemberBytes
	ArgMemberBigInt
	ArgMemberDecimal
	ArgMemberBigFloat
)

func ConvertArgKind added in v0.31.0

func ConvertArgKind(kind ArgLiteralKind, target predeclared.Name, pxf PxfNumber) (ArgMember, bool)

ConvertArgKind reports which member a literal of kind lands in once converted to target, and whether such a conversion exists.

target is predeclared.Unknown when there is nothing to convert to: an annotation on a message, a service or a file, or on a member whose type is a message with no scalar reading. The literal's own type then stands, which is what RFC-001 means by the argument carrying its own typing.

A false second return is a KIND mismatch and is always an error — a string is not a number however it is spelled. Range and integrality are separate questions, asked only once the kind fits, because they depend on the value rather than on how it was written.

func (ArgMember) String added in v0.31.0

func (m ArgMember) String() string

String names the member as a consumer sees it, for diagnostics.

type Element

type Element struct {
	// contains filtered or unexported fields
}

Element is an element within a Value.

This exists because array values contain multiple non-array elements; this type provides uniform access to such elements. See Value.Elements.

func (Element) AST

func (e Element) AST() ast.ExprAny

AST returns the expression this value was evaluated from.

func (Element) AsBool

func (e Element) AsBool() (value, ok bool)

AsBool returns the bool value of this element.

Returns ok == false if this is not a bool.

func (Element) AsEnum

func (e Element) AsEnum() Member

AsEnum returns the value of this element as a known enum value.

Returns zero if this is not an enum or if the enum value is out of range.

func (Element) AsFloat

func (e Element) AsFloat() (float64, bool)

AsFloat returns the value of this element as a floating-point number.

Returns false if this is not a float.

func (Element) AsInt

func (e Element) AsInt() (int64, bool)

AsInt returns the value of this element as a signed integer.

Returns false if this is not a signed integer (enums are included as signed integers).

func (Element) AsMessage

func (e Element) AsMessage() MessageValue

AsMessage returns the value of this element as a message literal.

Returns the zero value if this is not a message.

func (Element) AsString

func (e Element) AsString() (string, bool)

AsString returns the value of this element as a string.

Returns false if this is not a string.

func (Element) AsUInt

func (e Element) AsUInt() (uint64, bool)

AsUInt returns the value of this element as an unsigned integer.

Returns false if this is not an unsigned integer.

func (Element) Field

func (e Element) Field() Member

Field returns the field this value sets, which includes the value's type information.

func (Element) IsZeroValue

func (e Element) IsZeroValue() bool

IsZeroValue returns whether this element contains the zero value for its type.

Always returns false for repeated or message-typed fields.

func (Element) Type

func (e Element) Type() Type

Type returns the type of this element.

Note that this may be distinct from Member.Element. In the case that this is a google.protobuf.Any-typed field, this function will return the concrete type if known, rather than Any.

func (Element) Value

func (e Element) Value() Value

Value is the Value this element came from.

func (Element) ValueNodeIndex

func (e Element) ValueNodeIndex() int

ValueNodeIndex returns the index into Value.ValueASTs for this element's contributing expression. This can be used to obtain other ASTs related to this element, e.g.

key := e.Value().MessageKeys().At(e.ValueNodeIndex())

If the element is empty, this returns -1.

type ErrCycle

type ErrCycle = cycle.Error[ast.DeclImport]

ErrCycle is returned by an Importer when encountering an import cycle.

type Extend

type Extend id.Node[Extend, *File, *rawExtend]

Extend represents an extend block associated with some extension field.

func (Extend) AST

func (e Extend) AST() ast.DeclDef

AST returns the declaration for this extend block, if known.

func (Extend) Extendee

func (e Extend) Extendee() Type

Extendee returns the extendee type of this extend block.

func (Extend) Extensions

func (e Extend) Extensions() seq.Indexer[Member]

Extensions returns the extensions declared in this block.

func (Extend) InternedScope

func (e Extend) InternedScope() intern.ID

InternedScope returns the intern ID for Extend.Scope.

func (Extend) Parent

func (e Extend) Parent() Type

Parent returns the type this extend block is declared in.

func (Extend) Scope

func (e Extend) Scope() FullName

Scope returns the scope that symbol lookups in this block should be performed against.

type Feature

type Feature struct {
	// contains filtered or unexported fields
}

Feature is a feature setting retrieved from a FeatureSet.

func (Feature) Field

func (f Feature) Field() Member

Field returns the field corresponding to this feature value.

func (Feature) IsCustom

func (f Feature) IsCustom() bool

IsCustom returns whether this is a custom feature.

func (Feature) IsDefault

func (f Feature) IsDefault() bool

IsDefault returns whether this feature was inherited from edition defaults. An explicit setting to the default will return false for this method.

func (Feature) IsExplicit

func (f Feature) IsExplicit() bool

IsExplicit returns whether this feature was set explicitly.

func (Feature) IsInherited

func (f Feature) IsInherited() bool

IsInherited returns whether this feature value was inherited from its parent.

func (Feature) Type

func (f Feature) Type() Type

Type returns the type of this feature. May be zero if there is no specified default value for this feature in the current edition.

func (Feature) Value

func (f Feature) Value() Value

Value returns the value of this feature. May be zero if there is no specified value for this feature, given the current edition.

type FeatureInfo

type FeatureInfo struct {
	// contains filtered or unexported fields
}

FeatureInfo represents information about a message field being used as a feature. This corresponds to the edition_defaults and feature_support options on a field.

func (FeatureInfo) Default

func (f FeatureInfo) Default(edition syntax.Syntax) Value

Default returns the default value for this feature.

func (FeatureInfo) Deprecated

func (f FeatureInfo) Deprecated() syntax.Syntax

Deprecated returns whether this feature has been deprecated, and in which edition.

func (FeatureInfo) DeprecationWarning

func (f FeatureInfo) DeprecationWarning() string

DeprecationWarning returns the literal text of the deprecation warning for this feature, if it has been deprecated.

func (FeatureInfo) Introduced

func (f FeatureInfo) Introduced() syntax.Syntax

Introduced returns which edition this feature is first allowed in.

func (FeatureInfo) IsDeprecated

func (f FeatureInfo) IsDeprecated(in syntax.Syntax) bool

IsDeprecated returns whether this feature has been deprecated yet.

func (FeatureInfo) IsIntroduced

func (f FeatureInfo) IsIntroduced(in syntax.Syntax) bool

IsIntroduced returns whether this feature has been introduced yet.

func (FeatureInfo) IsRemoved

func (f FeatureInfo) IsRemoved(in syntax.Syntax) bool

IsRemoved returns whether this feature has been removed yet.

func (FeatureInfo) Removed

func (f FeatureInfo) Removed() syntax.Syntax

Removed returns whether this feature has been removed, and in which edition.

type FeatureSet

type FeatureSet id.Node[FeatureSet, *File, *rawFeatureSet]

FeatureSet represents the Editions-mediated features of a particular declaration.

func (FeatureSet) Lookup

func (fs FeatureSet) Lookup(field Member) Feature

Lookup looks up a feature with the given google.protobuf.FeatureSet member.

func (FeatureSet) LookupCustom

func (fs FeatureSet) LookupCustom(extension, field Member) Feature

LookupCustom looks up a custom feature in the given extension's field.

func (FeatureSet) Options

func (fs FeatureSet) Options() MessageValue

Options returns the value of the google.protobuf.FeatureSet message that this FeatureSet is built from.

func (FeatureSet) Parent

func (fs FeatureSet) Parent() FeatureSet

Parent returns the feature set of the parent scope for this feature.

Returns zero if this is the feature set for the file.

type File

type File struct {
	// contains filtered or unexported fields
}

File is an IR file, which provides access to the top-level declarations of a Protobuf *File.

func (*File) AST

func (f *File) AST() *ast.File

AST returns the AST this file was parsed from.

func (*File) AllExtends

func (f *File) AllExtends() seq.Indexer[Extend]

AllExtends returns all extend blocks in this file.

func (*File) AllExtensions

func (f *File) AllExtensions() seq.Indexer[Member]

AllExtensions returns all extensions defined in this file.

func (*File) AllMembers

func (f *File) AllMembers() iter.Seq[Member]

AllMembers returns all fields defined in this file, including extensions and enum values.

func (*File) AllTypes

func (f *File) AllTypes() seq.Indexer[Type]

AllTypes returns all types defined in this file.

func (*File) Annotations

func (f *File) Annotations() seq.Indexer[Annotation]

Annotations returns all annotation declarations introduced in this file.

func (*File) Deprecated

func (f *File) Deprecated() Value

Deprecated returns whether this file is deprecated, by returning the relevant option value for setting deprecation.

func (*File) ExportedSymbols

func (f *File) ExportedSymbols() seq.Indexer[Symbol]

ExportedSymbols returns this file's exported symbols.

func (*File) Extends

func (f *File) Extends() seq.Indexer[Extend]

Extends returns the top level extend blocks in this file.

func (*File) Extensions

func (f *File) Extensions() seq.Indexer[Member]

Extensions returns the top level extensions defined in this file (i.e., the contents of any top-level `extends` blocks).

func (*File) FeatureSet

func (f *File) FeatureSet() FeatureSet

FeatureSet returns the Editions features associated with this file.

func (*File) FindSymbol

func (f *File) FindSymbol(fqn FullName) Symbol

FindSymbol finds a symbol among File.Symbols with the given fully-qualified name.

func (*File) FromID

func (f *File) FromID(id uint64, want any) any

func (*File) Functions

func (f *File) Functions() seq.Indexer[Function]

Functions returns all function declarations introduced in this file.

func (*File) ImportFor

func (f *File) ImportFor(that *File) Import

ImportFor returns import metadata for a given file, if this file imports it.

func (*File) Imports

func (f *File) Imports() seq.Indexer[Import]

Imports returns an indexer over the imports declared in this file.

func (*File) InternedPackage

func (f *File) InternedPackage() intern.ID

InternedPackage returns the intern ID for the value of File.Package.

func (*File) InternedPath

func (f *File) InternedPath() intern.ID

InternedPath returns the intern ID for the value of File.Path.

func (*File) IsDescriptorProto

func (f *File) IsDescriptorProto() bool

IsDescriptorProto returns whether this is the special file google/protobuf/descriptor.proto, which is given special treatment in the language.

func (*File) NullMaskImport added in v0.35.0

func (f *File) NullMaskImport() *File

NullMaskImport returns the file declaring NullMaskTypeName when a message in f gets a `_null` mask and f does not import it itself, and nil otherwise. Descriptor generation lists it as a dependency, and TopoSort orders it before f, so a descriptor set carries it. It is not one of f's File.Imports: f cannot name its symbols.

func (*File) NullMasks added in v0.35.0

func (f *File) NullMasks() bool

NullMasks reports whether messages in f get a generated `_null` mask: its session selects it, it is not one of protobuf's own files, and the mask's type is available to it, through a regular import of NullMaskImport or through File.NullMaskImport. Protobuf's own files never get one: rewriting google/protobuf/descriptor.proto, whose proto2 option messages all have fields with presence, would change protobuf's descriptors. A descriptor may not list one file as both a regular and an option dependency, so an option import turns masks off for the file, and lowering reports it; so does a file that cannot import the mask's type. It is meaningful once f is lowered.

func (*File) Options

func (f *File) Options() MessageValue

Options returns the top level options applied to this file.

func (*File) Package

func (f *File) Package() FullName

Package returns the package name for this file.

The name will not include a leading dot. It will be empty for the empty package.

func (*File) Path

func (f *File) Path() string

Path returns the canonical path for this file.

This need not be the same as File.AST().Span().Path().

func (*File) Services

func (f *File) Services() seq.Indexer[Service]

Services returns all services defined in this file.

func (*File) Symbols

func (f *File) Symbols() seq.Indexer[Symbol]

Symbols returns this file's symbol table.

The symbol table includes both symbols defined in this file, and symbols imported by the file. The symbols are returned in an arbitrary but fixed order.

func (*File) Syntax

func (f *File) Syntax() syntax.Syntax

Syntax returns the syntax pragma that applies to this file.

func (*File) TransitiveImports

func (f *File) TransitiveImports() seq.Indexer[Import]

TransitiveImports returns an indexer over the transitive imports for this file.

This function does not report whether those imports are weak or not.

func (*File) TypeAliases

func (f *File) TypeAliases() seq.Indexer[TypeAlias]

TypeAliases returns all `type` alias declarations introduced in this file.

func (*File) Types

func (f *File) Types() seq.Indexer[Type]

Types returns the top level types of this file.

type FullName

type FullName string

FullName is a fully-qualified Protobuf name, which is a dot-separated list of identifiers, with an optional dot prefix.

This is a helper type for common operations on such names. This is essentially protoreflect.FullName, without depending on protoreflect. Unlike protoreflect, we do not provide validation methods.

func (FullName) Absolute

func (n FullName) Absolute() bool

Absolute returns whether this is an absolute name, i.e., has a leading dot.

func (FullName) Append

func (n FullName) Append(names ...string) FullName

Append returns a name with the given component(s) appended.

If this is an empty name, the resulting name will not be absolute.

func (FullName) Components

func (n FullName) Components() iter.Seq[string]

Components returns an iterator over the components of this name.

If there are adjacent dots, e.g. foo..bar, this will yield an empty string within the name.

func (FullName) First

func (n FullName) First() string

First returns the first component of this name.

func (FullName) IsIdent

func (n FullName) IsIdent() bool

IsIdent returns whether this name is a single identifier.

func (FullName) Name

func (n FullName) Name() string

Name returns the last component of this name.

func (FullName) Parent

func (n FullName) Parent() FullName

Parent returns the name of the parent entity for this name.

If the name only has one component, returns the zero value. In particular, the parent of ".foo" is "".

func (FullName) ToAbsolute

func (n FullName) ToAbsolute() FullName

ToAbsolute returns this name with a leading dot.

func (FullName) ToRelative

func (n FullName) ToRelative() FullName

ToRelative returns this name without a leading dot.

type Function

type Function id.Node[Function, *File, *rawFunction]

Function is a `function` declaration introduced by the Protowire Schema Extensions (PSE) grammar — see ast.DeclFunction.

Function declarations name an external function callable from inside `expression` arguments at annotation use sites. They live in the file's exported symbol table under SymbolKindFunction so cross-file resolution works the same way it does for `message`, `service`, and `annotation`.

Phase scope: symbol registration plus FDP emission via the [pwsv1.FileFunctions] file-scope carrier. Argument validation (verifying that a use-site call's arity matches the declared signature) requires the engine-language parser; the engine itself performs that check at runtime.

func (Function) AST

func (f Function) AST() ast.DeclFunction

AST returns the declaration for this function, if known.

func (Function) Annotations

func (f Function) Annotations() seq.Indexer[AnnotationUse]

Annotations returns the annotation use sites attached to this function declaration (trailing form: `function foo() @bar;`).

func (Function) FullName

func (f Function) FullName() FullName

FullName returns this function's fully-qualified name.

func (Function) InternedFullName

func (f Function) InternedFullName() intern.ID

InternedFullName returns the intern ID for Function.FullName.

func (Function) InternedName

func (f Function) InternedName() intern.ID

InternedName returns the intern ID for Function.FullName().Name().

func (Function) Name

func (f Function) Name() string

Name returns this function's declared name, i.e. the last component of its full name.

func (Function) Options added in v0.20.0

func (f Function) Options() seq.Indexer[FunctionOption]

Options returns the bracket-form options attached to this function declaration, in declaration order.

Option values are recorded without classification: the descriptor surface carries them AnnotationArg-shaped and consumers interpret them at use time.

func (Function) Params

func (f Function) Params() seq.Indexer[FunctionParam]

Params returns the parameters of this function declaration.

type FunctionOption added in v0.20.0

type FunctionOption struct {
	// Name is the unqualified option name: the last component of the
	// path the option was written with. The FunctionDecl descriptor
	// carrier keys its options map by this name.
	Name string
	// Value is the option's value expression, as written.
	Value ast.ExprAny
}

FunctionOption is one bracket-form option attached to a Function declaration site, e.g. `error_code = "common.matches.failed"` in `function matches(...) [error_code = "..."];`.

type FunctionParam

type FunctionParam id.Node[FunctionParam, *File, *rawFunctionParam]

FunctionParam is a single parameter of a Function declaration — see ast.DeclFunctionParam.

func (FunctionParam) AST

AST returns the declaration for this function parameter, if known.

func (FunctionParam) Function

func (p FunctionParam) Function() Function

Function returns the function declaration that this parameter belongs to.

func (FunctionParam) InternedName

func (p FunctionParam) InternedName() intern.ID

InternedName returns the intern ID for FunctionParam.Name.

func (FunctionParam) Name

func (p FunctionParam) Name() string

Name returns this parameter's declared name.

func (FunctionParam) TypeFQN added in v0.37.0

func (p FunctionParam) TypeFQN() string

TypeFQN returns the fully-qualified name of the parameter's type, which for a type alias is the alias itself, not its base. Falls back to FunctionParam.TypeName when the type did not resolve, or is `any`, which names no symbol.

func (FunctionParam) TypeName

func (p FunctionParam) TypeName() string

TypeName returns the textual type the parameter was declared with (e.g. "string", "any", or "Email"), as written in the source.

type Import

type Import struct {
	*File // The file that is imported.

	// The kind of import this is.
	Public, Weak, Option bool

	Direct  bool           // Whether this is a direct or transitive import.
	Visible bool           // Whether this import's symbols are visible in the current file.
	Used    bool           // Whether this import has been marked as used.
	Decl    ast.DeclImport // The import declaration.
}

Import is an import in a File.

type Importer

type Importer func(n int, path string, decl ast.DeclImport) (*File, error)

Importer is a callback to resolve the imports of an ast.File being lowered.

If a cycle is encountered, should return an *[incremental.ErrCycle], starting from decl and ending when the currently lowered file is imported.

Session.Lower may not call this function on all imports; only those for which it needs the caller to resolve a File for it.

This function will also be called with DescriptorProtoPath if it isn't transitively imported by the lowered file, with an index value of -1. Returning an error or a zero file will trigger an ICE.

When the session's Session.NullMask selects the file, it is also called with NullMaskImport and an index value of -2, unless the file declares an import of it. Returning an error or a zero file is reported as an error if a message in the file needs the mask.

type Member

type Member id.Node[Member, *File, *rawMember]

Member is a Protobuf message field, enum value, or extension field.

A member has three types associated with it. The English language struggles to give these succinct names, so we review them here.

  1. Its _element_, i.e. the type it contains. This is the type that a member is declared to be _of_. Not present for enum values.

  2. Its _parent_, i.e., the type it is syntactically defined within. Extensions appear syntactically within their parent.

  3. Its _container_, i.e., the type which it is part of for the purposes of serialization. Extensions are fields of their container, but are declared within their parent.

func (Member) AST

func (m Member) AST() ast.DeclDef

AST returns the declaration for this member, if known.

func (Member) Annotations

func (m Member) Annotations() seq.Indexer[AnnotationUse]

Annotations returns the annotation use sites attached to this member (trailing `@name(args)` annotations on a field or enum value). See Type.Annotations for the resolution model.

When the field's declared type referenced a type-alias chain (PSE v1), the chain's trailing annotations appear ahead of any field-site annotations, in base-to-derived order — the alias acts as a macro expansion per RFC-001 §5, and the resulting list matches §6.4 evaluation order (base → derived → field-level). See [propagateTypeAliasAnnotations]. A chain link living in another file is yielded under that file's context, so callers reading AnnotationUse.AST and AnnotationUse.Target still get coherent results.

func (Member) AsTagRange

func (m Member) AsTagRange() TagRange

AsTagRange wraps this member in a TagRange.

func (Member) CanTarget

func (m Member) CanTarget(target OptionTarget) bool

CanTarget returns whether this message field can be set as an option for the given option target type.

This is mediated by the option FieldOptions.targets, which controls whether this field can be set (transitively) on the options of a given entity type. This is useful for options which re-use the same message type for different option types, such as FeatureSet.

func (Member) Container

func (m Member) Container() Type

Container returns the type which contains this member: this is either Member.Parent, or the extendee if this is an extension. This is the type it is declared to be *part of*.

func (Member) Deprecated

func (m Member) Deprecated() Value

Deprecated returns whether this member is deprecated, by returning the relevant option value for setting deprecation.

func (Member) Element

func (m Member) Element() Type

Element returns the this member's element type. This is the type it is declared to be *of*, such as in the phrase "a string field's type is string".

This does not include the member's presence: for example, a repeated int32 member will report the type as being the int32 primitive, not an int32 array.

This is zero for enum values.

func (Member) Extend

func (m Member) Extend() Extend

Extend returns the extend block this member is declared in, if any.

func (Member) FDPType

FDPType returns the descriptor type that would be used for this field.

func (Member) FeatureInfo

func (m Member) FeatureInfo() FeatureInfo

FeatureInfo returns feature definition information relating to this field (for when using this field as a feature).

Returns a zero value if this information does not exist.

func (Member) FeatureSet

func (m Member) FeatureSet() FeatureSet

FeatureSet returns the Editions features associated with this member.

func (Member) FullName

func (m Member) FullName() FullName

FullName returns this member's fully-qualified name.

func (Member) InternedFullName

func (m Member) InternedFullName() intern.ID

InternedFullName returns the intern ID for Member.FullName.

func (Member) InternedJSONName

func (m Member) InternedJSONName() intern.ID

InternedJSONName returns the intern ID for Member.JSONName.

func (Member) InternedName

func (m Member) InternedName() intern.ID

InternedName returns the intern ID for Member.FullName().Name().

func (Member) InternedScope

func (m Member) InternedScope() intern.ID

InternedScope returns the intern ID for Member.Scope.

func (Member) IsEnumValue

func (m Member) IsEnumValue() bool

IsEnumValue returns whether this is an enum value.

func (Member) IsExtension

func (m Member) IsExtension() bool

IsExtension returns whether this is a extension message field.

func (Member) IsGroup

func (m Member) IsGroup() bool

IsGroup returns whether this is a group-encoded field.

func (Member) IsMap

func (m Member) IsMap() bool

IsMap returns whether this is a map field.

func (Member) IsMessageField

func (m Member) IsMessageField() bool

IsMessageField returns whether this is a non-extension message field.

func (Member) IsPacked

func (m Member) IsPacked() bool

IsPacked returns whether this is a packed message field.

func (Member) IsRepeated

func (m Member) IsRepeated() bool

IsRepeated returns whether this is a repeated field; this includes map fields.

func (Member) IsSingular

func (m Member) IsSingular() bool

IsSingular returns whether this is a singular field; this includes oneof members.

func (Member) IsSynthetic

func (m Member) IsSynthetic() bool

IsSynthetic returns whether or not this is a synthetic field, such as the fields of a map entry.

func (Member) IsUnicode

func (m Member) IsUnicode() bool

IsUnicode returns whether this is a string-typed message field that must contain UTF-8 bytes.

func (Member) JSONName

func (m Member) JSONName() string

JSONName returns this member's JSON name, either the default-generated one or the one set via the json_name pseudo-option.

func (Member) Name

func (m Member) Name() string

Name returns this member's name.

func (Member) Number

func (m Member) Number() int32

Number returns the number for this member after expression evaluation.

Defaults to zero if the number is not specified.

func (Member) Oneof

func (m Member) Oneof() Oneof

Oneof returns the oneof that this member is a member of.

Returns the zero value if this member does not have presence.Shared.

func (Member) Options

func (m Member) Options() MessageValue

Options returns the options applied to this member.

func (Member) Parent

func (m Member) Parent() Type

Parent returns the type this member is syntactically located in. This is the type it is declared *in*, but which it is not necessarily part of.

May be zero for extensions declared at the top level.

func (Member) Presence

func (m Member) Presence() presence.Kind

Presence returns this member's presence kind.

Returns presence.Unknown for enum values.

func (Member) PseudoOptions

func (m Member) PseudoOptions() PseudoFields

PseudoOptions returns this member's pseudo options.

func (Member) Scope

func (m Member) Scope() FullName

Scope returns the scope in which this member is defined.

func (Member) SyntheticOneofName

func (m Member) SyntheticOneofName() string

SyntheticOneofName returns the name of the corresponding synthetic oneof for this member, if there should be one.

For proto3 sources, a oneof is synthesized to track explicit optional presence of a field. For details on generating the synthesized name, see the docs for [syntheticNames] and/or refer to https://protobuf.com/docs/descriptors#synthetic-oneofs.

func (Member) Targets

func (m Member) Targets() iter.Seq[OptionTarget]

Targets returns an iterator over the valid option targets for this member.

func (Member) TypeAST

func (m Member) TypeAST() ast.TypeAny

TypeAST returns the type AST node for this member, if known.

func (Member) TypeAliasChain

func (m Member) TypeAliasChain() seq.Indexer[TypeAlias]

TypeAliasChain returns the type-alias chain this member's declared type resolved through, in base-to-derived order — the alias closest to the concrete message / enum / scalar base first, ending with the name the field was declared with. Returns an empty indexer for members whose declared type was not an alias.

Yielded TypeAlias values stay in their defining file's context, so TypeAlias.AST and TypeAlias.FullName resolve correctly even when the chain spans multiple files.

Populated by [propagateTypeAliasAnnotations].

type MessageValue

type MessageValue id.Node[MessageValue, *File, *rawMessageValue]

MessageValue is a message literal, represented as a list of ordered key-value pairs.

func (MessageValue) AsValue

func (v MessageValue) AsValue() Value

AsValue returns the Value corresponding to this message.

This value can be used to retrieve the associated Member and from it the message's declared Type.

func (MessageValue) Concrete

func (v MessageValue) Concrete() MessageValue

Concrete returns the concrete version of this value if it is an Any.

If it isn't an Any, or a .Raw()" Any (one not specified with the special type URL syntax), this returns v.

func (MessageValue) Field

func (v MessageValue) Field(field Member) Value

Field returns the field corresponding with the given member, if it is set.

Returns a zero Value if either the member or the message value is zero.

func (MessageValue) Fields

func (v MessageValue) Fields() iter.Seq[Value]

Fields yields the fields within this message literal, in insertion order.

func (MessageValue) IsEmpty

func (v MessageValue) IsEmpty() bool

IsEmpty returns whether any fields are set on this value.

func (MessageValue) Marshal

func (v MessageValue) Marshal(buf []byte, r *report.Report) []byte

Marshal serializes this message as wire format and appends it to buf.

If r is not nil, it will be used to record diagnostics generated during the marshal operation.

func (MessageValue) Type

func (v MessageValue) Type() Type

Type returns this value's message type.

If v was returned from MessageValue.Concrete, its type need not be the same as v.AsValue()'s (although it can be, in the case of pathological Any-within-an-Any messages).

func (MessageValue) TypeURL

func (v MessageValue) TypeURL() string

TypeURL returns this value's type URL, if it is the concrete value of an Any.

type Method

type Method id.Node[Method, *File, *rawMethod]

Method is a Protobuf service method.

func (Method) AST

func (m Method) AST() ast.DeclDef

AST returns the declaration for this method, if known.

func (Method) Annotations

func (m Method) Annotations() seq.Indexer[AnnotationUse]

Annotations returns the annotation use sites attached to this method. See Type.Annotations for the resolution model.

func (Method) Deprecated

func (m Method) Deprecated() Value

Deprecated returns whether this service is deprecated, by returning the relevant option value for setting deprecation.

func (Method) FeatureSet

func (m Method) FeatureSet() FeatureSet

FeatureSet returns the Editions features associated with this method.

func (Method) FullName

func (m Method) FullName() FullName

FullName returns this method's fully-qualified name.

func (Method) Input

func (m Method) Input() (ty Type, stream bool)

Input returns the input type for this method, and whether it is a streaming input.

func (Method) InternedFullName

func (m Method) InternedFullName() intern.ID

InternedFullName returns the intern ID for Method.FullName.

func (Method) InternedName

func (m Method) InternedName() intern.ID

InternedName returns the intern ID for Method.FullName().Name().

func (Method) Name

func (m Method) Name() string

Name returns this method's declared name, i.e. the last component of its full name.

func (Method) Options

func (m Method) Options() MessageValue

Options returns the options applied to this method.

func (Method) Output

func (m Method) Output() (ty Type, stream bool)

Output returns the output type for this method, and whether it is a streaming output.

func (Method) Service

func (m Method) Service() Service

Service returns the service this method is part of.

type Oneof

type Oneof id.Node[Oneof, *File, *rawOneof]

Oneof represents a oneof within a message definition.

func (Oneof) AST

func (o Oneof) AST() ast.DeclDef

AST returns the declaration for this oneof, if known.

func (Oneof) Annotations

func (o Oneof) Annotations() seq.Indexer[AnnotationUse]

Annotations returns the annotation use sites attached to this oneof. See Type.Annotations for the resolution model.

func (Oneof) Container

func (o Oneof) Container() Type

Container returns the message type which contains it.

func (Oneof) FeatureSet

func (o Oneof) FeatureSet() FeatureSet

FeatureSet returns the Editions features associated with this oneof.

func (Oneof) FullName

func (o Oneof) FullName() FullName

FullName returns this oneof's fully-qualified name.

func (Oneof) Index

func (o Oneof) Index() int

Index returns this oneof's index in its containing message.

func (Oneof) InternedFullName

func (o Oneof) InternedFullName() intern.ID

InternedFullName returns the intern ID for Oneof.FullName.

func (Oneof) InternedName

func (o Oneof) InternedName() intern.ID

InternedName returns the intern ID for Oneof.FullName().Name().

func (Oneof) Members

func (o Oneof) Members() seq.Indexer[Member]

Members returns this oneof's member fields.

func (Oneof) Name

func (o Oneof) Name() string

Name returns this oneof's declared name.

func (Oneof) Options

func (o Oneof) Options() MessageValue

Options returns the options applied to this oneof.

func (Oneof) Parent

func (o Oneof) Parent() Type

Parent returns the type that this oneof is declared within,.

type OptionTarget

type OptionTarget int32

OptionTarget is target for an Editions feature, corresponding to google.protobuf.FieldOptions.OptionTargetType. The values of this enum match those in descriptor.proto one-to-one.

const (
	OptionTargetInvalid OptionTarget = iota
	OptionTargetFile
	OptionTargetRange
	OptionTargetMessage
	OptionTargetField
	OptionTargetOneof
	OptionTargetEnum
	OptionTargetEnumValue
	OptionTargetService
	OptionTargetMethod
)

func (OptionTarget) GoString

func (v OptionTarget) GoString() string

GoString implements fmt.GoStringer.

func (OptionTarget) String

func (v OptionTarget) String() string

String implements fmt.Stringer.

type PseudoFields

type PseudoFields struct {
	Default  Value
	JSONName Value
}

PseudoFields contains pseudo options, which are special option-like syntax for fields which are not real options. They can be accessed via [Message.PseudoFields].

type PxfNumber added in v0.32.0

type PxfNumber int

PxfNumber names one of protowire's arbitrary-precision number types.

const (
	PxfNone PxfNumber = iota
	PxfBigInt
	PxfDecimal
	PxfBigFloat
)

type Ref

type Ref[T any] struct {
	// contains filtered or unexported fields
}

Ref is a reference in a Protobuf file: an id.ID along with information for retrieving which file that ID is for, relative to the referencing file's context.

The context needed for resolving a ref is called its "base context", which the user is expected to keep track of.

func (Ref[T]) ChangeContext

func (r Ref[T]) ChangeContext(base, next *File) Ref[T]

ChangeContext changes the implicit context for this ref to be with respect to the new one given.

func (Ref[T]) Context

func (r Ref[T]) Context(base *File) *File

Context returns the context for this reference relative to a base context.

func (Ref[T]) IsZero

func (r Ref[T]) IsZero() bool

IsZero returns whether this is the zero ID.

type ReservedName

type ReservedName struct {
	// contains filtered or unexported fields
}

ReservedName is a name for a field or enum value that has been reserved for future use.

func (ReservedName) AST

func (r ReservedName) AST() ast.ExprAny

AST returns the expression that this name was evaluated from, if known.

func (ReservedName) DeclAST

func (r ReservedName) DeclAST() ast.DeclRange

DeclAST returns the declaration this name came from. Multiple names may have the same declaration.

func (ReservedName) InternedName

func (r ReservedName) InternedName() intern.ID

InternedName returns the intern ID for ReservedName.Name.

func (ReservedName) Name

func (r ReservedName) Name() string

Name returns the name (i.e., an identifier) that was reserved.

type ReservedRange

type ReservedRange id.Node[ReservedRange, *File, *rawReservedRange]

ReservedRange is a range of reserved field or enum numbers, either from a reserved or extensions declaration.

func (ReservedRange) AST

func (r ReservedRange) AST() ast.ExprAny

AST returns the expression that this range was evaluated from, if known.

func (ReservedRange) AsTagRange

func (r ReservedRange) AsTagRange() TagRange

AsTagRange wraps this range in a TagRange.

func (ReservedRange) DeclAST

func (r ReservedRange) DeclAST() ast.DeclRange

DeclAST returns the declaration this range came from. Multiple ranges may have the same declaration.

func (ReservedRange) FeatureSet

func (r ReservedRange) FeatureSet() FeatureSet

FeatureSet returns the Editions features associated with this file.

func (ReservedRange) ForExtensions

func (r ReservedRange) ForExtensions() bool

ForExtensions returns whether this is an extension range.

func (ReservedRange) Options

func (r ReservedRange) Options() MessageValue

Options returns the options applied to this range.

Reserved ranges cannot carry options; only extension ranges do.

func (ReservedRange) Range

func (r ReservedRange) Range() (start, end int32)

Range returns the start and end of the range.

type Service

type Service id.Node[Service, *File, *rawService]

Service is a Protobuf service definition.

func (Service) AST

func (s Service) AST() ast.DeclDef

AST returns the declaration for this service, if known.

func (Service) Annotations

func (s Service) Annotations() seq.Indexer[AnnotationUse]

Annotations returns the annotation use sites attached to this service. See Type.Annotations for the resolution model.

func (Service) Deprecated

func (s Service) Deprecated() Value

Deprecated returns whether this service is deprecated, by returning the relevant option value for setting deprecation.

func (Service) FeatureSet

func (s Service) FeatureSet() FeatureSet

FeatureSet returns the Editions features associated with this service.

func (Service) FullName

func (s Service) FullName() FullName

FullName returns this service's fully-qualified name.

func (Service) InternedFullName

func (s Service) InternedFullName() intern.ID

InternedFullName returns the intern ID for Service.FullName.

func (Service) InternedName

func (s Service) InternedName() intern.ID

InternedName returns the intern ID for Service.FullName().Name().

func (Service) Methods

func (s Service) Methods() seq.Indexer[Method]

Methods returns the methods of this service.

func (Service) Name

func (s Service) Name() string

Name returns this service's declared name, i.e. the last component of its full name.

func (Service) Options

func (s Service) Options() MessageValue

Options returns the options applied to this service.

type Session

type Session struct {
	// NullMask, when non-nil, selects the files whose messages get a
	// generated `_null` mask (protocompile#248; see [NeedsNullMask]).
	// Lowering imports [NullMaskImport] for them and reports what stops a
	// message getting one, and descriptor generation adds the field. Set
	// it before the session lowers its first file. It is given canonical
	// paths. Nil generates none.
	NullMask func(path string) bool
	// contains filtered or unexported fields
}

Session is shared global configuration and state for all IR values that are being used together.

It is used to track shared book-keeping.

A zero Session is ready to use.

func (*Session) InternStats

func (s *Session) InternStats() intern.Stats

InternStats returns interning statistics, assuming Session.RecordInternStats was called first.

This function is intended for performance monitoring only.

func (*Session) Lower

func (s *Session) Lower(source *ast.File, errs *report.Report, importer Importer) (file *File, ok bool)

Lower lowers an AST into an IR module.

Diagnostics generated by this process are written to errs. Returns whether lowering succeeded without errors; warnings and remarks do not make it fail.

The ir package does not provide a mechanism for resolving imports; instead, they must be provided as an argument to this function.

func (*Session) NullMaskSelects added in v0.35.0

func (s *Session) NullMaskSelects(path string) bool

NullMaskSelects reports whether Session.NullMask selects the file at path, which must be canonical (see CanonicalizeFilePath): it is set, it selects path, and path is not one of protobuf's own files. Those never get a mask, and must not ask for NullMaskImport either: field_mask.proto imports descriptor.proto implicitly, so a descriptor.proto that asked for field_mask.proto would close a cycle.

func (*Session) RecordInternStats

func (s *Session) RecordInternStats()

RecordInternStats enables instrumentation of the session's intern table.

See Session.InternStats.

type Symbol

type Symbol id.Node[Symbol, *File, *rawSymbol]

Symbol is an entry in a File's symbol table.

[Symbol.Context] returns the context for the file which imported this symbol. To map this to the context in which the symbol was defined, use [Symbol.InDefFile].

func (Symbol) AsAnnotation

func (s Symbol) AsAnnotation() Annotation

AsAnnotation returns the annotation this symbol refers to, if it is one.

func (Symbol) AsFunction

func (s Symbol) AsFunction() Function

AsFunction returns the function this symbol refers to, if it is one.

func (Symbol) AsMember

func (s Symbol) AsMember() Member

AsMember returns the member this symbol refers to, if it is one.

func (Symbol) AsMethod

func (s Symbol) AsMethod() Method

AsMethod returns the method this symbol refers to, if it is one.

func (Symbol) AsOneof

func (s Symbol) AsOneof() Oneof

AsOneof returns the oneof this symbol refers to, if it is one.

func (Symbol) AsService

func (s Symbol) AsService() Service

AsService returns the service this symbol refers to, if it is one.

func (Symbol) AsType

func (s Symbol) AsType() Type

AsType returns the type this symbol refers to, if it is one.

func (Symbol) AsTypeAlias

func (s Symbol) AsTypeAlias() TypeAlias

AsTypeAlias returns the type alias this symbol refers to, if it is one.

func (Symbol) Definition

func (s Symbol) Definition() source.Span

Definition returns a span for the definition site of this symbol; specifically, this is (typically) just an identifier.

func (Symbol) Deprecated

func (s Symbol) Deprecated() Value

Deprecated returns whether this symbol is deprecated, but returning the relevant option value for setting deprecation.

Note that although files can be marked as deprecated, packages cannot, so package symbols never show up as deprecated.

func (Symbol) FeatureSet

func (s Symbol) FeatureSet() FeatureSet

FeatureSet returns the features associated with this symbol.

func (Symbol) FullName

func (s Symbol) FullName() FullName

FullName returns this symbol's fully-qualified name.

func (Symbol) Import

func (s Symbol) Import(in *File) Import

Import returns the import declaration that brought this symbol into scope in the given file.

Returns zero if s is defined in the current file or if s is not imported by in.

func (Symbol) InternedFullName

func (s Symbol) InternedFullName() intern.ID

InternedFullName returns the intern ID for Symbol.FullName.

func (Symbol) Kind

func (s Symbol) Kind() SymbolKind

Kind returns which kind of symbol this is.

func (Symbol) Visible

func (s Symbol) Visible(in *File, allowOptions bool) bool

Visible returns whether or not this symbol is visible according to Protobuf's import semantics, within the given file.

If allowOptions is true, symbols that were pulled in via import option are accepted.

type SymbolKind

type SymbolKind int8

SymbolKind is a kind of symbol, i.e. an IR entity that defines a fully-qualified name.

const (
	SymbolKindInvalid SymbolKind = iota
	SymbolKindPackage
	SymbolKindScalar
	SymbolKindMessage
	SymbolKindEnum
	SymbolKindField
	SymbolKindEnumValue
	SymbolKindExtension
	SymbolKindOneof
	SymbolKindService
	SymbolKindMethod
	SymbolKindAnnotation
	SymbolKindFunction
	SymbolKindTypeAlias
)

func (SymbolKind) GoString

func (v SymbolKind) GoString() string

GoString implements fmt.GoStringer.

func (SymbolKind) IsMember

func (k SymbolKind) IsMember() bool

IsMember returns whether this is a field's symbol kind. This includes enum values, which the ir package treats as fields of enum types.

func (SymbolKind) IsMessageField

func (k SymbolKind) IsMessageField() bool

IsMessageField returns whether this is a field's symbol kind.

func (SymbolKind) IsScope

func (k SymbolKind) IsScope() bool

IsScope returns whether this is a symbol that defines a scope, for the purposes of name lookup.

func (SymbolKind) IsType

func (k SymbolKind) IsType() bool

IsType returns whether this is a type's symbol kind.

func (SymbolKind) OptionTarget

func (k SymbolKind) OptionTarget() OptionTarget

OptionTarget returns the OptionTarget type for a symbol of this kind.

Returns OptionTargetInvalid if there is no corresponding target for this type of symbol.

func (SymbolKind) String

func (v SymbolKind) String() string

String implements fmt.Stringer.

type TagRange

type TagRange struct {
	// contains filtered or unexported fields
}

TagRange is a range of tag numbers in a Type.

This can represent either a Member or a ReservedRange.

func (TagRange) AsMember

func (r TagRange) AsMember() Member

AsMember returns the Member this range points to, or zero if it isn't a member.

func (TagRange) AsReserved

func (r TagRange) AsReserved() ReservedRange

AsReserved returns the ReservedRange this range points to, or zero if it isn't a member.

type Type

type Type id.Node[Type, *File, *rawType]

Type is a Protobuf message field type.

func PredeclaredType

func PredeclaredType(n predeclared.Name) Type

PredeclaredType returns the type corresponding to a predeclared name.

Returns the zero value if !n.IsScalar().

func (Type) AST

func (t Type) AST() ast.DeclDef

AST returns the declaration for this type, if known.

This need not be an ast.DefMessage or ast.DefEnum; it may be something else in the case of e.g. a map field's entry type.

func (Type) AbsoluteRange

func (t Type) AbsoluteRange() (start, end int32)

AbsoluteRange returns the smallest and largest number a member of this type can have.

This range is inclusive.

func (Type) AllRanges

func (t Type) AllRanges() seq.Indexer[ReservedRange]

AllRanges returns all reserved/extension ranges declared in this type.

This does not include reserved field names; see Type.ReservedNames.

func (Type) AllowsAlias

func (t Type) AllowsAlias() bool

AllowsAlias returns whether this is an enum type with the allow_alias option set.

func (Type) Annotations

func (t Type) Annotations() seq.Indexer[AnnotationUse]

Annotations returns the annotation use sites attached to this type (a `@name(args)` form leading the `message`/`enum` declaration).

Materialised by the Phase B2 resolve pass. Each entry's AnnotationUse.Target is the resolved Annotation, or zero when name resolution failed (a diagnostic was emitted at resolve time).

func (Type) CarrierScalar added in v0.31.0

func (t Type) CarrierScalar() predeclared.Name

CarrierScalar gives the scalar type an `any` annotation argument attached to a member of this type is CONVERTED TO, or predeclared.Unknown when there is none and the literal keeps its own type.

It resolves a conversion TARGET. It began as a routing hint — something consulted to pick an oneof member when the literal's spelling was ambiguous — and the difference matters: a hint is harmless when wrong, because the value survives in another member, while a target decides whether the source compiles. Both the lowering and the diagnostics reach it through ConvertArgKind, so there is one answer rather than two that have to agree (#188).

A wrapper resolves to the scalar it wraps: `google.protobuf.DoubleValue` is the canonical nullable double, and a `@default` on one is a value for that double. Without this the wrappers kept the spelling route and with it the (MaxInt64, MaxUint64] ambiguity #172 removed from bare scalars (#174).

The arbitrary-precision types protowire defines — `pxf.BigInt`, `pxf.Decimal`, `pxf.BigFloat` — are deliberately NOT mapped. They exist to hold values a `double` cannot represent, so routing them through `double_value` would lose the precision that is their entire purpose.

The cost of leaving them unmapped is worse than precision, though, and was recorded too mildly here before: a literal in (MaxInt64, MaxUint64] lowered into `int_value` and reached a consumer with the WRONG SIGN — `@default(1e19)` on a `pxf.BigInt` applied a negative number (#176). checkCarrierRange now rejects that at compile time rather than inventing a value, which is the outcome that does not guess.

Giving these types a faithful route still needs a carrier member that can hold them, not a different scalar route.

func (Type) Deprecated

func (t Type) Deprecated() Value

Deprecated returns whether this type is deprecated, by returning the relevant option value for setting deprecation.

func (Type) EntryFields

func (t Type) EntryFields() (key, value Member)

EntryFields returns the key and value fields for this map entry type.

func (Type) Extends

func (t Type) Extends() seq.Indexer[Extend]

Extends returns the options applied to this type.

func (Type) ExtensionRanges

func (t Type) ExtensionRanges() seq.Indexer[ReservedRange]

ExtensionRanges returns the extension ranges declared in this type.

func (Type) Extensions

func (t Type) Extensions() seq.Indexer[Member]

Extensions returns any extensions nested within this type.

func (Type) FeatureSet

func (t Type) FeatureSet() FeatureSet

FeatureSet returns the Editions features associated with this type.

func (Type) FullName

func (t Type) FullName() FullName

FullName returns this type's fully-qualified name.

If t is zero, returns "". Otherwise, the returned name will be absolute unless this is a primitive type.

func (Type) GroupField

func (t Type) GroupField() Member

GroupField returns the group field that generated this type, if any.

func (Type) InternedFullName

func (t Type) InternedFullName() intern.ID

InternedName returns the intern ID for Type.FullName

Predeclared types do not have an interned name.

func (Type) InternedName

func (t Type) InternedName() intern.ID

InternedName returns the intern ID for Type.FullName().Name()

Predeclared types do not have an interned name.

func (Type) InternedScope

func (t Type) InternedScope() intern.ID

InternedScope returns the intern ID for Type.Scope

Predeclared types do not have an interned name.

func (Type) IsAny

func (t Type) IsAny() bool

IsAny returns whether this is the type google.protobuf.Any, which gets special treatment in the language.

func (Type) IsClosedEnum

func (t Type) IsClosedEnum() bool

func (Type) IsEnum

func (t Type) IsEnum() bool

IsEnum returns whether this is an enum type.

func (Type) IsExported

func (t Type) IsExported() (exported, explicit bool)

IsExported returns whether this type is exported for the purposes of visibility in other files.

Returns whether this was set explicitly via the export or local keywords.

func (Type) IsMapEntry

func (t Type) IsMapEntry() bool

IsMapEntry returns whether this is a map type's entry.

func (Type) IsMessage

func (t Type) IsMessage() bool

IsMessage returns whether this is a message type.

func (Type) IsMessageSet

func (t Type) IsMessageSet() bool

IsMessageSet returns whether this is a message type using the message set encoding.

func (Type) IsPackable

func (t Type) IsPackable() bool

IsPackable returns whether this type can be the element of a packed repeated field.

func (Type) IsPredeclared

func (t Type) IsPredeclared() bool

IsPredeclared returns whether this is a predeclared type.

func (Type) MapField

func (t Type) MapField() Member

MapField returns the map field that generated this type, if any.

func (Type) MemberByInternedName

func (t Type) MemberByInternedName(name intern.ID) Member

MemberByInternedName is like Type.MemberByName, but takes an interned string.

func (Type) MemberByName

func (t Type) MemberByName(name string) Member

MemberByName looks up a member with the given name.

Returns a zero member if there is no such member.

func (Type) MemberByNumber

func (t Type) MemberByNumber(number int32) Member

MemberByNumber looks up a member with the given number.

Returns a zero member if there is no such member.

func (Type) Members

func (t Type) Members() seq.Indexer[Member]

Members returns the members of this type.

Predeclared types have no members; message and enum types do.

func (Type) Name

func (t Type) Name() string

Name returns this type's declared name, i.e. the last component of its full name.

func (Type) Nested

func (t Type) Nested() seq.Indexer[Type]

Nested returns those types which are nested within this one.

Only message types have nested types.

func (Type) OccupiedRanges

func (t Type) OccupiedRanges() iter.Seq2[[2]int32, seq.Indexer[TagRange]]

OccupiedRanges returns ranges of member numbers currently in use in this type. The pairs of numbers are inclusive ranges.

func (Type) Oneofs

func (t Type) Oneofs() seq.Indexer[Oneof]

Oneofs returns the options applied to this type.

func (Type) Options

func (t Type) Options() MessageValue

Options returns the options applied to this type.

func (Type) Parent

func (t Type) Parent() Type

Parent returns the type that this type is declared inside of, if it isn't at the top level.

func (Type) Predeclared

func (t Type) Predeclared() predeclared.Name

Predeclared returns the predeclared type that this Type corresponds to, if any.

Returns either predeclared.Unknown or a value such that predeclared.Name.IsScalar returns true. For example, this will *not* return predeclared.Map for map fields.

func (Type) PxfNumber added in v0.32.0

func (t Type) PxfNumber() PxfNumber

PxfNumber reports which arbitrary-precision type this is, or PxfNone.

These three exist to hold values `int64` and `double` cannot, so an annotation argument on one of them is carried in the matching AnnotationArg member whatever its magnitude — routing a small value through `int_value` and a large one through `big_int_value` would give a consumer two cases for one type, and routing either through `double` would lose the precision the type was declared for (protowire#263).

A map field resolves through its value type, as CarrierScalar does.

func (Type) Ranges

func (t Type) Ranges(number int32) iter.Seq[TagRange]

Ranges returns an iterator over [TagRange]s that contain number.

func (Type) ReservedNames

func (t Type) ReservedNames() seq.Indexer[ReservedName]

ReservedNames returns the reserved named declared in this type.

func (Type) ReservedRanges

func (t Type) ReservedRanges() seq.Indexer[ReservedRange]

ReservedRanges returns the reserved ranges declared in this type.

This does not include reserved field names; see Type.ReservedNames.

func (Type) Scope

func (t Type) Scope() FullName

Scope returns the scope in which this type is defined.

type TypeAlias

type TypeAlias id.Node[TypeAlias, *File, *rawTypeAlias]

TypeAlias is a `type` declaration introduced by the Protowire Schema Extensions (PSE) grammar — see ast.DeclType.

Type aliases are language sugar that lower to standard protobuf: `type Email = string` declares `Email` as a name that fields can use in place of `string` (per RFC-001 §5). Annotations attached at the alias declaration become part of every use site's annotation list, giving authors a single place to refine a primitive base type with validation rules and documentation.

Phase scope here is symbol registration plus FDP emission via the [pwsv1.FileTypeDecls] file-scope carrier (1330). Field-type resolution against type aliases (so that `Email email = 1;` produces a `string` field with the alias's annotations expanded on the field-level [pwsv1.AnnotationList]) lives in the broader field-type resolution stack and is a separate follow-up.

func (TypeAlias) AST

func (t TypeAlias) AST() ast.DeclType

AST returns the declaration for this type alias, if known.

func (TypeAlias) Annotations

func (t TypeAlias) Annotations() seq.Indexer[AnnotationUse]

Annotations returns the annotation use sites attached to this alias (trailing form: `type Email = string @validate(...);`). See Type.Annotations for the resolution model.

func (TypeAlias) BaseTypeFQN added in v0.21.0

func (t TypeAlias) BaseTypeFQN() string

BaseTypeFQN returns the fully-qualified name of the alias's resolved base type — `type CompanyEmail = Email` written bare in-package yields "fixtures.lib.Email" — or the predeclared name ("string") for primitive bases. For a chained alias the immediate base is returned, itself fully qualified.

Falls back to TypeAlias.BaseTypeName's as-written text when the base did not resolve; broken bases are diagnosed at the alias declaration site by the base-resolution pass.

func (TypeAlias) BaseTypeName

func (t TypeAlias) BaseTypeName() string

BaseTypeName returns the canonical text of the alias's base-type expression as the user wrote it (e.g. "string", or "myco.commons.Address"). Field-type resolution against this name is deferred to the broader resolution stack — see the package- level note on TypeAlias.

func (TypeAlias) FullName

func (t TypeAlias) FullName() FullName

FullName returns the alias's fully-qualified name.

func (TypeAlias) InternedFullName

func (t TypeAlias) InternedFullName() intern.ID

InternedFullName returns the intern ID for TypeAlias.FullName.

func (TypeAlias) InternedName

func (t TypeAlias) InternedName() intern.ID

InternedName returns the intern ID for TypeAlias.FullName().Name().

func (TypeAlias) Name

func (t TypeAlias) Name() string

Name returns the alias's declared name, i.e. the last component of its full name.

type Value

type Value id.Node[Value, *File, *rawValue]

Value is an evaluated expression, corresponding to an option in a Protobuf file.

func (Value) AsBool

func (v Value) AsBool() (value, ok bool)

AsBool is a shortcut for Element.AsBool, if this value is singular.

func (Value) AsEnum

func (v Value) AsEnum() Member

AsEnum is a shortcut for Element.AsEnum, if this value is singular.

func (Value) AsFloat

func (v Value) AsFloat() (float64, bool)

AsFloat is a shortcut for Element.AsFloat, if this value is singular.

func (Value) AsInt

func (v Value) AsInt() (int64, bool)

AsInt is a shortcut for Element.AsInt, if this value is singular.

func (Value) AsMessage

func (v Value) AsMessage() MessageValue

AsMessage is a shortcut for Element.AsMessage, if this value is singular.

func (Value) AsString

func (v Value) AsString() (string, bool)

AsString is a shortcut for Element.AsString, if this value is singular.

func (Value) AsUInt

func (v Value) AsUInt() (uint64, bool)

AsUInt is a shortcut for Element.AsUInt, if this value is singular.

func (Value) Container

func (v Value) Container() MessageValue

Container returns the message value which contains this value, assuming it is not a top-level value.

This function is analogous to Member.Container, which returns the type that contains a member; in particular, for extensions, it returns an extendee.

func (Value) Elements

func (v Value) Elements() seq.Indexer[Element]

Elements returns an indexer over the elements within this value.

If the value is not an array, it contains the singular element within; otherwise, it returns the elements of the array.

The indexer will be nonempty except for the zero Value. That is to say, unset fields of [MessageValue]s are not represented as a distinct "empty" Value.

func (Value) Field

func (v Value) Field() Member

Field returns the field this value sets, which includes the value's type information.

NOTE: Member.Element returns google.protobuf.Any, the concrete type of the values in Value.Elements may be distinct from it.

func (Value) IsTopLevel

func (v Value) IsTopLevel() bool

IsTopLevel returns whether this value corresponds with a top-level option declaration in source.

This will return false on options for synthetic types, e.g. the map_entry option on map entry types, because this is not set for synthetic types.

func (Value) IsZeroValue

func (v Value) IsZeroValue() bool

IsZeroValue is a shortcut for Element.IsZeroValue.

func (Value) KeyAST

func (v Value) KeyAST() ast.ExprAny

KeyAST returns a representative AST node for the message key that evaluated from this value.

func (Value) KeyASTs

func (v Value) KeyASTs() seq.Indexer[ast.ExprAny]

KeyASTs returns the AST nodes for each key associated with a value in Value.ValueASTs.

This will either be the key value from an ast.FieldExpr (which need not be an ast.PathExpr, in the case of an extension) or the ast.PathExpr associated with the left-hand-side of an option setting.

func (Value) Marshal

func (v Value) Marshal(buf []byte, r *report.Report) []byte

Marshal converts this value into a wire format record and appends it to buf.

If r is not nil, it will be used to record diagnostics generated during the marshal operation.

func (Value) OptionPaths

func (v Value) OptionPaths() seq.Indexer[ast.Path]

OptionPaths returns the AST nodes for option paths that set this node.

There will be one path per value returned from Value.ValueASTs. Generally, you'll want to use Value.KeyASTs instead.

func (Value) OptionSpan

func (v Value) OptionSpan() source.Spanner

OptionSpan returns a representative span for the option that set this value.

The Spanner will be an ast.ExprField, if it is set in an ast.ExprDict.

func (Value) OptionSpans

func (v Value) OptionSpans() seq.Indexer[source.Spanner]

OptionSpans returns an indexer over spans for the option that set this value.

The Spanner will be an ast.ExprField, if it is set in an ast.ExprDict.

func (Value) ValueAST

func (v Value) ValueAST() ast.ExprAny

ValueAST returns a representative expression that evaluated to this value.

For complicated options (such as repeated fields), there may be more than one contributing expression; this will just return *one* of them.

func (Value) ValueASTs

func (v Value) ValueASTs() seq.Indexer[ast.ExprAny]

ValueASTs returns all expressions that contributed to evaluating this value.

There may be more than one such expression, for repeated fields set more than once.

Directories

Path Synopsis
Package presence provides Kind, which denotes the way in which a field can be present in a Protobuf message.
Package presence provides Kind, which denotes the way in which a field can be present in a Protobuf message.
Package sourceinfo contains decoding operations for Protobuf descriptor SourceCodeInfo paths.
Package sourceinfo contains decoding operations for Protobuf descriptor SourceCodeInfo paths.
decode command
decode is a helper tool for ingesting an encoded FileDescriptorSet and dumping its SourceCodeInfo in a readable format.
decode is a helper tool for ingesting an encoded FileDescriptorSet and dumping its SourceCodeInfo in a readable format.

Jump to

Keyboard shortcuts

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