chore: cleanup after closed term extraction by removing dead values (#12717)

This commit is contained in:
Henrik Böving 2026-02-26 23:33:08 +01:00 committed by GitHub
parent adf3e5e661
commit 738688efee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 23 deletions

View file

@ -10,6 +10,7 @@ public import Lean.Compiler.ClosedTermCache
public import Lean.Compiler.NeverExtractAttr
public import Lean.Compiler.LCNF.Internalize
public import Lean.Compiler.LCNF.ToExpr
import Lean.Compiler.LCNF.ElimDead
public section
@ -159,7 +160,10 @@ end ExtractClosed
partial def Decl.extractClosed (decl : Decl .pure) (sccDecls : Array (Decl .pure)) :
CompilerM (Array (Decl .pure)) := do
let ⟨decl, s⟩ ← ExtractClosed.visitDecl decl |>.run { baseName := decl.name, sccDecls } |>.run {}
let mut ⟨decl, s⟩ ← ExtractClosed.visitDecl decl |>.run { baseName := decl.name, sccDecls } |>.run {}
if !s.decls.isEmpty then
-- Closed term extraction might have left behind dead values.
decl ← decl.elimDeadVars
return s.decls.push decl
def extractClosed : Pass where

View file

@ -61,26 +61,14 @@
let _x.2 := foo._closed_0;
let _x.3 := Syntax.atom _x.2 _x.1;
return _x.3
[Compiler.extractClosed] size: 20
[Compiler.extractClosed] size: 8
def foo n : Syntax :=
let _x.1 := Syntax.missing;
let _x.2 := 1;
let _x.3 := false;
let _x.4 := foo._closed_0;
let _x.5 := foo._closed_1;
let _x.6 := foo._closed_2;
let _x.7 := foo._closed_3;
let _x.8 := foo._closed_4;
let _x.9 := foo._closed_5;
let _x.10 := foo._closed_6;
let _x.11 := foo._closed_7;
let _x.12 := foo._closed_8;
let _x.13 := [] ◾;
let _x.14 := foo._closed_9;
let _x.15 := foo._closed_10;
let _x.16 := foo._closed_11;
let _x.17 := Nat.reprFast n;
let _x.18 := SourceInfo.none;
let _x.19 := @Syntax.mkNumLit _x.17 _x.18;
let _x.20 := Syntax.node3 _x.4 _x.8 _x.14 _x.16 _x.19;
return _x.20
let _x.1 := foo._closed_0;
let _x.2 := foo._closed_4;
let _x.3 := foo._closed_9;
let _x.4 := foo._closed_11;
let _x.5 := Nat.reprFast n;
let _x.6 := SourceInfo.none;
let _x.7 := @Syntax.mkNumLit _x.5 _x.6;
let _x.8 := Syntax.node3 _x.1 _x.2 _x.3 _x.4 _x.7;
return _x.8