chore: avoid hack that may introduce unnecessary dependencies

This commit is contained in:
Leonardo de Moura 2022-02-15 12:17:40 -08:00
parent e07823bb12
commit 993ec54db6
2 changed files with 5 additions and 6 deletions

View file

@ -600,9 +600,8 @@ private def generalize (discrs : Array Expr) (matchType : Expr) (altViews : Arra
if !gen then
return (discrs, matchType, altViews, false)
else
let ysFVarIds ← getFVarsToGeneralize discrs
/- let-decls are currently being ignored by the generalizer. -/
let ysFVarIds ← ysFVarIds.filterM fun fvarId => return !(← getLocalDecl fvarId).isLet
let ysFVarIds ← getFVarsToGeneralize discrs (ignoreLetDecls := true)
if ysFVarIds.isEmpty then
return (discrs, matchType, altViews, false)
else

View file

@ -54,20 +54,20 @@ where
Remark: we *not* collect instance implicit arguments nor auxiliary declarations for compiling
recursive declarations.
-/
def getFVarSetToGeneralize (targets : Array Expr) (forbidden : FVarIdSet) : MetaM FVarIdSet := do
def getFVarSetToGeneralize (targets : Array Expr) (forbidden : FVarIdSet) (ignoreLetDecls := false) : MetaM FVarIdSet := do
let mut s : FVarIdSet := targets.foldl (init := {}) fun s target => if target.isFVar then s.insert target.fvarId! else s
let mut r : FVarIdSet := {}
for localDecl in (← getLCtx) do
unless forbidden.contains localDecl.fvarId do
unless localDecl.isAuxDecl || localDecl.binderInfo.isInstImplicit do
unless localDecl.isAuxDecl || localDecl.binderInfo.isInstImplicit || (ignoreLetDecls && localDecl.isLet) do
if (← getMCtx).findLocalDeclDependsOn localDecl fun fvarId => s.contains fvarId then
r := r.insert localDecl.fvarId
s := s.insert localDecl.fvarId
return r
def getFVarsToGeneralize (targets : Array Expr) (forbidden : FVarIdSet := {}) : MetaM (Array FVarId) := do
def getFVarsToGeneralize (targets : Array Expr) (forbidden : FVarIdSet := {}) (ignoreLetDecls := false) : MetaM (Array FVarId) := do
let forbidden ← mkGeneralizationForbiddenSet targets forbidden
let s ← getFVarSetToGeneralize targets forbidden
let s ← getFVarSetToGeneralize targets forbidden ignoreLetDecls
sortFVarIds s.toArray
end Lean.Meta