resolver

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package resolver turns syntax imports into project or compiler-known package identities before type checking. Backends therefore never interpret a raw TypeRB import path on their own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalPackageImport added in v0.2.27

func CanonicalPackageImport(importPath string, aliases map[string]string) string

CanonicalPackageImport applies the longest matching TypeRB package alias to a source import path. Compile-time providers use the same mapping before the ordinary resolver has produced its import graph.

func CollectExports

func CollectExports(statements []ast.Statement) map[string]Export

func ProjectImportModuleCandidates added in v0.2.29

func ProjectImportModuleCandidates(importPath string) ([]string, bool)

ProjectImportModuleCandidates returns the canonical module identities that may satisfy one project import. File-root discovery and the resolver share this function so extension trimming, path validation, and directory-index fallback cannot drift between the source graph and semantic resolution.

func ValidateImportGraph

func ValidateImportGraph(catalog *Catalog, results map[string]Result) map[string][]diagnostic.Diagnostic

ValidateImportGraph rejects project import cycles with a deterministic path. A single cross-mode rule keeps initialization order independent of Ruby, TypeScript, or Go runtime loader behavior.

Types

type Binding

type Binding struct {
	Import  *Import
	Name    string
	Export  *Export
	Member  *Member
	Library *stdlib.Symbol
}

func (Binding) Type

func (b Binding) Type() types.Type

type Catalog

type Catalog struct {
	Modules            map[string]*Module
	CompilerOwnedTypes map[string]Export
}

func NewCatalog

func NewCatalog(modules []Module) (*Catalog, map[string][]diagnostic.Diagnostic)

type EnumVariant

type EnumVariant struct {
	Name     string
	Fields   []RecordField
	RawValue string
}

type Export

type Export struct {
	Name                   string
	Kind                   ExportKind
	Type                   types.Type
	Parameters             []types.Type
	ParameterResultBridges []NativeResultBridge
	Required               int
	Variadic               bool
	Members                map[string]Member
	Fields                 []RecordField
	EnumMembers            []string
	EnumVariants           []EnumVariant
	EnumRawType            types.Type
	TypeParameters         []string
	AliasTarget            types.Type
	AliasEnum              bool
	Superclass             string
	Interfaces             []types.Type
	Span                   token.Span
	UnsupportedFields      map[string]string
	// NativeExported distinguishes a real target-package type export from a
	// provider-only structural record used to describe another declaration.
	NativeExported bool
}

type ExportKind

type ExportKind string
const (
	ClassExport     ExportKind = "class"
	RecordExport    ExportKind = "record"
	EnumExport      ExportKind = "enum"
	TypeAliasExport ExportKind = "type_alias"
	ModuleExport    ExportKind = "module"
	InterfaceExport ExportKind = "interface"
	FunctionExport  ExportKind = "function"
	ValueExport     ExportKind = "value"
)

type Import

type Import struct {
	Node       *ast.ImportStatement
	Kind       ImportKind
	Path       string
	ModulePath string
	Alias      string
	Symbols    []string
	Definition *stdlib.Package
	Exports    map[string]Export
	Filename   string
}

func (*Import) RuntimePath

func (i *Import) RuntimePath() string

type ImportKind

type ImportKind string
const (
	StandardImport ImportKind = "standard"
	OfficialImport ImportKind = "official"
	ProjectImport  ImportKind = "project"
	NativeImport   ImportKind = "native"
)

type Member

type Member struct {
	Name              string
	Kind              ExportKind
	Type              types.Type
	TypeParameters    []string
	Parameters        []types.Type
	Required          int
	Variadic          bool
	Class             bool
	Readonly          bool
	EnumOwner         string
	Generated         string
	UnsupportedFields map[string]string
}

type Module

type Module struct {
	Path          string
	Filename      string
	Program       *ast.Program
	Exports       map[string]Export
	CompilerOwned bool
	Official      bool
}

type NativeResultBridge added in v0.3.0

type NativeResultBridge struct {
	Kind  string
	Type  types.Type
	Error types.Type
}

NativeResultBridge keeps both sides of a package-owned callback boundary. Type is the native Promise success signature, while Error is the TypeRB Result error payload accepted by the adapter.

type Options

type Options struct {
	Mode           string
	SourceRoot     string
	Filename       string
	PackageAliases map[string]string
	CompilerOwned  bool
	Official       bool
	Catalog        *Catalog
	Declarations   *declaration.Catalog
	NativePackages *nativepackage.Catalog
}

type RecordField

type RecordField struct {
	Name         string
	JSONName     string
	Type         types.Type
	Optional     bool
	ResultBridge NativeResultBridge
}

type Result

type Result struct {
	Imports      map[*ast.ImportStatement]*Import
	Packages     map[string]*Import
	Symbols      map[string]Binding
	NativeSyntax bool
	Declarations *declaration.Catalog
	Catalog      *Catalog
}

func Resolve

func Resolve(program *ast.Program, options Options) (Result, []diagnostic.Diagnostic)

func (Result) CatalogTypeAlias added in v0.3.0

func (r Result) CatalogTypeAlias(name string) (Export, bool)

CatalogTypeAlias resolves a transparent alias from the complete project catalog for semantic expansion only. Imported value contracts retain their declared alias names even when the alias is owned by another module, so the checker needs this lookup to interpret the value without making the alias name available to source annotations. NewCatalog rejects duplicate exported type names, which keeps this lookup unambiguous.

func (Result) CompilerOwnedType added in v0.1.9

func (r Result) CompilerOwnedType(name string) (Export, bool)

CompilerOwnedType returns declarations that were inferred from a portable library result. It supports member checking on inferred values without making the type name available to source annotations that omitted an import.

func (Result) ContractTypeAlias added in v0.3.0

func (r Result) ContractTypeAlias(name string) (Export, bool)

ContractTypeAlias resolves a catalog-owned transparent alias only when it is reachable from a source-selected import contract. This is narrower than source visibility: it lets the checker interpret a returned value while preventing an unrelated project alias from changing an opaque native type that happens to use the same name.

func (Result) ImportedType

func (r Result) ImportedType(typeName string) (Binding, bool)

func (Result) InferredType added in v0.2.3

func (r Result) InferredType(typeName string) (Binding, bool)

InferredType resolves a type that appears in the contract of an explicitly imported symbol without making that type available to source annotations. Source-visible type names continue to use ImportedType and therefore still require an explicit named or namespace import.

func (Result) InferredTypeMember added in v0.2.3

func (r Result) InferredTypeMember(typeName, memberName string) (Binding, bool)

InferredTypeMember resolves a member on a type produced by an explicitly imported package even when the source did not import that type by name. This keeps inferred library values usable without weakening named-import rules for source annotations.

func (Result) Member

func (r Result) Member(alias, name string) (Binding, bool)

func (Result) ReceiverMethod

func (r Result) ReceiverMethod(receiver types.Type, name string) (Binding, bool)

ReceiverMethod returns an implicit portable method binding. The binding is deliberately backed by the same standard package definition as its function form, even though TypeRB source does not need to import the method.

func (Result) TypeMember

func (r Result) TypeMember(typeName, name string) (Binding, bool)

Jump to

Keyboard shortcuts

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