Expand description
The canonical representation of a zelkova programs is a translation of a local source into the broader world.
This phase is where we integrate the local parsed module into the rest of the program. We do the following steps:
- Resolve all imports
- Qualify all
Name(eg. a local valuetestin aMod.Amodule will be renamedMod.A.test) - Checks that exported names are actually present in the module
- Checks there is none cyclic dependency between this module and others (Might be done earlier, let’s see)
Note that we use HashMap’s a lot in this module’s structures. This is because later phases will
want to have cheap access to the different components of a Module.
TODO Rename this to core ? I feel it’s going to be te main internal representation of the language.
Structs§
- Ambiguous
Operator - One side of an
Error::AmbiguousOperatorPrecedence: the operator as the user spelled it, how itsinfixdeclaration said it associates, and where that declaration was written. - Broken
- A value declaration canonicalization rejected, recorded in
Module::broken. - Canonicalized
- What
canonicalize_recoveringbuilt of a module, beside every error it reported. - Case
Branch - Class
- A
classdeclaration of the module under check. - Class
Signature - What a class declares that another module can see: its members and superclasses, and the derivations it carries.
- Constraint
- A constraint: a class, resolved to its declaration, and the type variable it is on.
- Cycle
Member - One declaration of a cycle
Error::SelfDependencyreports. - Derivation
- A derivation in a class body, once it has passed the checks a derivation is held to:
derived eqand the bindings under it. - Derived
Context Gap - A constraint a
derivedinstance needs and the context written on it does not provide — seeError::DerivedInstanceContextTooNarrow. - Derived
Requirement - An argument of a derived instance’s type with no instance of the derived class — see
Error::DerivedInstanceRequires. - Expression
- A canonical expression, and where it was written.
- Field
- One field of a record or an update: a label, where the label was written, and the expression it was given.
- Infix
- Instance
- An
instancedeclaration of the module under check. - Instance
Name - What identifies an instance: its class, and the name at the front of its head.
- Instance
Signature - What an instance declares that another module can see: everything but its body.
- Member
- One member signature of a class:
compare : a -> a -> Order. - Module
- A resolved module
- Pattern
- A canonical pattern, and where it was written.
- Pattern
Field - One entry of a record pattern: the label it names, where the label alone was written, and the pattern that field’s value is matched against.
- Published
Instance - An instance as an
Interfacepublishes it: its signature, and where it was written when the interface that first published it knew its file. - Type
Constructor - Union
Type - Value
Signature - What an
Interfacepublishes of a value: where it was declared, its type, and the constraints its annotation wrote in front of that type.
Enums§
- Associativity
- Declaration
Site - Where a declaration an error refers to was written: in the module under check, in an imported module whose file is known, or somewhere no label can honestly point at.
- Derivation
Bindings - The bindings of a derivation. Which three or two there are is decided by the member’s
signature, and each is held in its own field so that none can be missing. Each is
boxed, for the reason a
Valueis large. - Derivation
Role - Which binding of a derivation a value is. The type each has is the one
the chapter
gives it, over
Derivation::resultandPosition. - Derivation
Signature Problem - What is wrong with the signature of a member a derivation was written for — see
Error::DerivationSignature. - Derived
Part - The part of a type a walk found an argument in: where a requirement of a derived instance came from.
- Derived
Shape Problem - What is wrong with the type a
derivedinstance is for, that it has no shape to walk — seeError::DerivedInstanceNoShape. - Error
- Everything canonicalization can reject.
- Export
Type - Exports
- Expression
Kind - Expression is an optimized version for checks and caches.
- Facade
Rejected Kind - The two forms What a facade signature may not
name
rejects — see
Error::FacadeTypeNotAdmitted. - Head
Name - The name at the front of an
InstanceHead. Two instances of one class whose heads share it are one instance declared twice. - Import
Origin - Part of
Error::AmbiguousVariablesandError::AmbiguousVariants’s public shape, so it is re-exported alongside the error rather than left behind a private module. Whether a contributor to a module’s scope was named by animportline the file wrote, or supplied by the default import list because the file wrote none for that module. - Infix
Declaration - Part of
Error::AmbiguousOperatorPrecedence’s public shape, so it is re-exported alongside the error rather than left behind a private module. Where an operator’sinfixdeclaration was written, to the extent canonicalization can say — the three cases aSpanLabelunder it has to distinguish. - Instance
Head - The type an instance is for: a declared type applied to distinct variables, one per
parameter; a tuple of distinct variables; or
(). - Instance
Head Problem - What is wrong with an instance head — see
Error::InvalidInstanceHead. - Invalid
Constraint Kind - What was written in front of
=>in place of a constraint — seeError::InvalidConstraint. - Invalid
Variant Kind - What was written where a
typedeclaration expected a variant — seeError::InvalidVariant. - Name
Taken By - What had a class’s name first — see
Error::ClassNameTaken. - Pattern
Kind - Record
Form - Which of the four record forms a
Error::RepeatedLabelwas found in. - Type
- A canonical type.
- Value
Functions§
- canonicalize
- Transform a given
parser::Moduleinto acanonical::Module, or into the errors that kept it from being one. - canonicalize_
recovering - Transform a given
parser::Moduleinto acanonical::Module, and hand it back beside every error found on the way. - effectful_
result_ payload - The payload
aoftpe, whentpeis exactly the shape an unmarked facade’s result must be —Task (Result Failure a),Task,ResultandFailureeach recognised by the qualified name of their declaration and never by spelling.Nonefor any other shape,Task IntandMaybe (Task Int)included — those areError::FacadeResultNotEffect, not this function’s business to name.