Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Export.lean
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ structure State where
noMDataExprs : HashMap Expr Expr := HashMap.emptyWithCapacity 100000
exportMData : Bool := false
exportUnsafe : Bool := false
ignoreMissing : Bool := false
/-- Maps the name of an inductive type to a list of names of corresponding recursors.
This is used to facilitate exporting of related inductives, constructors, and recursors as a unit. -/
recursorMap : NameMap NameSet := {}
Expand Down Expand Up @@ -68,8 +69,9 @@ def initState (env : Environment) (cliOptions : List String := []) : M Unit := d
| none => some <| NameSet.empty.insert recVal.name
| some recNames => some <| recNames.insert recVal.name
modify fun st => { st with
exportMData := cliOptions.any (· == "--export-mdata")
exportUnsafe := cliOptions.any (· == "--export-unsafe")
exportMData := cliOptions.any (· == "--export-mdata")
exportUnsafe := cliOptions.any (· == "--export-unsafe")
ignoreMissing := cliOptions.any (· == "--ignore-missing")
recursorMap
}

Expand Down Expand Up @@ -232,7 +234,7 @@ partial def dumpExpr (e : Expr) : M Nat := do

partial def dumpConstant (c : Name) : M Unit := do
let some declar := (← read).env.find? c
| panic! s!"Constant {c} not found in environment."
| if (← get).ignoreMissing then return else panic! s!"Constant {c} not found in environment."
if (declar.isUnsafe && !(← get).exportUnsafe) || (← get).visitedConstants.contains c then
return
modify fun st => { st with visitedConstants := st.visitedConstants.insert c }
Expand Down Expand Up @@ -291,7 +293,7 @@ partial def dumpConstant (c : Name) : M Unit := do
dumpConstant ``Eq
for c in [`Quot, ``Quot.mk, ``Quot.lift, ``Quot.ind] do
let some (.quotInfo val) := (← read).env.find? c
| panic! s!"Constant {c} not found in environment."
| if (← get).ignoreMissing then return else panic! s!"Constant {c} not found in environment."
modify fun st => { st with visitedConstants := st.visitedConstants.insert c }
dumpObj [
("quot", .mkObj [
Expand Down
5 changes: 4 additions & 1 deletion Main.lean
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ def main (args : List String) : IO Unit := do
dumpMetadata
for c in constants do
modify (fun st => { st with noMDataExprs := {} })
dumpConstant c
if (← get).ignoreMissing then
try dumpConstant c catch _ => pure ()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should ignoreMissing allow us to ignore any error that is thrown during constant dumping? Furthermore, which error that is not already handled by your changes in Export is handled by this?

else
dumpConstant c
Loading