lean4-htt/tests/lean/run/Decidable-decide-erasure.lean
Cameron Zwarich 1880c61507
feat: support erasure of Decidable.decide in new code generator (#6405)
This PR adds support for erasure of `Decidable.decide` to the new code
generator. It also adds a new `Probe.runOnDeclsNamed` function, which is
helpful for writing targeted single-file tests of compiler internals.

---------

Co-authored-by: Cameron Zwarich <cameron@lean-fro.org>
2024-12-17 01:48:55 +00:00

23 lines
607 B
Text

import Lean.Compiler
import Lean.Compiler.LCNF.Probing
open Lean.Compiler.LCNF
def f (a : Nat) : Bool :=
decide (a = 1)
-- This is only required until the new code generator is enabled.
run_meta Lean.Compiler.compile #[``f]
def countCalls : Probe Decl Nat :=
Probe.getLetValues >=>
Probe.filter (fun e => return e matches .const `Decidable.decide ..) >=>
Probe.count
#eval do
let numCalls <- Probe.runOnDeclsNamed #[`f] (phase := .base) <| countCalls
assert! numCalls == #[1]
#eval do
let numCalls <- Probe.runOnDeclsNamed #[`f] (phase := .mono) <| countCalls
assert! numCalls == #[0]