|
| 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 |
0 commit comments