Documentation
¶
Overview ¶
Package sema lowers a parse tree to the resolved semantic model in the ir package: it resolves names, lowers sugar to prelude types, and interns type references. It is private and free to change; see docs/design/ir-plan.md for what each pass adds.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Diagnostic ¶
Diagnostic is one problem found while lowering, at a source position.
func (*Diagnostic) Error ¶
func (d *Diagnostic) Error() string
type Diagnostics ¶
type Diagnostics []*Diagnostic
Diagnostics is every problem one pass found. A non-empty list means no later pass should run.
func Lower ¶
Lower turns a parsed file into a model and every diagnostic the pass produced. A non-empty diagnostic list means the model is incomplete.
The prelude is loaded into an outer scope, so a file's declaration shadows a prelude name.
func (Diagnostics) Error ¶
func (ds Diagnostics) Error() string
type FSLoader ¶
type FSLoader struct{}
FSLoader resolves an import as a filesystem path relative to the file that imports it.
type Loader ¶
type Loader interface {
// Load returns the resolved name of the file imported as path from the
// file at from, and its source.
Load(from, path string) (name, src string, err error)
}
Loader reads the source of an imported file. Lowering does not touch the filesystem itself.
type Option ¶
type Option func(*config)
Option configures a lowering.
func WithLoader ¶
WithLoader supplies the Loader that reads imported files. Without one, any import is a diagnostic.
func WithPrelude ¶
WithPrelude lowers against the given prelude source instead of the embedded one.
func WithReferences ¶ added in v0.2.2
func WithReferences(out *References) Option
WithReferences records every name lowering resolves into out.
type Reference ¶ added in v0.2.2
type Reference struct {
Pos ast.Position // where the name was written
Len int // its length in bytes
Name string // the name as written
// Target is where the name's referent was declared, as bound in scope.
// It is zero for an unresolved or qualified name. A name a `_` import
// merged in points into the dependency that declares it.
Target ast.Position
// Decl is the declaration the name refers to, unset for a type
// parameter and for an unresolved name.
Decl *ir.ID
}
Reference is one name, as written, and what it resolved to. The type table interns a second mention away, so this is what "go to definition" reads.
type References ¶ added in v0.2.2
type References []Reference
References is every name one lowering resolved, in source order.