src/Pure/Tools/build.ML
author wenzelm
Tue, 09 Apr 2013 15:59:02 +0200
changeset 51661 92e58b76dbb1
parent 51553 63327f679cff
child 51662 3391a493f39a
permissions -rw-r--r--
clarified protocol_message undefinedness;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50686
d703e3aafa8c moved files;
wenzelm
parents: 50683
diff changeset
     1
(*  Title:      Pure/Tools/build.ML
48418
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
     3
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
     4
Build Isabelle sessions.
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
     5
*)
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
     6
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
     7
signature BUILD =
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
     8
sig
48731
a45ba78abcc1 more casual exit back to ML toplevel, to accomodate commit in SML/NJ which continues at the saved point;
wenzelm
parents: 48681
diff changeset
     9
  val build: string -> unit
48418
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
    10
end;
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
    11
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
    12
structure Build: BUILD =
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
    13
struct
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
    14
50683
34b109c5324c inline ML statistics into build log;
wenzelm
parents: 50280
diff changeset
    15
(* protocol messages *)
34b109c5324c inline ML statistics into build log;
wenzelm
parents: 50280
diff changeset
    16
51216
e6e7685fc8f8 emit command_timing properties into build log;
wenzelm
parents: 51045
diff changeset
    17
(* FIXME avoid hardwired stuff!? *)
e6e7685fc8f8 emit command_timing properties into build log;
wenzelm
parents: 51045
diff changeset
    18
val protocol_echo = [Markup.ML_statistics, Markup.task_statistics, Markup.command_timing];
50683
34b109c5324c inline ML statistics into build log;
wenzelm
parents: 50280
diff changeset
    19
34b109c5324c inline ML statistics into build log;
wenzelm
parents: 50280
diff changeset
    20
fun protocol_message props output =
51216
e6e7685fc8f8 emit command_timing properties into build log;
wenzelm
parents: 51045
diff changeset
    21
  (case props of
e6e7685fc8f8 emit command_timing properties into build log;
wenzelm
parents: 51045
diff changeset
    22
    function :: args =>
e6e7685fc8f8 emit command_timing properties into build log;
wenzelm
parents: 51045
diff changeset
    23
      if member (op =) protocol_echo function then
e6e7685fc8f8 emit command_timing properties into build log;
wenzelm
parents: 51045
diff changeset
    24
        writeln ("\f" ^ #2 function ^ " = " ^ YXML.string_of_body (XML.Encode.properties args))
e6e7685fc8f8 emit command_timing properties into build log;
wenzelm
parents: 51045
diff changeset
    25
      else
e6e7685fc8f8 emit command_timing properties into build log;
wenzelm
parents: 51045
diff changeset
    26
        (case Markup.dest_loading_theory props of
e6e7685fc8f8 emit command_timing properties into build log;
wenzelm
parents: 51045
diff changeset
    27
          SOME name => writeln ("\floading_theory = " ^ name)
51661
92e58b76dbb1 clarified protocol_message undefinedness;
wenzelm
parents: 51553
diff changeset
    28
        | NONE => raise Output.Protocol_Message props)
92e58b76dbb1 clarified protocol_message undefinedness;
wenzelm
parents: 51553
diff changeset
    29
  | [] => raise Output.Protocol_Message props);
51045
630c0895d9d1 more efficient inlined properties, especially relevant for voluminous tasks trace;
wenzelm
parents: 50982
diff changeset
    30
50683
34b109c5324c inline ML statistics into build log;
wenzelm
parents: 50280
diff changeset
    31
34b109c5324c inline ML statistics into build log;
wenzelm
parents: 50280
diff changeset
    32
(* build *)
34b109c5324c inline ML statistics into build log;
wenzelm
parents: 50280
diff changeset
    33
48465
a25daffda966 observe "condition";
wenzelm
parents: 48464
diff changeset
    34
local
a25daffda966 observe "condition";
wenzelm
parents: 48464
diff changeset
    35
48500
bf7f434b91d7 clarified no_document situation;
wenzelm
parents: 48492
diff changeset
    36
fun no_document options =
50121
97d2b77313a0 isabelle build no longer supports document_dump/document_dump_mode (no INCOMPATIBILITY, since it was never in official release);
wenzelm
parents: 49911
diff changeset
    37
  (case Options.string options "document" of "" => true | "false" => true | _ => false);
48500
bf7f434b91d7 clarified no_document situation;
wenzelm
parents: 48492
diff changeset
    38
51217
65ab2c4f4c32 support for prescient timing information within command transactions;
wenzelm
parents: 51216
diff changeset
    39
fun use_theories last_timing options =
65ab2c4f4c32 support for prescient timing information within command transactions;
wenzelm
parents: 51216
diff changeset
    40
  Thy_Info.use_theories {last_timing = last_timing, master_dir = Path.current}
48457
fd9e28d5a143 pass build options to ML;
wenzelm
parents: 48419
diff changeset
    41
    |> Unsynchronized.setmp Proofterm.proofs (Options.int options "proofs")
fd9e28d5a143 pass build options to ML;
wenzelm
parents: 48419
diff changeset
    42
    |> Unsynchronized.setmp print_mode
fd9e28d5a143 pass build options to ML;
wenzelm
parents: 48419
diff changeset
    43
        (space_explode "," (Options.string options "print_mode") @ print_mode_value ())
fd9e28d5a143 pass build options to ML;
wenzelm
parents: 48419
diff changeset
    44
    |> Unsynchronized.setmp Goal.parallel_proofs (Options.int options "parallel_proofs")
51423
e5f9a6d9ca82 clarified parallel_subproofs_saturation (blind guess) vs. parallel_subproofs_threshold (precient timing estimate);
wenzelm
parents: 51399
diff changeset
    45
    |> Unsynchronized.setmp Goal.parallel_subproofs_saturation
e5f9a6d9ca82 clarified parallel_subproofs_saturation (blind guess) vs. parallel_subproofs_threshold (precient timing estimate);
wenzelm
parents: 51399
diff changeset
    46
        (Options.int options "parallel_subproofs_saturation")
e5f9a6d9ca82 clarified parallel_subproofs_saturation (blind guess) vs. parallel_subproofs_threshold (precient timing estimate);
wenzelm
parents: 51399
diff changeset
    47
    |> Unsynchronized.setmp Goal.parallel_subproofs_threshold
e5f9a6d9ca82 clarified parallel_subproofs_saturation (blind guess) vs. parallel_subproofs_threshold (precient timing estimate);
wenzelm
parents: 51399
diff changeset
    48
        (Options.real options "parallel_subproofs_threshold")
48457
fd9e28d5a143 pass build options to ML;
wenzelm
parents: 48419
diff changeset
    49
    |> Unsynchronized.setmp Multithreading.trace (Options.int options "threads_trace")
48460
20170ae271a5 tuned options;
wenzelm
parents: 48459
diff changeset
    50
    |> Unsynchronized.setmp Multithreading.max_threads (Options.int options "threads")
50698
49621c755075 always enable Future.ML_statistics where this makes sense -- runtime overhead should be negligible;
wenzelm
parents: 50686
diff changeset
    51
    |> Unsynchronized.setmp Future.ML_statistics true
48500
bf7f434b91d7 clarified no_document situation;
wenzelm
parents: 48492
diff changeset
    52
    |> no_document options ? Present.no_document
48486
691d0b44a793 more build options;
wenzelm
parents: 48482
diff changeset
    53
    |> Unsynchronized.setmp quick_and_dirty (Options.bool options "quick_and_dirty")
51553
63327f679cff more ambitious Goal.skip_proofs: covers Goal.prove forms as well, and do not insist in quick_and_dirty (for the sake of Isabelle/jEdit);
wenzelm
parents: 51423
diff changeset
    54
    |> Unsynchronized.setmp Goal.skip_proofs (Options.bool options "skip_proofs")
48486
691d0b44a793 more build options;
wenzelm
parents: 48482
diff changeset
    55
    |> Unsynchronized.setmp Printer.show_question_marks_default
691d0b44a793 more build options;
wenzelm
parents: 48482
diff changeset
    56
        (Options.bool options "show_question_marks")
691d0b44a793 more build options;
wenzelm
parents: 48482
diff changeset
    57
    |> Unsynchronized.setmp Name_Space.names_long_default (Options.bool options "names_long")
691d0b44a793 more build options;
wenzelm
parents: 48482
diff changeset
    58
    |> Unsynchronized.setmp Name_Space.names_short_default (Options.bool options "names_short")
48492
03530cf284ca more build options;
wenzelm
parents: 48486
diff changeset
    59
    |> Unsynchronized.setmp Name_Space.names_unique_default (Options.bool options "names_unique")
48520
6d4ea2efa64b more build options;
wenzelm
parents: 48516
diff changeset
    60
    |> Unsynchronized.setmp Thy_Output.display_default (Options.bool options "thy_output_display")
6d4ea2efa64b more build options;
wenzelm
parents: 48516
diff changeset
    61
    |> Unsynchronized.setmp Thy_Output.quotes_default (Options.bool options "thy_output_quotes")
6d4ea2efa64b more build options;
wenzelm
parents: 48516
diff changeset
    62
    |> Unsynchronized.setmp Thy_Output.indent_default (Options.int options "thy_output_indent")
6d4ea2efa64b more build options;
wenzelm
parents: 48516
diff changeset
    63
    |> Unsynchronized.setmp Thy_Output.source_default (Options.bool options "thy_output_source")
6d4ea2efa64b more build options;
wenzelm
parents: 48516
diff changeset
    64
    |> Unsynchronized.setmp Thy_Output.break_default (Options.bool options "thy_output_break")
48527
4ee8d70cd5a3 more build options;
wenzelm
parents: 48520
diff changeset
    65
    |> Unsynchronized.setmp Pretty.margin_default (Options.int options "pretty_margin")
48492
03530cf284ca more build options;
wenzelm
parents: 48486
diff changeset
    66
    |> Unsynchronized.setmp Toplevel.timing (Options.bool options "timing");
48457
fd9e28d5a143 pass build options to ML;
wenzelm
parents: 48419
diff changeset
    67
51217
65ab2c4f4c32 support for prescient timing information within command transactions;
wenzelm
parents: 51216
diff changeset
    68
fun use_theories_condition last_timing (options, thys) =
48465
a25daffda966 observe "condition";
wenzelm
parents: 48464
diff changeset
    69
  let val condition = space_explode "," (Options.string options "condition") in
a25daffda966 observe "condition";
wenzelm
parents: 48464
diff changeset
    70
    (case filter_out (can getenv_strict) condition of
51217
65ab2c4f4c32 support for prescient timing information within command transactions;
wenzelm
parents: 51216
diff changeset
    71
      [] => use_theories last_timing options (map (rpair Position.none) thys)
48465
a25daffda966 observe "condition";
wenzelm
parents: 48464
diff changeset
    72
    | conds =>
48512
wenzelm
parents: 48511
diff changeset
    73
        Output.physical_stderr ("Skipping theories " ^ commas_quote thys ^
48477
322fbf571782 tuned message;
wenzelm
parents: 48472
diff changeset
    74
          " (undefined " ^ commas conds ^ ")\n"))
48465
a25daffda966 observe "condition";
wenzelm
parents: 48464
diff changeset
    75
  end;
a25daffda966 observe "condition";
wenzelm
parents: 48464
diff changeset
    76
51228
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    77
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    78
(* command timings *)
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    79
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    80
type timings = ((string * Time.time) Inttab.table) Symtab.table;  (*file -> offset -> name * time *)
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    81
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    82
val empty_timings: timings = Symtab.empty;
51218
6425a0d3b7ac support for build passing timings from Scala to ML;
wenzelm
parents: 51217
diff changeset
    83
51228
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    84
fun update_timings props =
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    85
  (case Markup.parse_command_timing_properties props of
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    86
    SOME ({file, offset, name}, time) =>
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    87
      Symtab.map_default (file, Inttab.empty) (Inttab.update (offset, (name, time)))
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    88
  | NONE => I);
51218
6425a0d3b7ac support for build passing timings from Scala to ML;
wenzelm
parents: 51217
diff changeset
    89
51228
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    90
fun lookup_timings timings tr =
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    91
  (case Toplevel.approximative_id tr of
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    92
    SOME {file, offset, name} =>
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    93
      (case Symtab.lookup timings file of
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    94
        SOME offsets =>
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
    95
          (case Inttab.lookup offsets offset of
51423
e5f9a6d9ca82 clarified parallel_subproofs_saturation (blind guess) vs. parallel_subproofs_threshold (precient timing estimate);
wenzelm
parents: 51399
diff changeset
    96
            SOME (name', time) => if name = name' then SOME time else NONE
e5f9a6d9ca82 clarified parallel_subproofs_saturation (blind guess) vs. parallel_subproofs_threshold (precient timing estimate);
wenzelm
parents: 51399
diff changeset
    97
          | NONE => NONE)
e5f9a6d9ca82 clarified parallel_subproofs_saturation (blind guess) vs. parallel_subproofs_threshold (precient timing estimate);
wenzelm
parents: 51399
diff changeset
    98
      | NONE => NONE)
e5f9a6d9ca82 clarified parallel_subproofs_saturation (blind guess) vs. parallel_subproofs_threshold (precient timing estimate);
wenzelm
parents: 51399
diff changeset
    99
  | NONE => NONE);
51218
6425a0d3b7ac support for build passing timings from Scala to ML;
wenzelm
parents: 51217
diff changeset
   100
48465
a25daffda966 observe "condition";
wenzelm
parents: 48464
diff changeset
   101
in
a25daffda966 observe "condition";
wenzelm
parents: 48464
diff changeset
   102
48681
181b91e1d1c1 prefer general Command_Line.tool wrapper (cf. Scala version);
wenzelm
parents: 48673
diff changeset
   103
fun build args_file = Command_Line.tool (fn () =>
48672
9bc7922ba2ae further robustification of interrupts during build;
wenzelm
parents: 48662
diff changeset
   104
    let
51220
e140c8fa485a recover timing information from old log files;
wenzelm
parents: 51218
diff changeset
   105
      val (command_timings, (do_output, (options, (verbose, (browser_info,
51399
6ac3c29a300e discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents: 51398
diff changeset
   106
          (parent_name, (chapter, (name, theories)))))))) =
48672
9bc7922ba2ae further robustification of interrupts during build;
wenzelm
parents: 48662
diff changeset
   107
        File.read (Path.explode args_file) |> YXML.parse_body |>
9bc7922ba2ae further robustification of interrupts during build;
wenzelm
parents: 48662
diff changeset
   108
          let open XML.Decode in
51218
6425a0d3b7ac support for build passing timings from Scala to ML;
wenzelm
parents: 51217
diff changeset
   109
            pair (list properties) (pair bool (pair Options.decode (pair bool (pair string
51399
6ac3c29a300e discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents: 51398
diff changeset
   110
              (pair string (pair string (pair string
6ac3c29a300e discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents: 51398
diff changeset
   111
                ((list (pair Options.decode (list string)))))))))))
48672
9bc7922ba2ae further robustification of interrupts during build;
wenzelm
parents: 48662
diff changeset
   112
          end;
48418
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
   113
48804
6348e5fca42e more direct interpretation of document_variants for build (unchanged for usedir);
wenzelm
parents: 48734
diff changeset
   114
      val document_variants =
6348e5fca42e more direct interpretation of document_variants for build (unchanged for usedir);
wenzelm
parents: 48734
diff changeset
   115
        map Present.read_variant (space_explode ":" (Options.string options "document_variants"));
48672
9bc7922ba2ae further robustification of interrupts during build;
wenzelm
parents: 48662
diff changeset
   116
      val _ =
48805
c3ea910b3581 explicit document_output directory, without implicit purge of default in ISABELLE_BROWSER_INFO;
wenzelm
parents: 48804
diff changeset
   117
        (case duplicates (op =) (map fst document_variants) of
c3ea910b3581 explicit document_output directory, without implicit purge of default in ISABELLE_BROWSER_INFO;
wenzelm
parents: 48804
diff changeset
   118
          [] => ()
c3ea910b3581 explicit document_output directory, without implicit purge of default in ISABELLE_BROWSER_INFO;
wenzelm
parents: 48804
diff changeset
   119
        | dups => error ("Duplicate document variants: " ^ commas_quote dups));
49242
e28b5d8f5613 more explicit indication of legacy features;
wenzelm
parents: 48927
diff changeset
   120
50982
a7aa17a1f721 use inlined session name as title for charts;
wenzelm
parents: 50975
diff changeset
   121
      val _ = writeln ("\fSession.name = " ^ name);
49242
e28b5d8f5613 more explicit indication of legacy features;
wenzelm
parents: 48927
diff changeset
   122
      val _ =
51399
6ac3c29a300e discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents: 51398
diff changeset
   123
        Session.init do_output
6ac3c29a300e discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents: 51398
diff changeset
   124
          (Options.bool options "browser_info")
6ac3c29a300e discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents: 51398
diff changeset
   125
          (Path.explode browser_info)
48672
9bc7922ba2ae further robustification of interrupts during build;
wenzelm
parents: 48662
diff changeset
   126
          (Options.string options "document")
9bc7922ba2ae further robustification of interrupts during build;
wenzelm
parents: 48662
diff changeset
   127
          (Options.bool options "document_graph")
48805
c3ea910b3581 explicit document_output directory, without implicit purge of default in ISABELLE_BROWSER_INFO;
wenzelm
parents: 48804
diff changeset
   128
          (Options.string options "document_output")
48804
6348e5fca42e more direct interpretation of document_variants for build (unchanged for usedir);
wenzelm
parents: 48734
diff changeset
   129
          document_variants
51399
6ac3c29a300e discontinued "isabelle usedir" option -r (reset session path);
wenzelm
parents: 51398
diff changeset
   130
          parent_name (chapter, name)
51398
c3d02b3518c2 discontinued "isabelle usedir" option -P (remote path);
wenzelm
parents: 51228
diff changeset
   131
          (false, "")
50121
97d2b77313a0 isabelle build no longer supports document_dump/document_dump_mode (no INCOMPATIBILITY, since it was never in official release);
wenzelm
parents: 49911
diff changeset
   132
          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: 49242
diff changeset
   133
51228
dff3471dd8bc more tight representation of command timing;
wenzelm
parents: 51220
diff changeset
   134
      val last_timing = lookup_timings (fold update_timings command_timings empty_timings);
51218
6425a0d3b7ac support for build passing timings from Scala to ML;
wenzelm
parents: 51217
diff changeset
   135
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: 49242
diff changeset
   136
      val res1 =
48673
b2b09970c571 let with_timing report overall number of threads;
wenzelm
parents: 48672
diff changeset
   137
        theories |>
51218
6425a0d3b7ac support for build passing timings from Scala to ML;
wenzelm
parents: 51217
diff changeset
   138
          (List.app (use_theories_condition last_timing)
48673
b2b09970c571 let with_timing report overall number of threads;
wenzelm
parents: 48672
diff changeset
   139
            |> Session.with_timing name verbose
50683
34b109c5324c inline ML statistics into build log;
wenzelm
parents: 50280
diff changeset
   140
            |> Unsynchronized.setmp Output.Private_Hooks.protocol_message_fn protocol_message
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: 49242
diff changeset
   141
            |> Unsynchronized.setmp Multithreading.max_threads (Options.int options "threads")
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: 49242
diff changeset
   142
            |> Exn.capture);
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: 49242
diff changeset
   143
      val res2 = Exn.capture Session.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: 49242
diff changeset
   144
      val _ = Par_Exn.release_all [res1, res2];
48673
b2b09970c571 let with_timing report overall number of threads;
wenzelm
parents: 48672
diff changeset
   145
48734
af91cd2301ba back to implicit commit via isabelle-process -- save image only once (cf. 181b91e1d1c1);
wenzelm
parents: 48731
diff changeset
   146
      val _ = if do_output then () else exit 0;
48681
181b91e1d1c1 prefer general Command_Line.tool wrapper (cf. Scala version);
wenzelm
parents: 48673
diff changeset
   147
    in 0 end);
48418
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
   148
1a634f9614fb some actual build function on ML side;
wenzelm
parents:
diff changeset
   149
end;
48465
a25daffda966 observe "condition";
wenzelm
parents: 48464
diff changeset
   150
a25daffda966 observe "condition";
wenzelm
parents: 48464
diff changeset
   151
end;