This PR roughly halves the time needed to load the .ilean files by optimizing the JSON parser and the conversion from JSON to Lean data structures. The code is optimized roughly as follows: - String operations are inlined more aggressively - Parsers are changed to use new `String.Iterator` functions `curr'` and `next'` that receive a proof and hence do not need to perform an additional check - The `RefIdent` of .ilean files now uses a `String` instead of a `Name` to avoid the expensive parse step from `String` to `Name` (despite the fact that we only very rarely actually need a `Name` in downstream code) - Instead of `List`s and `Subarray`s, the JSON to Lean conversion now directly passes around arrays and array indices to avoid redundant boxing - Parsec's `peek?` sometimes generates redundant `Option` wrappers because the generation of basic blocks interferes with the ctor-match optimization, so it is changed to use an `isEof` check where possible - Early returns and inline-do-blocks cause the code generator to generate new functions, which then interfere with optimizations, so they are now avoided - Mutual defs are used instead of unspecialized passing of higher-order functions to generate faster code - The object parser is made tail-recursive This PR also fixes a stack overflow in `Lean.Json.compress` that would occur with long lists and adds a benchmark for the .ilean roundtrip (compressed pretty-printing -> parsing).
41 lines
904 B
Text
41 lines
904 B
Text
import Lean
|
||
|
||
def f1 (x : Nat) : Except String Nat :=
|
||
if x > 0 then
|
||
.ok x
|
||
else
|
||
.error "argument is zero"
|
||
|
||
namespace Lean.Elab
|
||
open Lsp
|
||
|
||
def identOf : Info → Option (RefIdent × Bool)
|
||
| .ofTermInfo ti => match ti.expr with
|
||
| .const n .. => some (.const (`anonymous).toString n.toString, ti.isBinder)
|
||
| .fvar id .. => some (.fvar (`anonymous).toString id.name.toString, ti.isBinder)
|
||
| _ => none
|
||
| .ofFieldInfo fi => some (.const (`anonymous).toString fi.projName.toString, false)
|
||
| _ => none
|
||
|
||
def isConst (e : Expr) : Bool :=
|
||
e matches .const ..
|
||
|
||
def isImplicit (bi : BinderInfo) : Bool :=
|
||
bi matches .implicit
|
||
|
||
end Lean.Elab
|
||
|
||
def f2 (xs : List Nat) : List Nat :=
|
||
.map (· + 1) xs
|
||
|
||
def f2' (xs : List Nat) : List Nat :=
|
||
.map .succ xs
|
||
|
||
def f3 : Nat :=
|
||
.zero
|
||
|
||
def f4 (x : Nat) : Nat :=
|
||
.succ x
|
||
|
||
example (xs : List α) : Lean.RBTree α ord :=
|
||
xs.foldl .insert ∅
|