Skip to content

Commit

Permalink
[fleche] Prepare for caching / sharing of .vo contents
Browse files Browse the repository at this point in the history
For now we just update the types to get ready for coq/coq#17393 , we
will add the cache in the next commit.

Based on work from #641
  • Loading branch information
ejgallego committed Jun 3, 2024
1 parent 46342ed commit a4115a8
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 22 deletions.
8 changes: 4 additions & 4 deletions coq/init.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ let coq_init opts =
(**************************************************************************)

(* Inits the context for a document *)
let doc_init ~root_state ~workspace ~uri () =
let doc_init ~intern ~root_state ~workspace ~uri () =
(* Lsp.Io.log_error "init" "starting"; *)
Vernacstate.unfreeze_full_state (State.to_coq root_state);

(* Set load paths from workspace info. *Important*, this has to happen before
we declare the library below as [Declaremods/Library] will infer the module
name by looking at the load path! *)
Workspace.apply ~uri workspace;
Workspace.apply ~intern ~uri workspace;

(* We return the state at this point! *)
Vernacstate.freeze_full_state () |> State.of_coq

let doc_init ~token:_ ~root_state ~workspace ~uri =
let doc_init ~token:_ ~intern ~root_state ~workspace ~uri =
(* Don't interrupt document creation. *)
let token = Limits.create_atomic () in
Protect.eval ~token ~f:(doc_init ~root_state ~workspace ~uri) ()
Protect.eval ~token ~f:(doc_init ~intern ~root_state ~workspace ~uri) ()
1 change: 1 addition & 0 deletions coq/init.mli
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ val coq_init : coq_opts -> State.t

val doc_init :
token:Limits.Token.t
-> intern:Library.Intern.t
-> root_state:State.t
-> workspace:Workspace.t
-> uri:Lang.LUri.File.t
Expand Down
15 changes: 8 additions & 7 deletions coq/interp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@
(* Written by: Emilio J. Gallego Arias *)
(************************************************************************)

let coq_interp ~st cmd =
let coq_interp ~intern ~st cmd =
let st = State.to_coq st in
let cmd = Ast.to_coq cmd in
Vernacinterp.interp ~st cmd |> State.of_coq
Vernacinterp.interp ~intern ~st cmd |> State.of_coq

let interp ~token ~st cmd = Protect.eval ~token cmd ~f:(coq_interp ~st)
let interp ~token ~intern ~st cmd =
Protect.eval ~token cmd ~f:(coq_interp ~intern ~st)

module Require = struct
(* We could improve this Coq upstream by making the API a bit more
orthogonal *)
let interp ~st _files
let interp ~intern ~st _files
{ Ast.Require.from; export; mods; loc = _; attrs; control } =
let () = Vernacstate.unfreeze_full_state (State.to_coq st) in
let fn () = Vernacentries.vernac_require from export mods in
let fn () = Vernacentries.vernac_require ~intern from export mods in
(* Check generic attributes *)
let fn () =
Synterp.with_generic_atts ~check:true attrs (fun ~atts ->
Expand All @@ -40,6 +41,6 @@ module Require = struct
let () = Utils.with_control ~fn ~control ~st in
Vernacstate.freeze_full_state () |> State.of_coq

let interp ~token ~st files cmd =
Protect.eval ~token ~f:(interp ~st files) cmd
let interp ~token ~intern ~st files cmd =
Protect.eval ~token ~f:(interp ~intern ~st files) cmd
end
7 changes: 6 additions & 1 deletion coq/interp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
assumed not to interact with the file-system, etc... Note these commands
will be memoized. *)
val interp :
token:Limits.Token.t -> st:State.t -> Ast.t -> (State.t, Loc.t) Protect.E.t
token:Limits.Token.t
-> intern:Library.Intern.t
-> st:State.t
-> Ast.t
-> (State.t, Loc.t) Protect.E.t

(** Interpretation of "require". We wrap this function for two reasons:
Expand All @@ -28,6 +32,7 @@ val interp :
module Require : sig
val interp :
token:Limits.Token.t
-> intern:Library.Intern.t
-> st:State.t
-> Files.t
-> Ast.Require.t
Expand Down
8 changes: 4 additions & 4 deletions coq/workspace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,12 @@ let describe_guess = function
| Error msg -> (msg, "")

(* Require a set of libraries *)
let load_objs libs =
let load_objs ~intern libs =
let rq_file { Require.library; from; flags } =
let mp = Libnames.qualid_of_string library in
let mfrom = Option.map Libnames.qualid_of_string from in
Flags_.silently
(Vernacentries.vernac_require mfrom flags)
(Vernacentries.vernac_require ~intern mfrom flags)
[ (mp, Vernacexpr.ImportAll) ]
in
List.(iter rq_file (rev libs))
Expand Down Expand Up @@ -295,7 +295,7 @@ let dirpath_of_uri ~uri =
ldir

(* NOTE: Use exhaustive match below to avoid bugs by skipping fields *)
let apply ~uri
let apply ~intern ~uri
{ coqlib = _
; coqcorelib = _
; ocamlpath
Expand All @@ -314,7 +314,7 @@ let apply ~uri
findlib_init ~ml_include_path ~ocamlpath;
List.iter Loadpath.add_vo_path vo_load_path;
Declaremods.start_library (dirpath_of_uri ~uri);
load_objs require_libs
load_objs ~intern require_libs

(* This can raise, and will do in incorrect CoqProject files *)
let dirpath_of_string_exn coq_path = Libnames.dirpath_of_string coq_path
Expand Down
2 changes: 1 addition & 1 deletion coq/workspace.mli
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ val guess :
val default : debug:bool -> cmdline:CmdLine.t -> t

(** [apply libname w] will prepare Coq for a new file [libname] on workspace [w] *)
val apply : uri:Lang.LUri.File.t -> t -> unit
val apply : intern:Library.Intern.t -> uri:Lang.LUri.File.t -> t -> unit

(** *)
val dirpath_of_uri : uri:Lang.LUri.File.t -> Names.DirPath.t
5 changes: 4 additions & 1 deletion fleche/doc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,10 @@ end = struct
->
Io.Log.trace "recovery" "bullet";
Coq.State.admit_goal ~token ~st
|> Coq.Protect.E.bind ~f:(fun st -> Coq.Interp.interp ~token ~st v)
|> Coq.Protect.E.bind ~f:(fun st ->
(* We skip the cache here, but likely we don't want to do that. *)
let intern = Vernacinterp.fs_intern in
Coq.Interp.interp ~token ~intern ~st v)
| _ ->
(* Fallback to qed special lex case *)
lex_recovery_heuristic ~token last_tok contents nodes st
Expand Down
10 changes: 7 additions & 3 deletions fleche/memo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ module VernacEval = struct

type output = Coq.State.t

let eval ~token (st, stm) = Coq.Interp.interp ~token ~st stm
let eval ~token (st, stm) =
let intern = Vernacinterp.fs_intern in
Coq.Interp.interp ~token ~intern ~st stm
end

module Interp = CEval (VernacEval)
Expand Down Expand Up @@ -316,7 +318,8 @@ module RequireEval = struct
type output = Coq.State.t

let eval ~token (st, files, stm) =
Coq.Interp.Require.interp ~token ~st files stm
let intern = Vernacinterp.fs_intern in
Coq.Interp.Require.interp ~token ~intern ~st files stm
end

module Require = CEval (RequireEval)
Expand Down Expand Up @@ -347,7 +350,8 @@ module InitEval = struct
type output = Coq.State.t

let eval ~token (root_state, workspace, uri) =
Coq.Init.doc_init ~token ~root_state ~workspace ~uri
let intern = Vernacinterp.fs_intern in
Coq.Init.doc_init ~token ~intern ~root_state ~workspace ~uri

let input_info (st, ws, file) =
Format.asprintf "st %d | ws %d | file %s" (Hashtbl.hash st)
Expand Down
1 change: 1 addition & 0 deletions test/serlib/genarg/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; Eventually we should use the "put binaries in scope feature of Dune"

(rule
(targets test_roundtrip)
(deps
Expand Down
2 changes: 1 addition & 1 deletion vendor/coq
Submodule coq updated 90 files
+60 −16 .gitlab-ci.yml
+4 −2 checker/mod_checking.ml
+1 −1 coq-core.opam
+1 −1 dev/bench/gitlab-bench.yml
+8 −4 dev/ci/README-users.md
+3 −0 dev/ci/user-overlays/17393-ejgallego-skip_vofile.sh
+1 −0 dev/ci/user-overlays/19120-ppedrot-conversion-no-inner-exception-api.sh
+6 −0 doc/changelog/02-specification-language/19100-master+fix19099-poly-prim-constant-with-udecl.rst
+5 −0 doc/changelog/03-notations/19049-warn_notation_incompatible_prefix.rst
+6 −0 doc/changelog/04-tactics/19115-setoid-rewrite-coqlib.rst
+5 −0 doc/changelog/04-tactics/19129-deprecate-gintuition.rst
+11 −4 doc/sphinx/language/extensions/arguments-command.rst
+27 −0 doc/sphinx/proof-engine/ltac.rst
+2 −39 doc/sphinx/proof-engine/ltac2.rst
+2 −0 doc/sphinx/proofs/automatic-tactics/logic.rst
+1 −1 doc/sphinx/proofs/creating-tactics/index.rst
+22 −4 doc/sphinx/proofs/writing-proofs/equality.rst
+21 −6 doc/sphinx/user-extensions/syntax-extensions.rst
+1 −1 dune-project
+3 −2 kernel/constant_typing.ml
+72 −57 kernel/conversion.ml
+16 −22 kernel/conversion.mli
+11 −9 kernel/mod_typing.ml
+4 −4 kernel/mod_typing.mli
+33 −5 kernel/nativeconv.ml
+1 −1 kernel/nativeconv.mli
+33 −13 kernel/safe_typing.ml
+7 −10 kernel/subtyping.ml
+1 −1 kernel/subtyping.mli
+37 −16 kernel/typeops.ml
+33 −6 kernel/vconv.ml
+1 −1 kernel/vconv.mli
+2 −158 library/coqlib.ml
+1 −190 library/coqlib.mli
+34 −1 parsing/notgram_ops.ml
+7 −0 parsing/notgram_ops.mli
+84 −30 plugins/firstorder/formula.ml
+13 −5 plugins/firstorder/formula.mli
+1 −1 plugins/firstorder/g_ground.mlg
+1 −1 plugins/firstorder/instances.ml
+1 −1 plugins/firstorder/rules.mli
+54 −44 plugins/firstorder/sequent.ml
+3 −1 plugins/firstorder/sequent.mli
+3 −3 plugins/firstorder/unify.ml
+1 −1 plugins/firstorder/unify.mli
+3 −2 plugins/ltac2/tac2print.ml
+64 −48 pretyping/reductionops.ml
+2 −2 pretyping/reductionops.mli
+103 −63 pretyping/unification.ml
+0 −20 pretyping/unification.mli
+3 −2 stm/stm.ml
+6 −6 sysinit/coqinit.ml
+2 −1 sysinit/coqinit.mli
+32 −20 tactics/equality.ml
+2 −2 tactics/hipattern.ml
+56 −62 tactics/rewrite.ml
+4 −0 test-suite/bugs/bug_19099.v
+ test-suite/output/BinaryPrintingNotations.v
+7 −0 test-suite/output/Notations.out
+5 −0 test-suite/output/Notations3.out
+1 −1 test-suite/output/NumberNotations.out
+1 −1 test-suite/output/allBytes.out
+2 −0 test-suite/output/allBytes.v
+16 −0 test-suite/output/lexical_convention_in_doc.out
+1 −1 test-suite/output/lexical_convention_in_doc.v
+10 −0 test-suite/output/notation_prefix_incompatible_level.out
+7 −0 test-suite/output/notation_prefix_incompatible_level.v
+47 −27 theories/Classes/CMorphisms.v
+14 −0 theories/Classes/CRelationClasses.v
+23 −18 theories/Classes/Morphisms.v
+11 −0 theories/Classes/RelationClasses.v
+1 −0 theories/Classes/SetoidTactics.v
+1 −0 theories/Init/Logic.v
+3 −0 theories/Program/Basics.v
+1 −1 theories/Program/Utils.v
+1 −0 theories/Relations/Operators_Properties.v
+0 −1 theories/ssr/ssreflect.v
+10 −9 vernac/declare.ml
+77 −53 vernac/library.ml
+18 −1 vernac/library.mli
+0 −25 vernac/locality.ml
+0 −4 vernac/locality.mli
+32 −2 vernac/metasyntax.ml
+3 −3 vernac/retrieveObl.ml
+13 −14 vernac/synterp.ml
+2 −0 vernac/synterp.mli
+80 −44 vernac/vernacentries.ml
+2 −1 vernac/vernacentries.mli
+11 −3 vernac/vernacinterp.ml
+5 −1 vernac/vernacinterp.mli

0 comments on commit a4115a8

Please sign in to comment.