Skip to content

Commit 8e87752

Browse files
committed
normalize the result of case_rwlist and cache it.
A huge amount of time is spent calling SPEC_ALL when adding the results of case_rwlist to the rewrites or simpset. By caching this expensive operation is now only done whenever the TypeBase is updated.
1 parent 76fc328 commit 8e87752

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/basicProof/BasicProvers.sml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,17 +693,37 @@ fun PURE_FULL_CASE_TAC (g as (asl,w)) =
693693
in Cases_on `^t` end g;
694694

695695
local
696-
fun tot f x = f x handle HOL_ERR _ => NONE
697-
in
696+
697+
fun tot f x = f x handle HOL_ERR _ => NONE
698+
698699
fun case_rws tyi =
699700
List.mapPartial I
700701
[Lib.total TypeBasePure.case_def_of tyi,
701702
tot TypeBasePure.distinct_of tyi,
702703
tot TypeBasePure.one_one_of tyi]
703704

704-
fun case_rwlist () =
705-
itlist (fn tyi => fn rws => case_rws tyi @ rws)
706-
(TypeBase.elts()) [];
705+
fun decompose (th::res) =
706+
let val th = SPEC_ALL th
707+
val t = concl th
708+
in
709+
if is_conj t then (let val (th1,th2) = CONJ_PAIR th
710+
in decompose (th1::th2::res) end)
711+
else (th::decompose res)
712+
end
713+
| decompose [] = []
714+
715+
val cache = ref (List.concat (map case_rws (TypeBase.elts ())))
716+
717+
fun update_cache tyinfo =
718+
let val thms = decompose (case_rws tyinfo)
719+
in
720+
cache := List.revAppend (thms,!cache)
721+
end
722+
in
723+
724+
val _ = TypeBase.register_update_fn (fn tyinfo => (update_cache tyinfo;tyinfo))
725+
726+
fun case_rwlist () = !cache
707727

708728
(* Add the rewrites into a simpset to avoid re-processing them when
709729
* (PURE_CASE_SIMP_CONV rws) is called multiple times by EVERY_CASE_TAC. This

0 commit comments

Comments
 (0)