forked from ocaml/dune
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR is a RFC, as I'm not convinced at all this should be the way to go before we introduce handling of public Coq theories as to allow their inter-scope composition. The current approach to handling Coq theories ─ introduced in ocaml#2053 ─ modified `Scope` and `Lib` adding a new library-like stanza type, `Coq_theory`. However, handling of libraries and theories is quite different so the above approach led to a few spurious code cases. There are two choices to improve this situation before we introduce `coq_public_libs`: - refactor `Scope` a bit more so we don't have to mess with `Lib.library_related_stanza` That's one option but still seems a bit invasive and messy for `scope.ml`. - split all Coq-related scope code to `Coq_scope` and handle things there. This is what this PR does. This approach does introduce some code duplication, so it is not clear if it is indeed a gain w.r.t. current status-quo. Code duplication could be solved by using some programming abstractions. Signed-off-by: Emilio Jesus Gallego Arias <e+git@x80.org>
- Loading branch information
Showing
9 changed files
with
109 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
(* This file is licensed under The MIT License *) | ||
(* (c) MINES ParisTech 2019 *) | ||
(* (c) INRIA 2020 *) | ||
(* Written by: Emilio Jesús Gallego Arias *) | ||
|
||
open! Stdune | ||
|
||
type t = { db : Coq_lib.DB.t } | ||
|
||
let libs { db; _ } = db | ||
|
||
module DB = struct | ||
type scope = t | ||
|
||
type t = | ||
{ by_dir : scope Path.Source.Map.t | ||
; context : Context_name.t | ||
} | ||
|
||
let find_by_dir t (dir : Path.Source.t) = | ||
let rec loop d = | ||
match Path.Source.Map.find t.by_dir d with | ||
| Some s -> s | ||
| None -> ( | ||
match Path.Source.parent d with | ||
| Some d -> loop d | ||
| None -> | ||
Code_error.raise "find_by_dir: invalid directory" | ||
[ ("d", Path.Source.to_dyn d); ("dir", Path.Source.to_dyn dir) ] ) | ||
in | ||
loop dir | ||
|
||
let find_by_project t project = | ||
Path.Source.Map.find_exn t.by_dir (Dune_project.root project) | ||
|
||
let scopes_by_dir stanzas = | ||
let stanzas_by_project_dir = | ||
List.map stanzas | ||
~f:(fun ((dir, stanza) : Path.Build.t * Dune_file.Coq.t) -> | ||
let project = stanza.project in | ||
(Dune_project.root project, (dir, stanza))) | ||
|> Path.Source.Map.of_list_multi | ||
in | ||
Path.Source.Map.map stanzas_by_project_dir ~f:(fun stanza -> | ||
let db = Coq_lib.DB.create_from_coqlib_stanzas stanza in | ||
{ db }) | ||
|
||
let create ~context stanzas = | ||
let by_dir = scopes_by_dir stanzas in | ||
{ by_dir; context } | ||
|
||
let find_by_dir t dir = | ||
if Path.Build.is_root dir then | ||
Code_error.raise "Scope.DB.find_by_dir got an invalid path" | ||
[ ("dir", Path.Build.to_dyn dir) | ||
; ("context", Context_name.to_dyn t.context) | ||
]; | ||
find_by_dir t (Path.Build.drop_build_context_exn dir) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(* This file is licensed under The MIT License *) | ||
(* (c) MINES ParisTech 2019 *) | ||
(* (c) INRIA 2020 *) | ||
(* Written by: Emilio Jesús Gallego Arias *) | ||
|
||
open! Stdune | ||
|
||
type t | ||
|
||
(** Return the library database associated to this scope *) | ||
val libs : t -> Coq_lib.DB.t | ||
|
||
module DB : sig | ||
type scope = t | ||
|
||
type t | ||
|
||
val create : | ||
context:Context_name.t -> (Path.Build.t * Dune_file.Coq.t) list -> t | ||
|
||
val find_by_dir : t -> Path.Build.t -> scope | ||
|
||
val find_by_project : t -> Dune_project.t -> scope | ||
end | ||
with type scope := t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters