diff options
author | Matthieu Sozeau <matthieu.sozeau@inria.fr> | 2014-09-24 11:16:11 +0200 |
---|---|---|
committer | Matthieu Sozeau <matthieu.sozeau@inria.fr> | 2014-09-27 21:22:50 +0200 |
commit | ad2e11471dbfc0894b4fdfedd895e7f0a75bd930 (patch) | |
tree | 20c6b4107dd5a5a584e060920922289d16ce0cbc /library | |
parent | 929cba74dc2ba2d1b232b61fb3539babad9e7c76 (diff) |
First version of keyed subterm selection in unification.
Diffstat (limited to 'library')
-rw-r--r-- | library/keys.ml | 46 | ||||
-rw-r--r-- | library/keys.mli | 15 | ||||
-rw-r--r-- | library/library.mllib | 1 |
3 files changed, 62 insertions, 0 deletions
diff --git a/library/keys.ml b/library/keys.ml new file mode 100644 index 000000000..5c295a385 --- /dev/null +++ b/library/keys.ml @@ -0,0 +1,46 @@ +open Globnames +open Term +open Libobject + +(* Union-find structure for references to be considered equivalent *) + +module RefUF = Unionfind.Make(Refset)(Refmap) + +let keys = (* Summary.ref ( *)RefUF.create ()(* ) ~name:"Keys_decl" *) + +let add_key k v = RefUF.union k v keys + +let equiv_keys k k' = RefUF.find k keys == RefUF.find k' keys + +(** Registration of keys as an object *) + +let load_key _ (_,(ref,ref')) = + add_key ref ref' + +let cache_key o = + load_key 1 o + +let subst_key (subst,(ref,ref')) = + (subst_global_reference subst ref, + subst_global_reference subst ref') + +let discharge_key (_,refs) = + match refs with + | VarRef _, _ | _, VarRef _ -> None + | ref, ref' -> Some (pop_global_reference ref, pop_global_reference ref') + +let rebuild_key (ref,ref') = (ref, ref') + +type key_obj = global_reference * global_reference + +let inKeys : key_obj -> obj = + declare_object {(default_object "KEYS") with + cache_function = cache_key; + load_function = load_key; + subst_function = subst_key; + classify_function = (fun x -> Substitute x); + discharge_function = discharge_key; + rebuild_function = rebuild_key } + +let declare_keys ref ref' = + Lib.add_anonymous_leaf (inKeys (ref,ref')) diff --git a/library/keys.mli b/library/keys.mli new file mode 100644 index 000000000..4e6a803e4 --- /dev/null +++ b/library/keys.mli @@ -0,0 +1,15 @@ +(************************************************************************) +(* v * The Coq Proof Assistant / The Coq Development Team *) +(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2012 *) +(* \VV/ **************************************************************) +(* // * This file is distributed under the terms of the *) +(* * GNU Lesser General Public License Version 2.1 *) +(************************************************************************) + +open Globnames + +val declare_keys : global_reference -> global_reference -> unit +(** Declare two keys as being equivalent. *) + +val equiv_keys : global_reference -> global_reference -> bool +(** Check equivalence of keys. *) diff --git a/library/library.mllib b/library/library.mllib index 6a58a1057..04244160b 100644 --- a/library/library.mllib +++ b/library/library.mllib @@ -17,3 +17,4 @@ Goptions Decls Heads Assumptions + |