pub struct Specialisation {
pub of: Subject,
pub key: Vec<Type>,
pub declaration: Declaration,
}Expand description
A constrained declaration, or a member of an instance with a context, at one assignment of ground types to its constrained variables: an ordinary declaration of the module that uses it.
specialise makes these. The body is a copy of the declaring module’s code with the
assignment applied to every type in it, and with each reference that carried obligations
resolved at the types they are now at, so nothing in it asks which instance is meant and
nothing is passed at run time to say
(DEC-2 decision 7).
It is placed in the module that uses it and not in the module that declares the function,
because the instance a copy calls may be declared by a module that imports the
declaring one: emitted beside min, a copy that called the compare of an App that
imports Basics would make Basics import App.
Two uses at one key in one module are one specialisation, and two modules that use one key each hold a copy. For a function that is code written twice and nothing a program can observe. For a binding with no parameters it is one evaluation for each module that uses it where the chapter says “once”, and a Zelkova value has no identity, so what differs is the work done and never an answer.
Fields§
§of: SubjectWhat this is a copy of.
key: Vec<Type>The ground type each constrained variable of the declaration is at, in the order
the variables first occur in its context.
Only the variables a constraint is on are in it: nothing a JavaScript module emits
depends on any other, so a variable with no constraint needs no copy. A target whose
code does depend on one reads its type off the nodes of
declaration, where it is left a variable.
declaration: DeclarationThe copy: the declaring declaration’s name and parameters, its type and every type in
its body with the key applied, an empty context, and
Declaration::arity and Declaration::span as it was written.