author | wenzelm |
Tue, 24 Jul 2012 12:14:16 +0200 | |
changeset 48467 | a4318c36a829 |
parent 48457 | fd9e28d5a143 |
child 48516 | c5d0f19ef7cb |
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 -> |
|
14 |
string -> string -> bool * string -> string -> bool -> unit |
|
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 |
||
25 |
(* session state *) |
|
26 |
||
32738 | 27 |
val session = Unsynchronized.ref ([Context.PureN]: string list); |
28 |
val session_path = Unsynchronized.ref ([]: string list); |
|
29 |
val session_finished = Unsynchronized.ref false; |
|
30 |
val remote_path = Unsynchronized.ref (NONE: Url.T option); |
|
9414 | 31 |
|
32 |
||
33 |
(* access path *) |
|
6346 | 34 |
|
25840 | 35 |
fun id () = ! session; |
6346 | 36 |
fun path () = ! session_path; |
37 |
||
16451 | 38 |
fun str_of [] = Context.PureN |
6346 | 39 |
| str_of elems = space_implode "/" elems; |
40 |
||
11509 | 41 |
fun name () = "Isabelle/" ^ str_of (path ()); |
26109
c69c3559355b
more elaborate structure Distribution (filled-in by makedist);
wenzelm
parents:
25840
diff
changeset
|
42 |
|
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
|
43 |
|
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
|
44 |
(* 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
|
45 |
|
26109
c69c3559355b
more elaborate structure Distribution (filled-in by makedist);
wenzelm
parents:
25840
diff
changeset
|
46 |
fun welcome () = |
26134 | 47 |
if Distribution.is_official then |
48 |
"Welcome to " ^ name () ^ " (" ^ Distribution.version ^ ")" |
|
49 |
else |
|
50 |
"Unofficial version of " ^ name () ^ " (" ^ Distribution.version ^ ")" ^ |
|
27643 | 51 |
(if Distribution.changelog <> "" then "\nSee also " ^ Distribution.changelog else ""); |
6346 | 52 |
|
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
|
53 |
val _ = |
46961
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
44389
diff
changeset
|
54 |
Outer_Syntax.improper_command ("welcome", Keyword.diag) "print welcome message" |
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
|
55 |
(Scan.succeed (Toplevel.no_timing o Toplevel.imperative (writeln o 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
|
56 |
|
6346 | 57 |
|
9414 | 58 |
(* add_path *) |
59 |
||
60 |
fun add_path reset s = |
|
61 |
let val sess = ! session @ [s] in |
|
18964 | 62 |
(case duplicates (op =) sess of |
9414 | 63 |
[] => (session := sess; session_path := ((if reset then [] else ! session_path) @ [s])) |
64 |
| dups => error ("Duplicate session identifiers " ^ commas_quote dups ^ " in " ^ str_of sess)) |
|
65 |
end; |
|
66 |
||
67 |
||
48457 | 68 |
(* init_name *) |
6346 | 69 |
|
48457 | 70 |
fun init_name reset parent name = |
20664 | 71 |
if not (member (op =) (! session) parent) orelse not (! session_finished) then |
6346 | 72 |
error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name) |
73 |
else (add_path reset name; session_finished := false); |
|
74 |
||
75 |
||
76 |
(* finish *) |
|
77 |
||
78 |
fun finish () = |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36953
diff
changeset
|
79 |
(Thy_Info.finish (); |
28207 | 80 |
Present.finish (); |
46970
9667e0dcb5e2
check declared vs. defined commands at end of session;
wenzelm
parents:
46961
diff
changeset
|
81 |
Outer_Syntax.check_syntax (); |
28205 | 82 |
Future.shutdown (); |
6346 | 83 |
session_finished := true); |
84 |
||
85 |
||
86 |
(* use_dir *) |
|
87 |
||
17207 | 88 |
fun get_rpath rpath = |
89 |
(if rpath = "" then () else |
|
15979 | 90 |
if is_some (! remote_path) then |
7227
a8e86b8e6fd1
Path for remote theory browsing information is now stored in referece variable rpath.
berghofe
parents:
6663
diff
changeset
|
91 |
error "Path for remote theory browsing information may only be set once" |
a8e86b8e6fd1
Path for remote theory browsing information is now stored in referece variable rpath.
berghofe
parents:
6663
diff
changeset
|
92 |
else |
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
20664
diff
changeset
|
93 |
remote_path := SOME (Url.explode rpath); |
17207 | 94 |
(! remote_path, rpath <> "")); |
95 |
||
96 |
fun dumping (_, "") = NONE |
|
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
20664
diff
changeset
|
97 |
| dumping (cp, path) = SOME (cp, Path.explode path); |
7236
e077484d50d8
Better handling of path for remote theory browsing information.
berghofe
parents:
7227
diff
changeset
|
98 |
|
48457 | 99 |
fun with_timing _ false f x = f x |
100 |
| with_timing item true f x = |
|
101 |
let |
|
102 |
val start = Timing.start (); |
|
103 |
val y = f x; |
|
104 |
val timing = Timing.result start; |
|
105 |
val factor = Time.toReal (#cpu timing) / Time.toReal (#elapsed timing) |
|
106 |
|> Real.fmt (StringCvt.FIX (SOME 2)); |
|
107 |
val _ = |
|
108 |
Output.physical_stderr ("Timing " ^ item ^ " (" ^ |
|
109 |
string_of_int (Multithreading.max_threads_value ()) ^ " threads, " ^ |
|
110 |
Timing.message timing ^ ", factor " ^ factor ^ ")\n"); |
|
111 |
in y end; |
|
112 |
||
113 |
fun init build reset info info_path doc doc_graph doc_variants parent name dump rpath verbose = |
|
114 |
(init_name reset parent name; |
|
48467
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48457
diff
changeset
|
115 |
Present.init build info info_path (if doc = "false" then "" else doc) doc_graph doc_variants |
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48457
diff
changeset
|
116 |
(path ()) name (dumping dump) (get_rpath rpath) verbose |
a4318c36a829
more precise propagation of options: build, session, theories;
wenzelm
parents:
48457
diff
changeset
|
117 |
(map Thy_Info.get_theory (Thy_Info.get_names ()))); |
48457 | 118 |
|
48445 | 119 |
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
|
120 |
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
|
121 |
parallel_proofs parallel_proofs_threshold = |
23972 | 122 |
((fn () => |
48457 | 123 |
(init build reset info info_path doc doc_graph doc_variants parent name dump rpath verbose; |
124 |
with_timing item timing use root; |
|
23972 | 125 |
finish ())) |
39616
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents:
37216
diff
changeset
|
126 |
|> Unsynchronized.setmp Proofterm.proofs level |
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents:
37216
diff
changeset
|
127 |
|> Unsynchronized.setmp print_mode (modes @ print_mode_value ()) |
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents:
37216
diff
changeset
|
128 |
|> 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
|
129 |
|> 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
|
130 |
|> Unsynchronized.setmp Multithreading.trace trace_threads |
8052101883c3
renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents:
37216
diff
changeset
|
131 |
|> Unsynchronized.setmp Multithreading.max_threads |
23979 | 132 |
(if Multithreading.available then max_threads |
133 |
else (if max_threads = 1 then () else warning "Multithreading support unavailable"; 1))) () |
|
31478 | 134 |
handle exn => (Output.error_msg (ML_Compiler.exn_message exn); exit 1); |
6346 | 135 |
|
136 |
end; |