Skip to content

Commit 73bb1f6

Browse files
alleystoughtonstrub
authored andcommitted
Exposed in the API for EcScope.Theory functions for beginning and
finishing a require, for use when creating the required theory manually, not using a loader. Used these functions in the implementation of the ordinary require.
1 parent 99d826d commit 73bb1f6

2 files changed

Lines changed: 33 additions & 14 deletions

File tree

src/ecScope.ml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,20 @@ module Theory = struct
19741974
"end-of-file while processing proof %s" (fst scope.sc_name)
19751975

19761976
(* -------------------------------------------------------------------- *)
1977+
let require_start (scope : scope) (thname : symbol) (mode : thmode)
1978+
: scope =
1979+
let new_ = enter (for_loading scope) mode thname `Global in
1980+
{ new_ with sc_env = EcSection.astop new_.sc_env }
1981+
1982+
let require_finish ?(old : scope option = None) ~(new_ : scope)
1983+
(ri : required_info) : scope =
1984+
let (cth, rqs), (name1, _), new_ = exit_r ~pempty:`No new_ in
1985+
assert (ri.rqd_name = name1);
1986+
let scope =
1987+
{ (odfl new_ old) with sc_loaded =
1988+
Msym.add ri.rqd_name (oget cth, rqs) new_.sc_loaded; } in
1989+
bump_prelude (require_loaded ri scope)
1990+
19771991
let require (scope : scope) ((name, mode) : required_info * thmode) loader =
19781992
assert (scope.sc_pr_uc = None);
19791993

@@ -1984,24 +1998,13 @@ module Theory = struct
19841998
end else
19851999
match Msym.find_opt name.rqd_name scope.sc_loaded with
19862000
| Some _ -> require_loaded name scope
1987-
19882001
| None ->
19892002
try
1990-
let imported = enter (for_loading scope) mode name.rqd_name `Global in
1991-
let imported = { imported with sc_env = EcSection.astop imported.sc_env } in
2003+
let imported = require_start scope name.rqd_name mode in
19922004
let thname = fst imported.sc_name in
19932005
let imported = loader imported in
1994-
19952006
check_end_required imported thname;
1996-
1997-
let cth = exit_r ~pempty:`No imported in
1998-
let (cth, rqs), (name1, _), imported = cth in
1999-
assert (name.rqd_name = name1);
2000-
let scope = { scope with sc_loaded =
2001-
Msym.add name.rqd_name (oget cth, rqs) imported.sc_loaded; } in
2002-
2003-
bump_prelude (require_loaded name scope)
2004-
2007+
require_finish ~old:(Some scope) ~new_:imported name
20052008
with e -> begin
20062009
match toperror_of_exn_r e with
20072010
| Some (l, e) when not (EcLocation.isdummy l) ->
@@ -2112,7 +2115,7 @@ module Cloning = struct
21122115
| Some pt ->
21132116
let t = { pt_core = pt; pt_intros = []; } in
21142117
let t = { pl_loc = pt.pl_loc; pl_desc = Pby (Some [t]); } in
2115-
let t = { pt_core = t; pt_intros = []; } in
2118+
let t = { pt_core = t; pt_intros = []; } in
21162119
let (x, ax) = axc.C.axc_axiom in
21172120

21182121
let pucflags = { puc_smt = true; puc_local = false; } in

src/ecScope.mli

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,22 @@ module Theory : sig
188188
* theory. *)
189189
val require : scope -> (required_info * thmode) -> (scope -> scope) -> scope
190190

191+
(* start/finish adding a new top-level required theory, not using loader
192+
*
193+
* [require_start] enters the theory, with the given name and theory mode,
194+
* starting from the initial scope
195+
*
196+
* [require_finish old new_ ri] exits the top-level theory of [new_],
197+
* resulting in a new scope, new', and a new loaded theory, th, and then
198+
* forms a loaded theory map from the map of new', adding the binding of
199+
* ri.rqd_name -> th
200+
* if old is supplied, it requires ri in the result of replacing
201+
the loaded theories of old with the updated map
202+
* otherwise, it requires ri in the result of replacing the
203+
the loaded theories of new' with the updated map *)
204+
val require_start : scope -> symbol -> thmode -> scope
205+
val require_finish : ?old:scope option -> new_:scope -> required_info -> scope
206+
191207
val add_clears : (pqsymbol option) list -> scope -> scope
192208

193209
val required : scope -> required

0 commit comments

Comments
 (0)