src/Pure/thm.ML
changeset 28446 a01de3b3fa2e
parent 28441 9b0daffc4054
child 28624 d983515e5cdf
equal deleted inserted replaced
28445:526b8adcd117 28446:a01de3b3fa2e
   150   val incr_indexes_cterm: int -> cterm -> cterm
   150   val incr_indexes_cterm: int -> cterm -> cterm
   151   val varifyT: thm -> thm
   151   val varifyT: thm -> thm
   152   val varifyT': (string * sort) list -> thm -> ((string * sort) * indexname) list * thm
   152   val varifyT': (string * sort) list -> thm -> ((string * sort) * indexname) list * thm
   153   val freezeT: thm -> thm
   153   val freezeT: thm -> thm
   154   val join_futures: theory -> unit
   154   val join_futures: theory -> unit
   155   val promise: (unit -> thm) -> cterm -> thm
   155   val future: (unit -> thm) -> cterm -> thm
   156   val proof_of: thm -> Proofterm.proof
   156   val proof_of: thm -> Proofterm.proof
   157   val extern_oracles: theory -> xstring list
   157   val extern_oracles: theory -> xstring list
   158   val add_oracle: bstring * ('a -> cterm) -> theory -> (string * ('a -> thm)) * theory
   158   val add_oracle: bstring * ('a -> cterm) -> theory -> (string * ('a -> thm)) * theory
   159 end;
   159 end;
   160 
   160 
  1623         in finished end)
  1623         in finished end)
  1624       |> Future.join_results |> Exn.release_all |> null);
  1624       |> Future.join_results |> Exn.release_all |> null);
  1625   in while not (joined ()) do () end;
  1625   in while not (joined ()) do () end;
  1626 
  1626 
  1627 
  1627 
  1628 (* promise *)
  1628 (* future rule *)
  1629 
  1629 
  1630 fun promise_result i orig_thy orig_shyps orig_prop raw_thm =
  1630 fun future_result i orig_thy orig_shyps orig_prop raw_thm =
  1631   let
  1631   let
  1632     val _ = Theory.check_thy orig_thy;
  1632     val _ = Theory.check_thy orig_thy;
  1633     val thm = strip_shyps (transfer orig_thy raw_thm);
  1633     val thm = strip_shyps (transfer orig_thy raw_thm);
  1634     val _ = Theory.check_thy orig_thy;
  1634     val _ = Theory.check_thy orig_thy;
  1635     fun err msg = raise THM ("promise_result: " ^ msg, 0, [thm]);
  1635     fun err msg = raise THM ("future_result: " ^ msg, 0, [thm]);
  1636 
  1636 
  1637     val Thm (Deriv {promises, ...}, {shyps, hyps, tpairs, prop, ...}) = thm;
  1637     val Thm (Deriv {promises, ...}, {shyps, hyps, tpairs, prop, ...}) = thm;
  1638     val _ = prop aconv orig_prop orelse err "bad prop";
  1638     val _ = prop aconv orig_prop orelse err "bad prop";
  1639     val _ = null tpairs orelse err "bad tpairs";
  1639     val _ = null tpairs orelse err "bad tpairs";
  1640     val _ = null hyps orelse err "bad hyps";
  1640     val _ = null hyps orelse err "bad hyps";
  1641     val _ = Sorts.subset (shyps, orig_shyps) orelse err "bad shyps";
  1641     val _ = Sorts.subset (shyps, orig_shyps) orelse err "bad shyps";
  1642     val _ = forall (fn (j, _) => j < i) promises orelse err "bad dependencies";
  1642     val _ = forall (fn (j, _) => j < i) promises orelse err "bad dependencies";
  1643   in thm end;
  1643   in thm end;
  1644 
  1644 
  1645 fun promise make_result ct =
  1645 fun future make_result ct =
  1646   let
  1646   let
  1647     val {thy_ref = thy_ref, t = prop, T, maxidx, sorts} = rep_cterm ct;
  1647     val {thy_ref = thy_ref, t = prop, T, maxidx, sorts} = rep_cterm ct;
  1648     val thy = Context.reject_draft (Theory.deref thy_ref);
  1648     val thy = Context.reject_draft (Theory.deref thy_ref);
  1649     val _ = T <> propT andalso raise CTERM ("promise: prop expected", [ct]);
  1649     val _ = T <> propT andalso raise CTERM ("future: prop expected", [ct]);
  1650 
  1650 
  1651     val i = serial ();
  1651     val i = serial ();
  1652     val future = Future.fork_background (promise_result i thy sorts prop o make_result);
  1652     val future = Future.fork_background (future_result i thy sorts prop o make_result);
  1653     val _ = add_future thy future;
  1653     val _ = add_future thy future;
  1654   in
  1654   in
  1655     Thm (make_deriv false [(i, future)] (Pt.promise_proof i prop),
  1655     Thm (make_deriv false [(i, future)] (Pt.promise_proof i prop),
  1656      {thy_ref = thy_ref,
  1656      {thy_ref = thy_ref,
  1657       tags = [],
  1657       tags = [],
  1661       tpairs = [],
  1661       tpairs = [],
  1662       prop = prop})
  1662       prop = prop})
  1663   end;
  1663   end;
  1664 
  1664 
  1665 
  1665 
  1666 (* fulfill *)
  1666 (* join_deriv *)
  1667 
  1667 
  1668 fun fulfill (thm as Thm (Deriv {oracle, proof, promises}, args)) =
  1668 fun join_deriv (thm as Thm (Deriv {oracle, proof, promises}, args)) =
  1669   let
  1669   let
  1670     val _ = Exn.release_all (Future.join_results (rev (map #2 promises)));
  1670     val _ = Exn.release_all (Future.join_results (rev (map #2 promises)));
  1671     val results = map (apsnd Future.join) promises;
  1671     val results = map (apsnd Future.join) promises;
  1672     val proofs = fold (fn (i, Thm (Deriv {proof = prf, ...}, _)) => Inttab.update (i, prf))
  1672     val proofs = fold (fn (i, Thm (Deriv {proof = prf, ...}, _)) => Inttab.update (i, prf))
  1673       results Inttab.empty;
  1673       results Inttab.empty;
  1674     val ora = oracle orelse exists (oracle_of o #2) results;
  1674     val ora = oracle orelse exists (oracle_of o #2) results;
  1675   in Thm (make_deriv ora [] (Pt.fulfill proofs proof), args) end;
  1675   in Thm (make_deriv ora [] (Pt.fulfill proofs proof), args) end;
  1676 
  1676 
  1677 val proof_of = fulfill #> (fn Thm (Deriv {proof, ...}, _) => proof);
  1677 val proof_of = join_deriv #> (fn Thm (Deriv {proof, ...}, _) => proof);
  1678 
  1678 
  1679 
  1679 
  1680 
  1680 
  1681 (*** Oracles ***)
  1681 (*** Oracles ***)
  1682 
  1682