Skip to content

Commit

Permalink
[fleche] [doc] Interpret require via special custom path.
Browse files Browse the repository at this point in the history
This will allow us to:

- postpone the document checking when the require is not ready
- correctly track file dependencies in memoization
- apply the .vo parsing optimization, by intercepting the call

Co-authored-by: BHAKTISHAH <shahbhakti21@gmail.com>
  • Loading branch information
ejgallego and bhaktishh committed Apr 3, 2024
1 parent 2f9411f commit 1d3e516
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
- new option `--no_vo` for `fcc`, which will skip the `.vo` saving
step. `.vo` saving is now an `fcc` plugins, but for now, it is
enabled by default (@ejgallego, #650)
- interpret require thru our own custom execution env-aware path
(@bhaktishh, @ejgallego, #642, #643, #644)

# coq-lsp 0.1.8.1: Spring fix
-----------------------------
Expand Down
3 changes: 2 additions & 1 deletion compiler/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ let compile_file ~cc file =
| Error _ -> ()
| Ok uri -> (
let workspace = workspace_of_uri ~io ~workspaces ~uri ~default in
let env = Doc.Env.make ~init:root_state ~workspace in
let files = Coq.Files.make () in
let env = Doc.Env.make ~init:root_state ~workspace ~files in
let raw = Util.input_all file in
let () = Theory.create ~io ~env ~uri ~raw ~version:1 in
match Theory.Check.maybe_check ~io with
Expand Down
3 changes: 2 additions & 1 deletion controller/lsp_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ let do_open ~io ~(state : State.t) params =
in
let Lsp.Doc.TextDocumentItem.{ uri; version; text; _ } = document in
let init, workspace = State.workspace_of_uri ~uri ~state in
let env = Fleche.Doc.Env.make ~init ~workspace in
let files = Coq.Files.make () in
let env = Fleche.Doc.Env.make ~init ~workspace ~files in
Fleche.Theory.create ~io ~env ~uri ~raw:text ~version

let do_change ~ofn ~io params =
Expand Down
16 changes: 11 additions & 5 deletions fleche/doc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,10 @@ module Env = struct
type t =
{ init : Coq.State.t
; workspace : Coq.Workspace.t
; files : Coq.Files.t
}

let make ~init ~workspace = { init; workspace }
let make ~init ~workspace ~files = { init; workspace; files }
end

(** A Flèche document is basically a [node list], which is a crude form of a
Expand Down Expand Up @@ -626,11 +627,16 @@ end = struct
| Completed (Error _) -> st
end

let interp_and_info ~parsing_time ~st ast =
let interp_and_info ~st ~files ast =
match Coq.Ast.Require.extract ast with
| None -> Memo.Interp.eval (st, ast)
| Some ast -> Memo.Require.eval (st, files, ast)

let interp_and_info ~parsing_time ~st ~files ast =
let { Gc.major_words = mw_prev; _ } = Gc.quick_stat () in
(* memo memory stats are disabled: slow and misleading *)
let { Memo.Stats.res; cache_hit; memory = _; time } =
Memo.Interp.eval (st, ast)
interp_and_info ~st ~files ast
in
let { Gc.major_words = mw_after; _ } = Gc.quick_stat () in
let stats = Stats.dump () in
Expand Down Expand Up @@ -771,8 +777,8 @@ let document_action ~st ~parsing_diags ~parsing_feedback ~parsing_time ~doc
Continue { state = st; last_tok; node }
(* We can interpret the command now *)
| Process ast -> (
let lines = doc.contents.lines in
let process_res, info = interp_and_info ~parsing_time ~st ast in
let lines, files = (doc.contents.lines, doc.env.files) in
let process_res, info = interp_and_info ~parsing_time ~st ~files ast in
let f = Coq.Utils.to_range ~lines in
let { Coq.Protect.E.r; feedback } = Coq.Protect.E.map_loc ~f process_res in
match r with
Expand Down
4 changes: 3 additions & 1 deletion fleche/doc.mli
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ module Env : sig
type t = private
{ init : Coq.State.t
; workspace : Coq.Workspace.t
; files : Coq.Files.t
}

val make : init:Coq.State.t -> workspace:Coq.Workspace.t -> t
val make :
init:Coq.State.t -> workspace:Coq.Workspace.t -> files:Coq.Files.t -> t
end

(** A Flèche document is basically a [node list], which is a crude form of a
Expand Down

0 comments on commit 1d3e516

Please sign in to comment.