diff --git a/src/Lean/Compiler/LCNF/Basic.lean b/src/Lean/Compiler/LCNF/Basic.lean index 9a085e34df..6e0299985a 100644 --- a/src/Lean/Compiler/LCNF/Basic.lean +++ b/src/Lean/Compiler/LCNF/Basic.lean @@ -644,17 +644,20 @@ def Decl.instantiateParamsLevelParams (decl : Decl) (us : List Level) : Array Pa /-- Return `true` if the arrow type contains an instance implicit argument. -/ -def hasLocalInst (type : Expr) : Bool := +def hasLocalInst (type : Expr) : CoreM Bool := do match type with - | .forallE _ _ b bi => bi.isInstImplicit || hasLocalInst b - | _ => false + | .forallE _ d b bi => + (pure bi.isInstImplicit) <||> + ((pure bi.isImplicit) <&&> (pure (← isArrowClass? d).isSome)) <||> + hasLocalInst b + | _ => return false /-- Return `true` if `decl` is supposed to be inlined/specialized. -/ def Decl.isTemplateLike (decl : Decl) : CoreM Bool := do let env ← getEnv - if hasLocalInst decl.type then + if ← hasLocalInst decl.type then return true -- `decl` applications will be specialized else if Meta.isInstanceCore env decl.name then return true -- `decl` is "fuel" for code specialization diff --git a/src/Lean/Compiler/LCNF/Simp/Main.lean b/src/Lean/Compiler/LCNF/Simp/Main.lean index 8fbf163765..cbe260ec75 100644 --- a/src/Lean/Compiler/LCNF/Simp/Main.lean +++ b/src/Lean/Compiler/LCNF/Simp/Main.lean @@ -81,7 +81,7 @@ def etaPolyApp? (letDecl : LetDecl) : OptionT SimpM FunDecl := do guard <| (← read).config.etaPoly let .const declName us args := letDecl.value | failure let some info := (← getEnv).find? declName | failure - guard <| hasLocalInst info.type + guard <| (← hasLocalInst info.type) guard <| !(← Meta.isInstance declName) let some decl ← getDecl? declName | failure guard <| decl.getArity > args.size