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 <[email protected]>
  • Loading branch information
ejgallego and bhaktishh committed Jan 20, 2024
1 parent 800b6ce commit 226c5a5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion compiler/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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 226c5a5

Please sign in to comment.