src/HOL/Tools/Sledgehammer/sledgehammer_isar_preplay.ML
changeset 55255 eceebcea3e00
parent 55253 cfd276a7dbeb
child 55256 6c317e374614
equal deleted inserted replaced
55254:2bc951e6761a 55255:eceebcea3e00
    14   type label = Sledgehammer_Isar_Proof.label
    14   type label = Sledgehammer_Isar_Proof.label
    15 
    15 
    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     {set_preplay_outcomes: label -> (proof_method * play_outcome Lazy.lazy) list -> unit,
    19     {preplay_step: Time.time -> proof_method -> isar_step -> play_outcome,
       
    20      set_preplay_outcomes: label -> (proof_method * play_outcome Lazy.lazy) list -> unit,
    20      preplay_outcome: label -> proof_method -> play_outcome Lazy.lazy,
    21      preplay_outcome: label -> proof_method -> play_outcome Lazy.lazy,
    21      preplay_quietly: Time.time -> isar_step -> play_outcome,
       
    22      overall_preplay_outcome: isar_proof -> play_outcome}
    22      overall_preplay_outcome: isar_proof -> play_outcome}
    23 
    23 
    24   val preplay_data_of_isar_proof : bool -> Proof.context -> string -> string -> Time.time ->
    24   val preplay_data_of_isar_proof : bool -> Proof.context -> string -> string -> Time.time ->
    25     isar_proof -> isar_preplay_data
    25     isar_proof -> isar_preplay_data
    26 end;
    26 end;
    93     | Blast_Method => blast_tac ctxt
    93     | Blast_Method => blast_tac ctxt
    94     | Algebra_Method => Groebner.algebra_tac [] [] ctxt
    94     | Algebra_Method => Groebner.algebra_tac [] [] ctxt
    95     | _ => raise Fail "Sledgehammer_Isar_Preplay: tac_of_method"))
    95     | _ => raise Fail "Sledgehammer_Isar_Preplay: tac_of_method"))
    96 
    96 
    97 (* main function for preplaying Isar steps; may throw exceptions *)
    97 (* main function for preplaying Isar steps; may throw exceptions *)
    98 fun preplay_raw debug type_enc lam_trans ctxt timeout meth
    98 fun raw_preplay_step debug type_enc lam_trans ctxt timeout meth
    99       (Prove (_, xs, _, t, subproofs, (fact_names, _))) =
    99       (Prove (_, xs, _, t, subproofs, (fact_names, _))) =
   100     let
   100     let
   101       val goal =
   101       val goal =
   102         (case xs of
   102         (case xs of
   103           [] => t
   103           [] => t
   135     end
   135     end
   136 
   136 
   137 type isar_preplay_data =
   137 type isar_preplay_data =
   138   {set_preplay_outcomes: label -> (proof_method * play_outcome Lazy.lazy) list -> unit,
   138   {set_preplay_outcomes: label -> (proof_method * play_outcome Lazy.lazy) list -> unit,
   139    preplay_outcome: label -> proof_method -> play_outcome Lazy.lazy,
   139    preplay_outcome: label -> proof_method -> play_outcome Lazy.lazy,
   140    preplay_quietly: Time.time -> isar_step -> play_outcome,
   140    preplay_step: Time.time -> proof_method -> isar_step -> play_outcome,
   141    overall_preplay_outcome: isar_proof -> play_outcome}
   141    overall_preplay_outcome: isar_proof -> play_outcome}
   142 
   142 
   143 fun enrich_context_with_local_facts proof ctxt =
   143 fun enrich_context_with_local_facts proof ctxt =
   144   let
   144   let
   145     val thy = Proof_Context.theory_of ctxt
   145     val thy = Proof_Context.theory_of ctxt
   174    "Slegehammer_Isar_Proof.relabel_isar_proof_canonically". *)
   174    "Slegehammer_Isar_Proof.relabel_isar_proof_canonically". *)
   175 fun preplay_data_of_isar_proof debug ctxt type_enc lam_trans preplay_timeout proof =
   175 fun preplay_data_of_isar_proof debug ctxt type_enc lam_trans preplay_timeout proof =
   176   let
   176   let
   177     val ctxt = enrich_context_with_local_facts proof ctxt
   177     val ctxt = enrich_context_with_local_facts proof ctxt
   178 
   178 
   179     fun preplay quietly timeout meth step =
   179     fun preplay_step timeout meth =
   180       preplay_raw debug type_enc lam_trans ctxt timeout meth step
   180       try (raw_preplay_step debug type_enc lam_trans ctxt timeout meth)
   181       handle exn =>
   181       #> the_default Play_Failed
   182         if Exn.is_interrupt exn then
       
   183           reraise exn
       
   184         else
       
   185           (if not quietly andalso debug then
       
   186              warning ("Preplay failure:\n " ^ @{make_string} step ^ "\n " ^ @{make_string} exn)
       
   187            else
       
   188              ();
       
   189            Play_Failed)
       
   190 
       
   191     (* preplay steps treating exceptions like timeouts *)
       
   192     fun preplay_quietly timeout (step as Prove (_, _, _, _, _, (_, meth :: _))) =
       
   193         preplay true timeout meth step
       
   194       | preplay_quietly _ _ = Played Time.zeroTime
       
   195 
   182 
   196     val preplay_tab = Unsynchronized.ref Canonical_Label_Tab.empty
   183     val preplay_tab = Unsynchronized.ref Canonical_Label_Tab.empty
   197 
   184 
   198     fun set_preplay_outcomes l meths_outcomes =
   185     fun set_preplay_outcomes l meths_outcomes =
   199       preplay_tab := Canonical_Label_Tab.map_entry l (fold (AList.update (op =)) meths_outcomes)
   186       preplay_tab := Canonical_Label_Tab.map_entry l (fold (AList.update (op =)) meths_outcomes)
   214     fun overall_preplay_outcome (Proof (_, _, steps)) =
   201     fun overall_preplay_outcome (Proof (_, _, steps)) =
   215       fold_isar_steps (merge_preplay_outcomes o result_of_step) steps (Played Time.zeroTime)
   202       fold_isar_steps (merge_preplay_outcomes o result_of_step) steps (Played Time.zeroTime)
   216 
   203 
   217     fun reset_preplay_outcomes (step as Prove (_, _, l, _, _, (_, meths))) =
   204     fun reset_preplay_outcomes (step as Prove (_, _, l, _, _, (_, meths))) =
   218         preplay_tab := Canonical_Label_Tab.update (l, map (fn meth =>
   205         preplay_tab := Canonical_Label_Tab.update (l, map (fn meth =>
   219             (meth, Lazy.lazy (fn () => preplay false preplay_timeout meth step))) meths)
   206             (meth, Lazy.lazy (fn () => preplay_step preplay_timeout meth step))) meths)
   220           (!preplay_tab)
   207           (!preplay_tab)
   221       | reset_preplay_outcomes _ = ()
   208       | reset_preplay_outcomes _ = ()
   222 
   209 
   223     val _ = fold_isar_steps (K o reset_preplay_outcomes) (steps_of_proof proof) ()
   210     val _ = fold_isar_steps (K o reset_preplay_outcomes) (steps_of_proof proof) ()
   224   in
   211   in
   225     {set_preplay_outcomes = set_preplay_outcomes,
   212     {preplay_step = preplay_step,
       
   213      set_preplay_outcomes = set_preplay_outcomes,
   226      preplay_outcome = preplay_outcome,
   214      preplay_outcome = preplay_outcome,
   227      preplay_quietly = preplay_quietly,
       
   228      overall_preplay_outcome = overall_preplay_outcome}
   215      overall_preplay_outcome = overall_preplay_outcome}
   229   end
   216   end
   230 
   217 
   231 end;
   218 end;