Skip to content

Commit

Permalink
feat: add rewriter that's based on fuel, which tries applying the rew…
Browse files Browse the repository at this point in the history
…riter at every 'ix' until it runs out of fuel
  • Loading branch information
bollu committed Nov 16, 2023
1 parent 9a46d69 commit 6283edb
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions SSA/Core/Framework.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@ def rewritePeepholeAt (pr : PeepholeRewrite Op Γ t)
| none => target
else target


theorem denote_rewritePeepholeAt (pr : PeepholeRewrite Op Γ t)
(pos : ℕ) (target : Com Op Γ₂ t₂) :
(rewritePeepholeAt pr pos target).denote = target.denote := by
Expand All @@ -1196,6 +1197,23 @@ theorem denote_rewritePeepholeAt (pr : PeepholeRewrite Op Γ t)
section SimpPeephole


/- repeatedly apply peephole on program. -/
section SimpPeepholeApplier

/-- rewrite with `pr` to `target` program, at location `ix` and later, running at most `fuel` steps. -/
def rewritePeephole_go (fuel : ℕ) (pr : PeepholeRewrite Op Γ t) (ix : ℕ) (target : Com Op Γ₂ t₂) :
(Com Op Γ₂ t₂) :=
match fuel with
| 0 => target
| fuel' + 1 =>
let target' := rewritePeepholeAt pr ix target
rewritePeephole_go fuel' pr (ix + 1) target'

/-- rewrite with `pr` to `target` program, running at most `fuel` steps. -/
def rewritePeephole (fuel : ℕ) (pr : PeepholeRewrite Op Γ t) (target : Com Op Γ₂ t₂) :
(Com Op Γ₂ t₂) := rewritePeephole_go fuel pr 0 target
end SimpPeepholeApplier

/--
`simp_peephole [t1, t2, ... tn]` at Γ simplifies the evaluation of the context Γ,
leaving behind a bare Lean level proposition to be proven.
Expand Down

0 comments on commit 6283edb

Please sign in to comment.