8 sig |
8 sig |
9 val facts_of: theory -> Facts.T |
9 val facts_of: theory -> Facts.T |
10 val intern_fact: theory -> xstring -> string |
10 val intern_fact: theory -> xstring -> string |
11 val defined_fact: theory -> string -> bool |
11 val defined_fact: theory -> string -> bool |
12 val hide_fact: bool -> string -> theory -> theory |
12 val hide_fact: bool -> string -> theory -> theory |
13 val join_proofs: theory -> exn list |
13 val join_proofs: theory -> unit |
14 val cancel_proofs: theory -> unit |
|
15 val get_fact: Context.generic -> theory -> Facts.ref -> thm list |
14 val get_fact: Context.generic -> theory -> Facts.ref -> thm list |
16 val get_thms: theory -> xstring -> thm list |
15 val get_thms: theory -> xstring -> thm list |
17 val get_thm: theory -> xstring -> thm |
16 val get_thm: theory -> xstring -> thm |
18 val all_thms_of: theory -> (string * thm) list |
17 val all_thms_of: theory -> (string * thm) list |
19 val map_facts: ('a -> 'b) -> ('c * ('a list * 'd) list) list -> ('c * ('b list * 'd) list) list |
18 val map_facts: ('a -> 'b) -> ('c * ('a list * 'd) list) list -> ('c * ('b list * 'd) list) list |
57 |
56 |
58 (** theory data **) |
57 (** theory data **) |
59 |
58 |
60 structure FactsData = TheoryDataFun |
59 structure FactsData = TheoryDataFun |
61 ( |
60 ( |
62 type T = Facts.T * (unit lazy list * Task_Queue.group Inttab.table); |
61 type T = Facts.T * thm list; |
63 val empty = (Facts.empty, ([], Inttab.empty)); |
62 val empty = (Facts.empty, []); |
64 val copy = I; |
63 val copy = I; |
65 fun extend (facts, _) = (facts, ([], Inttab.empty)); |
64 fun extend (facts, _) = (facts, []); |
66 fun merge _ ((facts1, _), (facts2, _)) = (Facts.merge (facts1, facts2), ([], Inttab.empty)); |
65 fun merge _ ((facts1, _), (facts2, _)) = (Facts.merge (facts1, facts2), []); |
67 ); |
66 ); |
68 |
67 |
69 |
68 |
70 (* facts *) |
69 (* facts *) |
71 |
70 |
77 fun hide_fact fully name = FactsData.map (apfst (Facts.hide fully name)); |
76 fun hide_fact fully name = FactsData.map (apfst (Facts.hide fully name)); |
78 |
77 |
79 |
78 |
80 (* proofs *) |
79 (* proofs *) |
81 |
80 |
82 fun lazy_proof thm = Lazy.lazy (fn () => Thm.join_proof thm); |
81 fun register_proofs (thy, thms) = (FactsData.map (apsnd (append thms)) thy, thms); |
83 |
82 |
84 fun join_proofs thy = |
83 fun join_proofs thy = Thm.join_proofs (rev (#2 (FactsData.get thy))); |
85 map_filter (Exn.get_exn o Lazy.force_result) (rev (#1 (#2 (FactsData.get thy)))); |
|
86 |
|
87 fun cancel_proofs thy = |
|
88 Inttab.fold (fn (_, group) => fn () => Future.cancel_group group) |
|
89 (#2 (#2 (FactsData.get thy))) (); |
|
90 |
84 |
91 |
85 |
92 |
86 |
93 (** retrieve theorems **) |
87 (** retrieve theorems **) |
94 |
88 |
144 burrow_fact (name_thms true official pos name) fact; |
138 burrow_fact (name_thms true official pos name) fact; |
145 |
139 |
146 |
140 |
147 (* enter_thms *) |
141 (* enter_thms *) |
148 |
142 |
149 val pending_groups = |
|
150 Thm.promises_of #> fold (fn (_, future) => |
|
151 if Future.is_finished future then I |
|
152 else Inttab.update (`Task_Queue.group_id (Future.group_of future))); |
|
153 |
|
154 fun enter_proofs (thy, thms) = |
|
155 (FactsData.map (apsnd (fn (proofs, groups) => |
|
156 (fold (cons o lazy_proof) thms proofs, fold pending_groups thms groups))) thy, thms); |
|
157 |
|
158 fun enter_thms pre_name post_name app_att (b, thms) thy = |
143 fun enter_thms pre_name post_name app_att (b, thms) thy = |
159 if Binding.is_empty b |
144 if Binding.is_empty b |
160 then swap (enter_proofs (app_att (thy, thms))) |
145 then swap (register_proofs (app_att (thy, thms))) |
161 else |
146 else |
162 let |
147 let |
163 val naming = Sign.naming_of thy; |
148 val naming = Sign.naming_of thy; |
164 val name = NameSpace.full_name naming b; |
149 val name = NameSpace.full_name naming b; |
165 val (thy', thms') = |
150 val (thy', thms') = |
166 enter_proofs (apsnd (post_name name) (app_att (thy, pre_name name thms))); |
151 register_proofs (apsnd (post_name name) (app_att (thy, pre_name name thms))); |
167 val thms'' = map (Thm.transfer thy') thms'; |
152 val thms'' = map (Thm.transfer thy') thms'; |
168 val thy'' = thy' |> (FactsData.map o apfst) (Facts.add_global naming (b, thms'') #> snd); |
153 val thy'' = thy' |> (FactsData.map o apfst) (Facts.add_global naming (b, thms'') #> snd); |
169 in (thms'', thy'') end; |
154 in (thms'', thy'') end; |
170 |
155 |
171 |
156 |