The Mirror Library (mirror)
Collection of mirror Rel definitions.
Module: rel:mirror
View sourcerel:mirrorThis module contains the entry points to load the Mirror MetaModel.
Each entry point takes a Config relation which specifies what part of the metamodel
to load and through what phase. The dependencies and dependencies_all entry points also
accept :extra items of :code and :docstring which respectively add the code_string
and docstring properties to the returned metamodel.
The returned metamodel is described by the rel:mirror:metamodel_schema relation.
PhaseName
View sourcePhaseName(x)Members of PhaseName are valid phases for use in the rel:mirror entry point relations.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | Any | Any value to check whether it is of type PhaseName. |
Explanation
Mirror returns metamodel information at different phases during the compilation process.
Some of the properties of the metamodel only apply for certain phases of compilation. When
this is the case, a rel:mirror:metamodel_schema:Phase is taken as a parameter.
The PhaseName members are used as values with the mirror config’s :entry_point key to
limit the phase through which information is gathered and returned. Requesting only an early
phase means that nearly all metamodel information will already be available to the compiler
and less data will be returned, so it is generally faster to run. Requesting a late phase
could cause the compiler to need to evaluate parts of the program to generate the metamodel.
The phases are:
:syntax_analysis: Shortly after parsing, when names have been resolved.:simplify: After most desugaring has happened.:type_inference: After types have been inferred and applied. Outlining also happens at this phase and the decls generated during outlining are added to the dependency graph.:front: After front compilation. The decls are now inBack IRform.:eval: At the end of compilation. This may trigger evaluation of queried declarations and their dependencies.
dependencies
View sourcedependencies[Name, Config]Return the metamodel containing the dependency graph of relations and declarations with
the outer name Name as per the parameters specified in the Config relation.
Parameters
| Parameter | Type | Description |
|---|---|---|
Name | RelName | A unary relation of names to find the dependency graph of (must be grounded). |
Config | Relation | A binary relation of RelName keys and values describing the parameters to use when loading the metamodel (must be grounded). |
Explanation
Name must be a arity one relation of RelName, such as {:model; :variables}.
Mirror Config parameters:
:phase: The maximum phase (seerel:mirror:PhaseName) to return information on.:extra::codeand:docstringcan be passed as extras. This wil add thecode_stringanddocstringproperties to the returned metamodel where available.
The default config is {:phase, :front}. This will set the phase to :front if not
specified in the passed Config.
Note: Mirror can only fetch the metamodel of the installed model or base relations.
See rel:mirror:metamodel_schema for details on the returned data.
Examples
def metamodel = rel:mirror:dependencies[:add, {:phase, :syntax_analysis; :extra, :docstring}]
with metamodel use model_name, lookup_front_decl, depends_on_decl, docstring
def m_add = lookup_front_decl["add"]
ic { model_name[m_add] ≡ "rel/stdlib" }
ic { depends_on_decl(m_add, lookup_front_decl["rel_primitive_add"])}
// list all of the docstrings in this metamodel
def output(q, doc) = docstring(d, doc) and lookup_front_decl(q, d) from dSee Also
dependencies_all
View sourcedependencies_all[Config]Return the metamodel containing the dependency graph of all relations and declarations
in the database as per the parameters specified in the Config relation.
Parameters
| Parameter | Type | Description |
|---|---|---|
Config | Relation | A binary relation of RelName keys and values describing the parameters to use when loading the metamodel (must be grounded). |
Explanation
Mirror Config parameters:
:phase: The maximum phase (seerel:mirror:PhaseName) to return information on.:extra::codeand:docstringcan be passed as extras. This wil add thecode_stringanddocstringproperties to the returned metamodel where available.
The default config is {:phase, :front}. This will set the phase to :front if not
specified in the passed Config.
Note: Mirror can only fetch the metamodel of the installed model or base relations.
See rel:mirror:metamodel_schema for details on the returned data.
Examples
def insert:q = 1; 2; 3.14; "a"
def metamodel = rel:mirror:dependencies_all[{:phase, :eval}]
with metamodel use lookup_relation, cardinality_estimate
def specialization_count = count[lookup_relation["q"]]
// Be careful on the group by, otherwise the Float and String overloads' cardinalities collapse
def total_cardinality = sum[{id, c: cardinality_estimate(id, c) and lookup_relation("q", id)}]
ic { specialization_count ≡ 3 }
ic { total_cardinality ≡ 4 }See Also
list_derived_all
View sourcelist_derived_all[Config]Return the metamodel containing all of the derived relations in the dependency graph
as per the parameters in Config.
Parameters
| Parameter | Type | Description |
|---|---|---|
Config | Relation | A binary relation of RelName keys and values describing the parameters to use when loading the metamodel (must be grounded). |
Explanation
Mirror Config parameters:
:phase: The maximum phase (seerel:mirror:PhaseName) to return information on.
The default config is {:phase, :front}. This will set the phase to :front if not
specified in the passed Config.
Note: Mirror can only fetch the metamodel of the installed model or base relations.
See rel:mirror:metamodel_schema for details on the returned data.
Examples
def metamodel = rel:mirror:list_derived_all[{:phase, :eval}]
with metamodel use lookup_relation, cardinality_estimate
// find all of the derived relations in the `rel` namespace
def rel_rels(x) = exists(y: lookup_relation(y, x) and regex_match("^rel", y))
def output:num_rel_rels = count[rel_rels]
def output:total_card_rel_rels = sum[cardinality_estimate[x] for x in rel_rels]See Also
list_base_all
View sourcelist_base_all[Config]Return the metamodel containing all of the base relations in the dependency graph
as per the parameters in Config.
Parameters
| Parameter | Type | Description |
|---|---|---|
Config | Relation | A binary relation of RelName keys and values describing the parameters to use when loading the metamodel (must be grounded). |
Explanation
Mirror Config parameters:
:phase: The maximum phase (seerel:mirror:PhaseName) to return information on.
The default config is {:phase, :front}. This will set the phase to :front if not
specified in the passed Config.
Note: Mirror can only fetch the metamodel of the installed model or base relations.
See rel:mirror:metamodel_schema for details on the returned data.
Examples
def metamodel = rel:mirror:list_base_all[{:phase, :eval}]
with metamodel use lookup_relation, cardinality_estimate
// find all of the base relations in the `rel` namespace
def rel_rels(x) = exists(y: lookup_relation(y, x) and regex_match("^rel", y))
def output:num_rel_rels = count[rel_rels]
def output:total_card_rel_rels = sum[cardinality_estimate[x] for x in rel_rels]See Also
Module: rel:mirror:metamodel_schema
View sourcerel:mirror:metamodel_schemaThe schema of the data returned from the rel:mirror entry point relations. This can
be used to create a bound declaration on relations containing the metamodel.
Examples
bound metamodel = rel:mirror:metamodel_schema
def metamodel = rel:mirror:dependencies_all[{}]qualifier
View sourcequalifier(item in Hash, q in String)Relation, Declaration, and SourceModule all have qualifier strings to map the
unique identifier to a string displaying the qualifying prefix of the item. The qualifier
is the constant RelName prefix of the item.
Parameters
| Parameter | Type | Description |
|---|---|---|
item | Hash | An identifier for an entity in the metamodel. |
q | String | A qualifier for an entity in the metamodel. |
Explanation
The corrolary to qualifier is lookup_<item> where the lookup is specialized by the
type of the item.
Examples
// qualifier = "person:address"
def person:address = "123 Main St"
// qualifier = "cube"
@inline
def cube[n] = n^3
// qualifier of decl = "outer:inner:decl"
// qualifier of outer module = "outer"
// qualifier of inner module = "outer:inner"
@outline
module outer[R]
module inner
def decl = R + 1
end
end
// qualifier = "a:b"
@inline
def a:b[c in Int, :d] = c + 1
// qualifier of decl = "insert:name"
// qualifier of resulting base relation = "name"
def insert:name = "jodie"Entry Points
- dependencies
- list_base_all
- list_derived_all
See Also
lookup_back_decl, lookup_front_decl, lookup_module, and lookup_relation.
Declaration
View sourceDeclaration(x)The supertype of Front and Back.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | Hash | An identifier for an entity in the metamodel. |
Entry Points
- dependencies
depends_on_decl
View sourcedepends_on_decl(p in Phase, x in Declaration, y in Declaration)A declaration x depends directly on another declaration y at the given phase.
Parameters
| Parameter | Type | Description |
|---|---|---|
p | Phase | An identifier for a phase in the metamodel. |
x | Declaration | An identifier for a declaration entity in the metamodel. |
y | Declaration | An identifier for a declaration entity in the metamodel. |
Entry Points
- dependencies
code_string
View sourcecode_string(p in Phase, d in Declaration, s in String)A pretty printed representation of the code of declartion d at phase p.
Parameters
| Parameter | Type | Description |
|---|---|---|
p | Phase | An identifier for a phase in the metamodel. |
d | Declaration | An identifier for a declaration entity in the metamodel. |
s | String | A string representing code at the given phase of compilation. |
Explanation
During compilation the code gets lowered to intermediate representations (IR). These IRs are more rudimentary represntations of Rel than in the source code and are not valid Rel.
Entry Points
- dependencies (with
:extra, :codeset inConfig)
generated_from
View sourcegenerated_from(d in Delcaration, src_decl in Declaration)A declaration d was generated during compilation of declaration src_decl.
Parameters
| Parameter | Type | Description |
|---|---|---|
d | Declaration | An identifier for a declaration entity in the metamodel. |
src_decl | Declaration | An identifier for a declaration entity in the metamodel. |
Explanation
The compiler generates declarations in various situations:
- Desugaring (e.g. a
bounddeclartion generates an integrity constraint) - Outlining
- Breaking down a declaration into intermediates
Examples
In the following example, the generated declaration for tc[edge] is generated
from the original source declaration tc.
@outline
def tc[E] = E; tc[E].E
def reachable = tc[edge]In the following example, the generated declaration for rel:catalog:ic_violation
refers to the original soure delcaration ic foo.
def bar = 1; 2; 3
ic foo(x) { bar(x) implies Int(x) }Entry Points
- dependencies
is_recursive
View sourceis_recusive(p in Phase, d in Declaration)Declaration d is recusive at phase p.
Parameters
| Parameter | Type | Description |
|---|---|---|
p | Phase | An identifier for a phase in the metamodel. |
d | Declaration | An identifier for a declaration entity in the metamodel. |
Entry Points
- dependencies
Front
View sourceFront(x)The supertype of FrontDeclaration and FrontNativeDeclaration.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | Hash | An identifier for an entity in the metamodel. |
Entry Points
- dependencies
FrontDeclaration
View sourceFrontDeclaration(x)The type check relation for the FrontDeclaration entity.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | Hash | An identifier for an entity in the metamodel. |
Explanation
A FrontDeclaration corresponds to a user definition in rel source or a declaration
that the compiler generated while compiling that source.
The below are examples of declarations:
bound data = RelName, FilePos, Intdef values = 1; 2; 3ic { exists(data) }
Entry Points
- dependencies
FrontNativeDeclaration
View sourceFrontNativeDeclaration(x)The type check relation for the FrontNativeDeclaration entity.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | Hash | An identifier for an entity in the metamodel. |
Explanation
Some declarations are built into the compiler and do not refer back to a declaration in the installed model.
The below are examples of natives:
rel_primitive_addrel_primitive_round_up
Entry Points
- dependencies
lookup_front_decl
View sourcelookup_front_decl(q in String, x in Front)Lookup a Front identifier by its qualifier string. See
rel:mirror:metamodel_schema:qualifier for more information on qualifiers.
Parameters
| Parameter | Type | Description |
|---|---|---|
q | String | A qualifier for an entity in the metamodel. |
x | Front | An identifier for an entity in the metamodel. |
Entry Points
- dependencies
See Also
docstring
View sourcedocstring(d in FrontDeclaration, s in String)The documentation string associated with the front declaration d.
Parameters
| Parameter | Type | Description |
|---|---|---|
d | FrontDeclaration | An identifier for a front declaration entity in the metamodel. |
s | String | An string containing documentation on the declaration. |
Entry Points
- dependencies (with
:extra, :docstringset inConfig)
to_string
View sourceto_string(d in FrontDeclaration, s in String)A compact string representation of a FrontDeclaration (e.g. “rel/stdlib:6641 intersect”).
Parameters
| Parameter | Type | Description |
|---|---|---|
d | FrontDeclaration | An identifier for a front declaration entity in the metamodel. |
s | String | An string containing a compact representation of the declaration. |
Entry Points
- dependencies
model_name
View sourcemodel_name(d in FrontDeclaration, s in String)The name of the model where the declaration is installed.
Parameters
| Parameter | Type | Description |
|---|---|---|
d | FrontDeclaration | An identifier for a front declaration entity in the metamodel. |
s | String | An string containing the name of the model where the declaration is installed. |
Entry Points
- dependencies
is_native
View sourceis_native(d in Declaration)If the declaration is a Rel native (e.g. rel_primitive_add).
Parameters
| Parameter | Type | Description |
|---|---|---|
d | FrontDeclaration | An identifier for a front declaration entity in the metamodel. |
Explanation
Currently this is only true for FrontNatieDeclaration.
Entry Points
- dependencies
in_module
View sourcein_module(d in FrontDeclartion, m in SourceModule)A declaration d was declared in the source module m.
Parameters
| Parameter | Type | Description |
|---|---|---|
d | FrontDeclaration | An identifier for a front declaration entity in the metamodel. |
m | SourceModule | An identifier for a module entity in the metamodel. |
Explanation
This will point to the innermost module the declaration was nested in. That module will have a pointer to its parent module if nested.
Entry Points
- dependencies
See Also
is_inline
View sourceis_inline(d in FrontDeclaration)The declaration d has the attribute @inline.
Parameters
| Parameter | Type | Description |
|---|---|---|
d | FrontDeclaration | An identifier for a front declaration entity in the metamodel. |
Entry Points
- dependencies
is_outline
View sourceis_outline(d in FrontDeclaration)The declaration d has the attribute @outline.
Parameters
| Parameter | Type | Description |
|---|---|---|
d | FrontDeclaration | An identifier for a front declaration entity in the metamodel. |
Entry Points
- dependencies
is_higher_order
View sourceis_higher_order(d in Front)The declaration d has at least one higher order parameter.
Parameters
| Parameter | Type | Description |
|---|---|---|
d | FrontDeclaration | An identifier for a front declaration entity in the metamodel. |
Entry Points
- dependencies
compiles_to
View sourcecompiles_to(f in Front, b in Back)The front declaration d compiles to the back declaration b.
Parameters
| Parameter | Type | Description |
|---|---|---|
f | Front | An identifier for a front entity in the metamodel. |
b | Back | An identifier for a back entity in the metamodel. |
Entry Points
- dependencies
Module: range
View sourcestart:line
View sourcerange:start:line(d in FrontDeclaration, l in Int)The line in the source code of the model where declaration d begins.
Parameters
| Parameter | Type | Description |
|---|---|---|
d | FrontDeclaration | An identifier for a front declaration entity in the metamodel. |
l | Int | The line number in the source code. |
Entry Points
- dependencies
end:line
View sourcerange:end:line(d in FrontDeclaration, l in Int)The line in the source code of the model where declaration d ends.
Parameters
| Parameter | Type | Description |
|---|---|---|
d | FrontDeclaration | An identifier for a front declaration entity in the metamodel. |
l | Int | The line number in the source code. |
Entry Points
- dependencies
start:character
View sourcerange:start:character(d in FrontDeclaration, c in Int)The character in the line of source code of the model where declaration d begins.
Parameters
| Parameter | Type | Description |
|---|---|---|
d | FrontDeclaration | An identifier for a front declaration entity in the metamodel. |
c | Int | The character number in the line in the source code. |
Entry Points
- dependencies
end:character
View sourcerange:end:character(d in FrontDeclaration, c in Int)The character in the line of source code of the model where declaration d ends.
Parameters
| Parameter | Type | Description |
|---|---|---|
d | FrontDeclaration | An identifier for a front declaration entity in the metamodel. |
c | Int | The character number in the line in the source code. |
Entry Points
- dependencies
Diagnostic
View sourceDiagnostic(x)The type check relation for the Diagnostic entity.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | Hash | An identifier for an entity in the metamodel. |
Entry Points
- dependencies
generated_diagnostic
View sourcegenerated_diagnostic(d in FrontDeclaration, dx in Diagnostic)During compilation of declaration d, diagnostic dx was generated.
Parameters
| Parameter | Type | Description |
|---|---|---|
d | FrontDeclaration | An identifier for a front declaration entity in the metamodel. |
dx | Diagnostic | An identifier for a diagnostic entity in the metamodel. |
Entry Points
- dependencies
Module: diagnostic
View sourceseverity
View sourcediagnostic:severity(dx in Diagnostic, s in String)The diagnostic dx has severity s.
Parameters
| Parameter | Type | Description |
|---|---|---|
dx | Diagnostic | An identifier for a diagnostic entity in the metamodel. |
s | String | The severity level of the diagnostic. |
Explanation
Severity levels:
"exception""error""warning"
Entry Points
- dependencies
code
View sourcediagnostic:code(dx in Diagnostic, c in String)The diagnostic dx has code c.
Parameters
| Parameter | Type | Description |
|---|---|---|
dx | Diagnostic | An identifier for a diagnostic entity in the metamodel. |
c | String | The code of the diagnostic. |
Explanation
Sample codes:
"UNDEFINED_IDENTIFIER""UNTYPED_VARIABLE""EXPERIMENTAL"
Entry Points
- dependencies
Back
View sourceBack(x)The supertype of BackDeclaration. In the future, other back declaration types
will be added here.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | Hash | An identifier for an entity in the metamodel. |
Entry Points
- dependencies
BackDeclaration
View sourceBackDeclaration(x)The type check relation for the BackDeclaration entity.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | Hash | An identifier for an entity in the metamodel. |
Entry Points
- dependencies
lookup_back_decl
View sourcelookup_back_decl(q in String, x in Back)Lookup a Back identifier by its qualifier string. See
rel:mirror:metamodel_schema:qualifier for more information on qualifiers.
Parameters
| Parameter | Type | Description |
|---|---|---|
q | String | A qualifier for an entity in the metamodel. |
x | Back | An identifier for an entity in the metamodel. |
Entry Points
- dependencies
See Also
declares
View sourcedeclares(d in Back, r in Relation)The declaration d declares the relation r.
Parameters
| Parameter | Type | Description |
|---|---|---|
d | Back | An identifier for a back entity in the metamodel. |
r | Relation | An identifier for a relation entity in the metamodel. |
Entry Points
- dependencies
depends_on_relation
View sourcedepends_on_relation(p in Phase, d in Declaration, r in Relation)The declaration d directly depends on the relation r at phase p.
Parameters
| Parameter | Type | Description |
|---|---|---|
p | Phase | An identifier for a phase in the metamodel. |
d | Declaration | An identifier for a declaration entity in the metamodel. |
r | Relation | An identifier for a relation entity in the metamodel. |
Explanation
A FrontDeclaration can depend only on BaseRelation and not on DerivedRelation, as derived relations are not yet known to the compiler at this point. BackDeclaration depends on both BaseRelation and DerivedRelation.
Entry Points
- dependencies
See Also
Phase, Declaration, and Relation.
SCC
View sourceSCC(x)The type check relation for the SCC entity.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | Hash | An identifier for an entity in the metamodel. |
Explanation
An SCC is a Strongly Connected Component, which groups together mutually
dependent declarations.
Entry Points
- dependencies
scc
View sourcescc(p in Phase, d in Declaration, s in SCC)The declaration d is in the strongly connected component s at phase p.
Parameters
| Parameter | Type | Description |
|---|---|---|
p | Phase | An identifier for a phase in the metamodel. |
d | Declaration | An identifier for a declaration entity in the metamodel. |
s | SCC | An identifier for an SCC entity in the metamodel. |
Entry Points
- dependencies
Relation
View sourceRelation(x)The supertype of BaseRelation and DerivedRelation.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | Hash | An identifier for an entity in the metamodel. |
Entry Points
- dependencies
- list_base_all
- list_derived_all
BaseRelation
View sourceBaseRelation(x)The type check relation for the BaseRelation entity.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | Hash | An identifier for an entity in the metamodel. |
Explanation
A BaseRelation is a relation which is inserted into the database as a fact.
Entry Points
- dependencies
- list_base_all
DerivedRelation
View sourceDerivedRelation(x)The type check relation for the BaseRelation entity.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | Hash | An identifier for an entity in the metamodel. |
Explanation
A DerviedRelation is a relation which is derived from logic in the database’s model.
Entry Points
- dependencies
- list_derived_all
lookup_relation
View sourcelookup_relation(q in String, x in Relation)Lookup a Relation identifier by its qualifier string. See
rel:mirror:metamodel_schema:qualifier for more information on qualifiers.
Parameters
| Parameter | Type | Description |
|---|---|---|
q | String | A qualifier for an entity in the metamodel. |
x | Relation | An identifier for an entity in the metamodel. |
Entry Points
- dependencies
- list_base_all
- list_derived_all
See Also
cardinality_estimate
View sourcecardinality_estimate(r in Relation, n in Int)The estimate of the how many tuples are in the relation r in the database.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | Relation | An identifier for an entity in the metamodel. |
n | Int | An estimate of the number of tuples in the relation. |
Explanation
Cardinality estimate is only available at phase :eval and may be missing on relations
generated by the compiler.
Entry Points
- dependencies
- list_base_all
- list_derived_all
SourceModule
View sourceSourceModule(x)The type check relation for the SourceModule entity.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | Hash | An identifier for an entity in the metamodel. |
Explanation
An SourceModule corresponds a declared module in the source model.
Entry Points
- dependencies
lookup_module
View sourcelookup_module(q in String, m in SourceModule)Lookup a SourceModule identifier by its qualifier string. See
rel:mirror:metamodel_schema:qualifier for more information on qualifiers.
Parameters
| Parameter | Type | Description |
|---|---|---|
q | String | A qualifier for an entity in the metamodel. |
x | SourceModule | An identifier for an entity in the metamodel. |
Entry Points
- dependencies
See Also
parent_module
View sourceparent_module(m in SourceModule, parent in SourceModule)The module m is nested direclty inside module parent.
Parameters
| Parameter | Type | Description |
|---|---|---|
m | SourceModule | A qualifier for a module entity in the metamodel. |
parent | SourceModule | An identifier for a module entity in the metamodel. |
Entry Points
- dependencies
docstring
View sourcedocstring(m in SourceModule, s in String)The documentation string associated with the source module m.
Parameters
| Parameter | Type | Description |
|---|---|---|
m | SourceModule | An identifier for a module entity in the metamodel. |
s | String | An string containing documentation on the module. |
Entry Points
- dependencies (with
:extra, :docstringset inConfig)
Phase
View sourcePhase(x)The type check relation for the Phase entity.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | Hash | An identifier for an entity in the metamodel. |
Explanation
A Phase is an entity identifier corresponding to a rel:mirror:PhaseName.
Entry Points
- dependencies
- list_base_all
- list_derived_all
lookup_phase
View sourcelookup_phase(name in rel:mirror:PhaseName, p in Phase)Lookup a Phase identifier by it’s RelName identifier in rel:mirror:PhaseName.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | rel:mirror:PhaseName | The name of a mirror phase. |
p | Phase | An identifier for a phase entity in the metamodel. |
Entry Points
- dependencies
- list_base_all
- list_derived_all
phase_ordinal
View sourcephase_ordinal(p in Phase, n in Int)An integer n representing the order of the phase p in the compilation pipeline.
Parameters
| Parameter | Type | Description |
|---|---|---|
p | Phase | An identifier for a phase entity in the metamodel. |
n | Int | The order of the phase during compilation. |
Entry Points
- dependencies
- list_base_all
- list_derived_all