summaryrefslogtreecommitdiff
path: root/kernel/conv_oracle.ml
diff options
context:
space:
mode:
authorGravatar Enrico Tassi <gareuselesinge@debian.org>2015-01-25 14:42:51 +0100
committerGravatar Enrico Tassi <gareuselesinge@debian.org>2015-01-25 14:42:51 +0100
commit7cfc4e5146be5666419451bdd516f1f3f264d24a (patch)
treee4197645da03dc3c7cc84e434cc31d0a0cca7056 /kernel/conv_oracle.ml
parent420f78b2caeaaddc6fe484565b2d0e49c66888e5 (diff)
Imported Upstream version 8.5~beta1+dfsg
Diffstat (limited to 'kernel/conv_oracle.ml')
-rw-r--r--kernel/conv_oracle.ml80
1 files changed, 52 insertions, 28 deletions
diff --git a/kernel/conv_oracle.ml b/kernel/conv_oracle.ml
index 26b7a397..3b01538b 100644
--- a/kernel/conv_oracle.ml
+++ b/kernel/conv_oracle.ml
@@ -1,6 +1,6 @@
(************************************************************************)
(* v * The Coq Proof Assistant / The Coq Development Team *)
-(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2014 *)
+(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2015 *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
@@ -18,52 +18,76 @@ open Names
*)
type level = Expand | Level of int | Opaque
let default = Level 0
+let is_default = function
+| Level 0 -> true
+| _ -> false
let transparent = default
+let is_transparent = function
+| Level 0 -> true
+| _ -> false
-type oracle = level Idmap.t * level Cmap.t
+type oracle = {
+ var_opacity : level Id.Map.t;
+ cst_opacity : level Cmap.t;
+ var_trstate : Id.Pred.t;
+ cst_trstate : Cpred.t;
+}
-let var_opacity = ref Idmap.empty
-let cst_opacity = ref Cmap.empty
+let empty = {
+ var_opacity = Id.Map.empty;
+ cst_opacity = Cmap.empty;
+ var_trstate = Id.Pred.full;
+ cst_trstate = Cpred.full;
+}
-let get_strategy = function
+let get_strategy { var_opacity; cst_opacity } f = function
| VarKey id ->
- (try Idmap.find id !var_opacity
+ (try Id.Map.find id var_opacity
with Not_found -> default)
| ConstKey c ->
- (try Cmap.find c !cst_opacity
+ (try Cmap.find (f c) cst_opacity
with Not_found -> default)
| RelKey _ -> Expand
-let set_strategy k l =
+let set_strategy ({ var_opacity; cst_opacity } as oracle) k l =
match k with
| VarKey id ->
- var_opacity :=
- if l=default then Idmap.remove id !var_opacity
- else Idmap.add id l !var_opacity
+ let var_opacity =
+ if is_default l then Id.Map.remove id var_opacity
+ else Id.Map.add id l var_opacity
+ in
+ let var_trstate = match l with
+ | Opaque -> Id.Pred.remove id oracle.var_trstate
+ | _ -> Id.Pred.add id oracle.var_trstate
+ in
+ { oracle with var_opacity; var_trstate; }
| ConstKey c ->
- cst_opacity :=
- if l=default then Cmap.remove c !cst_opacity
- else Cmap.add c l !cst_opacity
- | RelKey _ -> Util.error "set_strategy: RelKey"
+ let cst_opacity =
+ if is_default l then Cmap.remove c cst_opacity
+ else Cmap.add c l cst_opacity
+ in
+ let cst_trstate = match l with
+ | Opaque -> Cpred.remove c oracle.cst_trstate
+ | _ -> Cpred.add c oracle.cst_trstate
+ in
+ { oracle with cst_opacity; cst_trstate; }
+ | RelKey _ -> Errors.error "set_strategy: RelKey"
-let get_transp_state () =
- (Idmap.fold
- (fun id l ts -> if l=Opaque then Idpred.remove id ts else ts)
- !var_opacity Idpred.full,
- Cmap.fold
- (fun c l ts -> if l=Opaque then Cpred.remove c ts else ts)
- !cst_opacity Cpred.full)
+let fold_strategy f { var_opacity; cst_opacity; } accu =
+ let fvar id lvl accu = f (VarKey id) lvl accu in
+ let fcst cst lvl accu = f (ConstKey cst) lvl accu in
+ let accu = Id.Map.fold fvar var_opacity accu in
+ Cmap.fold fcst cst_opacity accu
+
+let get_transp_state { var_trstate; cst_trstate } = (var_trstate, cst_trstate)
(* Unfold the first constant only if it is "more transparent" than the
second one. In case of tie, expand the second one. *)
-let oracle_order l2r k1 k2 =
- match get_strategy k1, get_strategy k2 with
+let oracle_order f o l2r k1 k2 =
+ match get_strategy o f k1, get_strategy o f k2 with
| Expand, _ -> true
| Level n1, Opaque -> true
| Level n1, Level n2 -> n1 < n2
| _ -> l2r (* use recommended default *)
-(* summary operations *)
-let init() = (cst_opacity := Cmap.empty; var_opacity := Idmap.empty)
-let freeze () = (!var_opacity, !cst_opacity)
-let unfreeze (vo,co) = (cst_opacity := co; var_opacity := vo)
+let get_strategy o = get_strategy o (fun x -> x)