lean4-htt/tests/lean/ppNotationCode.lean.expected.out
Sebastian Ullrich 51bba5338a
perf: make macro scope numbering less dependent on surrounding context (#10027)
This PR changes macro scope numbering from per-module to per-command,
ensuring that unrelated changes to other commands do not affect macro
scopes generated by a command, which improves `prefer_native` hit rates
on bootstrapping as well as avoids further rebuilds under the module
system.

In detail, instead of always using the current module name as a macro
scope prefix, each command now introduces a new macro scope prefix
(called "context") of the shape `<main module>._hygCtx_<uniq>` where
`uniq` is a `UInt32` derived from the command but automatically
incremented in case of conflicts (which must be local to the current
module). In the current implementation, `uniq` is the hash of the
declaration name, if any, or else the hash of the full command's syntax.
Thus, it is always independent of syntactic changes to other commands
(except in case of hash conflicts, which should only happen in practice
for syntactically identical commands) and, in the case of declarations,
also independent of syntactic changes to any private parts of the
declaration.
2025-08-22 13:16:02 +00:00

54 lines
2.4 KiB
Text

[Elab.definition.body] «term_+++_» : Lean.TrailingParserDescr :=
Lean.ParserDescr.trailingNode `«term_+++_» 45 46
(Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "+++") (Lean.ParserDescr.cat `term 46))
[Elab.definition.body] «_aux_ppNotationCode___macroRules_term_+++__1» : Lean.Macro :=
fun x =>
have __discr := x;
if __discr.isOfKind `«term_+++_» = true then
have __discr_1 := __discr.getArg 0;
have __discr_2 := __discr.getArg 1;
have __discr := __discr.getArg 2;
have rhs := { raw := __discr };
have lhs := { raw := __discr_1 };
do
let info ← Lean.MonadRef.mkInfoFromRefPos
let scp ← Lean.getCurrMacroScope
let quotCtx ← Lean.MonadQuotation.getContext
pure
{
raw :=
Lean.Syntax.node2 info `Lean.Parser.Term.app
(Lean.Syntax.ident info "Nat.add".toSubstring' (Lean.addMacroScope quotCtx `Nat.add scp)
[Lean.Syntax.Preresolved.decl `Nat.add [], Lean.Syntax.Preresolved.namespace `Nat.add])
(Lean.Syntax.node2 info `null lhs.raw rhs.raw) }.raw
else
have __discr := x;
throw Lean.Macro.Exception.unsupportedSyntax
[Elab.definition.body] _aux_ppNotationCode___unexpand_Nat_add_1 : Lean.PrettyPrinter.Unexpander :=
fun x =>
have __discr := x;
if __discr.isOfKind `Lean.Parser.Term.app = true then
have __discr_1 := __discr.getArg 0;
bif false || __discr_1.isOfKind `ident then
have __discr_2 := __discr.getArg 1;
if __discr_2.matchesNull 2 = true then
have __discr := __discr_2.getArg 0;
have __discr_3 := __discr_2.getArg 1;
have rhs := { raw := __discr_3 };
have lhs := { raw := __discr };
have f := { raw := __discr_1 };
Lean.withRef f.raw do
let info ← Lean.MonadRef.mkInfoFromRefPos
let _ ← Lean.getCurrMacroScope
let _ ← Lean.MonadQuotation.getContext
pure { raw := Lean.Syntax.node3 info `«term_+++_» lhs.raw (Lean.Syntax.atom info "+++") rhs.raw }.raw
else
have __discr := __discr.getArg 1;
throw ()
else
have __discr_2 := __discr.getArg 0;
have __discr := __discr.getArg 1;
throw ()
else
have __discr := x;
throw ()