@@ -915,12 +915,23 @@ def isTacticOrPostponedHole? (e : Expr) : TermElabM (Option MVarId) := do
915
915
| _ => return none
916
916
| _ => pure none
917
917
918
- def mkTermInfo (elaborator : Name) (stx : Syntax) (e : Expr) (expectedType? : Option Expr := none) (lctx? : Option LocalContext := none) (isBinder := false ) : TermElabM (Sum Info MVarId) := do
918
+ def mkTermInfo (elaborator : Name) (stx : Syntax) (e : Expr) (expectedType? : Option Expr := none) (lctx? : Option LocalContext := none) (isBinder := false ) : TermElabM ((PersistentArray InfoTree) → Sum Info MVarId) := do
919
919
match (← isTacticOrPostponedHole? e) with
920
- | some mvarId => return Sum.inr mvarId
920
+ | some mvarId => return fun _ => Sum.inr mvarId
921
921
| none =>
922
922
let e := removeSaveInfoAnnotation e
923
- return Sum.inl <| Info.ofTermInfo { elaborator, lctx := lctx?.getD (← getLCtx), expr := e, stx, expectedType?, isBinder }
923
+ let lctx ← getLCtx
924
+ return fun trees =>
925
+ -- NOTE: this can probably be made more efficient, but for now
926
+ -- a sufficient check for whether this node is responsible for `e` is to make sure
927
+ -- that no term subtree has the same expression
928
+ let isExprGenerator :=
929
+ trees.all fun tree => match tree with
930
+ | .node (Info.ofTermInfo info) _ =>
931
+ info.expr != e
932
+ | _ => true
933
+
934
+ Sum.inl <| Info.ofTermInfo { elaborator, lctx := lctx?.getD lctx, expr := e, isExprGenerator, stx, expectedType?, isBinder }
924
935
925
936
/--
926
937
Pushes a new leaf node to the info tree associating the expression `e` to the syntax `stx`.
@@ -949,7 +960,7 @@ def addTermInfo (stx : Syntax) (e : Expr) (expectedType? : Option Expr := none)
949
960
def addTermInfo' (stx : Syntax) (e : Expr) (expectedType? : Option Expr := none) (lctx? : Option LocalContext := none) (elaborator := Name.anonymous) (isBinder := false ) : TermElabM Unit :=
950
961
discard <| addTermInfo stx e expectedType? lctx? elaborator isBinder
951
962
952
- def withInfoContext' (stx : Syntax) (x : TermElabM Expr) (mkInfo : Expr → TermElabM (Sum Info MVarId)) : TermElabM Expr := do
963
+ def withInfoContext' (stx : Syntax) (x : TermElabM Expr) (mkInfo : Expr → TermElabM ((PersistentArray InfoTree) → Sum Info MVarId)) : TermElabM Expr := do
953
964
if (← read).inPattern then
954
965
let e ← x
955
966
return mkPatternWithRef e stx
0 commit comments