refactor: use more helper functions (#9862)

This commit is contained in:
Cameron Zwarich 2025-08-11 16:56:50 -07:00 committed by GitHub
parent 4df4968538
commit bf348ae60f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -45,27 +45,33 @@ private def visitParam (p : Param) : M Unit :=
else s.borrowedParams
}
private partial def addDerivedValue (parent : VarId) (child : VarId) : M Unit := do
modify fun s => { s with
varMap := s.varMap.modify parent fun info =>
{ info with children := info.children.insert child }
}
modify fun s => { s with
varMap := s.varMap.insert child {
parent? := some parent
children := {}
}
}
private partial def removeFromParent (child : VarId) : M Unit := do
if let some (some parent) := (← get).varMap.get? child |>.map (·.parent?) then
modify fun s => { s with
varMap := s.varMap.modify parent fun info =>
{ info with children := info.children.erase child }
}
private partial def visitFnBody (b : FnBody) : M Unit := do
match b with
| .vdecl x _ e b =>
match e with
| .proj _ parent =>
modify fun s => { s with
varMap := s.varMap.modify parent fun info =>
{ info with children := info.children.insert x }
}
modify fun s => { s with
varMap := s.varMap.insert x {
parent? := some parent
children := {}
}
}
addDerivedValue parent x
| .reset _ x =>
if let some (some parent) := (← get).varMap.get? x |>.map (·.parent?) then
modify fun s => { s with
varMap := s.varMap.modify parent fun info =>
{ info with children := info.children.erase x }
}
removeFromParent x
| _ => pure ()
visitFnBody b
| .jdecl _ ps v b =>