Skip to content

Commit 494340d

Browse files
zwarichwkrozowski
authored andcommitted
fix: run LCNF checks less often by default (leanprover#8764)
This PR changes the LCNF pass pipeline so checks are no longer run by default after every pass, only after `init`, `saveBase`, `toMono` and `saveMono`. This is a compile time improvement, and the utility of these checks is decreased a bit after the decision to no longer attempt to preserve types throughout compilation. They have not been a significant way to discover issues during development of the new compiler.
1 parent b8e88ff commit 494340d

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

src/Lean/Compiler/LCNF/Main.lean

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@ A checkpoint in code generation to print all declarations in between
5454
compiler passes in order to ease debugging.
5555
The trace can be viewed with `set_option trace.Compiler.step true`.
5656
-/
57-
def checkpoint (stepName : Name) (decls : Array Decl) : CompilerM Unit := do
57+
def checkpoint (stepName : Name) (decls : Array Decl) (shouldCheck : Bool) : CompilerM Unit := do
5858
for decl in decls do
5959
trace[Compiler.stat] "{decl.name} : {decl.size}"
6060
withOptions (fun opts => opts.setBool `pp.motives.pi false) do
6161
let clsName := `Compiler ++ stepName
6262
if (← Lean.isTracingEnabledFor clsName) then
6363
Lean.addTrace clsName m!"size: {decl.size}\n{← ppDecl' decl}"
64-
if compiler.check.get (← getOptions) then
64+
if shouldCheck then
6565
decl.check
66-
if compiler.check.get (← getOptions) then
66+
if shouldCheck then
6767
checkDeadLocalDecls decls
6868

6969
namespace PassManager
@@ -80,10 +80,11 @@ def run (declNames : Array Name) : CompilerM (Array IR.Decl) := withAtLeastMaxRe
8080
let mut decls ← declNames.mapM toDecl
8181
decls := markRecDecls decls
8282
let manager ← getPassManager
83+
let isCheckEnabled := compiler.check.get (← getOptions)
8384
for pass in manager.passes do
8485
decls ← withTraceNode `Compiler (fun _ => return m!"new compiler phase: {pass.phase}, pass: {pass.name}") do
8586
withPhase pass.phase <| pass.run decls
86-
withPhase pass.phaseOut <| checkpoint pass.name decls
87+
withPhase pass.phaseOut <| checkpoint pass.name decls (isCheckEnabled || pass.shouldAlwaysRunCheck)
8788
if (← Lean.isTracingEnabledFor `Compiler.result) then
8889
for decl in decls do
8990
-- We display the declaration saved in the environment because the names have been normalized

src/Lean/Compiler/LCNF/PassManager.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ structure Pass where
4949
phaseOut : Phase := phase
5050
phaseInv : phaseOut ≥ phase := by simp +arith +decide
5151
/--
52+
Whether IR validation checks should always run after this pass, regardless
53+
of configuration options.
54+
-/
55+
shouldAlwaysRunCheck : Bool := false
56+
/--
5257
The name of the `Pass`
5358
-/
5459
name : Name

src/Lean/Compiler/LCNF/Passes.lean

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,31 @@ def init : Pass where
3131
decls.forM (·.saveBase)
3232
return decls
3333
phase := .base
34+
shouldAlwaysRunCheck := true
3435

3536
-- Helper pass used for debugging purposes
3637
def trace (phase := Phase.base) : Pass where
3738
name := `trace
3839
run := pure
3940
phase := phase
4041

41-
def saveBase : Pass :=
42-
.mkPerDeclaration `saveBase (fun decl => do (← normalizeFVarIds decl).saveBase; return decl) .base
42+
def saveBase : Pass where
43+
occurrence := 0
44+
phase := .base
45+
name := `saveBase
46+
run decls := decls.mapM fun decl => do
47+
(← normalizeFVarIds decl).saveBase
48+
return decl
49+
shouldAlwaysRunCheck := true
4350

44-
def saveMono : Pass :=
45-
.mkPerDeclaration `saveMono (fun decl => do (← normalizeFVarIds decl).saveMono; return decl) .mono
51+
def saveMono : Pass where
52+
occurrence := 0
53+
phase := .mono
54+
name := `saveMono
55+
run decls := decls.mapM fun decl => do
56+
(← normalizeFVarIds decl).saveMono
57+
return decl
58+
shouldAlwaysRunCheck := true
4659

4760
def builtinPassManager : PassManager := {
4861
passes := #[

src/Lean/Compiler/LCNF/ToMono.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ def toMono : Pass where
340340
run := (·.mapM (·.toMono))
341341
phase := .base
342342
phaseOut := .mono
343+
shouldAlwaysRunCheck := true
343344

344345
builtin_initialize
345346
registerTraceClass `Compiler.toMono (inherited := true)

src/Lean/Compiler/Options.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Lean.Data.Options
1010
namespace Lean.Compiler
1111

1212
register_builtin_option compiler.check : Bool := {
13-
defValue := true
13+
defValue := false
1414
group := "compiler"
1515
descr := "type check code after each compiler step (this is useful for debugging purses)"
1616
}

0 commit comments

Comments
 (0)