@@ -47,8 +47,8 @@ are not presented in the list of suggested rewrites.
4747This is implemented with `unfoldProjDefaultInst?`.
4848
4949Additionally, we don't want to unfold into expressions involving `match` terms or other
50- constants marked as `Name.isInternalDetail`. So all such results are filtered out .
51- This is implemented with `isUserFriendly`.
50+ constants marked as `Name.isInternalDetail`, and we don't want raw projections .
51+ So, all such results are filtered out. This is implemented with `isUserFriendly`.
5252
5353-/
5454
@@ -106,13 +106,24 @@ where
106106 fun _ =>
107107 return acc
108108
109- /-- Determine whether `e` contains no internal names. -/
110- def isUserFriendly (e : Expr) : Bool :=
111- !e.foldConsts (init := false ) (fun name => (· || name.isInternalDetail))
109+ /-- Determine whether `e` contains no internal names or raw projections.
110+ We only consider the explicit parts of `e`, because it may happen that an
111+ instance implicit argument is marked as an internal detail, but that is not a problem. -/
112+ partial def isUserFriendly (e : Expr) : MetaM Bool := do
113+ match e with
114+ | .const name _ => return !name.isInternalDetail
115+ | .proj .. => return false
116+ | .app .. =>
117+ e.withApp fun f args => do
118+ (isUserFriendly f) <&&> do
119+ let finfo ← getFunInfoNArgs f e.getAppNumArgs
120+ e.getAppNumArgs.allM fun i _ =>
121+ if finfo.paramInfo[i]?.all (·.isExplicit) then isUserFriendly args[i]! else return true
122+ | _ => return true
112123
113124/-- Return the consecutive unfoldings of `e` that are user friendly. -/
114- def filteredUnfolds (e : Expr) : MetaM (Array Expr) :=
115- return (← unfolds e).filter isUserFriendly
125+ def filteredUnfolds (e : Expr) : MetaM (Array Expr) := do
126+ (← unfolds e).filterM isUserFriendly
116127
117128end InteractiveUnfold
118129
0 commit comments