(************************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) (* t val create : string -> 'a tag val eq : 'a tag -> 'b tag -> ('a, 'b) CSig.eq option val repr : 'a tag -> string val dump : unit -> (int * string) list end module Make(M : CSig.EmptyS) = struct (* Dynamics, programmed with DANGER !!! *) type 'a tag = int type t = Dyn : 'a tag * 'a -> t let dyntab = ref (Int.Map.empty : string Int.Map.t) (** Instead of working with tags as strings, which are costly, we use their hash. We ensure unicity of the hash in the [create] function. If ever a collision occurs, which is unlikely, it is sufficient to tweak the offending dynamic tag. *) let create (s : string) = let hash = Hashtbl.hash s in let () = if Int.Map.mem hash !dyntab then let old = Int.Map.find hash !dyntab in let () = Printf.eprintf "Dynamic tag collision: %s vs. %s\n%!" s old in assert false in let () = dyntab := Int.Map.add hash s !dyntab in hash let eq : 'a 'b. 'a tag -> 'b tag -> ('a, 'b) CSig.eq option = fun h1 h2 -> if Int.equal h1 h2 then Some (Obj.magic CSig.Refl) else None let repr s = try Int.Map.find s !dyntab with Not_found -> let () = Printf.eprintf "Unknown dynamic tag %i\n%!" s in assert false let dump () = Int.Map.bindings !dyntab end