-
Notifications
You must be signed in to change notification settings - Fork 5
/
getpremises.lean
65 lines (58 loc) · 2.42 KB
/
getpremises.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import LeanAide.Premises
import Lean.Meta
import LeanAide.Config
open Lean Meta LeanAide.Meta
set_option maxHeartbeats 10000000
set_option maxRecDepth 1000
set_option compiler.extract_closed false
def init : IO Unit := do
initSearchPath (← Lean.findSysroot) initFiles
def environment : IO Environment := do
importModules #[{module := `Mathlib},
{module:= `LeanAide.TheoremElab},
{module:= `LeanAide.VerboseDelabs},
{module:= `LeanAide.Premises},
{module := `Mathlib}] {}
def environment' : IO Environment := do
importModules #[{module := `Mathlib},
{module:= `LeanAide.TheoremElab},
{module:= `LeanAide.ConstDeps},
{module := `Mathlib}] {}
def coreContext : Core.Context := {fileName := "", fileMap := {source:= "", positions := #[]}, maxHeartbeats := 100000000000, maxRecDepth := 1000000, openDecls := [Lean.OpenDecl.simple `LeanAide.Meta []]
}
def main (_: List String) : IO Unit := do
init
let env ← environment
let env' ← environment'
let propMap ←
propMapCore.run' coreContext {env := env'} |>.runToIO'
IO.println s!"Obtained prop-map: {propMap.size} entries"
let propNames := propMap.toArray.map (·.1)
let groupedNames ← splitData propNames
let handles ← fileHandles
let concurrency := (← threadNum) * 3 / 4
IO.println s!"Using {concurrency} threads"
for group in groups do
IO.println s!"Finding premises for group {group}"
let allNames := groupedNames[group].get!
IO.println s!"Definitions in group {group}: {allNames.size}"
let batches := allNames.batches' concurrency
let batches := batches.map (fun batch => batch.map (·.toName) |>.toList)
IO.println s!"Made {batches.size} batches"
let batches' := batches.zip (Array.range batches.size)
let tasks ← batches'.mapM fun (names, k) => do
let writeCore := PremiseData.writeBatchCore names group handles propMap s!"batch: {k}"
let t ← writeCore.run' coreContext {env := env} |>.spawnToIO
pure (t, k)
IO.println "Spawned tasks"
let mut count := 0
for (task, k) in tasks.reverse do
count := count + 1
IO.println s!"Waiting for task {k}: {count} of {tasks.size}"
IO.println s!"Task {k} finished with premises: {← task.get}"
-- let unifyTasks ← BaseIO.mapTasks pure tasks.toList
-- let getTasks := unifyTasks.get
-- discard <| getTasks.mapM id
IO.println s!"Done {group}"
IO.println s!"Done: all tasks completed"
return ()