Skip to content

Commit 641ea91

Browse files
committed
chore: basic ExtraModUses
1 parent 69c8f13 commit 641ea91

File tree

16 files changed

+147
-9
lines changed

16 files changed

+147
-9
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.ErrorExplanations
4848
public import Lean.DefEqAttrib
4949
public import Lean.Shell
50+
public import Lean.ExtraModUses

src/Lean/Elab/BuiltinTerm.lean

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public import Lean.Elab.Open
1212
public import Lean.Elab.SetOption
1313
public import Lean.Elab.Eval
1414
meta import Lean.Parser.Command
15+
import Lean.ExtraModUses
1516

1617
public section
1718

@@ -237,9 +238,11 @@ def elabScientificLit : TermElab := fun stx expectedType? => do
237238
| some val => pure $ toExpr val
238239
| none => throwIllFormedSyntax
239240

240-
@[builtin_term_elab doubleQuotedName] def elabDoubleQuotedName : TermElab := fun stx _ =>
241+
@[builtin_term_elab doubleQuotedName] def elabDoubleQuotedName : TermElab := fun stx _ => do
241242
-- Always allow quoting private names.
242-
return toExpr (← withoutExporting <| realizeGlobalConstNoOverloadWithInfo stx[2])
243+
let n ← withoutExporting <| realizeGlobalConstNoOverloadWithInfo stx[2]
244+
recordExtraModUseFromDecl (isMeta := false) n
245+
return toExpr n
243246

244247
@[builtin_term_elab declName] def elabDeclName : TermElab := adaptExpander fun _ => do
245248
let some declName ← getDeclName?

src/Lean/Elab/Declaration.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,11 @@ def elabMutual : CommandElab := fun stx => do
333333
Term.applyAttributes declName attrs
334334
for attrName in toErase do
335335
Attribute.erase declName attrName
336+
if (← getEnv).isImportedConst declName && attrs.any (·.kind == .global) then
337+
-- If an imported declaration is marked with a global attribute, there is no good way to track
338+
-- its use generally and so Shake should conservatively preserve imports of the current
339+
-- module.
340+
recordExtraRevUseOfCurrentModule
336341

337342
@[builtin_command_elab Lean.Parser.Command.«initialize»] def elabInitialize : CommandElab
338343
| stx@`($declModifiers:declModifiers $kw:initializeKeyword $[$id? : $type? ←]? $doSeq) => do

src/Lean/Elab/PreDefinition/WF/Main.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public import Lean.Elab.PreDefinition.WF.Fix
1616
public import Lean.Elab.PreDefinition.WF.Unfold
1717
public import Lean.Elab.PreDefinition.WF.Preprocess
1818
public import Lean.Elab.PreDefinition.WF.GuessLex
19+
import Lean.ExtraModUses
1920

2021
public section
2122

@@ -72,6 +73,8 @@ def wfRecursion (docCtx : LocalContext × LocalInstances) (preDefs : Array PreDe
7273
eraseRecAppSyntaxExpr value
7374
/- `mkFix` invokes `decreasing_tactic` which may add auxiliary theorems to the environment. -/
7475
let value ← unfoldDeclsFrom envNew value
76+
-- Make sure we remember invoked tactics
77+
modifyEnv (copyExtraModUses envNew)
7578
return { unaryPreDefProcessed with value }
7679

7780
trace[Elab.definition.wf] ">> {preDefNonRec.declName} :=\n{preDefNonRec.value}"

src/Lean/Elab/RecommendedSpelling.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ prelude
99
public import Lean.Parser.Term.Doc
1010
public import Lean.Parser.Command
1111
public import Lean.Elab.Command
12+
import Lean.ExtraModUses
1213

1314
public section
1415

@@ -20,6 +21,7 @@ open Lean.Parser.Command
2021
@[builtin_command_elab «recommended_spelling»] def elabRecommendedSpelling : CommandElab
2122
| `(«recommended_spelling»|$[$docs:docComment]? recommended_spelling $spelling:str fornotation»:str in [$[$decls:ident],*]) => do
2223
let declNames ← liftTermElabM <| decls.mapM (fun decl => realizeGlobalConstNoOverloadWithInfo decl)
24+
declNames.forM (recordExtraModUseFromDecl (isMeta := false))
2325
let recommendedSpelling : RecommendedSpelling := {
2426
«notation» := «notation».getString
2527
recommendedSpelling := spelling.getString

src/Lean/Elab/Syntax.lean

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public import Lean.Elab.Command
1010
public import Lean.Parser.Syntax
1111
public import Lean.Elab.Util
1212
public meta import Lean.Parser.Syntax
13+
import Lean.ExtraModUses
1314

1415
public section
1516

@@ -394,7 +395,10 @@ def elabSyntax (stx : Syntax) : CommandElabM Name := do
394395
syntax%$tk $[: $prec? ]? $[(name := $name?)]? $[(priority := $prio?)]? $[$ps:stx]* : $catStx) := stx
395396
| throwUnsupportedSyntax
396397
let cat := catStx.getId.eraseMacroScopes
397-
unless (Parser.isParserCategory (← getEnv) cat) do
398+
if let some cat := Parser.getParserCategory? (← getEnv) cat then
399+
-- The category must be imported but is not directly referenced afterwards.
400+
recordExtraModUseFromDecl (isMeta := true) cat.declName
401+
else
398402
throwErrorAt catStx "unknown category `{cat}`"
399403
liftTermElabM <| Term.addCategoryInfo catStx cat
400404
let syntaxParser := mkNullNode ps

src/Lean/Elab/Tactic/Basic.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module
88
prelude
99
public import Lean.Meta.Tactic.Util
1010
public import Lean.Elab.Term
11+
import Lean.ExtraModUses
1112

1213
public section
1314

@@ -235,6 +236,7 @@ where
235236
withReader ({ · with elaborator := m.declName }) do
236237
withTacticInfoContext stx do
237238
let stx' ← adaptMacro m.value stx
239+
recordExtraModUseFromDecl (isMeta := true) m.declName
238240
-- Support incrementality; see also Note [Incremental Macros]
239241
if evalFns.isEmpty && ms.isEmpty then -- Only try incrementality in one branch
240242
if let some snap := (← readThe Term.Context).tacSnap? then

src/Lean/Elab/Tactic/Config.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ prelude
99
public import Lean.Meta.Eval
1010
public import Lean.Elab.Tactic.Basic
1111
public import Lean.Elab.SyntheticMVars
12+
public import Lean.ExtraModUses
1213
import Lean.Linter.MissingDocs
1314
meta import Lean.Parser.Tactic
1415

@@ -142,6 +143,7 @@ private meta def mkConfigElaborator
142143
return $empty
143144
unless (← getEnv).contains ``$type do
144145
throwError m!"Error evaluating configuration: Environment does not yet contain type {``$type}"
146+
recordExtraModUseFromDecl (isMeta := true) ``$type
145147
let c ← elabConfig recover ``$type items
146148
if c.hasSyntheticSorry then
147149
-- An error is already logged, return the default.

src/Lean/Elab/Tactic/Omega/Frontend.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,8 @@ open Lean Elab Tactic Parser.Tactic
675675

676676
/-- The `omega` tactic, for resolving integer and natural linear arithmetic problems. -/
677677
def omegaTactic (cfg : OmegaConfig) : TacticM Unit := do
678+
-- Conservatively expect all of `Init.Omega` to be imported.
679+
recordExtraModUse (isMeta := false) `Init.Omega
678680
liftMetaFinishingTactic fun g => do
679681
if debug.terminalTacticsAsSorry.get (← getOptions) then
680682
g.admit

src/Lean/EnvExtension.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ instance {α σ : Type} [Inhabited σ] : Inhabited (SimplePersistentEnvExtension
6666

6767
/-- Get the list of values used to update the state of the given
6868
`SimplePersistentEnvExtension` in the current file. -/
69-
def getEntries {α σ : Type} [Inhabited σ] (ext : SimplePersistentEnvExtension α σ) (env : Environment) : List α :=
70-
(PersistentEnvExtension.getState ext env).1
69+
def getEntries {α σ : Type} [Inhabited σ] (ext : SimplePersistentEnvExtension α σ)
70+
(env : Environment) (asyncMode := ext.toEnvExtension.asyncMode) : List α :=
71+
(PersistentEnvExtension.getState (asyncMode := asyncMode) ext env).1
7172

7273
/-- Get the current state of the given `SimplePersistentEnvExtension`. -/
7374
def getState {α σ : Type} [Inhabited σ] (ext : SimplePersistentEnvExtension α σ) (env : Environment)

0 commit comments

Comments
 (0)