Skip to content

Commit 6f4bee8

Browse files
kim-emclaude
andauthored
perf: avoid re-exporting Std.Time from grind_annotated (#11372)
This PR makes the `Std.Time.Format` import in `Lean.Elab.Tactic.Grind.Annotated` private rather than public, preventing the entire `Std.Time` infrastructure (including timezone databases) from being re-exported through `import Lean`. The `grindAnnotatedExt` extension is kept private, with a new public accessor function `isGrindAnnotatedModule` exposed for use by `LibrarySuggestions.Basic`. This should address the +2.5% instruction increase on `import Lean` observed after merging #11332. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <[email protected]>
1 parent 387833b commit 6f4bee8

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

src/Lean/Elab/Tactic/Grind/Annotated.lean

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ module
77
prelude
88
public import Lean.Elab.Command
99
import Init.Grind.Annotated
10-
public import Std.Time.Format
11-
12-
@[expose] public section
10+
import Std.Time.Format
1311

1412
namespace Lean.Elab.Tactic.Grind
1513
open Command Std.Time
@@ -26,6 +24,12 @@ builtin_initialize grindAnnotatedExt : SimplePersistentEnvExtension Name NameSet
2624
asyncMode := .sync
2725
}
2826

27+
/-- Check if a module has been marked as grind-annotated. -/
28+
public def isGrindAnnotatedModule (env : Environment) (modIdx : ModuleIdx) : Bool :=
29+
let state := grindAnnotatedExt.getState env
30+
let moduleName := env.header.moduleNames[modIdx.toNat]!
31+
state.contains moduleName
32+
2933
@[builtin_command_elab Lean.Parser.Command.grindAnnotated]
3034
def elabGrindAnnotated : CommandElab := fun stx => do
3135
let `(grind_annotated $dateStr) := stx | throwUnsupportedSyntax

src/Lean/LibrarySuggestions/Basic.lean

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,6 @@ def combine (selector₁ selector₂ : Selector) : Selector := fun g c => do
213213

214214
return sorted.take c.maxSuggestions
215215

216-
/-- Check if a module has been marked as grind-annotated. -/
217-
def isGrindAnnotatedModule (env : Environment) (modIdx : ModuleIdx) : Bool :=
218-
let state := Lean.Elab.Tactic.Grind.grindAnnotatedExt.getState env
219-
let moduleName := env.header.moduleNames[modIdx.toNat]!
220-
state.contains moduleName
221-
222216
/--
223217
Filter out theorems from grind-annotated modules when the caller is "grind".
224218
Modules marked with `grind_annotated` contain manually reviewed/annotated theorems,
@@ -234,7 +228,7 @@ def filterGrindAnnotated (selector : Selector) : Selector := fun g c => do
234228
-- Check if the suggestion's module is grind-annotated
235229
match env.getModuleIdxFor? s.name with
236230
| none => return true -- Keep suggestions with no module info
237-
| some modIdx => return !isGrindAnnotatedModule env modIdx
231+
| some modIdx => return !Lean.Elab.Tactic.Grind.isGrindAnnotatedModule env modIdx
238232
else
239233
return suggestions
240234

tests/lean/run/grind_annotated.lean

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@ Expected format: YYYY-MM-DD (e.g., "2025-01-15")
2525
#guard_msgs in
2626
grind_annotated "invalid-date"
2727

28-
/-- info: Extension state contains `Init.Data.List.Lemmas: true -/
28+
/-- info: Init.Data.List.Lemmas is grind-annotated: true -/
2929
#guard_msgs in
3030
#eval do
3131
let env ← getEnv
32-
let state := Lean.Elab.Tactic.Grind.grindAnnotatedExt.getState env
33-
logInfo m!"Extension state contains `Init.Data.List.Lemmas: {state.contains `Init.Data.List.Lemmas}"
32+
-- Use the public API to check if a module is grind-annotated
33+
-- First we need to get the module index for a theorem from Init.Data.List.Lemmas
34+
match env.getModuleIdxFor? `List.eq_nil_of_length_eq_zero with
35+
| none => logInfo "Could not find module"
36+
| some modIdx =>
37+
let isAnnotated := Lean.Elab.Tactic.Grind.isGrindAnnotatedModule env modIdx
38+
logInfo m!"Init.Data.List.Lemmas is grind-annotated: {isAnnotated}"
3439

3540
/-! ## Filtering logic -/
3641

@@ -58,9 +63,9 @@ example : True := by
5863
match env.getModuleIdxFor? theoremName with
5964
| none => logInfo "Theorem has no module index"
6065
| some modIdx =>
61-
let moduleName := env.header.moduleNames[modIdx.toNat]!
62-
let isAnnotated := Selector.isGrindAnnotatedModule env modIdx
63-
let state := Lean.Elab.Tactic.Grind.grindAnnotatedExt.getState env
66+
let _moduleName := env.header.moduleNames[modIdx.toNat]!
67+
let _isAnnotated := Grind.isGrindAnnotatedModule env modIdx
68+
pure ()
6469

6570
-- Test 1: Without filter, suggestion should be returned
6671
let suggestions1 ← testSelector mvarId {}

0 commit comments

Comments
 (0)