pub enum Value {
Value {
name: Name,
patterns: Vec<Pattern>,
body: Expression,
span: NodeSpan,
},
TypedValue {
name: Name,
patterns: Vec<(Pattern, Type)>,
body: Expression,
tpe: Type,
context: Vec<Constraint>,
marked_unsafe: bool,
span: NodeSpan,
annotation_span: NodeSpan,
},
}Variants§
Value
Fields
body: Expressionspan: NodeSpanWhere the declaration was written, annotation and body together.
TypedValue
Fields
body: Expressioncontext: Vec<Constraint>The constraints the annotation wrote in front of =>, each resolved to its
class, in the order written; empty for an annotation with no =>.
A field beside tpe and not a case of Type,
which keeps a context out of every match over a type. Nothing needs one
inside a type: a constraint stands only at the front of an annotation, and
a member signature carries
none. Always empty in a
facade, whose context is Error::FacadeConstrained and is not resolved.
marked_unsafe: boolTrue when the annotation was written unsafe name : Type.
The word is only meaningful on a facade signature, where it declares a
plain function in place of the effect a facade declares by default —
see Foreign interoperability. Only a
module whose binding_foreign is set can carry it: canonicalize
reports Error::UnsafeOutsideFacade for one written anywhere else,
so this is false on every value of an ordinary module.
span: NodeSpanWhere the declaration was written, annotation and body together.
annotation_span: NodeSpanWhere the name : Type annotation alone was written.
Type itself carries no span — it may have been cloned out of another
module’s Interface — so this is the only thing that can answer “where
was the expected type declared”. A type error uses it for the secondary
label that says the annotation is what the body is being held to.
Implementations§
Source§impl Value
impl Value
Sourcepub fn span(&self) -> NodeSpan
pub fn span(&self) -> NodeSpan
Where this declaration was written, whichever variant it is.
The typer falls back to this when a type error has no finer position of its
own — see typer::Error::labels.
Sourcepub fn arity(&self) -> usize
pub fn arity(&self) -> usize
How many parameters this declaration was written with.
This is the count of patterns on the left of the =, and deliberately not the
number of arrows in the declaration’s type: f : Int -> Int -> Int written f a = add a has arity 1, and returns a function for the second argument.
The rule lives here rather than at any of its readers because they feed fields a
backend reads together, from different phases. typer’s Translation uses it as
the callee’s arity at every call site naming this declaration, which is what
decides ir::Saturation; ir::build uses it as
ir::Declaration::arity, the count a
direct call has to supply; and Module::to_interface records it, through
Module::emitted_arity, for a module that imports the declaration. Copies that
drifted apart would mark a call site saturated at a count the emitted function
does not take. A facade signature has no patterns to count, and
Module::emitted_arity reads its arrows instead.
Sourcepub fn holds_hole(&self) -> bool
pub fn holds_hole(&self) -> bool
Whether the declaration’s parameters or body hold a hole, an
ExpressionKind::Hole or a PatternKind::Hole — a name that did not resolve.
A hole is made only where the error for it was raised, and that error is either
reported or dropped in an incomplete scope, where the failure
that made the scope incomplete stands in its place
(DEC-23 decision 3). So a declaration for which this
is true always has an error standing behind it, which is what
ir::Unchecked::reported asks of an entry.
A facade signature has no body, and the body of a TypedValue is read the same way
a Value’s is.