author | wenzelm |
Mon, 06 Aug 2012 21:11:42 +0200 | |
changeset 48698 | 2585042b1a30 |
parent 48646 | 91281e9472d8 |
child 48709 | 719f458cd89e |
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:
29435
diff
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 |
13 |
val init: bool -> bool -> bool -> string -> string -> bool -> string list -> |
|
48543 | 14 |
string -> string -> string * Present.dump_mode -> 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:
39733
diff
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:
25840
diff
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:
29435
diff
changeset
|
40 |
|
eabece26b89b
moved isabelle_process.ML, isabelle_process.scala, isar.ML, session.ML to Pure/System/ (together with associated Isar commands);
wenzelm
parents:
29435
diff
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:
29435
diff
changeset
|
42 |
|
26109
c69c3559355b
more elaborate structure Distribution (filled-in by makedist);
wenzelm
parents:
25840
diff
changeset
|
43 |
fun welcome () = |
26134 | 44 |
if Distribution.is_official then |
45 |
"Welcome to " ^ name () ^ " (" ^ Distribution.version ^ ")" |
|
46 |
else |
|
47 |
"Unofficial version of " ^ name () ^ " (" ^ Distribution.version ^ ")" ^ |
|
27643 | 48 |
(if Distribution.changelog <> "" then "\nSee also " ^ Distribution.changelog else ""); |
6346 | 49 |
|
50 |
||
9414 | 51 |
(* add_path *) |
52 |
||
53 |
fun add_path reset s = |
|
54 |
let val sess = ! session @ [s] in |
|
18964 | 55 |
(case duplicates (op =) sess of |
9414 | 56 |
[] => (session := sess; session_path := ((if reset then [] else ! session_path) @ [s])) |
48542 | 57 |
| dups => error ("Duplicate session identifiers " ^ commas_quote dups)) |
9414 | 58 |
end; |
59 |
||
60 |
||
48457 | 61 |
(* init_name *) |
6346 | 62 |
|
48457 | 63 |
fun init_name reset parent name = |
20664 | 64 |
if not (member (op =) (! session) parent) orelse not (! session_finished) then |
6346 | 65 |
error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name) |
66 |
else (add_path reset name; session_finished := false); |
|
67 |
||
68 |
||
69 |
(* finish *) |
|
70 |
||
71 |
fun finish () = |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36953
diff
changeset
|
72 |
(Thy_Info.finish (); |
28207 | 73 |
Present.finish (); |
46970
9667e0dcb5e2
check declared vs. defined commands at end of session;
wenzelm
parents:
46961
diff
changeset
|
74 |
Outer_Syntax.check_syntax (); |
28205 | 75 |
Future.shutdown (); |
48698
2585042b1a30
pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents:
48646
diff
changeset
|
76 |
Options.reset_default (); |
6346 | 77 |
session_finished := true); |
78 |
||
79 |
||
80 |
(* use_dir *) |
|
81 |
||
48457 | 82 |
fun with_timing _ false f x = f x |
83 |
| with_timing item true f x = |
|
84 |
let |
|
85 |
val start = Timing.start (); |
|
86 |
val y = f x; |
|
87 |
val timing = Timing.result start; |
|
88 |
val factor = Time.toReal (#cpu timing) / Time.toReal (#elapsed timing) |
|
89 |
|> Real.fmt (StringCvt.FIX (SOME 2)); |
|
90 |
val _ = |
|
91 |
Output.physical_stderr ("Timing " ^ item ^ " (" ^ |
|
92 |
string_of_int (Multithreading.max_threads_value ()) ^ " threads, " ^ |
|
93 |
Timing.message timing ^ ", factor " ^ factor ^ ")\n"); |
|
94 |
in y end; |
|
95 |
||
48516
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
96 |
fun get_rpath rpath = |
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
97 |
(if rpath = "" then () else |
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
98 |
if is_some (! remote_path) then |
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
99 |
error "Path for remote theory browsing information may only be set once" |
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
100 |
else |
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
101 |
remote_path := SOME (Url.explode rpath); |
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
102 |
(! remote_path, rpath <> "")); |
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
103 |
|
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
104 |
fun init build reset info info_path doc doc_graph doc_variants parent name doc_dump rpath verbose = |
48457 | 105 |
(init_name reset parent name; |
48467
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48457
diff
changeset
|
106 |
Present.init build info info_path (if doc = "false" then "" else doc) doc_graph doc_variants |
48516
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
107 |
(path ()) name doc_dump (get_rpath rpath) verbose |
48467
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48457
diff
changeset
|
108 |
(map Thy_Info.get_theory (Thy_Info.get_names ()))); |
48457 | 109 |
|
48516
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
110 |
local |
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
111 |
|
48543 | 112 |
fun doc_dump (cp, dump) = (dump, if cp then Present.Dump_all else Present.Dump_tex_sty); |
48516
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
113 |
|
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
114 |
in |
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
115 |
|
48445 | 116 |
fun use_dir item root build modes reset info info_path doc doc_graph doc_variants parent |
41703
d27950860514
parallelization of nested Isar proofs is subject to Goal.parallel_proofs_threshold;
wenzelm
parents:
39733
diff
changeset
|
117 |
name dump rpath level timing verbose max_threads trace_threads |
d27950860514
parallelization of nested Isar proofs is subject to Goal.parallel_proofs_threshold;
wenzelm
parents:
39733
diff
changeset
|
118 |
parallel_proofs parallel_proofs_threshold = |
23972 | 119 |
((fn () => |
48516
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
120 |
(init build reset info info_path doc doc_graph doc_variants parent name |
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
121 |
(doc_dump dump) rpath verbose; |
48457 | 122 |
with_timing item timing use root; |
23972 | 123 |
finish ())) |
39616
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents:
37216
diff
changeset
|
124 |
|> Unsynchronized.setmp Proofterm.proofs level |
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents:
37216
diff
changeset
|
125 |
|> Unsynchronized.setmp print_mode (modes @ print_mode_value ()) |
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents:
37216
diff
changeset
|
126 |
|> Unsynchronized.setmp Goal.parallel_proofs parallel_proofs |
41703
d27950860514
parallelization of nested Isar proofs is subject to Goal.parallel_proofs_threshold;
wenzelm
parents:
39733
diff
changeset
|
127 |
|> Unsynchronized.setmp Goal.parallel_proofs_threshold parallel_proofs_threshold |
39616
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents:
37216
diff
changeset
|
128 |
|> Unsynchronized.setmp Multithreading.trace trace_threads |
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents:
37216
diff
changeset
|
129 |
|> Unsynchronized.setmp Multithreading.max_threads |
23979 | 130 |
(if Multithreading.available then max_threads |
131 |
else (if max_threads = 1 then () else warning "Multithreading support unavailable"; 1))) () |
|
31478 | 132 |
handle exn => (Output.error_msg (ML_Compiler.exn_message exn); exit 1); |
6346 | 133 |
|
134 |
end; |
|
48516
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
135 |
|
c5d0f19ef7cb
refined "document_dump_mode": "all", "tex+sty", "tex";
wenzelm
parents:
48467
diff
changeset
|
136 |
end; |