This PR migrates usages of `Std.Range` to the new polymorphic ranges. This PR unfortunately increases the transitive imports for frequently-used parts of `Init` because the ranges now rely on iterators in order to provide their functionality for types other than `Nat`. However, iteration over ranges in compiled code is as efficient as before in the examples I checked. This is because of a special `IteratorLoop` implementation provided in the PR for this purpose. There were two issues that were uncovered during migration: * In `IndPredBelow.lean`, migrating the last remaining range causes `compilerTest1.lean` to break. I have minimized the issue and came to the conclusion it's a compiler bug. Therefore, I have not replaced said old range usage yet (see #9186). * In `BRecOn.lean`, we are publicly importing the ranges. Making this import private should theoretically work, but there seems to be a problem with the module system, causing the build to panic later in `Init.Data.Grind.Poly` (see #9185). * In `FuzzyMatching.lean`, inlining fails with the new ranges, which would have led to significant slowdown. Therefore, I have not migrated this file either.
29 lines
1.2 KiB
Text
29 lines
1.2 KiB
Text
import Lean.Data.Lsp
|
|
open IO Lean Lsp
|
|
|
|
def mkCompletionRequest (id : Nat) : JsonRpc.Request Json :=
|
|
let param := Json.parse r#"{"textDocument":{"uri":"file:///home/mhuisi/Lean/lean4/tests/bench/identifier_completion.lean"},"position":{"line":25,"character":40},"context":{"triggerKind":1}}"#
|
|
let param := param.toOption.get!
|
|
{ id, method := "textDocument/completion", param }
|
|
|
|
def main : IO Unit := do
|
|
Ipc.runWith (←IO.appPath) #["--server"] do
|
|
let hIn ← Ipc.stdin
|
|
hIn.write (← FS.readBinFile "identifier_completion_initialization.log")
|
|
hIn.flush
|
|
let _ ← Ipc.readResponseAs 0 InitializeResult
|
|
Ipc.writeNotification {
|
|
method := "initialized"
|
|
param := InitializedParams.mk
|
|
}
|
|
hIn.write (← FS.readBinFile "identifier_completion_didOpen.log")
|
|
-- Let file progress proceed to the point of the completion that we want to benchmark
|
|
Ipc.writeRequest <| mkCompletionRequest 1
|
|
let _ ← Ipc.readResponseAs 1 CompletionList
|
|
let startTime ← IO.monoMsNow
|
|
for i in 2...(5 : Nat) do
|
|
Ipc.writeRequest <| mkCompletionRequest i
|
|
let _ ← Ipc.readResponseAs i CompletionList
|
|
let endTime ← IO.monoMsNow
|
|
IO.println s!"completion: {(endTime - startTime).toFloat / 1000.0}"
|
|
Ipc.shutdown 5
|