sema

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

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

type Diagnostic struct {
	Pos ast.Position
	Msg string
}

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

func Lower(file *ast.File, opts ...Option) (*ir.Model, Diagnostics)

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.

func (FSLoader) Load

func (FSLoader) Load(from, path string) (string, string, error)

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

func WithLoader(l Loader) Option

WithLoader supplies the Loader that reads imported files. Without one, any import is a diagnostic.

func WithPrelude

func WithPrelude(name, src string) Option

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.

func (References) At added in v0.2.2

func (rs References) At(filename string, offset int) (Reference, bool)

At returns the reference covering a byte offset in a file, and whether there is one. It is a binary search over the sorted table.

Jump to

Keyboard shortcuts

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