Skip to content

Commit

Permalink
feat: make loose fvars pretty print as _fvar.123 instead of `_uniq.…
Browse files Browse the repository at this point in the history
…123` (#3380)

Loose fvars are never supposed to be pretty printed, but having them
print with "fvar" in the name can help with debugging broken tactics and
elaborators.

Metaprogramming users often do not realize at first that `_uniq.???` in
pretty printing output refers to fvars not in the current local context.
  • Loading branch information
kmill authored Feb 18, 2024
1 parent 3e5695e commit 3aee579
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/Lean/PrettyPrinter/Delaborator/Builtins.lean
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ def unfoldMDatas : Expr → Expr

@[builtin_delab fvar]
def delabFVar : Delab := do
let Expr.fvar fvarId ← getExpr | unreachable!
try
let l ← fvarId.getDecl
maybeAddBlockImplicit (mkIdent l.userName)
catch _ =>
-- loose free variable, use internal name
maybeAddBlockImplicit <| mkIdent fvarId.name
let Expr.fvar fvarId ← getExpr | unreachable!
try
let l ← fvarId.getDecl
maybeAddBlockImplicit (mkIdent l.userName)
catch _ =>
-- loose free variable, use internal name
maybeAddBlockImplicit <| mkIdent (fvarId.name.replacePrefix `_uniq `_fvar)

-- loose bound variable, use pseudo syntax
@[builtin_delab bvar]
Expand Down
2 changes: 1 addition & 1 deletion tests/lean/474.lean.expected.out
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let y := Nat.zero;
Nat.add y y
fun y_1 => Nat.add y y_1
fun y => Nat.add _uniq.1 y
fun y => Nat.add _fvar.1 y
fun (y : Nat) => Nat.add y y
Nat.add ?m y
Nat.add (?m #0) #0
Expand Down

0 comments on commit 3aee579

Please sign in to comment.