Modules¶
Static interpretation of a module graph: module paths and identities, loaders that find a module's source, name resolution against imported interfaces, the interfaces themselves, and the flat program the compiler sees. The modules reference describes the surface, and the semantics states the resolution rules.
modules
¶
Files as modules: imports, qualified names, visibility, and re-exports.
Each .qvr file is a module whose path follows the directory layout
below a search root, so syntax/lambda.qvr is syntax.lambda. A
module is a triple of its identity (ModuleIdentity), its public
interface (ModuleInterface), and its body. Importing includes another
module's interface and keeps the identity of every name it brings in, so a
declaration reached along two import paths is one declaration.
Compilation interprets the module graph statically into one flat program
(interpret) before any code generation, so the compiler, the reference
machine, and every transpile target see a single, fully qualified program.
The entry points are interpret_file, interpret_module, and
interpret_source; quivers.dsl.load and quivers.dsl.loads compile
their result.
ALLOCATING_EFFECTS
module-attribute
¶
The prelude interfaces whose instances name sites or parameters.
PROGRAM_INSTANCES
module-attribute
¶
The built-in instances every probabilistic program performs through.
HOLE_MARK
module-attribute
¶
Marks the display of a hole, so ?Worlds never names a source module.
ROOT_MODULE_NAME
module-attribute
¶
The path of a root module given as source text rather than a file.
QUOTED_NAME_POSITIONS
module-attribute
¶
QUOTED_NAME_POSITIONS: Mapping[str, int] = {'ValueCall': 0, 'ValueConstruct': 0, 'TypeName': 0, 'TypeApply': 0, 'IndexApply': 0, 'PatternConstructor': 0, 'CompCall': 0, 'MorphClause': 0}
The quoted-syntax constructors whose argument at the given position is a reference to a declaration: a callee, a constructor, a type, an index sort's constructor, or a source constructor of a signature morphism.
STANDARD_LIBRARY_NAME
module-attribute
¶
The first segment of every module path of the shipped standard library.
STANDARD_LIBRARY_ROOT
module-attribute
¶
The directory the standard library's modules live in, as std/....
MODULE_SUFFIXES
module-attribute
¶
MODULE_SUFFIXES = (MODULE_SUFFIX, LITERATE_SUFFIX)
The file suffixes of a module: QVR source and literate Markdown.
ModuleErrorCode
¶
ModuleErrorCode = Literal['module-unknown', 'module-cycle', 'module-ambiguous-path', 'module-alias-clash', 'name-unknown', 'name-private', 'name-ambiguous', 'name-not-imported', 'export-unknown', 'export-clash', 'export-expression', 'open-unknown', 'signature-mismatch', 'signature-item', 'sharing-mismatch', 'module-abstraction', 'module-application', 'module-recursion', 'implicit-ambiguous', 'implicit-missing', 'hole-conflict', 'hole-signature', 'hole-unfilled', 'link-unknown-hole', 'link-conflict', 'link-recursion']
The codes a module diagnostic carries.
Locate
¶
Locate = Callable[[int, int], SourceLocation]
Map a flat-program line and column to the source location they come from.
SiteKind
¶
What a site is: a program step's draw, observation, or marginalized latent, or a learned parameter.
NameResolver
¶
Resolve a name written at a line and column of a module to its flat name,
or None when the module binds no such name.
ResolutionRole
¶
Why a token resolved: it declares, refers to, exports, or imports a name.
ModuleDiagnostic
didactic-model
¶
ModuleDiagnostic(*, code: ModuleErrorCode, message: str, location: SourceLocation, suggestions: tuple[str, ...] = (), related: tuple[SourceLocation, ...] = ())
Bases: Model
One refusal of the module system.
| ATTRIBUTE | DESCRIPTION |
|---|---|
code |
The stable code.
TYPE:
|
message |
The description, without the location.
TYPE:
|
location |
Where the offending token is.
TYPE:
|
suggestions |
Near-miss names, best first.
TYPE:
|
related |
Further locations the message refers to, in order (the imports along a cycle, the two sources of an ambiguous name).
TYPE:
|
render
¶
The diagnostic as one line.
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/modules/errors.py
ModuleError
¶
ModuleError(diagnostic: ModuleDiagnostic)
Bases: Exception
Raised when the module graph does not load or a name does not resolve.
| PARAMETER | DESCRIPTION |
|---|---|
diagnostic
|
The structured diagnostic.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
diagnostic |
The structured diagnostic.
TYPE:
|
Source code in src/quivers/dsl/modules/errors.py
code
property
¶
code: ModuleErrorCode
The diagnostic's code.
| RETURNS | DESCRIPTION |
|---|---|
ModuleErrorCode
|
The stable code. |
SourceLocation
didactic-model
¶
Bases: Model
A position in one module's source.
| ATTRIBUTE | DESCRIPTION |
|---|---|
file |
The file (or label) of the module's source.
TYPE:
|
line |
The 1-based line.
TYPE:
|
column |
The 0-based column.
TYPE:
|
render
¶
file:line:column.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The location as editors and compilers print it. |
DeductionRequirement
didactic-model
¶
DeductionRequirement(*, atom: str, sorts: tuple[str, ...] = (), use: SourceLocation, fixes: tuple[SourceLocation, ...] = ())
Bases: Model
What generic code requires of one open atom of its parameter.
| ATTRIBUTE | DESCRIPTION |
|---|---|
atom |
The atom.
TYPE:
|
sorts |
Per slot,
TYPE:
|
use |
The first use, which fixes the arity.
TYPE:
|
fixes |
Per slot, the use that fixes its sort (the first use when no use fixes it).
TYPE:
|
render
¶
The requirement as an interface shows it.
| PARAMETER | DESCRIPTION |
|---|---|
parameter
|
The parameter's name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/modules/generic_uses.py
LoadedModule
¶
LoadedModule(source: ModuleSource, tree: _Tree, names: FileNames)
A module's source, parse tree, and names, before checking.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The source.
TYPE:
|
tree
|
Its parse tree.
TYPE:
|
names
|
Its name occurrences.
TYPE:
|
Source code in src/quivers/dsl/modules/graph.py
ModuleGraph
¶
ModuleGraph(root: ModuleIdentity, order: tuple[ModuleIdentity, ...], loaded: Mapping[ModuleIdentity, LoadedModule], checked: Mapping[ModuleIdentity, CheckedModule], holes: Mapping[HoleModule, HoleDeclaration] | None = None, hole_interfaces: Mapping[HoleModule, ModuleInterface] | None = None, links: Mapping[HoleModule, LinkDeclaration] | None = None)
A loaded, acyclic, checked module graph.
| PARAMETER | DESCRIPTION |
|---|---|
root
|
The module the graph was loaded from.
TYPE:
|
order
|
Every module, each after the modules it imports; the root is last.
TYPE:
|
loaded
|
Each module's source, tree, and names.
TYPE:
|
checked
|
Each module's resolutions and interface.
TYPE:
|
holes
|
The package's holes, each with the signature it is checked against.
TYPE:
|
hole_interfaces
|
What a module importing a hole sees: its signature's items.
TYPE:
|
links
|
The holes the graph fills, each with its filler.
TYPE:
|
Source code in src/quivers/dsl/modules/graph.py
interface
¶
interface(identity: ModuleIdentity) -> ModuleInterface
The interface of one module of the graph, or of one of its holes.
| PARAMETER | DESCRIPTION |
|---|---|
identity
|
The module or hole.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ModuleInterface
|
Its public names. |
Source code in src/quivers/dsl/modules/graph.py
imports_of
¶
imports_of(identity: ModuleIdentity) -> tuple[ModuleIdentity, ...]
The modules and holes a module imports directly.
| PARAMETER | DESCRIPTION |
|---|---|
identity
|
A module of the graph.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[ModuleIdentity, ...]
|
Its imports, in order. |
Source code in src/quivers/dsl/modules/graph.py
fillings
¶
fillings() -> dict[HoleModule, ModuleIdentity]
The filler of each filled hole.
| RETURNS | DESCRIPTION |
|---|---|
dict[HoleModule, ModuleIdentity]
|
The fillings. |
Source code in src/quivers/dsl/modules/graph.py
hole_closure
¶
hole_closure() -> dict[ModuleIdentity, tuple[HoleModule, ...]]
The holes each module needs (see linking.hole_closure).
| RETURNS | DESCRIPTION |
|---|---|
dict[ModuleIdentity, tuple[HoleModule, ...]]
|
Each module's holes, sorted by path. |
Source code in src/quivers/dsl/modules/graph.py
HoleModule
didactic-model
¶
Bases: ModuleIdentity
An unfilled hole of a package (hole Worlds : WorldModel).
Modules import a hole by its path like any module and are checked against its signature; linking fills it, and a module that depends on holes is then identified by the fillings it is linked with.
| ATTRIBUTE | DESCRIPTION |
|---|---|
path |
The hole's module path's segments.
TYPE:
|
ModuleIdentity
didactic-model
¶
Bases: TaggedUnion
Which module a module is.
Each variant names one way a module comes to exist. module_display
renders any of them for diagnostics and for the module prefix of the
flat names its declarations get.
SourceModule
didactic-model
¶
Bases: ModuleIdentity
A module given by a source file (or source text).
| ATTRIBUTE | DESCRIPTION |
|---|---|
path |
The module path's segments.
TYPE:
|
AppliedModule
didactic-model
¶
AppliedModule(*, functor: ModuleIdentity, arguments: tuple[ModuleArgument, ...] = (), instance: str = '', kind: Literal['applied_module'] = 'applied_module')
Bases: ModuleIdentity
A functor applied to its arguments.
An applicative application is identified by the functor and the
arguments alone, so F(X) written twice is one module. A generative
one also carries the application it came from, so each application is
a module of its own.
| ATTRIBUTE | DESCRIPTION |
|---|---|
functor |
The functor or template.
TYPE:
|
arguments |
The arguments, in parameter order.
TYPE:
|
instance |
Empty for an applicative application; for a generative one, the application site that makes it distinct.
TYPE:
|
ModuleArgument
didactic-model
¶
ModuleArgument(*, parameter: str, module: ModuleIdentity)
Bases: Model
One argument of a functor application.
| ATTRIBUTE | DESCRIPTION |
|---|---|
parameter |
The parameter it instantiates.
TYPE:
|
module |
The argument.
TYPE:
|
NestedModule
didactic-model
¶
NestedModule(*, parent: ModuleIdentity, name: str, kind: Literal['nested_module'] = 'nested_module')
Bases: ModuleIdentity
A module, signature, or computation template declared inside a module.
| ATTRIBUTE | DESCRIPTION |
|---|---|
parent |
The declaring module.
TYPE:
|
name |
The declared name.
TYPE:
|
ParameterModule
didactic-model
¶
ParameterModule(*, functor: ModuleIdentity, name: str, kind: Literal['parameter_module'] = 'parameter_module')
Bases: ModuleIdentity
A functor's (or a template's) module parameter, known by its signature.
Generic code names its parameter's items through this identity; an application substitutes the argument for it, and the generic check gives its abstract items fresh declarations.
| ATTRIBUTE | DESCRIPTION |
|---|---|
functor |
The functor or template.
TYPE:
|
name |
The parameter's name.
TYPE:
|
SealedModule
didactic-model
¶
SealedModule(*, module: ModuleIdentity, signature: str, instance: str, kind: Literal['sealed_module'] = 'sealed_module')
Bases: ModuleIdentity
A module sealed by a signature: M :> S.
Sealing hides what the signature leaves abstract, so each sealing is a module of its own, distinct from the sealed module and from every other sealing of it.
| ATTRIBUTE | DESCRIPTION |
|---|---|
module |
The sealed module.
TYPE:
|
signature |
The signature, as
TYPE:
|
instance |
The sealing site.
TYPE:
|
InterfaceEntry
didactic-model
¶
InterfaceEntry(*, name: str, origin: ModuleIdentity, origin_name: str, kinds: tuple[str, ...] = (), signature: str = '', docs: tuple[str, ...] = (), declared_with: str = '')
Bases: Model
One public name of a module.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
The name importers use.
TYPE:
|
origin |
The module that declares it.
TYPE:
|
origin_name |
Its name in that module.
TYPE:
|
kinds |
The declaration kinds of the name (
TYPE:
|
signature |
The declaring source line of each declaration, for documentation.
TYPE:
|
docs |
The declaration's doc-comment lines, once per declaring statement.
TYPE:
|
declared_with |
The name a declaration that declares several names is known by,
when it is not this one:
TYPE:
|
ModuleInterface
didactic-model
¶
ModuleInterface(*, identity: ModuleIdentity, entries: tuple[InterfaceEntry, ...] = (), dependencies: tuple[ModuleIdentity, ...] = ())
Bases: Model
What importers of a module see.
| ATTRIBUTE | DESCRIPTION |
|---|---|
identity |
The module.
TYPE:
|
entries |
The public names, sorted by name.
TYPE:
|
dependencies |
The modules it imports directly, in import order.
TYPE:
|
get
¶
get(name: str) -> InterfaceEntry | None
The entry for a public name.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
InterfaceEntry | None
|
The entry, or |
Source code in src/quivers/dsl/modules/interface.py
names
¶
The public names.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The names, sorted. |
is_reexport
¶
is_reexport(entry: InterfaceEntry) -> bool
Whether an entry is defined by another module.
| PARAMETER | DESCRIPTION |
|---|---|
entry
|
One of this interface's entries.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether its origin differs from this module. |
Source code in src/quivers/dsl/modules/interface.py
to_artifact
¶
The interface as a canonical JSON document.
| RETURNS | DESCRIPTION |
|---|---|
bytes
|
UTF-8 JSON with sorted keys and no insignificant whitespace, identical for equal interfaces. |
Source code in src/quivers/dsl/modules/interface.py
digest
¶
The SHA-256 digest of to_artifact.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The hex digest. |
FlatProgram
didactic-model
¶
FlatProgram(*, module: Module, root: ModuleIdentity, source_map: SourceMap, interfaces: tuple[ModuleInterface, ...] = (), checking: Module | None = None, checks: tuple[CheckSite, ...] = (), laws: tuple[LawObligation, ...] = (), unfilled: tuple[HoleModule, ...] = ())
Bases: Model
The module graph interpreted as one program.
| ATTRIBUTE | DESCRIPTION |
|---|---|
module |
The flat program: every module's statements, dependencies first, with every name resolved.
TYPE:
|
root |
The root module.
TYPE:
|
source_map |
Where each flat line comes from.
TYPE:
|
interfaces |
Every module's interface, in dependency order.
TYPE:
|
checking |
For a program that uses signatures, functors, sealing, or module parameters, the checking program: the same declarations, except that the abstract items of functor parameters and sealed modules are declarations of their own, generic code is included once at those, and every signature match is witnessed by generated code. It is compiled to check the module layer and discarded.
TYPE:
|
checks |
The witnesses of the checking program.
TYPE:
|
laws |
The laws of signatures that matching modules owe, checked once the program is compiled.
TYPE:
|
unfilled |
The holes the root needs that no link fills. The checking program checks the package with them abstract; the run-time program then holds only the modules that need none of them, and compiling it is refused.
TYPE:
|
root_interface
property
¶
root_interface: ModuleInterface
The root module's interface.
| RETURNS | DESCRIPTION |
|---|---|
ModuleInterface
|
What an importer of the root would see. |
interface
¶
interface(identity: ModuleIdentity) -> ModuleInterface
One module's interface.
| PARAMETER | DESCRIPTION |
|---|---|
identity
|
The module.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ModuleInterface
|
Its interface. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the module is not part of the program. |
Source code in src/quivers/dsl/modules/interpret.py
SourceMap
didactic-model
¶
SourceMap(*, spans: tuple[SourceSpan, ...] = ())
Bases: Model
Maps a line of a flat program to its module's file and line.
| ATTRIBUTE | DESCRIPTION |
|---|---|
spans |
Each module's lines; the root's start at line 1.
TYPE:
|
locate
¶
locate(line: int, column: int = 0) -> SourceLocation | None
The source location of a flat line.
| PARAMETER | DESCRIPTION |
|---|---|
line
|
A 1-based line of the flat program.
TYPE:
|
column
|
The column, passed through.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SourceLocation | None
|
The file and the line in it, or |
Source code in src/quivers/dsl/modules/interpret.py
module_at
¶
module_at(line: int) -> ModuleIdentity | None
The module a flat line belongs to.
| PARAMETER | DESCRIPTION |
|---|---|
line
|
A 1-based flat line.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ModuleIdentity | None
|
The module, or |
Source code in src/quivers/dsl/modules/interpret.py
SourceSpan
didactic-model
¶
SourceSpan(*, module: ModuleIdentity, label: str, first_line: int, line_count: int)
Bases: Model
The lines one module occupies in a flat program.
| ATTRIBUTE | DESCRIPTION |
|---|---|
module |
The module.
TYPE:
|
label |
Its file (or label).
TYPE:
|
first_line |
The first flat line of the module.
TYPE:
|
line_count |
How many lines it has.
TYPE:
|
CheckSite
didactic-model
¶
CheckSite(*, line: int, message: str, location: SourceLocation)
Bases: Model
Generated code of the checking program that witnesses a match.
| ATTRIBUTE | DESCRIPTION |
|---|---|
line |
The witness's line in the checking program (past every source line).
TYPE:
|
message |
The mismatch the witness reports when it does not check.
TYPE:
|
location |
Where the match is required.
TYPE:
|
HoleDeclaration
didactic-model
¶
HoleDeclaration(*, hole: HoleModule, module: ModuleIdentity, signature_module: ModuleIdentity, signature_name: str, location: SourceLocation)
Bases: Model
A hole statement of the graph, with its signature resolved.
| ATTRIBUTE | DESCRIPTION |
|---|---|
hole |
The hole.
TYPE:
|
module |
The module whose
TYPE:
|
signature_module |
The module that declares the hole's signature.
TYPE:
|
signature_name |
The signature's name there.
TYPE:
|
location |
The
TYPE:
|
LinkDeclaration
didactic-model
¶
LinkDeclaration(*, hole: HoleModule, filler: ModuleIdentity, location: SourceLocation)
Bases: Model
One filling of a hole.
| ATTRIBUTE | DESCRIPTION |
|---|---|
hole |
The hole filled.
TYPE:
|
filler |
The module that fills it.
TYPE:
|
location |
Where the link is written (the
TYPE:
|
OwnerTie
didactic-model
¶
Bases: Model
One declaration's learned parameters tied to another's.
| ATTRIBUTE | DESCRIPTION |
|---|---|
owner |
The tied flat declaration.
TYPE:
|
target |
The declaration whose parameters they are.
TYPE:
|
SiteAddress
didactic-model
¶
Bases: Model
Where a site is, as people read it.
| ATTRIBUTE | DESCRIPTION |
|---|---|
module |
The declaring module, extended by its instantiation.
TYPE:
|
declaration |
The declaring declaration's name in that module.
TYPE:
|
label |
The site's label below the declaration (
TYPE:
|
render
¶
The address as one dotted path.
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
SiteError
¶
Bases: ValueError
A site address, pattern, or stored record that does not resolve.
The message names the address, pattern, or record that does not resolve.
SitePattern
didactic-model
¶
Bases: Model
A path pattern over site addresses.
A pattern is an address with wildcards. Within a segment, * matches
any run of characters, so Discourse(*) matches every instantiation
of Discourse; a whole segment ** matches any number of
segments. A pattern is matched against the end of an address, so
fit.prior selects the site prior of every declaration fit
and Discourse(*).fit.prior that site in every instance of
Discourse wherever it is declared.
| ATTRIBUTE | DESCRIPTION |
|---|---|
text |
The pattern as written.
TYPE:
|
segments |
Its segments.
TYPE:
|
parse
classmethod
¶
parse(text: str) -> SitePattern
Read a pattern.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The pattern.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SitePattern
|
The pattern. |
| RAISES | DESCRIPTION |
|---|---|
SiteError
|
If it is empty, has an empty segment, or does not balance. |
Source code in src/quivers/dsl/modules/sites.py
matches
¶
matches(address: SiteAddress) -> bool
Whether the pattern selects an address.
| PARAMETER | DESCRIPTION |
|---|---|
address
|
The address.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether some suffix of the address's segments matches. |
Source code in src/quivers/dsl/modules/sites.py
SiteRecord
didactic-model
¶
SiteRecord(*, address: SiteAddress, kind: SiteKind, identity: str, key: str, target: str)
Bases: Model
One site or parameter of an entry point.
| ATTRIBUTE | DESCRIPTION |
|---|---|
address |
Where it is.
TYPE:
|
kind |
What it is.
TYPE:
|
identity |
Its rename-stable identity.
TYPE:
|
key |
What a run reads it under: the label a run conditions a sample site
on, or the spelled name a
TYPE:
|
target |
What a transpiled program calls it.
TYPE:
|
SiteTable
didactic-model
¶
SiteTable(*, entry: str, sites: tuple[SiteRecord, ...] = ())
Bases: Model
The sites and parameters of one entry point.
| ATTRIBUTE | DESCRIPTION |
|---|---|
entry |
The entry point's flat-program name.
TYPE:
|
sites |
Its sample sites, in the program's step order, then the learned parameters its computations read, by key.
TYPE:
|
record
¶
record(key: str) -> SiteRecord
The site a run reads under a key.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
A sample site's label or a parameter's name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SiteRecord
|
The site. |
| RAISES | DESCRIPTION |
|---|---|
SiteError
|
If no site of the entry has the key. |
Source code in src/quivers/dsl/modules/sites.py
select
¶
select(pattern: str) -> tuple[SiteRecord, ...]
The sites a path pattern selects.
| PARAMETER | DESCRIPTION |
|---|---|
pattern
|
A pattern (see
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[SiteRecord, ...]
|
The sites whose address the pattern matches, in table order. |
Source code in src/quivers/dsl/modules/sites.py
resolve
¶
Key values by the run's site keys, reading patterns as addresses.
A key that is a site's own key binds that site; any other key is a path pattern and binds every site it selects.
| PARAMETER | DESCRIPTION |
|---|---|
bindings
|
Values by site key or path pattern.
TYPE:
|
allow_runtime_labels
|
Pass through an unlisted bare label or a label with an occurrence number. The runtime checks that it reaches the requested draw.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, V]
|
The values by site key. |
| RAISES | DESCRIPTION |
|---|---|
SiteError
|
If a pattern selects no site, or two bindings give one site. |
Source code in src/quivers/dsl/modules/sites.py
reverse_map
¶
Each target spelling mapped to the address it spells.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, str]
|
The rendered address of each site, by its target spelling. |
Source code in src/quivers/dsl/modules/sites.py
readdress
¶
readdress(stored: SiteTable) -> dict[str, str]
Map a stored table's keys onto this table's, by identity.
| PARAMETER | DESCRIPTION |
|---|---|
stored
|
The table a run record was stored with, possibly under other spellings.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, str]
|
Each stored key mapped to the key the same site has now. |
| RAISES | DESCRIPTION |
|---|---|
SiteError
|
If a stored site's identity names no site of this entry: the declaration that declared it changed, so the stored values no longer describe it. |
Source code in src/quivers/dsl/modules/sites.py
to_data
¶
The table as JSON-compatible data, the reverse map of a run record.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, object]
|
The entry and, per site, its rendered address, its parts, kind, identity, key, and target spelling. |
Source code in src/quivers/dsl/modules/sites.py
from_data
classmethod
¶
from_data(data: Mapping[str, object]) -> SiteTable
Read a table back from to_data's form.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The stored form.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SiteTable
|
The table. |
| RAISES | DESCRIPTION |
|---|---|
SiteError
|
If the form is malformed. |
Source code in src/quivers/dsl/modules/sites.py
SiteTie
didactic-model
¶
Bases: Model
One sample site tied to another: they are one site.
| ATTRIBUTE | DESCRIPTION |
|---|---|
declaration, label |
The tied site: its flat declaration and its label.
TYPE:
|
target_declaration, target_label |
The site it is.
TYPE:
|
SiteTies
didactic-model
¶
Bases: Model
Declared sharing: sites and parameter owners tied to another's.
| ATTRIBUTE | DESCRIPTION |
|---|---|
sites |
The tied sample sites.
TYPE:
|
owners |
The tied parameter owners.
TYPE:
|
site
¶
The site a site is tied to, following ties to their end.
| PARAMETER | DESCRIPTION |
|---|---|
declaration
|
The declaring flat declaration.
TYPE:
|
label
|
The site's label.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, str]
|
The declaration and label of the site it is, itself when untied. |
Source code in src/quivers/dsl/modules/sites.py
owner
¶
The declaration whose parameters an owner's are, following ties.
| PARAMETER | DESCRIPTION |
|---|---|
owner
|
A flat declaration with learned parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The owner it shares with, itself when untied. |
Source code in src/quivers/dsl/modules/sites.py
NameParameter
didactic-model
¶
Bases: Model
How a computation receives quoted names through its value parameters.
| PARAMETER | DESCRIPTION |
|---|---|
parameters
|
The names of its value parameters, in order, so a named argument finds its position.
TYPE:
|
names
|
The positions of the parameters that carry a quoted name: those whose value reaches a quoted-name position, directly or through another computation's name parameter.
TYPE:
|
NameParameters
didactic-model
¶
NameParameters(*, computations: dict[str, NameParameter] = {}, local_computations: dict[str, dict[str, NameParameter]] = {})
Bases: Model
The name parameters of the computations a program has declared so far.
A string is a quoted name when it reaches a quoted-name position, so a
computation whose parameter flows into one, as image does in
define binary(image : String) = return ValueCall(image, ...),
receives a quoted name there, and a literal written as that argument
is resolved where it is written, as a literal written at the position
itself is. This infers which strings are names from how they are used,
the way a type system with a separate type of names would check them.
| PARAMETER | DESCRIPTION |
|---|---|
computations
|
Each module-level computation, under the name the flat program gives it.
TYPE:
|
local_computations
|
Each module-level computation's
TYPE:
|
learn
¶
learn(statements: Sequence[Statement]) -> NameParameters
Add the computations one module declares.
Modules are learned in dependency order, so every computation a module calls from another module is already known; the module's own computations, which may call each other in any order, are solved together as a least fixed point.
| PARAMETER | DESCRIPTION |
|---|---|
statements
|
The module's statements, with names as the flat program spells them.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NameParameters
|
The table with the module's computations added. |
Source code in src/quivers/dsl/modules/quoted_names.py
ChainLoader
¶
ChainLoader(loaders: Iterable[ModuleLoader])
Consult several loaders, the first that has a module winning.
| PARAMETER | DESCRIPTION |
|---|---|
loaders
|
The loaders, in priority order.
TYPE:
|
Source code in src/quivers/dsl/modules/loader.py
find
¶
find(path: tuple[str, ...]) -> tuple[ModuleSource, ...]
The sources of the first loader that has the module.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The module path's segments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[ModuleSource, ...]
|
That loader's sources, or nothing. |
Source code in src/quivers/dsl/modules/loader.py
available
¶
Every path any loader can find.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The dotted paths, sorted. |
Source code in src/quivers/dsl/modules/loader.py
FileSystemLoader
¶
Find modules as .qvr and .qvr.md files below search roots.
| PARAMETER | DESCRIPTION |
|---|---|
roots
|
The directories module paths are relative to.
TYPE:
|
Source code in src/quivers/dsl/modules/loader.py
find
¶
find(path: tuple[str, ...]) -> tuple[ModuleSource, ...]
Every root's file for a module path.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The module path's segments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[ModuleSource, ...]
|
One source per file |
Source code in src/quivers/dsl/modules/loader.py
available
¶
Every module below the roots.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The dotted paths of every |
Source code in src/quivers/dsl/modules/loader.py
module_path_of
¶
The module path of a file below one of the roots.
| PARAMETER | DESCRIPTION |
|---|---|
file
|
A
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
Its module path. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the file lies below no root, or its relative path is not a module path. |
Source code in src/quivers/dsl/modules/loader.py
root_path_of
¶
The path of a file compiled as a root module.
A root is named by its location like any module, but it is never
found by an import, so its file name need not be an identifier:
lexical-uncertainty.qvr is a root module named
lexical-uncertainty, which no module can import.
| PARAMETER | DESCRIPTION |
|---|---|
file
|
A
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
Its path segments relative to the root containing it. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the file lies below no root. |
Source code in src/quivers/dsl/modules/loader.py
MappingLoader
¶
Hold module sources in memory, keyed by dotted module path.
| PARAMETER | DESCRIPTION |
|---|---|
modules
|
Each dotted module path mapped to its source text.
TYPE:
|
label
|
The prefix of the label each module's diagnostics name.
TYPE:
|
Source code in src/quivers/dsl/modules/loader.py
find
¶
find(path: tuple[str, ...]) -> tuple[ModuleSource, ...]
The held source of a module path.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The module path's segments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[ModuleSource, ...]
|
The source, or nothing when the path is not held. |
Source code in src/quivers/dsl/modules/loader.py
available
¶
Every held module path.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The dotted paths, sorted. |
ModuleLoader
¶
Bases: Protocol
Answers which sources a module path names.
find
¶
find(path: tuple[str, ...]) -> tuple[ModuleSource, ...]
Every source named by a module path.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The module path's segments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[ModuleSource, ...]
|
The sources, one per root that has the module (empty when none does). |
Source code in src/quivers/dsl/modules/loader.py
available
¶
Every module path this loader can find, dotted.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The paths, sorted. |
ModuleSource
didactic-model
¶
ModuleSource(*, identity: SourceModule, label: str, text: str, file: str | None = None)
Bases: Model
The source of one module.
| ATTRIBUTE | DESCRIPTION |
|---|---|
identity |
The module's identity.
TYPE:
|
label |
The file path (or label) diagnostics name.
TYPE:
|
text |
The source text.
TYPE:
|
file |
The absolute file path, when the source is a file.
TYPE:
|
StandardLibraryLoader
¶
StandardLibraryLoader(root: Path = STANDARD_LIBRARY_ROOT)
Find the modules of the standard library that ships with quivers.
It answers exactly the paths whose first segment is std, from the
package's own directory, so a module path std.semiring names the
shipped module wherever the program is loaded from.
| PARAMETER | DESCRIPTION |
|---|---|
root
|
The directory holding
TYPE:
|
Source code in src/quivers/dsl/modules/loader.py
find
¶
find(path: tuple[str, ...]) -> tuple[ModuleSource, ...]
The shipped source of a standard library module path.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The module path's segments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[ModuleSource, ...]
|
The module's source, or nothing for a path outside |
Source code in src/quivers/dsl/modules/loader.py
available
¶
Every module of the standard library.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The dotted paths below |
Source code in src/quivers/dsl/modules/loader.py
CheckedModule
didactic-model
¶
CheckedModule(*, source: ModuleSource, names: FileNames, resolutions: tuple[Resolution, ...] = (), imports: tuple[ResolvedImport, ...] = (), interface: ModuleInterface, region: str = '', module_identity: ModuleIdentity | None = None)
Bases: Model
A module resolved against its dependencies' interfaces.
| ATTRIBUTE | DESCRIPTION |
|---|---|
source |
The module's source.
TYPE:
|
names |
Its name occurrences.
TYPE:
|
resolutions |
Every token that named a module-level name or split into member accesses, in source order.
TYPE:
|
imports |
Its imports.
TYPE:
|
interface |
What its importers see.
TYPE:
|
region |
The region node of a module declared inside a file,
TYPE:
|
module_identity |
The identity of a module declared inside a file (its source's identity is the file's).
TYPE:
|
identity
property
¶
identity: ModuleIdentity
The module's identity.
| RETURNS | DESCRIPTION |
|---|---|
ModuleIdentity
|
The identity of the module, the source's for a file. |
Resolution
didactic-model
¶
Resolution(*, start: int, end: int, role: ResolutionRole = 'reference', symbol: Symbol | None = None, module: ModuleIdentity | None = None, path: tuple[str, ...] = (), members: int = 0, name_start: int = 0, name_end: int = 0, line: int = 0, column: int = 0)
Bases: Model
What one name token resolved to.
| ATTRIBUTE | DESCRIPTION |
|---|---|
start, end |
The token's byte span.
TYPE:
|
role |
Why the token names the symbol.
TYPE:
|
symbol |
The module-level name, or
TYPE:
|
path |
The member path of a declaration the symbol generates, as in the
TYPE:
|
members |
Trailing segments that select members of the referenced value.
TYPE:
|
name_start, name_end |
The byte span of the segment that spells the symbol's own name, the span a rename rewrites.
TYPE:
|
line, column |
The token's location.
TYPE:
|
module |
For a token in a module or value position that names a whole
module (an import, an alias, a module parameter), that module;
TYPE:
|
ResolvedImport
didactic-model
¶
ResolvedImport(*, record: ModuleImport, module: ModuleIdentity)
Bases: Model
One import statement and the module it names.
| ATTRIBUTE | DESCRIPTION |
|---|---|
record |
The statement.
TYPE:
|
module |
The imported module.
TYPE:
|
Symbol
didactic-model
¶
Symbol(*, module: ModuleIdentity, name: str, kinds: tuple[str, ...] = ())
Bases: Model
A module-level name, identified by where it is declared.
| ATTRIBUTE | DESCRIPTION |
|---|---|
module |
The declaring module.
TYPE:
|
name |
The name in that module.
TYPE:
|
kinds |
Its declaration kinds.
TYPE:
|
module_error
¶
module_error(code: ModuleErrorCode, message: str, location: SourceLocation, *, suggestions: tuple[str, ...] = (), related: tuple[SourceLocation, ...] = ()) -> ModuleError
Build a ModuleError.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
The stable code.
TYPE:
|
message
|
The description.
TYPE:
|
location
|
The offending token's location.
TYPE:
|
suggestions
|
Near-miss names.
TYPE:
|
related
|
Further locations.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ModuleError
|
The error, ready to raise. |
Source code in src/quivers/dsl/modules/errors.py
near_misses
¶
The candidates closest to a misspelled name.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name as written.
TYPE:
|
candidates
|
The names that would have resolved.
TYPE:
|
limit
|
The most suggestions to return.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
Close candidates, best first. |
Source code in src/quivers/dsl/modules/errors.py
allocation
¶
allocation(statement: Statement, effect_of: Callable[[str], str]) -> str | None
What a declaration allocates, if anything.
| PARAMETER | DESCRIPTION |
|---|---|
statement
|
A walked declaration.
TYPE:
|
effect_of
|
The interface name of an effect instance, by the instance's name in the flat program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
A description of what it allocates, or |
Source code in src/quivers/dsl/modules/generativity.py
infer_requirements
¶
infer_requirements(declarations: Iterable[Model], parameters: Mapping[ParameterModule, Mapping[str, tuple[str, ...] | None]], locate: Locate) -> dict[ParameterModule, dict[str, DeductionRequirement]]
What generic code requires of the open atoms of its deduction parameters.
| PARAMETER | DESCRIPTION |
|---|---|
declarations
|
The checking program's declarations.
TYPE:
|
parameters
|
Each
TYPE:
|
locate
|
Where a flat-program line and column come from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[ParameterModule, dict[str, DeductionRequirement]]
|
Per parameter, the requirement on each open atom its generic code names, by atom. |
| RAISES | DESCRIPTION |
|---|---|
ModuleError
|
With code |
Source code in src/quivers/dsl/modules/generic_uses.py
render_slots
¶
Slot sorts as a diagnostic shows them.
| PARAMETER | DESCRIPTION |
|---|---|
sorts
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The sorts, parenthesized and comma-separated. |
Source code in src/quivers/dsl/modules/generic_uses.py
load_graph
¶
load_graph(root: ModuleSource, loader: ModuleLoader, *, links: Mapping[str, str] | None = None) -> ModuleGraph
Load every module root reaches and check each in dependency order.
A module path some module declares a hole is a hole: importing it
imports the hole's signature, and no file is loaded for it. A link
(in a module, or in links) fills a hole with a module, which is
loaded and checked with the graph.
| PARAMETER | DESCRIPTION |
|---|---|
root
|
The root module's source.
TYPE:
|
loader
|
Finds imported modules.
TYPE:
|
links
|
Further fillings, hole path to module path, as a package manifest or an experiment gives them.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ModuleGraph
|
The loaded and checked graph. |
| RAISES | DESCRIPTION |
|---|---|
ModuleError
|
If an import names no module or a module two roots both provide, the imports form a cycle, a module fails to resolve, a hole or link is malformed (a signature that is not found, a hole declared with two signatures, a link to a path that is not a hole, a hole linked twice), or the links are not well founded. |
ParseError
|
If a module does not parse. |
Source code in src/quivers/dsl/modules/graph.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | |
visible_constructors
¶
visible_constructors(names: FileNames, imports: tuple[ResolvedImport, ...], interfaces: Mapping[ModuleIdentity, ModuleInterface]) -> frozenset[str]
Imported constructors a bare pattern name may refer to.
| PARAMETER | DESCRIPTION |
|---|---|
names
|
The importing module's names.
TYPE:
|
imports
|
Its imports.
TYPE:
|
interfaces
|
The interfaces of the modules it imports.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
frozenset[str]
|
The constructor names that a selection list, an exclusion, or an
|
Source code in src/quivers/dsl/modules/graph.py
flat_name
¶
flat_name(identity: ModuleIdentity, name: str) -> str
The flat-program name of one of a module's declarations.
| PARAMETER | DESCRIPTION |
|---|---|
identity
|
The declaring module.
TYPE:
|
name
|
The declaration's name in the module, possibly a generated member
such as
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/modules/identity.py
module_display
¶
module_display(identity: ModuleIdentity) -> str
A module identity as people read it.
A nested module extends its parent's display with its name, an
application is F(A,B) (with #site when generative), a
functor's parameter is F#W, and a sealing is (M:>S)#site; the
rendering is injective.
| PARAMETER | DESCRIPTION |
|---|---|
identity
|
The identity.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The dotted module path for a source module; |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
Source code in src/quivers/dsl/modules/identity.py
parse_module_path
¶
Split a dotted module path into its segments.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
A dotted path such as
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The segments. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a segment is not an identifier. |
Source code in src/quivers/dsl/modules/identity.py
source_module
¶
source_module(text: str) -> SourceModule
The identity of the source module with a dotted path.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The dotted path.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SourceModule
|
Its identity. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/dsl/modules/identity.py
meta_only_modules
¶
meta_only_modules(graph: ModuleGraph) -> frozenset[ModuleIdentity]
The modules of a graph that serve its meta phase only.
A module serves the meta phase alone when the root reaches it, and
every path from the root to it crosses a meta import. An import of a
hole reaches the hole's filler. A module the root does not reach at
all, such as the filler of a hole no module imports, is not meta code:
the link that brings it into the program is run-time code, so it is
checked against its hole's signature as run-time code, like every other
filler.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The loaded graph.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
frozenset[ModuleIdentity]
|
The modules reached, but only through meta imports. |
Source code in src/quivers/dsl/modules/interpret.py
name_view
¶
name_view(checked: CheckedModule, root: ModuleIdentity, line_offset: int) -> NameView
The view one module's walk reads its names through.
| PARAMETER | DESCRIPTION |
|---|---|
checked
|
The resolved module.
TYPE:
|
root
|
The program's root.
TYPE:
|
line_offset
|
Added to the module's lines.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NameView
|
Each resolved token's flat reference and member split. |
Source code in src/quivers/dsl/modules/interpret.py
symbol_flat_name
¶
symbol_flat_name(symbol: Symbol, root: ModuleIdentity) -> str
The flat-program name of a module-level name.
| PARAMETER | DESCRIPTION |
|---|---|
symbol
|
The name and its declaring module.
TYPE:
|
root
|
The root of the program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The bare name for a root declaration; |
Source code in src/quivers/dsl/modules/interpret.py
check_well_founded
¶
check_well_founded(order: Iterable[ModuleIdentity], checked: Mapping[ModuleIdentity, CheckedModule], links: Mapping[HoleModule, LinkDeclaration], filler_interface: Mapping[ModuleIdentity, ModuleInterface]) -> None
Refuse a linked program in which a declaration depends on itself through declarations of other modules.
Imports alone never form a cycle (the module graph is acyclic), but a
filling can: worlds.boolean may use the hole Lexicon that
lex.core fills, while lex.core uses the hole Worlds that
worlds.boolean fills. Such mutually recursive linking is well
founded when the declarations themselves are: every declaration of the
linked program is defined from declarations that are defined before
it, across modules. A declaration that reaches itself through another
module's declaration has no such definition, and the link is refused
with the cycle's path.
| PARAMETER | DESCRIPTION |
|---|---|
order
|
The graph's modules.
TYPE:
|
checked
|
Each module's resolutions.
TYPE:
|
links
|
The fillings.
TYPE:
|
filler_interface
|
Each filler's interface, which tells which declaration a hole's item is in the filler.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ModuleError
|
With code |
Source code in src/quivers/dsl/modules/linking.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | |
describe_links
¶
describe_links(links: Mapping[HoleModule, ModuleIdentity]) -> str
The fillings as people read them.
| PARAMETER | DESCRIPTION |
|---|---|
links
|
The fillings.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/modules/linking.py
hole_closure
¶
hole_closure(order: Iterable[ModuleIdentity], imports: Mapping[ModuleIdentity, tuple[ModuleIdentity, ...]], links: Mapping[HoleModule, ModuleIdentity]) -> dict[ModuleIdentity, tuple[HoleModule, ...]]
The holes each module needs, through imports and fillings.
| PARAMETER | DESCRIPTION |
|---|---|
order
|
Every module of the graph.
TYPE:
|
imports
|
What each module imports directly (holes included).
TYPE:
|
links
|
The filler of each filled hole.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[ModuleIdentity, tuple[HoleModule, ...]]
|
Each module's holes, sorted by path: the holes it imports, the holes of the modules it imports, and the holes of the fillers of those holes, to a fixed point (fillings may be recursive). |
Source code in src/quivers/dsl/modules/linking.py
hole_interface
¶
hole_interface(hole: HoleModule, signature_module: ModuleIdentity, signature_name: str, names_of: Mapping[ModuleIdentity, FileNames], trees: Mapping[ModuleIdentity, _Tree], location: SourceLocation) -> ModuleInterface
What modules importing a hole see: its signature's items.
A signature written S = Base with ... has the items of Base.
| PARAMETER | DESCRIPTION |
|---|---|
hole
|
The hole.
TYPE:
|
signature_module
|
The module declaring the signature.
TYPE:
|
signature_name
|
The signature's name.
TYPE:
|
names_of
|
The loaded modules' names.
TYPE:
|
trees
|
The loaded modules' parse trees, which hold a signature's definition.
TYPE:
|
location
|
The
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ModuleInterface
|
One entry per item, each declared by the hole itself. |
| RAISES | DESCRIPTION |
|---|---|
ModuleError
|
If the signature (or one it is defined from) is not found. |
Source code in src/quivers/dsl/modules/linking.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
hole_of
¶
hole_of(path: str) -> HoleModule
The hole a dotted module path names.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The path as a
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
HoleModule
|
The hole. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the path is not a module path. |
Source code in src/quivers/dsl/modules/linking.py
hole_records
¶
hole_records(names: FileNames) -> tuple[ModuleHole, ...]
The hole statements of a module, at top level only.
| PARAMETER | DESCRIPTION |
|---|---|
names
|
The module's names.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[ModuleHole, ...]
|
Its |
Source code in src/quivers/dsl/modules/linking.py
link_records
¶
link_records(names: FileNames) -> tuple[ModuleLink, ...]
The link statements of a module.
| PARAMETER | DESCRIPTION |
|---|---|
names
|
The module's names.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[ModuleLink, ...]
|
Its |
Source code in src/quivers/dsl/modules/linking.py
linked_identity
¶
linked_identity(module: ModuleIdentity, closure: Mapping[ModuleIdentity, tuple[HoleModule, ...]], links: Mapping[HoleModule, ModuleIdentity]) -> ModuleIdentity
The identity a module has in a linked program.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
A module of the graph.
TYPE:
|
closure
|
The holes each module needs (
TYPE:
|
links
|
The fillings.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ModuleIdentity
|
The module itself when it needs no hole; otherwise the module applied to the filler of each hole it needs, keyed by the hole's path. The fillers are named by their own source identities, so the identity is finite even when fillings are recursive: the whole program is linked by one map, and that map restricted to the holes the module needs is what tells two of its instances apart. |
Source code in src/quivers/dsl/modules/linking.py
resolve_signature
¶
resolve_signature(module: ModuleIdentity, reference: str, names_of: Mapping[ModuleIdentity, FileNames], location: SourceLocation) -> tuple[ModuleIdentity, str]
Find the signature a hole names, from the declaring module's text.
A hole's signature is found before any module is checked, since the
modules importing the hole are checked against it. S names a
signature the module declares; L.S (or a.b.S) names one that
the module imported as L (or as a.b) declares.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module whose
TYPE:
|
reference
|
The signature as written.
TYPE:
|
names_of
|
The loaded modules' names.
TYPE:
|
location
|
The
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[ModuleIdentity, str]
|
The declaring module and the signature's name there. |
| RAISES | DESCRIPTION |
|---|---|
ModuleError
|
With code |
Source code in src/quivers/dsl/modules/linking.py
unfilled
¶
unfilled(closure: Mapping[ModuleIdentity, tuple[HoleModule, ...]], links: Mapping[HoleModule, ModuleIdentity], module: ModuleIdentity) -> tuple[HoleModule, ...]
The holes a module needs that no link fills.
| PARAMETER | DESCRIPTION |
|---|---|
closure
|
The holes each module needs.
TYPE:
|
links
|
The fillings.
TYPE:
|
module
|
The module.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[HoleModule, ...]
|
The unfilled holes, sorted by path. |
Source code in src/quivers/dsl/modules/linking.py
address_segments
¶
Split an address at the dots that are not inside an instantiation.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
A rendered address or pattern.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The segments: |
| RAISES | DESCRIPTION |
|---|---|
SiteError
|
If the parentheses do not balance. |
Source code in src/quivers/dsl/modules/sites.py
site_table
¶
site_table(module: QiecModule, entry: str, *, root: str | None = None, ties: SiteTies | None = None) -> SiteTable
The sites and parameters of one program of a checked module.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module of a flat program.
TYPE:
|
entry
|
The program's flat-program name.
TYPE:
|
root
|
The root module's path, which addresses the root's own declarations; the checked module's name when omitted.
TYPE:
|
ties
|
Declared sharing; a tied site or parameter takes the identity and address of the one it is tied to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SiteTable
|
The program's sample sites, in step order, then every learned parameter of the module, by key. |
| RAISES | DESCRIPTION |
|---|---|
SiteError
|
If the module has no such program. |
Source code in src/quivers/dsl/modules/sites.py
site_ties
¶
The sharing a flat program's share statements declare.
Each side of a share is a path, resolved to a flat-program name, of
a program's sample site (A.fit.prior), of a whole program (every
sample site of it, by label), or of a deduction (its learned
parameters). Two sample sites are one site only when they are drawn
from the same family over the same plate and axes, so they have one
type and one support; two deductions share their parameters only when
they declare the same productions, so each parameter has one
counterpart.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The flat program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SiteTies
|
The ties, in statement order. |
| RAISES | DESCRIPTION |
|---|---|
ShareError
|
If a path names no program site or deduction, the two sides are of different kinds, a site lacks its counterpart, or the counterparts differ in type, support, or productions. |
Source code in src/quivers/dsl/modules/sites.py
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | |
module_name_resolver
¶
module_name_resolver(graph: ModuleGraph, identity: ModuleIdentity, line_offset: int) -> NameResolver
Resolve names as a file-level module of a graph resolves identifiers.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The checked graph.
TYPE:
|
identity
|
A module of the graph.
TYPE:
|
line_offset
|
How far the module's lines are shifted in the flat program, so a diagnostic points into the module's own file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NameResolver
|
Maps a name written at a flat-program line and column to the flat
name of what it denotes: a declaration of the module, or a member
of a module it imports, possibly with a generated member path such
as |
| RAISES | DESCRIPTION |
|---|---|
ModuleError
|
From the returned resolver, when a name selects a member that its module does not have or does not export. |
Source code in src/quivers/dsl/modules/quoted_names.py
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 | |
resolve_quoted_names
¶
resolve_quoted_names(statement: Statement, resolve: NameResolver, *, names: NameParameters) -> Statement
Resolve every string literal a statement writes as a quoted name.
A literal is a quoted name when it is written at a quoted-name position
of a quoted-syntax constructor (QUOTED_NAME_POSITIONS), as the
argument of a computation's name parameter (NameParameters), or as
the value of a let whose variable reaches either.
| PARAMETER | DESCRIPTION |
|---|---|
statement
|
A statement of one module, typically a meta declaration or a splice.
TYPE:
|
resolve
|
Resolution in that module's scope.
TYPE:
|
names
|
The name parameters of every computation the statement can call.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Statement
|
The statement with each such literal replaced by the flat name it resolves to; literals the module does not bind are unchanged. |
Source code in src/quivers/dsl/modules/quoted_names.py
check_module
¶
check_module(source: ModuleSource, names: FileNames, imports: tuple[ResolvedImport, ...], interfaces: Mapping[ModuleIdentity, ModuleInterface], private_names: Mapping[ModuleIdentity, frozenset[str]]) -> CheckedModule
Resolve every name of one module against its imports' interfaces.
Only the interfaces of the module's dependencies are read, never their
bodies; private_names serves diagnostics alone (to say that a name
exists but is private).
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The module's source.
TYPE:
|
names
|
Its name occurrences.
TYPE:
|
imports
|
Its imports, each with the module it names.
TYPE:
|
interfaces
|
The interface of every module it imports.
TYPE:
|
private_names
|
The names each imported module declares without exporting.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CheckedModule
|
The resolutions and the module's interface. |
| RAISES | DESCRIPTION |
|---|---|
ModuleError
|
On an unknown, private, unimported, or ambiguous name, a clashing
alias, an unknown |
Source code in src/quivers/dsl/modules/resolve.py
load_file_graph
¶
load_file_graph(path: str | Path, *, roots: tuple[str | Path, ...] | None = None, loader: ModuleLoader | None = None, links: Mapping[str, str] | None = None) -> ModuleGraph
Load and check the module graph rooted at a file.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The root module's file.
TYPE:
|
roots
|
The directories module paths are relative to; the file's own directory when omitted.
TYPE:
|
loader
|
Consulted before the roots, for sources not on disk (an editor's unsaved buffers).
TYPE:
|
links
|
Fillings of the package's holes, hole path to module path, besides
the graph's own
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ModuleGraph
|
The checked graph. |
| RAISES | DESCRIPTION |
|---|---|
OSError
|
If the file cannot be read. |
ValueError
|
If the file lies below none of the roots. |
ModuleError
|
If the graph does not load or a name does not resolve. |
Source code in src/quivers/dsl/modules/__init__.py
interpret_file
¶
interpret_file(path: str | Path, *, roots: tuple[str | Path, ...] | None = None, loader: ModuleLoader | None = None, links: Mapping[str, str] | None = None) -> FlatProgram
Interpret the module graph rooted at a file as one flat program.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The root module's file.
TYPE:
|
roots
|
The directories module paths are relative to; the file's own directory when omitted.
TYPE:
|
loader
|
Consulted before the roots.
TYPE:
|
links
|
Fillings of the package's holes, hole path to module path, besides
the graph's own
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FlatProgram
|
The flat program. |
| RAISES | DESCRIPTION |
|---|---|
OSError
|
If the file cannot be read. |
ValueError
|
If the file lies below none of the roots. |
ModuleError
|
If the graph does not load or a name does not resolve. |
Source code in src/quivers/dsl/modules/__init__.py
interpret_module
¶
interpret_module(module_path: str, *, roots: tuple[str | Path, ...] = (Path('.'),), loader: ModuleLoader | None = None, links: Mapping[str, str] | None = None) -> FlatProgram
Interpret the module graph rooted at a module path.
| PARAMETER | DESCRIPTION |
|---|---|
module_path
|
The root module's dotted path, e.g.
TYPE:
|
roots
|
The directories module paths are relative to.
TYPE:
|
loader
|
Consulted before the roots.
TYPE:
|
links
|
Fillings of the package's holes, hole path to module path, besides
the graph's own
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FlatProgram
|
The flat program. |
| RAISES | DESCRIPTION |
|---|---|
ModuleError
|
If no root (or more than one) provides the module, or the graph does not load or resolve. |
Source code in src/quivers/dsl/modules/__init__.py
interpret_source
¶
interpret_source(text: str, *, label: str = '<source>', module_path: str = ROOT_MODULE_NAME, loader: ModuleLoader | None = None, roots: tuple[str | Path, ...] = (), links: Mapping[str, str] | None = None) -> FlatProgram
Interpret source text, as the root module, with its imports.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The root module's source.
TYPE:
|
label
|
The label its diagnostics name.
TYPE:
|
module_path
|
The root module's path.
TYPE:
|
loader
|
Finds the modules it imports.
TYPE:
|
roots
|
Directories searched after
TYPE:
|
links
|
Fillings of the package's holes, hole path to module path, besides
the graph's own
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FlatProgram
|
The flat program. |
| RAISES | DESCRIPTION |
|---|---|
ModuleError
|
If the graph does not load or a name does not resolve. |
Source code in src/quivers/dsl/modules/__init__.py
interpret
¶
Static interpretation of a module graph into one flat program.
Compilation never sees modules. Every module of the graph is walked into
statements whose names are already resolved, and the statements are
concatenated, dependencies first, into one flat Module, so the compiler,
the reference machine, and every transpile target see a single, fully
qualified program.
A module reached only through meta import serves the meta phase: its
computations, families, and index sorts enter the flat program as meta
declarations and its other declarations do not enter it.
A declaration of the root module keeps its name; a declaration of any
other module is named by the module and its name, syntax.lambda:Term
(quivers.qiec.names.module_qualified). A module reached along two
import paths is walked once, so its declarations appear once. The
imported modules' lines are numbered after the root's, and the
SourceMap maps a line of the flat program back to its file.
interpret
¶
interpret(graph: ModuleGraph) -> FlatProgram
Interpret a checked module graph as one flat program.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The loaded, checked graph.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FlatProgram
|
The flat program and its source map. |
Source code in src/quivers/dsl/modules/interpret.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |