@@ -96,13 +96,17 @@ def warnIfUsesSorry (decl : Declaration) : CoreM Unit := do
9696 -- This case should not happen, but it ensures a warning will get logged no matter what.
9797 logWarning <| .tagged `hasSorry m!"declaration uses 'sorry'"
9898
99+ builtin_initialize
100+ registerTraceClass `addDecl
101+
99102/--
100103Adds the given declaration to the environment's private scope, deriving a suitable presentation in
101104the public scope if under the module system and if the declaration is not private. If `forceExpose`
102105is true, exposes the declaration body, i.e. preserves the full representation in the public scope,
103106independently of `Environment.isExporting` and even for theorems.
104107-/
105- def addDecl (decl : Declaration) (forceExpose := false ) : CoreM Unit := do
108+ def addDecl (decl : Declaration) (forceExpose := false ) : CoreM Unit :=
109+ withTraceNode `addDecl (fun _ => return m!"adding declarations {decl.getNames}" ) do
106110 -- register namespaces for newly added constants; this used to be done by the kernel itself
107111 -- but that is incompatible with moving it to a separate task
108112 -- NOTE: we do not use `getTopLevelNames` here so that inductive types are registered as
@@ -115,26 +119,37 @@ def addDecl (decl : Declaration) (forceExpose := false) : CoreM Unit := do
115119 let (name, info, kind) ← match decl with
116120 | .thmDecl thm =>
117121 if !forceExpose && (← getEnv).header.isModule then
122+ trace[addDecl] "exporting theorem {thm.name} as axiom"
118123 exportedInfo? := some <| .axiomInfo { thm with isUnsafe := false }
119124 pure (thm.name, .thmInfo thm, .thm)
120125 | .defnDecl defn | .mutualDefnDecl [defn] =>
121126 if !forceExpose && (← getEnv).header.isModule && !(← getEnv).isExporting then
127+ trace[addDecl] "exporting definition {defn.name} as axiom"
122128 exportedInfo? := some <| .axiomInfo { defn with isUnsafe := defn.safety == .unsafe }
123129 pure (defn.name, .defnInfo defn, .defn)
124130 | .opaqueDecl op =>
125131 if !forceExpose && (← getEnv).header.isModule && !(← getEnv).isExporting then
132+ trace[addDecl] "exporting opaque {op.name} as axiom"
126133 exportedInfo? := some <| .axiomInfo { op with }
127134 pure (op.name, .opaqueInfo op, .opaque)
128135 | .axiomDecl ax => pure (ax.name, .axiomInfo ax, .axiom)
129- | _ => return (← doAdd)
136+ | _ =>
137+ trace[addDecl] "no matching async adding rules, adding synchronously"
138+ return (← doAdd)
130139
131- if decl.getTopLevelNames.all isPrivateName && !(← ResolveName.backward.privateInPublic.getM) then
132- exportedInfo? := none
140+ if decl.getTopLevelNames.all isPrivateName then
141+ if (← ResolveName.backward.privateInPublic.getM) then
142+ trace[addDecl] "private decl under `privateInPublic`, exporting as is"
143+ exportedInfo? := some info
144+ else
145+ trace[addDecl] "not exporting private declaration at all"
146+ exportedInfo? := none
133147 else
134148 -- preserve original constant kind in extension if different from exported one
135149 if exportedInfo?.isSome then
136150 modifyEnv (privateConstKindsExt.insert · name kind)
137151 else
152+ trace[addDecl] "no matching exporting rules, exporting as is"
138153 exportedInfo? := some info
139154
140155 -- no environment extension changes to report after kernel checking; ensures we do not
0 commit comments