| author | wenzelm | 
| Fri, 07 Dec 2012 16:33:17 +0100 | |
| changeset 50423 | 027d405951c8 | 
| parent 50121 | 97d2b77313a0 | 
| child 50430 | 702278df3b57 | 
| permissions | -rw-r--r-- | 
| 30173 
eabece26b89b
moved isabelle_process.ML, isabelle_process.scala, isar.ML, session.ML to Pure/System/ (together with associated Isar commands);
 wenzelm parents: 
29435diff
changeset | 1 | (* Title: Pure/System/session.ML | 
| 6346 | 2 | Author: Markus Wenzel, TU Muenchen | 
| 3 | ||
| 4 | Session management -- maintain state of logic images. | |
| 5 | *) | |
| 6 | ||
| 7 | signature SESSION = | |
| 8 | sig | |
| 25840 | 9 | val id: unit -> string list | 
| 11509 | 10 | val name: unit -> string | 
| 6346 | 11 | val welcome: unit -> string | 
| 48457 | 12 | val finish: unit -> unit | 
| 48805 
c3ea910b3581
explicit document_output directory, without implicit purge of default in ISABELLE_BROWSER_INFO;
 wenzelm parents: 
48804diff
changeset | 13 | val init: bool -> bool -> bool -> string -> string -> bool -> string -> (string * string) list -> | 
| 50121 
97d2b77313a0
isabelle build no longer supports document_dump/document_dump_mode (no INCOMPATIBILITY, since it was never in official release);
 wenzelm parents: 
49931diff
changeset | 14 | string -> string -> bool * string -> string -> bool -> unit | 
| 48457 | 15 |   val with_timing: string -> bool -> ('a -> 'b) -> 'a -> 'b
 | 
| 48445 | 16 | val use_dir: string -> string -> bool -> string list -> bool -> bool -> string -> | 
| 31688 | 17 | string -> bool -> string list -> string -> string -> bool * string -> | 
| 41703 
d27950860514
parallelization of nested Isar proofs is subject to Goal.parallel_proofs_threshold;
 wenzelm parents: 
39733diff
changeset | 18 | string -> int -> bool -> bool -> int -> int -> int -> int -> unit | 
| 6346 | 19 | end; | 
| 20 | ||
| 21 | structure Session: SESSION = | |
| 22 | struct | |
| 23 | ||
| 24 | (* session state *) | |
| 25 | ||
| 32738 | 26 | val session = Unsynchronized.ref ([Context.PureN]: string list); | 
| 27 | val session_finished = Unsynchronized.ref false; | |
| 48542 | 28 | |
| 29 | fun id () = ! session; | |
| 30 | fun name () = "Isabelle/" ^ List.last (! session); | |
| 9414 | 31 | |
| 32 | ||
| 33 | (* access path *) | |
| 6346 | 34 | |
| 48542 | 35 | val session_path = Unsynchronized.ref ([]: string list); | 
| 36 | val remote_path = Unsynchronized.ref (NONE: Url.T option); | |
| 6346 | 37 | |
| 48542 | 38 | fun path () = ! session_path; | 
| 26109 
c69c3559355b
more elaborate structure Distribution (filled-in by makedist);
 wenzelm parents: 
25840diff
changeset | 39 | |
| 30173 
eabece26b89b
moved isabelle_process.ML, isabelle_process.scala, isar.ML, session.ML to Pure/System/ (together with associated Isar commands);
 wenzelm parents: 
29435diff
changeset | 40 | |
| 
eabece26b89b
moved isabelle_process.ML, isabelle_process.scala, isar.ML, session.ML to Pure/System/ (together with associated Isar commands);
 wenzelm parents: 
29435diff
changeset | 41 | (* welcome *) | 
| 
eabece26b89b
moved isabelle_process.ML, isabelle_process.scala, isar.ML, session.ML to Pure/System/ (together with associated Isar commands);
 wenzelm parents: 
29435diff
changeset | 42 | |
| 26109 
c69c3559355b
more elaborate structure Distribution (filled-in by makedist);
 wenzelm parents: 
25840diff
changeset | 43 | fun welcome () = | 
| 26134 | 44 | if Distribution.is_official then | 
| 45 |     "Welcome to " ^ name () ^ " (" ^ Distribution.version ^ ")"
 | |
| 48990 | 46 |   else "Unofficial version of " ^ name () ^ " (" ^ Distribution.version ^ ")";
 | 
| 6346 | 47 | |
| 48 | ||
| 9414 | 49 | (* add_path *) | 
| 50 | ||
| 51 | fun add_path reset s = | |
| 52 | let val sess = ! session @ [s] in | |
| 18964 | 53 | (case duplicates (op =) sess of | 
| 9414 | 54 | [] => (session := sess; session_path := ((if reset then [] else ! session_path) @ [s])) | 
| 48542 | 55 |     | dups => error ("Duplicate session identifiers " ^ commas_quote dups))
 | 
| 9414 | 56 | end; | 
| 57 | ||
| 58 | ||
| 48457 | 59 | (* init_name *) | 
| 6346 | 60 | |
| 48457 | 61 | fun init_name reset parent name = | 
| 20664 | 62 | if not (member (op =) (! session) parent) orelse not (! session_finished) then | 
| 6346 | 63 |     error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
 | 
| 64 | else (add_path reset name; session_finished := false); | |
| 65 | ||
| 66 | ||
| 67 | (* finish *) | |
| 68 | ||
| 49931 
85780e6f8fd2
more basic Goal.reset_futures as snapshot of implicit state;
 wenzelm parents: 
49911diff
changeset | 69 | fun finish_futures () = | 
| 
85780e6f8fd2
more basic Goal.reset_futures as snapshot of implicit state;
 wenzelm parents: 
49911diff
changeset | 70 | (case map_filter Task_Queue.group_status (Goal.reset_futures ()) of | 
| 
85780e6f8fd2
more basic Goal.reset_futures as snapshot of implicit state;
 wenzelm parents: 
49911diff
changeset | 71 | [] => () | 
| 
85780e6f8fd2
more basic Goal.reset_futures as snapshot of implicit state;
 wenzelm parents: 
49911diff
changeset | 72 | | exns => raise Par_Exn.make exns); | 
| 
85780e6f8fd2
more basic Goal.reset_futures as snapshot of implicit state;
 wenzelm parents: 
49911diff
changeset | 73 | |
| 6346 | 74 | fun finish () = | 
| 49911 
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
 wenzelm parents: 
49895diff
changeset | 75 | (Future.shutdown (); | 
| 49931 
85780e6f8fd2
more basic Goal.reset_futures as snapshot of implicit state;
 wenzelm parents: 
49911diff
changeset | 76 | finish_futures (); | 
| 49911 
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
 wenzelm parents: 
49895diff
changeset | 77 | Thy_Info.finish (); | 
| 
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
 wenzelm parents: 
49895diff
changeset | 78 | Present.finish (); | 
| 
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
 wenzelm parents: 
49895diff
changeset | 79 | Keyword.status (); | 
| 
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
 wenzelm parents: 
49895diff
changeset | 80 | Outer_Syntax.check_syntax (); | 
| 
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
 wenzelm parents: 
49895diff
changeset | 81 | Options.reset_default (); | 
| 
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
 wenzelm parents: 
49895diff
changeset | 82 | session_finished := true); | 
| 6346 | 83 | |
| 84 | ||
| 85 | (* use_dir *) | |
| 86 | ||
| 48457 | 87 | fun with_timing _ false f x = f x | 
| 88 | | with_timing item true f x = | |
| 89 | let | |
| 90 | val start = Timing.start (); | |
| 91 | val y = f x; | |
| 92 | val timing = Timing.result start; | |
| 93 | val factor = Time.toReal (#cpu timing) / Time.toReal (#elapsed timing) | |
| 94 | |> Real.fmt (StringCvt.FIX (SOME 2)); | |
| 95 | val _ = | |
| 96 |           Output.physical_stderr ("Timing " ^ item ^ " (" ^
 | |
| 97 | string_of_int (Multithreading.max_threads_value ()) ^ " threads, " ^ | |
| 98 | Timing.message timing ^ ", factor " ^ factor ^ ")\n"); | |
| 99 | in y end; | |
| 100 | ||
| 48516 
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
 wenzelm parents: 
48467diff
changeset | 101 | fun get_rpath rpath = | 
| 
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
 wenzelm parents: 
48467diff
changeset | 102 | (if rpath = "" then () else | 
| 
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
 wenzelm parents: 
48467diff
changeset | 103 | if is_some (! remote_path) then | 
| 
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
 wenzelm parents: 
48467diff
changeset | 104 | error "Path for remote theory browsing information may only be set once" | 
| 
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
 wenzelm parents: 
48467diff
changeset | 105 | else | 
| 
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
 wenzelm parents: 
48467diff
changeset | 106 | remote_path := SOME (Url.explode rpath); | 
| 
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
 wenzelm parents: 
48467diff
changeset | 107 | (! remote_path, rpath <> "")); | 
| 
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
 wenzelm parents: 
48467diff
changeset | 108 | |
| 48805 
c3ea910b3581
explicit document_output directory, without implicit purge of default in ISABELLE_BROWSER_INFO;
 wenzelm parents: 
48804diff
changeset | 109 | fun init build reset info info_path doc doc_graph doc_output doc_variants | 
| 
c3ea910b3581
explicit document_output directory, without implicit purge of default in ISABELLE_BROWSER_INFO;
 wenzelm parents: 
48804diff
changeset | 110 | parent name doc_dump rpath verbose = | 
| 48457 | 111 | (init_name reset parent name; | 
| 48805 
c3ea910b3581
explicit document_output directory, without implicit purge of default in ISABELLE_BROWSER_INFO;
 wenzelm parents: 
48804diff
changeset | 112 | Present.init build info info_path (if doc = "false" then "" else doc) doc_graph doc_output | 
| 
c3ea910b3581
explicit document_output directory, without implicit purge of default in ISABELLE_BROWSER_INFO;
 wenzelm parents: 
48804diff
changeset | 113 | doc_variants (path ()) name doc_dump (get_rpath rpath) verbose | 
| 48467 
a4318c36a829
more precise propagation of options: build, session, theories;
 wenzelm parents: 
48457diff
changeset | 114 | (map Thy_Info.get_theory (Thy_Info.get_names ()))); | 
| 48457 | 115 | |
| 48516 
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
 wenzelm parents: 
48467diff
changeset | 116 | local | 
| 
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
 wenzelm parents: 
48467diff
changeset | 117 | |
| 48804 
6348e5fca42e
more direct interpretation of document_variants for build (unchanged for usedir);
 wenzelm parents: 
48709diff
changeset | 118 | fun read_variants strs = | 
| 
6348e5fca42e
more direct interpretation of document_variants for build (unchanged for usedir);
 wenzelm parents: 
48709diff
changeset | 119 |   rev (distinct (eq_fst (op =)) (rev (("document", "") :: map Present.read_variant strs)))
 | 
| 
6348e5fca42e
more direct interpretation of document_variants for build (unchanged for usedir);
 wenzelm parents: 
48709diff
changeset | 120 | |> filter_out (fn (_, s) => s = "-"); | 
| 
6348e5fca42e
more direct interpretation of document_variants for build (unchanged for usedir);
 wenzelm parents: 
48709diff
changeset | 121 | |
| 48516 
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
 wenzelm parents: 
48467diff
changeset | 122 | in | 
| 
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
 wenzelm parents: 
48467diff
changeset | 123 | |
| 48445 | 124 | fun use_dir item root build modes reset info info_path doc doc_graph doc_variants parent | 
| 50121 
97d2b77313a0
isabelle build no longer supports document_dump/document_dump_mode (no INCOMPATIBILITY, since it was never in official release);
 wenzelm parents: 
49931diff
changeset | 125 | name doc_dump rpath level timing verbose max_threads trace_threads | 
| 41703 
d27950860514
parallelization of nested Isar proofs is subject to Goal.parallel_proofs_threshold;
 wenzelm parents: 
39733diff
changeset | 126 | parallel_proofs parallel_proofs_threshold = | 
| 23972 | 127 | ((fn () => | 
| 49911 
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
 wenzelm parents: 
49895diff
changeset | 128 | let | 
| 
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
 wenzelm parents: 
49895diff
changeset | 129 | val _ = | 
| 
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
 wenzelm parents: 
49895diff
changeset | 130 | Output.physical_stderr | 
| 
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
 wenzelm parents: 
49895diff
changeset | 131 | "### Legacy feature: old \"isabelle usedir\" -- use \"isabelle build\" instead!\n"; | 
| 
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
 wenzelm parents: 
49895diff
changeset | 132 | val _ = | 
| 
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
 wenzelm parents: 
49895diff
changeset | 133 | init build reset info info_path doc doc_graph "" (read_variants doc_variants) parent name | 
| 50121 
97d2b77313a0
isabelle build no longer supports document_dump/document_dump_mode (no INCOMPATIBILITY, since it was never in official release);
 wenzelm parents: 
49931diff
changeset | 134 | doc_dump rpath verbose; | 
| 49911 
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
 wenzelm parents: 
49895diff
changeset | 135 | val res1 = (use |> with_timing item timing |> Exn.capture) root; | 
| 
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
 wenzelm parents: 
49895diff
changeset | 136 | val res2 = Exn.capture finish (); | 
| 
262c36fd5f26
collective errors from use_thys and Session.finish/Goal.finish_futures -- avoid uninformative interrupts stemming from failure of goal forks that are not registered in the theory (e.g. unnamed theorems);
 wenzelm parents: 
49895diff
changeset | 137 | in ignore (Par_Exn.release_all [res1, res2]) end) | 
| 39616 
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
 wenzelm parents: 
37216diff
changeset | 138 | |> Unsynchronized.setmp Proofterm.proofs level | 
| 
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
 wenzelm parents: 
37216diff
changeset | 139 | |> Unsynchronized.setmp print_mode (modes @ print_mode_value ()) | 
| 
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
 wenzelm parents: 
37216diff
changeset | 140 | |> Unsynchronized.setmp Goal.parallel_proofs parallel_proofs | 
| 41703 
d27950860514
parallelization of nested Isar proofs is subject to Goal.parallel_proofs_threshold;
 wenzelm parents: 
39733diff
changeset | 141 | |> Unsynchronized.setmp Goal.parallel_proofs_threshold parallel_proofs_threshold | 
| 39616 
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
 wenzelm parents: 
37216diff
changeset | 142 | |> Unsynchronized.setmp Multithreading.trace trace_threads | 
| 
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
 wenzelm parents: 
37216diff
changeset | 143 | |> Unsynchronized.setmp Multithreading.max_threads | 
| 23979 | 144 | (if Multithreading.available then max_threads | 
| 145 | else (if max_threads = 1 then () else warning "Multithreading support unavailable"; 1))) () | |
| 31478 | 146 | handle exn => (Output.error_msg (ML_Compiler.exn_message exn); exit 1); | 
| 6346 | 147 | |
| 148 | end; | |
| 48516 
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
 wenzelm parents: 
48467diff
changeset | 149 | |
| 
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
 wenzelm parents: 
48467diff
changeset | 150 | end; |