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 ¶
- func CanonicalPackageImport(importPath string, aliases map[string]string) string
- func CanonicalProjectImportPath(importPath string, modulePaths map[string]bool, aliases map[string]string) string
- func CollectExports(statements []ast.Statement) map[string]Export
- func ProjectImportModuleCandidates(importPath string) ([]string, bool)
- func ValidateImportGraph(catalog *Catalog, results map[string]Result) map[string][]diagnostic.Diagnostic
- type Binding
- type Catalog
- type EnumVariant
- type Export
- type ExportKind
- type Import
- type ImportKind
- type Member
- type Module
- type NativeCallResultBridge
- type NativeResultBridge
- type Options
- type RecordField
- type Result
- func (r Result) CatalogType(name string) (Binding, bool)
- func (r Result) CatalogTypeAlias(name string) (Export, bool)
- func (r Result) CompilerOwnedType(name string) (Export, bool)
- func (r Result) ContractType(name string) (Binding, bool)
- func (r Result) ContractTypeAlias(name string) (Export, bool)
- func (r Result) ImportedType(typeName string) (Binding, bool)
- func (r Result) InferredType(typeName string) (Binding, bool)
- func (r Result) InferredTypeMember(typeName, memberName string) (Binding, bool)
- func (r Result) Member(alias, name string) (Binding, bool)
- func (r Result) ReceiverMethod(receiver types.Type, name string) (Binding, bool)
- func (r Result) TypeMember(typeName, name string) (Binding, bool)
- type RuntimeBinding
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanonicalPackageImport ¶ added in v0.2.27
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 CanonicalProjectImportPath ¶ added in v0.3.9
func CanonicalProjectImportPath(importPath string, modulePaths map[string]bool, aliases map[string]string) string
CanonicalProjectImportPath removes a terminal /index only when the shorter authored path resolves to the same known module. Callers provide the module identities available in their project snapshot so formatting and import completion cannot change the selected module when both name.trb and name/index.trb exist.
func ProjectImportModuleCandidates ¶ added in v0.2.29
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 Catalog ¶
type Catalog struct {
Modules map[string]*Module
CompilerOwnedTypes map[string]Export
// contains filtered or unexported fields
}
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
Source bool
Type types.Type
Parameters []callsignature.Parameter
ParameterResultBridges []NativeResultBridge
CallResultBridge NativeCallResultBridge
Variadic bool
Members map[string]Member
Fields []RecordField
EnumMembers []string
EnumVariants []EnumVariant
EnumRawType types.Type
TypeParameters []string
AliasTarget types.Type
AliasEnum bool
NewtypeTarget types.Type
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
Runtime *RuntimeBinding
}
type ExportKind ¶
type ExportKind string
const ( ClassExport ExportKind = "class" RecordExport ExportKind = "record" EnumExport ExportKind = "enum" TypeAliasExport ExportKind = "type_alias" NewtypeExport ExportKind = "newtype" 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
CompilerGenerated bool
DeclarationProvider bool
}
func (*Import) RuntimePath ¶
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 []callsignature.Parameter
Variadic bool
Class bool
Readonly bool
EnumOwner string
Generated string
CallResultBridge NativeCallResultBridge
UnsupportedFields map[string]string
}
type NativeCallResultBridge ¶ added in v0.3.22
NativeCallResultBridge converts one native call's Promise settlement into a checked TypeRB Result. Unlike NativeResultBridge, it applies to the callee's return boundary rather than to a callback parameter.
type NativeResultBridge ¶ added in v0.3.0
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 RecordField ¶
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) CatalogType ¶ added in v0.3.31
CatalogType resolves a type declaration and its owner from the complete project catalog. NewCatalog rejects duplicate exported type names, so the result is unambiguous. This lookup is for compiler-generated references; source annotations must continue to use ImportedType.
func (Result) CatalogTypeAlias ¶ added in v0.3.0
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
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) ContractType ¶ added in v0.3.31
ContractType resolves a catalog-owned type only when it is reachable from a source-selected import contract. This is narrower than source visibility: it lets the checker interpret returned values while preventing an unrelated project type from replacing an opaque type with the same name.
func (Result) ContractTypeAlias ¶ added in v0.3.0
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) InferredType ¶ added in v0.2.3
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
InferredTypeMember resolves a member on a type produced by an explicitly imported package or exposed through one of its selected value contracts, even when the source did not import that type by name. This keeps inferred values usable without weakening named-import rules for source annotations.
func (Result) ReceiverMethod ¶
ReceiverMethod returns an implicit portable method binding. The binding is backed by the compiler-owned contract catalog even when that contract has no public package form.