aboutsummaryrefslogtreecommitdiff
path: root/clib/cMap.ml
diff options
context:
space:
mode:
authorGaëtan Gilbert2019-06-04 14:39:29 +0200
committerGaëtan Gilbert2019-10-24 16:33:26 +0200
commitd13e7e924437b043f83b6a47bfefda69379264b7 (patch)
tree06cbf24074c8c8e1803bcaad8c4e297d15149ca9 /clib/cMap.ml
parent4c779c4fee1134c5d632885de60db73d56021df4 (diff)
Raise an anomaly when looking up unknown constant/inductive
If you have access to a kernel name you also should have the environment in which it is defined, barring hacks. In order to disfavor hacks we make the standard lookups raise anomalies so that people are forced to admit they rely on the internals of the environment. We find that hackers operated on the code for side effects, for finding inductive schemes, for simpl and for Print Assumptions. They attempted to operate on funind but the error handling code they wrote would have raised another Not_found instead of being useful. All these uses are indeed hacky so I am satisfied that we are not forcing new hacks on callers.
Diffstat (limited to 'clib/cMap.ml')
-rw-r--r--clib/cMap.ml10
1 files changed, 9 insertions, 1 deletions
diff --git a/clib/cMap.ml b/clib/cMap.ml
index baac892b9e..8d822667c3 100644
--- a/clib/cMap.ml
+++ b/clib/cMap.ml
@@ -58,6 +58,7 @@ module MapExt (M : Map.OrderedType) :
sig
type 'a map = 'a Map.Make(M).t
val set : M.t -> 'a -> 'a map -> 'a map
+ val get : M.t -> 'a map -> 'a
val modify : M.t -> (M.t -> 'a -> 'a) -> 'a map -> 'a map
val domain : 'a map -> Set.Make(M).t
val bind : (M.t -> 'a) -> Set.Make(M).t -> 'a map
@@ -124,6 +125,14 @@ struct
if r == r' then s
else map_inj (MNode {l; v=k'; d=v'; r=r'; h})
+ let rec get k (s:'a map) : 'a = match map_prj s with
+ | MEmpty -> assert false
+ | MNode {l; v=k'; d=v; r; h} ->
+ let c = M.compare k k' in
+ if c < 0 then get k l
+ else if c = 0 then v
+ else get k r
+
let rec modify k f (s : 'a map) : 'a map = match map_prj s with
| MEmpty -> raise Not_found
| MNode {l; v; d; r; h} ->
@@ -324,5 +333,4 @@ module Make(M : Map.OrderedType) =
struct
include Map.Make(M)
include MapExt(M)
- let get k m = try find k m with Not_found -> assert false
end