Skip to content

Commit 43afbe5

Browse files
JLimpergJannis Limperg
and
Jannis Limperg
authored
fix: enable initialisers in Extract[Module] (#81)
Prior to this change, `subverso-extract` and `subverso-extract-mod` would fail on any module that imports a non-core module with `initialize` declarations. Co-authored-by: Jannis Limperg <[email protected]>
1 parent 47d9bba commit 43afbe5

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

Extract.lean

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import SubVerso.Examples.Env
99
open Lean
1010
open SubVerso.Examples
1111

12-
def main : (args : List String) → IO UInt32
12+
unsafe def main : (args : List String) → IO UInt32
1313
| [mod, outFile] => do
1414
try
1515
initSearchPath (← findSysroot)
1616
let modName := mod.toName
17+
enableInitializersExecution
1718
let env ← SubVerso.Compat.importModules #[{module := modName, runtimeOnly := false}] {}
1819
let modExamples := highlighted.getState env
1920
let useful := relevant modName modExamples

ExtractModule.lean

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ open Lean.Elab.Command (liftTermElabM)
1212
open SubVerso Examples
1313
open SubVerso.Highlighting (Highlighted highlight)
1414

15-
16-
def main : (args : List String) → IO UInt32
15+
unsafe def main : (args : List String) → IO UInt32
1716
| [mod, outFile] => do
1817
try
1918
initSearchPath (← findSysroot)
@@ -29,6 +28,7 @@ def main : (args : List String) → IO UInt32
2928
let ictx := Parser.mkInputContext (← IO.FS.readFile fname) fname.toString
3029
let (headerStx, parserState, msgs) ← Parser.parseHeader ictx
3130
let imports := headerToImports headerStx
31+
enableInitializersExecution
3232
let env ← importModules imports {}
3333
let pctx : Context := {inputCtx := ictx}
3434

@@ -55,6 +55,3 @@ def main : (args : List String) → IO UInt32
5555
| other => do
5656
IO.eprintln s!"Didn't understand args: {other}"
5757
pure 1
58-
where
59-
relevant (mod : Name) (examples : NameMap (NameMap Json)) : List (String × Json) :=
60-
examples.find? mod |>.getD {} |>.toList |>.map fun p => {p with fst := p.fst.toString (escape := false)}

0 commit comments

Comments
 (0)