Skip to main content

Module canonical

Module canonical 

Source
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 value test in a Mod.A module will be renamed Mod.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§

AmbiguousOperator
One side of an Error::AmbiguousOperatorPrecedence: the operator as the user spelled it, how its infix declaration said it associates, and where that declaration was written.
Broken
A value declaration canonicalization rejected, recorded in Module::broken.
Canonicalized
What canonicalize_recovering built of a module, beside every error it reported.
CaseBranch
Class
A class declaration of the module under check.
ClassSignature
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.
CycleMember
One declaration of a cycle Error::SelfDependency reports.
Derivation
A derivation in a class body, once it has passed the checks a derivation is held to: derived eq and the bindings under it.
DerivedContextGap
A constraint a derived instance needs and the context written on it does not provide — see Error::DerivedInstanceContextTooNarrow.
DerivedRequirement
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 instance declaration of the module under check.
InstanceName
What identifies an instance: its class, and the name at the front of its head.
InstanceSignature
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.
PatternField
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.
PublishedInstance
An instance as an Interface publishes it: its signature, and where it was written when the interface that first published it knew its file.
TypeConstructor
UnionType
ValueSignature
What an Interface publishes of a value: where it was declared, its type, and the constraints its annotation wrote in front of that type.

Enums§

Associativity
DeclarationSite
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.
DerivationBindings
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 Value is large.
DerivationRole
Which binding of a derivation a value is. The type each has is the one the chapter gives it, over Derivation::result and Position.
DerivationSignatureProblem
What is wrong with the signature of a member a derivation was written for — see Error::DerivationSignature.
DerivedPart
The part of a type a walk found an argument in: where a requirement of a derived instance came from.
DerivedShapeProblem
What is wrong with the type a derived instance is for, that it has no shape to walk — see Error::DerivedInstanceNoShape.
Error
Everything canonicalization can reject.
ExportType
Exports
ExpressionKind
Expression is an optimized version for checks and caches.
FacadeRejectedKind
The two forms What a facade signature may not name rejects — see Error::FacadeTypeNotAdmitted.
HeadName
The name at the front of an InstanceHead. Two instances of one class whose heads share it are one instance declared twice.
ImportOrigin
Part of Error::AmbiguousVariables and Error::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 an import line the file wrote, or supplied by the default import list because the file wrote none for that module.
InfixDeclaration
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’s infix declaration was written, to the extent canonicalization can say — the three cases a SpanLabel under it has to distinguish.
InstanceHead
The type an instance is for: a declared type applied to distinct variables, one per parameter; a tuple of distinct variables; or ().
InstanceHeadProblem
What is wrong with an instance head — see Error::InvalidInstanceHead.
InvalidConstraintKind
What was written in front of => in place of a constraint — see Error::InvalidConstraint.
InvalidVariantKind
What was written where a type declaration expected a variant — see Error::InvalidVariant.
NameTakenBy
What had a class’s name first — see Error::ClassNameTaken.
PatternKind
RecordForm
Which of the four record forms a Error::RepeatedLabel was found in.
Type
A canonical type.
Value

Functions§

canonicalize
Transform a given parser::Module into a canonical::Module, or into the errors that kept it from being one.
canonicalize_recovering
Transform a given parser::Module into a canonical::Module, and hand it back beside every error found on the way.
effectful_result_payload
The payload a of tpe, when tpe is exactly the shape an unmarked facade’s result must be — Task (Result Failure a), Task, Result and Failure each recognised by the qualified name of their declaration and never by spelling. None for any other shape, Task Int and Maybe (Task Int) included — those are Error::FacadeResultNotEffect, not this function’s business to name.