This requires a few pieces: * Make node tags use `Fin n` intead of natural numbers. This makes it possible to build a finite lattice over AST nodes, and also ensure automatic, total indexing from CFG nodes into the AST that created them. For this, use the elaborator to derive the ordering statements etc. where possible. * Adjust the forward framework to enable proofs that don't just state correctness on the environment, but also on an arbitrary additional state accumulated from traversing the trace. * State the reaching definition analysis's correctness in terms of this new framework. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
32 lines
1.0 KiB
Lean4
32 lines
1.0 KiB
Lean4
import Spa.Analysis.Forward.Lattices
|
||
|
||
namespace Spa
|
||
|
||
namespace Forward
|
||
|
||
variable (L : Type) [Lattice L] (prog : Program)
|
||
|
||
class StmtEvaluator where
|
||
eval : (s : prog.State) → (bs : BasicStmt) → prog.code s = some bs →
|
||
VariableValues L prog → VariableValues L prog
|
||
eval_mono : ∀ s bs h, Monotone (eval s bs h)
|
||
|
||
class ExprEvaluator where
|
||
eval : Expr → VariableValues L prog → L
|
||
eval_mono : ∀ e, Monotone (eval e)
|
||
|
||
class ValidExprEvaluator [ExprEvaluator L prog] [I : LatticeInterpretation L] :
|
||
Prop where
|
||
valid : ∀ {vs : VariableValues L prog} {ρ : Env} {e : Expr} {v : Value},
|
||
EvalExpr ρ e v → ⟦ vs ⟧ ρ () → I.interp (ExprEvaluator.eval e vs) v
|
||
|
||
class ValidStmtEvaluator [E : StmtEvaluator L prog] [LatticeInterpretation L] :
|
||
Prop where
|
||
valid : ∀ {s : prog.State} {vs : VariableValues L prog} {ρ₁ ρ₂ : Env}
|
||
{bs : BasicStmt} (hcode : prog.code s = some bs),
|
||
EvalBasicStmt ρ₁ bs ρ₂ → ⟦ vs ⟧ ρ₁ () → ⟦ E.eval s bs hcode vs ⟧ ρ₂ ()
|
||
|
||
end Forward
|
||
|
||
end Spa
|