Expected interface for pure expressions that can be used to specialize the Imperative dialect.
- Ident : Type
Kinds of identifiers allowed in expressions. We expect identifiers to have decidable equality; see
EqIdent. - EqIdent : DecidableEq self.Ident
Decidable equality on identifiers.
- Expr : Type
Expressions
- Ty : Type
Types
- ExprMetadata : Type
Expression metadata type (for use in function declarations, etc.)
- TyEnv : Type
Typing environment, expected to contain a map of variables to their types, type substitution, etc.
- TyContext : Type
Typing context, expected to contain information that does not change during type checking/inference (e.g., known types and known functions.)
- Factory : Type u
Factory for function/operator resolution. A factory may also carry a semantic model (as Core's runtime factory does), which is why it lives in an arbitrary universe.
- Val : Type u
Runtime values held by variable stores and produced by
eval. A value may record the model it was produced in;HasVal.valuesays which values belong to a given factory. The expression evaluator. Takes a factory, a variable store, and an expression, and returns an optional value.
Instances For
[DecidableEq P.Ident] resolves to the bundled PureExpr.EqIdent field,
keeping the term on a single instance across a proof.
Equations
Type Classes for Expressions #
Lawfulness of HasIdent: the canonical identifier-injection is injective.
- ident_inj : Function.Injective HasIdent.ident
Instances
A free variable carrying its type. A pass that introduces a variable after type checking has run must annotate it itself, since nothing downstream will.
Instances
Multi-variable version of HasFvar.getFvar: returns ALL free variables in
a (possibly compound) expression. HasFvar.getFvar only returns Some when
the expression is a single fvar atom; HasFvars.getFvars recurses into
compounds.
The free-variable occurrences of an expression that carry a type annotation, with their annotations. There is no default: a language whose expressions carry no annotations says so with
fun _ => [].
Instances
Lawfulness of HasFvars against HasFvar: the free-variable list of an
mkFvar x expression, as computed by the HasFvars.getFvars extractor, is a
subset of [x].
The annotation contributes no free variables of its own.
- mem_getFvars_of_typed (e : P.Expr) (x : P.Ident) (ty : P.Ty) : (x, ty) ∈ HasFvars.getTypedFvars e → x ∈ HasFvars.getFvars e
An annotated occurrence is a free variable.
A bare variable carries no annotation.
- mkTypedFvar_getTypedFvars (x : P.Ident) (ty : P.Ty) : HasFvars.getTypedFvars (HasFvar.mkTypedFvar x ty) ⊆ [(x, ty)]
A typed variable carries only its own annotation.
Instances
Predicates on runtime values (P.Val): which values belong to a factory
(and so may be held by its stores), and which values inhabit a type.
vis a runtime value of factoryf.vis a value of the monomorphic typety.
Instances
Laws for the abstract typed-value predicate.
- valueOfTy_isVal (f : P.Factory) (v : P.Val) (ty : P.Ty) : HasVal.valueOfTy f v ty → HasVal.value f v
Every typed value is a value.
Every value has a type.
- valueOfTy_congr (f : P.Factory) (a b : P.Val) (ty₁ ty₂ : P.Ty) : HasVal.valueOfTy f a ty₁ → HasVal.valueOfTy f a ty₂ → HasVal.valueOfTy f b ty₂ → HasVal.valueOfTy f b ty₁
Typed-value membership is congruent across the shared type of a witness: if some value
ahas both typesty₁andty₂, then any value of typety₂is also a value of typety₁.
Instances
Boolean expressions and values. Extends HasVal P. The expression
constants tt/ff are syntax; ttVal f/ffVal f are the runtime values
of factory f they evaluate to (see WellFormedSemanticEvalVal).
- tt : P.Expr
- ff : P.Expr
- boolTy : P.Ty
The runtime value
trueof a factory.The runtime value
falseof a factory.The Boolean values are distinct.
- boolIsValOfTy (f : P.Factory) : HasVal.valueOfTy f (ttVal f) boolTy ∧ HasVal.valueOfTy f (ffVal f) boolTy
Boolean values have the Boolean type.
Instances
Boolean values are values, induced by their typed-value proofs.
Equations
- ⋯ = ⋯
Instances For
A variable reference, annotated with ty when given.
Equations
Instances For
A Boolean variable reference.
Equations
Instances For
Laws for the Boolean expression constants: they read no variables.
Instances
Boolean operations: not, and, imp.
- boolIsValOfTy (f : P.Factory) : HasVal.valueOfTy f (ttVal f) boolTy ∧ HasVal.valueOfTy f (ffVal f) boolTy
Instances
Typing of expressions #
The command semantics only steps when expressions evaluate, and an evaluator may
fail on ill-typed expressions (Core's denotational evaluator does). These
definitions state the typing assumption under which evaluation cannot fail; their
consequences for commands are in Strata.DL.Imperative.CmdSemanticsProps.
The types assigned to variables, as computed by a type checker.
Equations
- Imperative.VarTyping P = (P.Ident → Option P.Ty)
Instances For
Type soundness of the evaluator against the typing judgment.
- eval_of_hasType (f : P.Factory) (Γ : VarTyping P) (σ : P.Ident → Option P.Val) (e : P.Expr) (ty : P.Ty) : HasTyping.HasType f Γ e ty → StoreHasTyping f σ Γ → ∃ (v : P.Val), P.eval f σ e = some v ∧ HasVal.valueOfTy f v ty
A well-typed expression evaluates, in a store conforming to its typing, to a value of its type.
- valueOfTy_bool (f : P.Factory) (v : P.Val) : HasVal.valueOfTy f v HasBool.boolTy → v = HasBool.ttVal f ∨ v = HasBool.ffVal f
The values of the Boolean type are the two Boolean values.
Instances
Integer constants and the integer type.
Instances
Substitution of free variables in expressions. Used for closure capture in function declarations.
Substitute a single free variable with an expression
Simultaneously substitute multiple free variables with expressions. Replaces all variables in a single pass, avoiding capture between substitutions.
Simultaneously rename free variables by NAME, in a single pass with first-match semantics (
a ↦ bfor the first(a, b)in the list, else unchanged). UnlikesubstFvars, this rewrites a free variable's name in place and preserves everything else about the occurrence — in particular any type annotation it carries — so renaming never drops type information the way substituting a freshly-built bare free variable would.
Instances
A function declaration for use with PureExpr - instantiation of Func for
any expression system that implements the PureExpr interface.
Equations
- Imperative.PureFunc P = Strata.DL.Util.Func P.Ident P.Expr P.Ty P.ExprMetadata