aboutsummaryrefslogtreecommitdiff
path: root/vernac/search.ml
diff options
context:
space:
mode:
authorPierre-Marie Pédrot2019-12-12 18:44:06 +0100
committerPierre-Marie Pédrot2019-12-22 14:03:06 +0100
commitc2341feb58a233598658eeb68a08395b12715b2a (patch)
treeba5d4caa869298be94beda0e40767107814954b3 /vernac/search.ml
parent1de15982dceaf28740f49f1d6cba61a5473656b0 (diff)
Remove the hacks relying on hardwired libobject tags.
The patch is done in a minimal way. The hacks are turned into a new kind of safer hacks, but hacks nonetheless. They should go away at some point, but the current patch is focussed on the removal of Libobject cruft, not making the dirty code of its upper-layer callers any cleaner.
Diffstat (limited to 'vernac/search.ml')
-rw-r--r--vernac/search.ml21
1 files changed, 16 insertions, 5 deletions
diff --git a/vernac/search.ml b/vernac/search.ml
index 364dae7152..b8825c3b29 100644
--- a/vernac/search.ml
+++ b/vernac/search.ml
@@ -71,6 +71,14 @@ let iter_hypothesis ?pstate glnum (fn : GlobRef.t -> env -> constr -> unit) =
let pfctxt = named_context e in
iter_named_context_name_type iter_hyp pfctxt
+(* FIXME: this is a Libobject hack that should be replaced with a proper
+ registration mechanism. *)
+module DynHandle = Libobject.Dyn.Map(struct type 'a t = 'a -> unit end)
+
+let handle h (Libobject.Dyn.Dyn (tag, o)) = match DynHandle.find tag h with
+| f -> f o
+| exception Not_found -> ()
+
(* General search over declarations *)
let iter_declarations (fn : GlobRef.t -> env -> constr -> unit) =
let env = Global.env () in
@@ -78,13 +86,14 @@ let iter_declarations (fn : GlobRef.t -> env -> constr -> unit) =
(Environ.named_context env);
let iter_obj (sp, kn) lobj = match lobj with
| AtomicObject o ->
- begin match object_tag o with
- | "CONSTANT" ->
+ let handler =
+ DynHandle.add Declare.Internal.objConstant begin fun _ ->
let cst = Global.constant_of_delta_kn kn in
let gr = GlobRef.ConstRef cst in
let (typ, _) = Typeops.type_of_global_in_context (Global.env ()) gr in
fn gr env typ
- | "INDUCTIVE" ->
+ end @@
+ DynHandle.add DeclareInd.Internal.objInductive begin fun _ ->
let mind = Global.mind_of_delta_kn kn in
let mib = Global.lookup_mind mind in
let iter_packet i mip =
@@ -97,8 +106,10 @@ let iter_declarations (fn : GlobRef.t -> env -> constr -> unit) =
iter_constructors ind u fn env len
in
Array.iteri iter_packet mib.mind_packets
- | _ -> ()
- end
+ end @@
+ DynHandle.empty
+ in
+ handle handler o
| _ -> ()
in
try Declaremods.iter_all_segments iter_obj