File tree Expand file tree Collapse file tree 16 files changed +147
-9
lines changed
Expand file tree Collapse file tree 16 files changed +147
-9
lines changed Original file line number Diff line number Diff line change @@ -47,3 +47,4 @@ public import Lean.ErrorExplanation
4747public import Lean.ErrorExplanations
4848public import Lean.DefEqAttrib
4949public import Lean.Shell
50+ public import Lean.ExtraModUses
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ public import Lean.Elab.Open
1212public import Lean.Elab.SetOption
1313public import Lean.Elab.Eval
1414meta import Lean.Parser.Command
15+ import Lean.ExtraModUses
1516
1617public 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?
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ public import Lean.Elab.PreDefinition.WF.Fix
1616public import Lean.Elab.PreDefinition.WF.Unfold
1717public import Lean.Elab.PreDefinition.WF.Preprocess
1818public import Lean.Elab.PreDefinition.WF.GuessLex
19+ import Lean.ExtraModUses
1920
2021public 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}"
Original file line number Diff line number Diff line change 99public import Lean.Parser.Term.Doc
1010public import Lean.Parser.Command
1111public import Lean.Elab.Command
12+ import Lean.ExtraModUses
1213
1314public 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 for $«notation »: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
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ public import Lean.Elab.Command
1010public import Lean.Parser.Syntax
1111public import Lean.Elab.Util
1212public meta import Lean.Parser.Syntax
13+ import Lean.ExtraModUses
1314
1415public 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
Original file line number Diff line number Diff line change 88prelude
99public import Lean.Meta.Tactic.Util
1010public import Lean.Elab.Term
11+ import Lean.ExtraModUses
1112
1213public 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
Original file line number Diff line number Diff line change 99public import Lean.Meta.Eval
1010public import Lean.Elab.Tactic.Basic
1111public import Lean.Elab.SyntheticMVars
12+ public import Lean.ExtraModUses
1213import Lean.Linter.MissingDocs
1314meta 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.
Original file line number Diff line number Diff 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. -/
677677def 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
Original file line number Diff line number Diff 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`. -/
7374def getState {α σ : Type } [Inhabited σ] (ext : SimplePersistentEnvExtension α σ) (env : Environment)
You can’t perform that action at this time.
0 commit comments