Skip to content

Commit

Permalink
Merge pull request #43 from leanprover-community/jmc-unusedtransitive…
Browse files Browse the repository at this point in the history
…main

chore: move `Core.withImportModules` to `Imports.lean`
  • Loading branch information
kim-em authored Nov 11, 2024
2 parents ac7b989 + f0a1ccc commit b0b73e5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
1 change: 0 additions & 1 deletion ImportGraph.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ import ImportGraph.Imports
import ImportGraph.CurrentModule
import ImportGraph.Lean.Name
import ImportGraph.RequiredModules
import ImportGraph.UnusedTransitiveImports
6 changes: 6 additions & 0 deletions ImportGraph/Imports.lean
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ def unusedTransitiveImports (amongst : List Name) (verbose : Bool := false) : Co
let unused := (transitiveImports.find? n).getD {} \ (transitivelyRequired.find? n |>.getD {})
amongst.filter (fun m => unused.contains m))

def Core.withImportModules (modules : Array Name) {α} (f : CoreM α) : IO α := do
searchPathRef.set compile_time_search_path%
unsafe Lean.withImportModules (modules.map (fun m => {module := m})) {} (trustLevel := 1024)
fun env => Prod.fst <$> Core.CoreM.toIO
(ctx := { fileName := "<CoreM>", fileMap := default }) (s := { env := env }) do f

/--
Return the redundant imports (i.e. those transitively implied by another import)
of a specified module (or the current module if `none` is specified).
Expand Down
6 changes: 0 additions & 6 deletions ImportGraph/UnusedTransitiveImports.lean
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import ImportGraph.Imports

open Lean

def Core.withImportModules (modules : Array Name) {α} (f : CoreM α) : IO α := do
searchPathRef.set compile_time_search_path%
unsafe Lean.withImportModules (modules.map (fun m => {module := m})) {} (trustLevel := 1024)
fun env => Prod.fst <$> Core.CoreM.toIO
(ctx := { fileName := "<CoreM>", fileMap := default }) (s := { env := env }) do f

/--
`lake exe unused_transitive_imports m1 m2 ...`
Expand Down

0 comments on commit b0b73e5

Please sign in to comment.