Skip to content

Commit a7b9a3d

Browse files
authored
refactor: move getOriginalConstKind? into its own module to avoid future import cycle (#12265)
1 parent c25468f commit a7b9a3d

File tree

4 files changed

+48
-22
lines changed

4 files changed

+48
-22
lines changed

src/Lean.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ public import Lean.ErrorExplanation
4747
public import Lean.DefEqAttrib
4848
public import Lean.Shell
4949
public import Lean.ExtraModUses
50+
public import Lean.OriginalConstKind

src/Lean/AddDecl.lean

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module
88
prelude
99
public import Lean.Meta.Sorry
1010
public import Lean.Util.CollectAxioms
11+
public import Lean.OriginalConstKind
12+
import all Lean.OriginalConstKind -- for accessing `privateConstKindsExt`
1113

1214
public section
1315

@@ -45,28 +47,6 @@ where go env
4547
| .str p _ => if isNamespaceName p then go (env.registerNamespace p) p else env
4648
| _ => env
4749

48-
private builtin_initialize privateConstKindsExt : MapDeclarationExtension ConstantKind ←
49-
-- Use `sync` so we can add entries from anywhere without restrictions
50-
mkMapDeclarationExtension (asyncMode := .sync)
51-
52-
/--
53-
Returns the kind of the declaration as originally declared instead of as exported. This information
54-
is stored by `Lean.addDecl` and may be inaccurate if that function was circumvented. Returns `none`
55-
if the declaration was not found.
56-
-/
57-
def getOriginalConstKind? (env : Environment) (declName : Name) : Option ConstantKind := do
58-
-- Use `local` as for asynchronous decls from the current module, `findAsync?` below will yield
59-
-- the same result but potentially earlier (after `addConstAsync` instead of `addDecl`)
60-
privateConstKindsExt.find? (asyncMode := .local) env declName <|>
61-
(env.setExporting false |>.findAsync? declName).map (·.kind)
62-
63-
/--
64-
Checks whether the declaration was originally declared as a theorem; see also
65-
`Lean.getOriginalConstKind?`. Returns `false` if the declaration was not found.
66-
-/
67-
def wasOriginallyTheorem (env : Environment) (declName : Name) : Bool :=
68-
getOriginalConstKind? env declName |>.map (· matches .thm) |>.getD false
69-
7050
/-- If `warn.sorry` is set to true, then, so long as the message log does not already have any errors,
7151
declarations with `sorryAx` generate the "declaration uses `sorry`" warning. -/
7252
register_builtin_option warn.sorry : Bool := {

src/Lean/OriginalConstKind.lean

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/-
2+
Copyright (c) 2026 Lean FRO. All Rights Reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Sebastian Ullrich
5+
-/
6+
module
7+
8+
prelude
9+
public import Lean.Environment
10+
import Lean.EnvExtension
11+
12+
namespace Lean
13+
14+
-- No public mutating interface as this is an implementation detail of `addDecl` and separated only
15+
-- to avoid an import cycle.
16+
private builtin_initialize privateConstKindsExt : MapDeclarationExtension ConstantKind ←
17+
-- Use `sync` so we can add entries from anywhere without restrictions
18+
mkMapDeclarationExtension (asyncMode := .sync)
19+
20+
/--
21+
Returns the kind of the declaration as originally declared instead of as exported. This information
22+
is stored by `Lean.addDecl` and may be inaccurate if that function was circumvented. Returns `none`
23+
if the declaration was not found.
24+
-/
25+
public def getOriginalConstKind? (env : Environment) (declName : Name) : Option ConstantKind := do
26+
-- Use `local` as for asynchronous decls from the current module, `findAsync?` below will yield
27+
-- the same result but potentially earlier (after `addConstAsync` instead of `addDecl`)
28+
privateConstKindsExt.find? (asyncMode := .local) env declName <|>
29+
(env.setExporting false |>.findAsync? declName).map (·.kind)
30+
31+
/--
32+
Checks whether the declaration was originally declared as a definition; see also
33+
`Lean.getOriginalConstKind?`. Returns `false` if the declaration was not found.
34+
-/
35+
public def wasOriginallyDefn (env : Environment) (declName : Name) : Bool :=
36+
getOriginalConstKind? env declName |>.map (· matches .defn) |>.getD false
37+
38+
/--
39+
Checks whether the declaration was originally declared as a theorem; see also
40+
`Lean.getOriginalConstKind?`. Returns `false` if the declaration was not found.
41+
-/
42+
public def wasOriginallyTheorem (env : Environment) (declName : Name) : Bool :=
43+
getOriginalConstKind? env declName |>.map (· matches .thm) |>.getD false

stage0/src/stdlib_flags.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "util/options.h"
22

3+
// Dear CI, please update stage 0
4+
35
namespace lean {
46
options get_default_options() {
57
options opts;

0 commit comments

Comments
 (0)