Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Lean/Compiler/LCNF/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ def Decl.isTemplateLike (decl : Decl) : CoreM Bool := do
else
return false

private partial def collectType (e : Expr) : FVarIdSetFVarIdSet :=
private partial def collectType (e : Expr) : FVarIdHashSetFVarIdHashSet :=
match e with
| .forallE _ d b _ => collectType b ∘ collectType d
| .lam _ d b _ => collectType b ∘ collectType d
Expand All @@ -669,30 +669,30 @@ private partial def collectType (e : Expr) : FVarIdSet → FVarIdSet :=
| .proj .. | .letE .. => unreachable!
| _ => id

private def collectArg (arg : Arg) (s : FVarIdSet) : FVarIdSet :=
private def collectArg (arg : Arg) (s : FVarIdHashSet) : FVarIdHashSet :=
match arg with
| .erased => s
| .fvar fvarId => s.insert fvarId
| .type e => collectType e s

private def collectArgs (args : Array Arg) (s : FVarIdSet) : FVarIdSet :=
private def collectArgs (args : Array Arg) (s : FVarIdHashSet) : FVarIdHashSet :=
args.foldl (init := s) fun s arg => collectArg arg s

private def collectLetValue (e : LetValue) (s : FVarIdSet) : FVarIdSet :=
private def collectLetValue (e : LetValue) (s : FVarIdHashSet) : FVarIdHashSet :=
match e with
| .fvar fvarId args => collectArgs args <| s.insert fvarId
| .const _ _ args => collectArgs args s
| .proj _ _ fvarId => s.insert fvarId
| .lit .. | .erased => s

private partial def collectParams (ps : Array Param) (s : FVarIdSet) : FVarIdSet :=
private partial def collectParams (ps : Array Param) (s : FVarIdHashSet) : FVarIdHashSet :=
ps.foldl (init := s) fun s p => collectType p.type s

mutual
partial def FunDecl.collectUsed (decl : FunDecl) (s : FVarIdSet := {}) : FVarIdSet :=
partial def FunDecl.collectUsed (decl : FunDecl) (s : FVarIdHashSet := {}) : FVarIdHashSet :=
decl.value.collectUsed <| collectParams decl.params <| collectType decl.type s

partial def Code.collectUsed (code : Code) (s : FVarIdSet := {}) : FVarIdSet :=
partial def Code.collectUsed (code : Code) (s : FVarIdHashSet := {}) : FVarIdHashSet :=
match code with
| .let decl k => k.collectUsed <| collectLetValue decl.value <| collectType decl.type s
| .jp decl k | .fun decl k => k.collectUsed <| decl.collectUsed s
Expand All @@ -708,7 +708,7 @@ partial def Code.collectUsed (code : Code) (s : FVarIdSet := {}) : FVarIdSet :=
| .jmp fvarId args => collectArgs args <| s.insert fvarId
end

abbrev collectUsedAtExpr (s : FVarIdSet) (e : Expr) : FVarIdSet :=
abbrev collectUsedAtExpr (s : FVarIdHashSet) (e : Expr) : FVarIdHashSet :=
collectType e s

/--
Expand Down
2 changes: 1 addition & 1 deletion src/Lean/Compiler/LCNF/PullFunDecls.lean
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Local function declaration and join point being pulled.
structure ToPull where
isFun : Bool
decl : FunDecl
used : FVarIdSet
used : FVarIdHashSet
deriving Inhabited

/--
Expand Down
Loading