Meta phase¶
The meta phase of a module: check-time evaluation of meta declarations, static assertions, splices of generated declarations, and deriving, together with the reflection between checked families, quoted syntax, and source syntax. The meta-phase reference describes the surface, and the semantics states the rules.
meta
¶
The meta phase of QVR: check-time evaluation, generated declarations, deriving.
A module's meta phase holds its meta declarations, static assert
statements, splices ($gen(args)), and deriving requests. It is checked
and evaluated by the reference machine while the module is checked; the
declarations it generates are spliced into the run-time module and checked
like hand-written ones.
expand_metaruns the meta phase of a parsed module.persisting_meta_librarykeeps the checked library in an artifact store, so a later process reuses it.quivers.dsl.meta.reflectrelates checked families, quoted syntax, and source syntax.quivers.dsl.meta.universebuilds and reads meta-phase values.quivers.dsl.meta.libraryloads the meta-phase prelude and the built-in deriving handlers, both written in QVR.quivers.dsl.meta.provenancedigests a generated declaration together with its meta inputs.
LIBRARY_DIRECTORY
module-attribute
¶
The directory the library's source files live in.
LIBRARY_FILES
module-attribute
¶
The library sources, in the order their declarations enter the meta phase.
LIBRARY_NAMESPACE
module-attribute
¶
The store namespace of checked meta-phase libraries.
META_FUEL
module-attribute
¶
The reference-machine steps one meta evaluation may take.
SCALAR_TYPES
module-attribute
¶
The primitive types meta-phase fields are built from, by name.
SyntaxValue
¶
SyntaxValue = Model | tuple[SyntaxValue, ...] | str | int | float | bool | None
A syntax node, a tuple of them, or a leaf of a syntax tree.
MetaField
¶
MetaField = RuntimeConstructor | str | int | float | bool | Tensor
One field of a runtime value of a meta-phase family.
MetaLibrary
didactic-model
¶
MetaLibrary(*, statements: tuple[Statement, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), names: frozenset[str] = field(opaque=True, extras=OPAQUE_BY_VALUE), computations: frozenset[str] = field(opaque=True, extras=OPAQUE_BY_VALUE), digest: str)
Bases: ValueModel
The parsed meta-phase library.
| PARAMETER | DESCRIPTION |
|---|---|
statements
|
Every library declaration, in file order.
TYPE:
|
names
|
Every name the library declares in any namespace: families, constructors, computations, effect instances, and handlers.
TYPE:
|
computations
|
The names of the library's computations.
TYPE:
|
digest
|
The content-hash-domain digest, of kind
TYPE:
|
GeneratedDeclaration
didactic-model
¶
GeneratedDeclaration(*, name: str, statement: Statement | TestDecl = field(opaque=True, extras=OPAQUE_BY_VALUE), provenance: MetaProvenance)
Bases: ValueModel
One declaration the meta phase generated and spliced.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The declaration's name.
TYPE:
|
statement
|
The declaration, as source syntax, or a generated property, which the run-time module keeps among its tests.
TYPE:
|
provenance
|
Where it came from and the digest of everything it depends on.
TYPE:
|
LibraryStore
¶
Bases: Protocol
A content-addressed store the checked library can persist in.
ArtifactStore is one.
get
¶
Read an entry's payload, or None when there is no entry.
| PARAMETER | DESCRIPTION |
|---|---|
namespace
|
The namespace.
TYPE:
|
key
|
The key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bytes | None
|
The payload. |
Source code in src/quivers/dsl/meta/phase.py
put
¶
Write an entry.
| PARAMETER | DESCRIPTION |
|---|---|
namespace
|
The namespace.
TYPE:
|
key
|
The key.
TYPE:
|
payload
|
The payload.
TYPE:
|
label
|
A description of the entry.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Model
|
The written entry's record. |
Source code in src/quivers/dsl/meta/phase.py
MetaExpansion
didactic-model
¶
MetaExpansion(*, module: Module = field(opaque=True, extras=OPAQUE_BY_VALUE), generated: tuple[GeneratedDeclaration, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), assertions: tuple[StaticAssertion, ...] = ())
Bases: ValueModel
The run-time module that remains once the meta phase has run.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The run-time module: the source's run-time declarations, their deriving clauses discharged, with the generated declarations spliced in where they were requested. It has no meta phase of its own.
TYPE:
|
generated
|
Every generated declaration, in splice order.
TYPE:
|
assertions
|
Every static assertion, each of which held.
TYPE:
|
locate
¶
locate(error: QiecDiagnosticError) -> QiecDiagnosticError
Name the generator of a generated declaration a diagnostic is in.
| PARAMETER | DESCRIPTION |
|---|---|
error
|
A diagnostic from checking the run-time module.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
The same diagnostic when it is not located at a splice site; otherwise a diagnostic at the site whose message also names the generator and its location, and the generated declarations. |
Source code in src/quivers/dsl/meta/phase.py
StaticAssertion
didactic-model
¶
Bases: Model
The outcome of one static assert.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The asserted condition as written.
TYPE:
|
line
|
The assertion's 1-based source line.
TYPE:
|
col
|
The assertion's 0-based source column.
TYPE:
|
holds
|
Whether the condition evaluated to
TYPE:
|
MetaProvenance
didactic-model
¶
MetaProvenance(*, generator: str, generator_line: int, generator_col: int, site_line: int, site_col: int, digest: str)
Bases: Model
Where a generated declaration came from and what it depends on.
| PARAMETER | DESCRIPTION |
|---|---|
generator
|
The meta computation that produced it: a splice's generator or a deriving handler.
TYPE:
|
generator_line
|
The generator's declaration line.
TYPE:
|
generator_col
|
The generator's declaration column.
TYPE:
|
site_line
|
The line of the splice or deriving class that requested it.
TYPE:
|
site_col
|
The column of that site.
TYPE:
|
digest
|
The content-hash-domain digest of the meta inputs and the declaration.
TYPE:
|
ReflectionError
¶
Bases: ValueError
A declaration or a quoted value has no reflection in the other stratum.
MetaUniverse
¶
MetaUniverse(module: QiecModule)
The checked meta module, seen as a universe of buildable values.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked meta-phase module, which contains the meta prelude.
TYPE:
|
Source code in src/quivers/dsl/meta/universe.py
family_type
¶
family_type(name: str, arguments: tuple[StaticArgument, ...] = ()) -> TypeApplication
The type of a family of the universe at static arguments.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The family's name.
TYPE:
|
arguments
|
Its parameters, in order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TypeApplication
|
The applied family type. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the module declares no family of that name. |
Source code in src/quivers/dsl/meta/universe.py
seq_type
¶
seq_type(element: TypeExpr) -> TypeApplication
The type Seq[element].
| PARAMETER | DESCRIPTION |
|---|---|
element
|
The element type.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TypeApplication
|
The sequence type. |
Source code in src/quivers/dsl/meta/universe.py
make
¶
make(constructor: str, fields: Sequence[MetaField] = (), static_arguments: tuple[StaticArgument, ...] = ()) -> RuntimeConstructor
Build a runtime value of one constructor.
| PARAMETER | DESCRIPTION |
|---|---|
constructor
|
The constructor's name.
TYPE:
|
fields
|
Its field values in declaration order. Host strings stay strings; integers, reals, and truth values become the scalar tensors the reference machine computes with.
TYPE:
|
static_arguments
|
The family's parameters, for a constructor of a parameterized
family such as
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConstructor
|
The value. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the constructor is unknown or the number of fields or static arguments is wrong. |
Source code in src/quivers/dsl/meta/universe.py
seq
¶
seq(items: Sequence[MetaField], element: TypeExpr) -> RuntimeConstructor
Build Seq[element] holding the items in order.
| PARAMETER | DESCRIPTION |
|---|---|
items
|
The elements.
TYPE:
|
element
|
Their type.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConstructor
|
The sequence. |
Source code in src/quivers/dsl/meta/universe.py
strings
¶
strings(items: Sequence[str]) -> RuntimeConstructor
Build Seq[String].
| PARAMETER | DESCRIPTION |
|---|---|
items
|
The strings.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConstructor
|
The sequence. |
Source code in src/quivers/dsl/meta/universe.py
name_of
¶
The constructor a runtime value of the universe was built by.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The value.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Its constructor's name. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the value is not a constructor value of this module. |
Source code in src/quivers/dsl/meta/universe.py
fields_of
¶
The fields of a value built by an expected constructor.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The value.
TYPE:
|
expected
|
The constructor it must have been built by.
TYPE:
|
arity
|
The number of fields that constructor has.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[object, ...]
|
The fields. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the value was built by another constructor. |
Source code in src/quivers/dsl/meta/universe.py
read_seq
¶
The elements of a Seq value, in order.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The sequence.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[object, ...]
|
Its elements. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the value is not a sequence. |
Source code in src/quivers/dsl/meta/universe.py
MetaValueError
¶
Bases: ValueError
A runtime value does not have the shape its meta-phase family requires.
declared_names
¶
declared_names(statement: Statement) -> tuple[str, ...]
The names a declaration introduces in any namespace.
| PARAMETER | DESCRIPTION |
|---|---|
statement
|
The declaration.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
A family's name and its constructors' names, an index sort's name and its constructors' names, or the name of a computation, effect instance, handler, or pattern synonym. Other statements contribute no names. |
Source code in src/quivers/dsl/meta/library.py
meta_library
cached
¶
meta_library() -> MetaLibrary
Parse the meta-phase library once per process.
| RETURNS | DESCRIPTION |
|---|---|
MetaLibrary
|
The library's declarations, names, and digest. |
Source code in src/quivers/dsl/meta/library.py
checked_library
¶
checked_library() -> QiecModule
The meta-phase library, checked once per process.
Inside a persisting_meta_library block the library is read from the
block's store when an earlier process wrote it there, and written there
otherwise.
| RETURNS | DESCRIPTION |
|---|---|
QiecModule
|
The library alone, checked under |
| RAISES | DESCRIPTION |
|---|---|
StoreError
|
If the store's entry does not match its recorded digest. |
TypeError
|
If the store's entry holds something other than a QIEC module. |
Source code in src/quivers/dsl/meta/phase.py
expand_meta
¶
expand_meta(module: Module, *, module_name: str, file_path: str) -> MetaExpansion
Run the meta phase of a parsed module.
The module's quotations are elaborated through its notations first
(expand_notation),
so meta code may quote terms, and the expanded module carries no
notation statements.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The parsed module.
TYPE:
|
module_name
|
The module's name, from which the meta module's identities derive.
TYPE:
|
file_path
|
The path recorded on diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MetaExpansion
|
The run-time module, the generated declarations, and the assertions' outcomes. |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If a meta declaration does not check, a run-time declaration names
a meta declaration ( |
Source code in src/quivers/dsl/meta/phase.py
has_meta_surface
¶
has_meta_surface(module: Module) -> bool
Whether a module has anything for the meta phase to do.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The parsed module.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when it has a meta declaration, a static assertion, a splice, or a deriving clause. |
Source code in src/quivers/dsl/meta/phase.py
library_key
¶
The store key of the checked meta-phase library.
| PARAMETER | DESCRIPTION |
|---|---|
engine
|
The digest of the engine that checks the library.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The content-hash-domain digest, of kind |
Source code in src/quivers/dsl/meta/phase.py
persisting_meta_library
¶
persisting_meta_library(store: LibraryStore, *, engine: str) -> Iterator[LibraryStore]
Persist the checked meta-phase library in a store while in the block.
Every meta phase run inside the block reads the checked library from the store, or checks it and writes it there, so a later process with the same store and engine reuses it instead of checking it again.
| PARAMETER | DESCRIPTION |
|---|---|
store
|
The store, usually the project's
(
TYPE:
|
engine
|
The digest of the engine that checks the library
(
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
LibraryStore
|
The store. |
Source code in src/quivers/dsl/meta/phase.py
canonical_syntax
¶
canonical_syntax(node: SyntaxValue) -> str
Render source syntax canonically, without positions or doc comments.
| PARAMETER | DESCRIPTION |
|---|---|
node
|
A syntax node, a tuple of them, or a leaf.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
A rendering in which every node shows its class and its fields by name, so two syntax trees render alike exactly when they say the same thing, wherever they were written. |
Source code in src/quivers/dsl/meta/provenance.py
provenance_digest
¶
provenance_digest(*, library: str, closure: Sequence[str], inputs: Sequence[str], declaration: str) -> str
Digest a generated declaration together with its meta inputs.
| PARAMETER | DESCRIPTION |
|---|---|
library
|
The digest of the meta-phase library's source.
TYPE:
|
closure
|
The canonical source of each module meta declaration the generator reached, in name order.
TYPE:
|
inputs
|
The rendered inputs the generator ran on, in order.
TYPE:
|
declaration
|
The generated declaration's canonical source.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The content-hash-domain digest, of kind |
Source code in src/quivers/dsl/meta/provenance.py
describe_family
¶
describe_family(universe: MetaUniverse, family: FamilyDecl, constructors: Sequence[ConstructorDecl], written: Mapping[str, tuple[QiecTypeExpr, ...]], records: Mapping[str, QiecRecordDecl]) -> RuntimeConstructor
The description of a checked family, as a Desc value.
A checked row lists its labels in alphabetical order, so a record or
variant field type is quoted with its entries in the order its source
writes them: the order of the record type written in the field, or of
the record declaration the field names.
| PARAMETER | DESCRIPTION |
|---|---|
universe
|
The meta universe the value is built in.
TYPE:
|
family
|
The family, declared in source or generated by a declaration.
TYPE:
|
constructors
|
Its constructors, in any order; they are described in the order the family lists them.
TYPE:
|
written
|
The field types each constructor's source declaration writes, by the constructor's declared name; empty for a family a declaration generates, whose checked fields are its declaration.
TYPE:
|
records
|
The
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConstructor
|
|
| RAISES | DESCRIPTION |
|---|---|
ReflectionError
|
If a constructor is missing, or a field type has no quoted form. |
Source code in src/quivers/dsl/meta/reflect.py
read_declarations
¶
read_declarations(universe: MetaUniverse, value: object, *, line: int, col: int) -> tuple[Statement | TestDecl, ...]
Read the declarations a meta computation returned.
| PARAMETER | DESCRIPTION |
|---|---|
universe
|
The meta universe the value was built in.
TYPE:
|
value
|
A
TYPE:
|
line
|
The source line the declarations are checked at.
TYPE:
|
col
|
The source column the declarations are checked at.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Statement | TestDecl, ...]
|
The source declarations and properties, in order. |
| RAISES | DESCRIPTION |
|---|---|
ReflectionError
|
If the value is not quoted declarations. |
Source code in src/quivers/dsl/meta/reflect.py
syn_static
¶
syn_static(universe: MetaUniverse, argument: QiecStaticArgument) -> RuntimeConstructor
Quote a source static argument.
| PARAMETER | DESCRIPTION |
|---|---|
universe
|
The meta universe.
TYPE:
|
argument
|
The argument as written.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConstructor
|
The |
Source code in src/quivers/dsl/meta/reflect.py
syn_type
¶
syn_type(universe: MetaUniverse, type_: QiecTypeExpr) -> RuntimeConstructor
Quote a source type as a SynType value.
| PARAMETER | DESCRIPTION |
|---|---|
universe
|
The meta universe.
TYPE:
|
type_
|
The type as written.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConstructor
|
The quoted type. |
| RAISES | DESCRIPTION |
|---|---|
ReflectionError
|
If the type has no quoted form. |
Source code in src/quivers/dsl/meta/reflect.py
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 | |
syn_type_of_kernel
¶
syn_type_of_kernel(universe: MetaUniverse, type_: TypeExpr) -> RuntimeConstructor
Quote a checked type as a SynType value.
An argument whose binder is refinable, or which is a shape, is written
in parentheses after the bracketed static arguments, as source writes
Vec[A](n) and Real[Fin 3].
| PARAMETER | DESCRIPTION |
|---|---|
universe
|
The meta universe.
TYPE:
|
type_
|
The checked type.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConstructor
|
The quoted type. |
| RAISES | DESCRIPTION |
|---|---|
ReflectionError
|
If the type has no quoted form. |
Source code in src/quivers/dsl/meta/reflect.py
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 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 | |
read_bool
¶
Read a Bool field.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The field: a truth tensor of one element, or a host Boolean.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
The truth value. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the field is not a truth value. |
Source code in src/quivers/dsl/meta/universe.py
read_int
¶
Read an Int field.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The field: an integer tensor of one element, or a host integer.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The integer. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the field is not an integer. |
Source code in src/quivers/dsl/meta/universe.py
read_real
¶
Read a Real field.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The field: a tensor of one element, or a host number.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The number. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the field is not a number. |
Source code in src/quivers/dsl/meta/universe.py
read_string
¶
Read a String field.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The field.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The string. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the field is not a string. |
Source code in src/quivers/dsl/meta/universe.py
reflect
¶
Reflection between checked declarations, quoted syntax, and source syntax.
Three directions meet here:
- a checked family, user-declared or generated, becomes a
Descvalue, the code of the sum of products the family is (describe_family); - a source type becomes a
SynTypevalue (syn_type), so a deriving class's static arguments reach its handler as data; - a
SynDeclvalue a meta computation returns becomes source declarations (read_declarations), which are then checked like hand-written ones.
The quoted-syntax families are the single representation of quoted code: a typed quotation elaborates to their constructor trees, and an antiquotation is a value of the same families.
ReflectionError
¶
Bases: ValueError
A declaration or a quoted value has no reflection in the other stratum.
describe_family
¶
describe_family(universe: MetaUniverse, family: FamilyDecl, constructors: Sequence[ConstructorDecl], written: Mapping[str, tuple[QiecTypeExpr, ...]], records: Mapping[str, QiecRecordDecl]) -> RuntimeConstructor
The description of a checked family, as a Desc value.
A checked row lists its labels in alphabetical order, so a record or
variant field type is quoted with its entries in the order its source
writes them: the order of the record type written in the field, or of
the record declaration the field names.
| PARAMETER | DESCRIPTION |
|---|---|
universe
|
The meta universe the value is built in.
TYPE:
|
family
|
The family, declared in source or generated by a declaration.
TYPE:
|
constructors
|
Its constructors, in any order; they are described in the order the family lists them.
TYPE:
|
written
|
The field types each constructor's source declaration writes, by the constructor's declared name; empty for a family a declaration generates, whose checked fields are its declaration.
TYPE:
|
records
|
The
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConstructor
|
|
| RAISES | DESCRIPTION |
|---|---|
ReflectionError
|
If a constructor is missing, or a field type has no quoted form. |
Source code in src/quivers/dsl/meta/reflect.py
syn_type_of_kernel
¶
syn_type_of_kernel(universe: MetaUniverse, type_: TypeExpr) -> RuntimeConstructor
Quote a checked type as a SynType value.
An argument whose binder is refinable, or which is a shape, is written
in parentheses after the bracketed static arguments, as source writes
Vec[A](n) and Real[Fin 3].
| PARAMETER | DESCRIPTION |
|---|---|
universe
|
The meta universe.
TYPE:
|
type_
|
The checked type.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConstructor
|
The quoted type. |
| RAISES | DESCRIPTION |
|---|---|
ReflectionError
|
If the type has no quoted form. |
Source code in src/quivers/dsl/meta/reflect.py
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 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 | |
syn_type
¶
syn_type(universe: MetaUniverse, type_: QiecTypeExpr) -> RuntimeConstructor
Quote a source type as a SynType value.
| PARAMETER | DESCRIPTION |
|---|---|
universe
|
The meta universe.
TYPE:
|
type_
|
The type as written.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConstructor
|
The quoted type. |
| RAISES | DESCRIPTION |
|---|---|
ReflectionError
|
If the type has no quoted form. |
Source code in src/quivers/dsl/meta/reflect.py
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 | |
syn_static
¶
syn_static(universe: MetaUniverse, argument: QiecStaticArgument) -> RuntimeConstructor
Quote a source static argument.
| PARAMETER | DESCRIPTION |
|---|---|
universe
|
The meta universe.
TYPE:
|
argument
|
The argument as written.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConstructor
|
The |
Source code in src/quivers/dsl/meta/reflect.py
read_declarations
¶
read_declarations(universe: MetaUniverse, value: object, *, line: int, col: int) -> tuple[Statement | TestDecl, ...]
Read the declarations a meta computation returned.
| PARAMETER | DESCRIPTION |
|---|---|
universe
|
The meta universe the value was built in.
TYPE:
|
value
|
A
TYPE:
|
line
|
The source line the declarations are checked at.
TYPE:
|
col
|
The source column the declarations are checked at.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Statement | TestDecl, ...]
|
The source declarations and properties, in order. |
| RAISES | DESCRIPTION |
|---|---|
ReflectionError
|
If the value is not quoted declarations. |
Source code in src/quivers/dsl/meta/reflect.py
universe
¶
Building and reading the values of the meta-phase universe.
The meta prelude declares the families meta computations exchange with the
checker: sequences, quoted syntax, family descriptions, and signature
morphisms. A MetaUniverse wraps the checked meta module and builds runtime
values of those families from host data, and reads runtime values of them
back, so the checker can hand a description to a deriving handler and read
the declarations it returns.
SCALAR_TYPES
module-attribute
¶
The primitive types meta-phase fields are built from, by name.
MetaField
¶
MetaField = RuntimeConstructor | str | int | float | bool | Tensor
One field of a runtime value of a meta-phase family.
MetaValueError
¶
Bases: ValueError
A runtime value does not have the shape its meta-phase family requires.
MetaUniverse
¶
MetaUniverse(module: QiecModule)
The checked meta module, seen as a universe of buildable values.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked meta-phase module, which contains the meta prelude.
TYPE:
|
Source code in src/quivers/dsl/meta/universe.py
family_type
¶
family_type(name: str, arguments: tuple[StaticArgument, ...] = ()) -> TypeApplication
The type of a family of the universe at static arguments.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The family's name.
TYPE:
|
arguments
|
Its parameters, in order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TypeApplication
|
The applied family type. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the module declares no family of that name. |
Source code in src/quivers/dsl/meta/universe.py
seq_type
¶
seq_type(element: TypeExpr) -> TypeApplication
The type Seq[element].
| PARAMETER | DESCRIPTION |
|---|---|
element
|
The element type.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TypeApplication
|
The sequence type. |
Source code in src/quivers/dsl/meta/universe.py
make
¶
make(constructor: str, fields: Sequence[MetaField] = (), static_arguments: tuple[StaticArgument, ...] = ()) -> RuntimeConstructor
Build a runtime value of one constructor.
| PARAMETER | DESCRIPTION |
|---|---|
constructor
|
The constructor's name.
TYPE:
|
fields
|
Its field values in declaration order. Host strings stay strings; integers, reals, and truth values become the scalar tensors the reference machine computes with.
TYPE:
|
static_arguments
|
The family's parameters, for a constructor of a parameterized
family such as
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConstructor
|
The value. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the constructor is unknown or the number of fields or static arguments is wrong. |
Source code in src/quivers/dsl/meta/universe.py
seq
¶
seq(items: Sequence[MetaField], element: TypeExpr) -> RuntimeConstructor
Build Seq[element] holding the items in order.
| PARAMETER | DESCRIPTION |
|---|---|
items
|
The elements.
TYPE:
|
element
|
Their type.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConstructor
|
The sequence. |
Source code in src/quivers/dsl/meta/universe.py
strings
¶
strings(items: Sequence[str]) -> RuntimeConstructor
Build Seq[String].
| PARAMETER | DESCRIPTION |
|---|---|
items
|
The strings.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeConstructor
|
The sequence. |
Source code in src/quivers/dsl/meta/universe.py
name_of
¶
The constructor a runtime value of the universe was built by.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The value.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Its constructor's name. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the value is not a constructor value of this module. |
Source code in src/quivers/dsl/meta/universe.py
fields_of
¶
The fields of a value built by an expected constructor.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The value.
TYPE:
|
expected
|
The constructor it must have been built by.
TYPE:
|
arity
|
The number of fields that constructor has.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[object, ...]
|
The fields. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the value was built by another constructor. |
Source code in src/quivers/dsl/meta/universe.py
read_seq
¶
The elements of a Seq value, in order.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The sequence.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[object, ...]
|
Its elements. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the value is not a sequence. |
Source code in src/quivers/dsl/meta/universe.py
read_string
¶
Read a String field.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The field.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The string. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the field is not a string. |
Source code in src/quivers/dsl/meta/universe.py
read_int
¶
Read an Int field.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The field: an integer tensor of one element, or a host integer.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The integer. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the field is not an integer. |
Source code in src/quivers/dsl/meta/universe.py
read_real
¶
Read a Real field.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The field: a tensor of one element, or a host number.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The number. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the field is not a number. |
Source code in src/quivers/dsl/meta/universe.py
read_bool
¶
Read a Bool field.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The field: a truth tensor of one element, or a host Boolean.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
The truth value. |
| RAISES | DESCRIPTION |
|---|---|
MetaValueError
|
If the field is not a truth value. |
Source code in src/quivers/dsl/meta/universe.py
library
¶
The meta-phase library: the prelude and the built-in deriving handlers.
Both are ordinary QVR source shipped with quivers. Their declarations are in scope in the meta phase of every module, so a module's own declarations may not reuse their names there.
LIBRARY_DIRECTORY
module-attribute
¶
The directory the library's source files live in.
LIBRARY_FILES
module-attribute
¶
The library sources, in the order their declarations enter the meta phase.
MetaLibrary
didactic-model
¶
MetaLibrary(*, statements: tuple[Statement, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), names: frozenset[str] = field(opaque=True, extras=OPAQUE_BY_VALUE), computations: frozenset[str] = field(opaque=True, extras=OPAQUE_BY_VALUE), digest: str)
Bases: ValueModel
The parsed meta-phase library.
| PARAMETER | DESCRIPTION |
|---|---|
statements
|
Every library declaration, in file order.
TYPE:
|
names
|
Every name the library declares in any namespace: families, constructors, computations, effect instances, and handlers.
TYPE:
|
computations
|
The names of the library's computations.
TYPE:
|
digest
|
The content-hash-domain digest, of kind
TYPE:
|
declared_names
¶
declared_names(statement: Statement) -> tuple[str, ...]
The names a declaration introduces in any namespace.
| PARAMETER | DESCRIPTION |
|---|---|
statement
|
The declaration.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
A family's name and its constructors' names, an index sort's name and its constructors' names, or the name of a computation, effect instance, handler, or pattern synonym. Other statements contribute no names. |
Source code in src/quivers/dsl/meta/library.py
meta_library
cached
¶
meta_library() -> MetaLibrary
Parse the meta-phase library once per process.
| RETURNS | DESCRIPTION |
|---|---|
MetaLibrary
|
The library's declarations, names, and digest. |