Skip to content

Commit 9780605

Browse files
committed
Add back the Loc module
In OCamlPro#1284 we replaced custom locations with Dolmen locations explicitly, which breaks API users such as Owi. This patch makes the `Loc.t` type abstract and provides a conversion function from Dolmen locations instead.
1 parent 8c717b4 commit 9780605

23 files changed

+141
-57
lines changed

src/bin/js/worker_js.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ let main worker_id filename filecontent =
102102
| None -> begin
103103
match Expr.form_view f with
104104
| Lemma {name=name;loc=loc;_} ->
105-
let b,e = Dolmen.Std.Loc.lexing_positions loc in
105+
let b,e = Loc.lexing_positions loc in
106106
let used =
107107
if Options.get_unsat_core () then Worker_interface.Unused
108108
else Worker_interface.Unknown in
109109
(name,b.Lexing.pos_lnum,e.Lexing.pos_lnum,!nb,used) :: acc
110110
| _ -> acc
111111
end
112112
| Some r ->
113-
let b,e = Dolmen.Std.Loc.lexing_positions r.loc in
113+
let b,e = Loc.lexing_positions r.loc in
114114
(r.name,b.Lexing.pos_lnum,e.Lexing.pos_lnum,
115115
!nb,Worker_interface.Used)
116116
:: acc

src/lib/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
; util
6161
Emap Gc_debug Hconsing Hstring Heap Numbers Uqueue
6262
Options Timers Util Vec Version Steps Printer
63-
My_list Theories Nest Compat
63+
My_list Theories Nest Compat Loc
6464
)
6565

6666
(js_of_ocaml

src/lib/frontend/frontend.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ module type S = sig
135135
mutable expl : Explanation.t
136136
}
137137

138-
type 'a process = ?loc : Dolmen.Std.Loc.loc -> 'a -> env -> unit
138+
type 'a process = ?loc : Loc.t -> 'a -> env -> unit
139139

140140
val init_env : ?selector_inst:(Expr.t -> bool) -> used_context -> env
141141

@@ -221,7 +221,7 @@ module Make(SAT : Sat_solver_sig.S) : S with type sat_env = SAT.t = struct
221221
mutable expl : Explanation.t
222222
}
223223

224-
type 'a process = ?loc : DStd.Loc.loc -> 'a -> env -> unit
224+
type 'a process = ?loc : Loc.t -> 'a -> env -> unit
225225

226226
let init_env ?selector_inst used_context =
227227
{
@@ -294,20 +294,20 @@ module Make(SAT : Sat_solver_sig.S) : S with type sat_env = SAT.t = struct
294294
else Ex.empty
295295

296296
let internal_decl
297-
?(loc = DStd.Loc.dummy) (id : Id.typed) (env : env) : unit =
297+
?(loc = Loc.dummy) (id : Id.typed) (env : env) : unit =
298298
ignore loc;
299299
match env.res with
300300
| `Sat | `Unknown ->
301301
SAT.declare env.sat_env id
302302
| `Unsat -> ()
303303

304-
let internal_push ?(loc = DStd.Loc.dummy) (n : int) (env : env) : unit =
304+
let internal_push ?(loc = Loc.dummy) (n : int) (env : env) : unit =
305305
ignore loc;
306306
Util.loop ~f:(fun _ res () -> Stack.push res env.consistent_dep_stack)
307307
~max:n ~elt:(env.res, env.expl) ~init:();
308308
Steps.apply_without_step_limit (fun () -> SAT.push env.sat_env n)
309309

310-
let internal_pop ?(loc = DStd.Loc.dummy) (n : int) (env : env) : unit =
310+
let internal_pop ?(loc = Loc.dummy) (n : int) (env : env) : unit =
311311
ignore loc;
312312
let res, expl =
313313
Util.loop ~f:(fun _n () _env -> Stack.pop env.consistent_dep_stack)
@@ -318,7 +318,7 @@ module Make(SAT : Sat_solver_sig.S) : S with type sat_env = SAT.t = struct
318318
env.expl <- expl
319319

320320
let internal_assume
321-
?(loc = DStd.Loc.dummy)
321+
?(loc = Loc.dummy)
322322
((name, f, mf) : string * E.t * bool)
323323
(env : env) =
324324
let is_hyp = try (Char.equal '@' name.[0]) with _ -> false in
@@ -350,13 +350,13 @@ module Make(SAT : Sat_solver_sig.S) : S with type sat_env = SAT.t = struct
350350
| `Unsat ->
351351
env.expl <- expl
352352

353-
let internal_pred_def ?(loc = DStd.Loc.dummy) (name, f) env =
353+
let internal_pred_def ?(loc = Loc.dummy) (name, f) env =
354354
if not (unused_context name env.used_context) then
355355
let expl = mk_root_dep name f loc in
356356
SAT.pred_def env.sat_env f name expl loc;
357357
env.expl <- expl
358358

359-
let internal_query ?(loc = DStd.Loc.dummy) (n, f, sort) env =
359+
let internal_query ?(loc = Loc.dummy) (n, f, sort) env =
360360
ignore loc;
361361
let expl =
362362
match env.res with
@@ -385,7 +385,7 @@ module Make(SAT : Sat_solver_sig.S) : S with type sat_env = SAT.t = struct
385385
env.expl <- expl
386386

387387
let internal_th_assume
388-
?(loc = DStd.Loc.dummy)
388+
?(loc = Loc.dummy)
389389
({ Expr.ax_name; Expr.ax_form ; _ } as th_elt)
390390
env =
391391
if not (unused_context ax_name env.used_context) then
@@ -396,7 +396,7 @@ module Make(SAT : Sat_solver_sig.S) : S with type sat_env = SAT.t = struct
396396
env.expl <- expl
397397
| `Unsat -> ()
398398

399-
let internal_optimize ?(loc = DStd.Loc.dummy) fn env =
399+
let internal_optimize ?(loc = Loc.dummy) fn env =
400400
ignore loc;
401401
match env.res with
402402
| `Sat | `Unknown ->

src/lib/frontend/frontend.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module type S = sig
6464
They catch the [Sat], [Unsat] and [I_dont_know] exceptions to update the
6565
frontend environment, but not the [Timeout] exception which is raised to
6666
the user. *)
67-
type 'a process = ?loc:Dolmen.Std.Loc.loc -> 'a -> env -> unit
67+
type 'a process = ?loc:Loc.t -> 'a -> env -> unit
6868

6969
val push : int process
7070

src/lib/frontend/translate.ml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ let rec dty_to_ty ?(update = false) ?(is_var = false) dty =
495495
let vty = aux vty in
496496
Ty.Tfarray (ity, vty)
497497
| `Bitv n ->
498-
if n <= 0 then Errors.typing_error (NonPositiveBitvType n) DStd.Loc.dummy;
498+
if n <= 0 then Errors.typing_error (NonPositiveBitvType n) Loc.dummy;
499499
Ty.Tbitv n
500500

501501
| `App (`Builtin B.Unit, []) -> Ty.tunit
@@ -763,7 +763,7 @@ let arith_ty = function
763763
- [lb] is the (optional) lower bound for the variable [var]
764764
- [ub] is the (optional) upper bound for the variable [var]
765765
*)
766-
let parse_semantic_bound ?(loc = DStd.Loc.dummy) ~var b x y =
766+
let parse_semantic_bound ?(loc = Loc.dummy) ~var b x y =
767767
let is_main_var { DE.term_descr; _ } =
768768
match term_descr with
769769
| DE.Var v -> DE.Id.equal v var
@@ -779,7 +779,7 @@ let parse_semantic_bound ?(loc = DStd.Loc.dummy) ~var b x y =
779779
| _ ->
780780
Fmt.failwith
781781
"%aInternal error: invalid semantic bound"
782-
DStd.Loc.fmt loc
782+
Loc.report loc
783783
in
784784
let sort = arith_ty t in
785785
let parse_bound_kind { DE.term_descr; _ } =
@@ -790,7 +790,7 @@ let parse_semantic_bound ?(loc = DStd.Loc.dummy) ~var b x y =
790790
| _ ->
791791
Fmt.failwith
792792
"%aInternal error: invalid semantic bound"
793-
DStd.Loc.fmt loc
793+
Loc.report loc
794794
in
795795
(* Parse [main_var `op` b] *)
796796
let parse_bound ?(flip = false) b =
@@ -869,7 +869,7 @@ let mk_rounding fpar =
869869
Builds an Alt-Ergo hashconsed expression from a dolmen term
870870
*)
871871
let rec mk_expr
872-
?(loc = DStd.Loc.dummy) ?(name_base = "") ?(toplevel = false)
872+
?(loc = Loc.dummy) ?(name_base = "") ?(toplevel = false)
873873
~decl_kind dt =
874874
let name_tag = ref 0 in
875875
let rec aux_mk_expr ?(toplevel = false)
@@ -984,7 +984,7 @@ let rec mk_expr
984984
| _ ->
985985
Fmt.failwith
986986
"%asemantic trigger should have at most one bound variable"
987-
DStd.Loc.fmt loc
987+
Loc.report loc
988988
in
989989
semantic_trigger ~loc ?var trigger
990990

@@ -1400,7 +1400,7 @@ let rec mk_expr
14001400
res
14011401
| _ -> res
14021402

1403-
and semantic_trigger ?var ?(loc = DStd.Loc.dummy) t =
1403+
and semantic_trigger ?var ?(loc = Loc.dummy) t =
14041404
let cst, args =
14051405
match destruct_app t with
14061406
| Some (cst, args) -> cst, args
@@ -1424,7 +1424,7 @@ let rec mk_expr
14241424
| _ ->
14251425
Fmt.failwith
14261426
"%aMaps_to: expected a variable but got: %a"
1427-
DStd.Loc.fmt loc DE.Term.print x
1427+
Loc.report loc DE.Term.print x
14281428
end
14291429

14301430
(* open-ended in interval *)
@@ -1467,16 +1467,16 @@ let rec mk_expr
14671467
E.mk_term (Sy.mk_in lb ub) [aux_mk_expr main_expr] Ty.Tbool
14681468
| _ ->
14691469
Fmt.failwith "%aInvalid semantic trigger: %a"
1470-
DStd.Loc.fmt loc DE.Term.print t
1470+
Loc.report loc DE.Term.print t
14711471
end
14721472

14731473
| _ ->
14741474
Fmt.failwith "%aInvalid semantic trigger: %a"
1475-
DStd.Loc.fmt loc DE.Term.print t
1475+
Loc.report loc DE.Term.print t
14761476

14771477
in aux_mk_expr ~toplevel dt
14781478

1479-
and make_trigger ?(loc = DStd.Loc.dummy) ~name_base ~decl_kind
1479+
and make_trigger ?(loc = Loc.dummy) ~name_base ~decl_kind
14801480
~(in_theory: bool) (name: string) (hyp: E.t list)
14811481
(e, from_user: DE.term * bool) =
14821482
(* Dolmen adds an existential quantifier to bind the '?xxx' variables *)
@@ -1618,11 +1618,12 @@ let rec is_pure_term t =
16181618

16191619
let make file acc stmt =
16201620
let rec aux acc (stmt: _ Typer_Pipe.stmt) =
1621-
let st_loc = Dolmen.Std.Loc.loc file stmt.loc in
1621+
let loc = Dolmen.Std.Loc.loc file stmt.loc in
1622+
let st_loc = Loc.from_dolmen_loc loc in
16221623
match stmt with
16231624
(* Optimize terms *)
16241625
| { contents = `Optimize (t, is_max); _ } ->
1625-
let e = mk_expr ~loc:st_loc ~toplevel:true ~decl_kind:Dobjective t in
1626+
let e = mk_expr t ~loc:st_loc ~toplevel:true ~decl_kind:Dobjective in
16261627
let fn = Objective.Function.mk ~is_max e in
16271628
if not @@ is_pure_term e then
16281629
begin
@@ -1760,7 +1761,7 @@ let make file acc stmt =
17601761
| _ ->
17611762
Fmt.failwith
17621763
"%a: Internal error: multiple theories."
1763-
DStd.Loc.fmt st_loc
1764+
DStd.Loc.fmt loc
17641765
in
17651766
let decl_kind, assume =
17661767
match theory with
@@ -1837,7 +1838,7 @@ let make file acc stmt =
18371838
in
18381839
let qb = E.mk_eq ~iff:true defn ff in
18391840
let ff =
1840-
E.mk_forall name_base DStd.Loc.dummy binders [] qb
1841+
E.mk_forall name_base Loc.dummy binders [] qb
18411842
~toplevel:true ~decl_kind
18421843
in
18431844
assert (Var.Map.is_empty (E.free_vars ff Var.Map.empty));
@@ -1858,7 +1859,7 @@ let make file acc stmt =
18581859
let iff = Ty.equal (Expr.type_info defn) (Ty.Tbool) in
18591860
let qb = E.mk_eq ~iff defn ff in
18601861
let ff =
1861-
E.mk_forall name_base DStd.Loc.dummy binders [] qb
1862+
E.mk_forall name_base Loc.dummy binders [] qb
18621863
~toplevel:true ~decl_kind
18631864
in
18641865
assert (Var.Map.is_empty (E.free_vars ff Var.Map.empty));

src/lib/frontend/translate.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ val dty_to_ty : ?update:bool -> ?is_var:bool -> D_loop.DStd.Expr.ty -> Ty.t
3535
val make_form :
3636
string ->
3737
D_loop.DStd.Expr.term ->
38-
Dolmen.Std.Loc.loc ->
38+
Loc.t ->
3939
decl_kind:Expr.decl_kind ->
4040
Expr.t
4141

src/lib/reasoners/fun_sat.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module Make (_ : Theory.S) : sig
5151
val assume_th_elt : t -> Expr.th_elt -> Explanation.t -> t
5252

5353
val pred_def :
54-
t -> Expr.t -> string -> Explanation.t -> Dolmen.Std.Loc.loc -> t
54+
t -> Expr.t -> string -> Explanation.t -> Loc.t -> t
5555

5656
val unsat : t -> Expr.gformula -> Explanation.t
5757

src/lib/reasoners/sat_solver_sig.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ module type S = sig
114114
Expr.t ->
115115
string ->
116116
Explanation.t ->
117-
Dolmen.Std.Loc.loc ->
117+
Loc.t ->
118118
unit
119119
(** [pred_def env f] assumes a new predicate definition [f] in [env]. *)
120120

src/lib/reasoners/sat_solver_sig.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ module type S = sig
9494
Expr.t ->
9595
string ->
9696
Explanation.t ->
97-
Dolmen.Std.Loc.loc ->
97+
Loc.t ->
9898
unit
9999
(** [pred_def env f] assumes a new predicate definition [f] in [env]. *)
100100

src/lib/structures/commands.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type sat_decl_aux =
4141
| Pop of int
4242

4343
type sat_tdecl = {
44-
st_loc : Dolmen.Std.Loc.loc;
44+
st_loc : Loc.t;
4545
st_decl : sat_decl_aux
4646
}
4747

@@ -68,4 +68,3 @@ let print_aux fmt = function
6868
Format.fprintf fmt "%s %a" s Expr.print e
6969

7070
let print fmt decl = print_aux fmt decl.st_decl
71-

0 commit comments

Comments
 (0)