src/Pure/PIDE/session.ML
author wenzelm
Tue, 01 Sep 2020 18:03:17 +0200
changeset 72235 a5bf0b69c22a
parent 72156 065dcd80293e
child 72309 564012e31db1
permissions -rw-r--r--
discontinue export_document --- always enabled (reverting f0f83ce0badd);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56210
c7c85cdb725d clarified module arrangement;
wenzelm
parents: 55386
diff changeset
     1
(*  Title:      Pure/PIDE/session.ML
52052
892061142ba6 discontinued obsolete isabelle usedir, mkdir, make;
wenzelm
parents: 52050
diff changeset
     2
    Author:     Makarius
6346
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
     3
56210
c7c85cdb725d clarified module arrangement;
wenzelm
parents: 55386
diff changeset
     4
Prover session: persistent state of logic image.
6346
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
     5
*)
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
     6
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
     7
signature SESSION =
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
     8
sig
60081
9fb7b44e3e7e tuned signature;
wenzelm
parents: 59448
diff changeset
     9
  val get_name: unit -> string
6346
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
    10
  val welcome: unit -> string
59086
94b2690ad494 node-specific keywords, with session base syntax as default;
wenzelm
parents: 58928
diff changeset
    11
  val get_keywords: unit -> Keyword.keywords
71611
fb6953e77000 eliminated pointless flag (see also 6533ceee4cd7);
wenzelm
parents: 62944
diff changeset
    12
  val init: HTML.symbols -> bool -> Path.T -> string -> string -> (string * string) list ->
59445
2c27c3d1fd3b provide session_graph.pdf via Isabelle/Scala;
wenzelm
parents: 59369
diff changeset
    13
    (Path.T * Path.T) list -> Path.T -> string -> string * string -> bool -> unit
59369
7090199d3f78 more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents: 59345
diff changeset
    14
  val shutdown: unit -> unit
48457
fd9e28d5a143 pass build options to ML;
wenzelm
parents: 48445
diff changeset
    15
  val finish: unit -> unit
6346
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
    16
end;
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
    17
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
    18
structure Session: SESSION =
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
    19
struct
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
    20
62928
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    21
(** persistent session information **)
6346
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
    22
62944
3ee643c5ed00 more standard session build process, including browser_info;
wenzelm
parents: 62936
diff changeset
    23
val session = Synchronized.var "Session.session" ({chapter = "", name = ""}, true);
48542
0a5f598cacec simplified Session.name;
wenzelm
parents: 48518
diff changeset
    24
62928
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    25
fun get_name () = #name (#1 (Synchronized.value session));
60081
9fb7b44e3e7e tuned signature;
wenzelm
parents: 59448
diff changeset
    26
9fb7b44e3e7e tuned signature;
wenzelm
parents: 59448
diff changeset
    27
fun description () = "Isabelle/" ^ get_name ();
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
    28
26109
c69c3559355b more elaborate structure Distribution (filled-in by makedist);
wenzelm
parents: 25840
diff changeset
    29
fun welcome () =
57649
a43898f76ae9 further distinction of Isabelle distribution: alert for identified release candidates;
wenzelm
parents: 56533
diff changeset
    30
  if Distribution.is_identified then
60081
9fb7b44e3e7e tuned signature;
wenzelm
parents: 59448
diff changeset
    31
    "Welcome to " ^ description () ^ " (" ^ Distribution.version ^ ")"
9fb7b44e3e7e tuned signature;
wenzelm
parents: 59448
diff changeset
    32
  else "Unofficial version of " ^ description () ^ " (" ^ Distribution.version ^ ")";
6346
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
    33
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
    34
59086
94b2690ad494 node-specific keywords, with session base syntax as default;
wenzelm
parents: 58928
diff changeset
    35
(* base syntax *)
94b2690ad494 node-specific keywords, with session base syntax as default;
wenzelm
parents: 58928
diff changeset
    36
62928
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    37
val keywords = Synchronized.var "Session.keywords" Keyword.empty_keywords;
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    38
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    39
fun get_keywords () = Synchronized.value keywords;
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    40
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    41
fun update_keywords () =
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    42
  Synchronized.change keywords
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    43
    (K (fold (curry Keyword.merge_keywords o Thy_Header.get_keywords o Thy_Info.get_theory)
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    44
      (Thy_Info.get_names ()) Keyword.empty_keywords));
59086
94b2690ad494 node-specific keywords, with session base syntax as default;
wenzelm
parents: 58928
diff changeset
    45
94b2690ad494 node-specific keywords, with session base syntax as default;
wenzelm
parents: 58928
diff changeset
    46
51399
6ac3c29a300e discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents: 51398
diff changeset
    47
(* init *)
9414
1463576f3968 disallow duplicates in session identifiers;
wenzelm
parents: 8807
diff changeset
    48
71611
fb6953e77000 eliminated pointless flag (see also 6533ceee4cd7);
wenzelm
parents: 62944
diff changeset
    49
fun init symbols info info_path doc doc_output doc_variants doc_files graph_file
56530
5c178501cf78 removed obsolete doc_dump option (see also 892061142ba6);
wenzelm
parents: 56333
diff changeset
    50
    parent (chapter, name) verbose =
62928
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    51
  (Synchronized.change session (fn ({name = parent_name, ...}, parent_finished) =>
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    52
    if parent_name <> parent orelse not parent_finished then
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    53
      error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    54
    else ({chapter = chapter, name = name}, false));
71611
fb6953e77000 eliminated pointless flag (see also 6533ceee4cd7);
wenzelm
parents: 62944
diff changeset
    55
    Present.init symbols info info_path (if doc = "false" then "" else doc)
62928
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    56
      doc_output doc_variants doc_files graph_file (chapter, name) verbose);
6346
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
    57
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
    58
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
    59
(* finish *)
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
    60
59369
7090199d3f78 more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents: 59345
diff changeset
    61
fun shutdown () =
7090199d3f78 more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents: 59345
diff changeset
    62
 (Execution.shutdown ();
7090199d3f78 more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents: 59345
diff changeset
    63
  Event_Timer.shutdown ();
7090199d3f78 more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents: 59345
diff changeset
    64
  Future.shutdown ());
7090199d3f78 more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents: 59345
diff changeset
    65
6346
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
    66
fun finish () =
59369
7090199d3f78 more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents: 59345
diff changeset
    67
 (shutdown ();
72098
8c547eac8381 more robust treatment of thm_names, with strict check after all theories are loaded;
wenzelm
parents: 71611
diff changeset
    68
  Par_List.map (Global_Theory.get_thm_names o Thy_Info.get_theory) (Thy_Info.get_names ());
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: 49895
diff changeset
    69
  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: 49895
diff changeset
    70
  Present.finish ();
59369
7090199d3f78 more informative build_theories_result: cumulative Runtime.exn_message;
wenzelm
parents: 59345
diff changeset
    71
  shutdown ();
62928
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    72
  update_keywords ();
0953dec1fcb0 prefer Synchronized.var;
wenzelm
parents: 62469
diff changeset
    73
  Synchronized.change session (apsnd (K true)));
6346
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
    74
643a1bd31a91 moved Thy/session.ML to Isar/session.ML;
wenzelm
parents:
diff changeset
    75
end;