16 val trace : bool Config.T |
16 val trace : bool Config.T |
17 |
17 |
18 type isar_preplay_data |
18 type isar_preplay_data |
19 |
19 |
20 val enrich_context_with_local_facts : isar_proof -> Proof.context -> Proof.context |
20 val enrich_context_with_local_facts : isar_proof -> Proof.context -> Proof.context |
21 val preplay_isar_step_for_method : Proof.context -> bool -> Time.time -> proof_method -> |
21 val preplay_isar_step_for_method : Proof.context -> Time.time -> proof_method -> isar_step -> |
22 isar_step -> play_outcome |
22 play_outcome |
23 val preplay_isar_step : Proof.context -> bool -> Time.time -> proof_method list -> isar_step -> |
23 val preplay_isar_step : Proof.context -> Time.time -> proof_method list -> isar_step -> |
24 (proof_method * play_outcome) list |
24 (proof_method * play_outcome) list |
25 val set_preplay_outcomes_of_isar_step : Proof.context -> bool -> Time.time -> |
25 val set_preplay_outcomes_of_isar_step : Proof.context -> Time.time -> |
26 isar_preplay_data Unsynchronized.ref -> isar_step -> (proof_method * play_outcome) list -> unit |
26 isar_preplay_data Unsynchronized.ref -> isar_step -> (proof_method * play_outcome) list -> unit |
27 val forced_intermediate_preplay_outcome_of_isar_step : isar_preplay_data -> label -> play_outcome |
27 val forced_intermediate_preplay_outcome_of_isar_step : isar_preplay_data -> label -> play_outcome |
28 val preplay_outcome_of_isar_step_for_method : isar_preplay_data -> label -> proof_method -> |
28 val preplay_outcome_of_isar_step_for_method : isar_preplay_data -> label -> proof_method -> |
29 play_outcome Lazy.lazy |
29 play_outcome Lazy.lazy |
30 val fastest_method_of_isar_step : isar_preplay_data -> label -> proof_method |
30 val fastest_method_of_isar_step : isar_preplay_data -> label -> proof_method |
99 |> subst_free subst |
99 |> subst_free subst |
100 |> Skip_Proof.make_thm thy |
100 |> Skip_Proof.make_thm thy |
101 end |
101 end |
102 |
102 |
103 (* may throw exceptions *) |
103 (* may throw exceptions *) |
104 fun raw_preplay_step_for_method ctxt debug timeout meth |
104 fun raw_preplay_step_for_method ctxt timeout meth (Prove (_, xs, _, t, subproofs, facts, _, _)) = |
105 (Prove (_, xs, _, t, subproofs, facts, _, _)) = |
|
106 let |
105 let |
107 val goal = |
106 val goal = |
108 (case xs of |
107 (case xs of |
109 [] => t |
108 [] => t |
110 | _ => |
109 | _ => |
127 resolve_fact_names ctxt facts |
126 resolve_fact_names ctxt facts |
128 |>> append (map (thm_of_proof ctxt) subproofs) |
127 |>> append (map (thm_of_proof ctxt) subproofs) |
129 |
128 |
130 fun prove () = |
129 fun prove () = |
131 Goal.prove ctxt [] [] goal (fn {context = ctxt, ...} => |
130 Goal.prove ctxt [] [] goal (fn {context = ctxt, ...} => |
132 HEADGOAL (tac_of_proof_method ctxt debug assmsp meth)) |
131 HEADGOAL (tac_of_proof_method ctxt assmsp meth)) |
133 handle ERROR msg => error ("Preplay error: " ^ msg) |
132 handle ERROR msg => error ("Preplay error: " ^ msg) |
134 |
133 |
135 val play_outcome = take_time timeout prove () |
134 val play_outcome = take_time timeout prove () |
136 in |
135 in |
137 if Config.get ctxt trace then preplay_trace ctxt assmsp goal play_outcome else (); |
136 if Config.get ctxt trace then preplay_trace ctxt assmsp goal play_outcome else (); |
138 play_outcome |
137 play_outcome |
139 end |
138 end |
140 |
139 |
141 fun preplay_isar_step_for_method ctxt debug timeout meth = |
140 fun preplay_isar_step_for_method ctxt timeout meth = |
142 try (raw_preplay_step_for_method ctxt debug timeout meth) #> the_default Play_Failed |
141 try (raw_preplay_step_for_method ctxt timeout meth) #> the_default Play_Failed |
143 |
142 |
144 fun preplay_isar_step ctxt debug timeout hopeless step = |
143 fun preplay_isar_step ctxt timeout hopeless step = |
145 let |
144 let |
146 fun try_method meth = |
145 fun try_method meth = |
147 (case preplay_isar_step_for_method ctxt debug timeout meth step of |
146 (case preplay_isar_step_for_method ctxt timeout meth step of |
148 outcome as Played _ => SOME (meth, outcome) |
147 outcome as Played _ => SOME (meth, outcome) |
149 | _ => NONE) |
148 | _ => NONE) |
150 |
149 |
151 val meths = proof_methods_of_isar_step step |> subtract (op =) hopeless |
150 val meths = proof_methods_of_isar_step step |> subtract (op =) hopeless |
152 in |
151 in |
162 | add_preplay_outcomes _ Play_Failed = Play_Failed |
161 | add_preplay_outcomes _ Play_Failed = Play_Failed |
163 | add_preplay_outcomes (Played time1) (Played time2) = Played (Time.+ (time1, time2)) |
162 | add_preplay_outcomes (Played time1) (Played time2) = Played (Time.+ (time1, time2)) |
164 | add_preplay_outcomes play1 play2 = |
163 | add_preplay_outcomes play1 play2 = |
165 Play_Timed_Out (Time.+ (pairself time_of_play (play1, play2))) |
164 Play_Timed_Out (Time.+ (pairself time_of_play (play1, play2))) |
166 |
165 |
167 fun set_preplay_outcomes_of_isar_step ctxt debug timeout preplay_data |
166 fun set_preplay_outcomes_of_isar_step ctxt timeout preplay_data |
168 (step as Prove (_, _, l, _, _, _, meths, _)) meths_outcomes0 = |
167 (step as Prove (_, _, l, _, _, _, meths, _)) meths_outcomes0 = |
169 let |
168 let |
170 fun lazy_preplay meth = |
169 fun lazy_preplay meth = |
171 Lazy.lazy (fn () => preplay_isar_step_for_method ctxt debug timeout meth step) |
170 Lazy.lazy (fn () => preplay_isar_step_for_method ctxt timeout meth step) |
172 val meths_outcomes = meths_outcomes0 |
171 val meths_outcomes = meths_outcomes0 |
173 |> map (apsnd Lazy.value) |
172 |> map (apsnd Lazy.value) |
174 |> fold (fn meth => AList.default (op =) (meth, lazy_preplay meth)) meths |
173 |> fold (fn meth => AList.default (op =) (meth, lazy_preplay meth)) meths |
175 in |
174 in |
176 preplay_data := Canonical_Label_Tab.update (l, fold (AList.update (op =)) meths_outcomes []) |
175 preplay_data := Canonical_Label_Tab.update (l, fold (AList.update (op =)) meths_outcomes []) |
177 (!preplay_data) |
176 (!preplay_data) |
178 end |
177 end |
179 | set_preplay_outcomes_of_isar_step _ _ _ _ _ _ = () |
178 | set_preplay_outcomes_of_isar_step _ _ _ _ _ = () |
180 |
179 |
181 fun peek_at_outcome outcome = |
180 fun peek_at_outcome outcome = |
182 if Lazy.is_finished outcome then Lazy.force outcome else Play_Timed_Out Time.zeroTime |
181 if Lazy.is_finished outcome then Lazy.force outcome else Play_Timed_Out Time.zeroTime |
183 |
182 |
184 fun get_best_method_outcome force = |
183 fun get_best_method_outcome force = |