about summary refs log tree commit diff stats
path: root/020run.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-07-26 10:09:29 -0700
committerKartik Agaram <vc@akkartik.com>2018-07-26 10:09:29 -0700
commit257add0f7e437f0a1a355a748be0c97e03882b0c (patch)
tree917af5e78761b1ce7f6f5e47b3736777b4930896 /020run.cc
parent3b798ea2c9dadca94f808f168dc2cb37abcaeb94 (diff)
downloadmu-257add0f7e437f0a1a355a748be0c97e03882b0c.tar.gz
4421
Clean up the rat's nest that all my trace management globals had
gradually turned into.

  a) Get rid of 'Start_tracing'. Horryibly named, I don't know how I
  missed that until now.

  b) Never use START_TRACING_UNTIL_END_OF_SCOPE in main(). It's
  confusing to combine it with atexit(delete Trace_stream), because the
  atexit() never has to run. Instead we'll just manually initialize
  Trace_stream and let atexit() clean up.

  c) If we run tests we only want a trace for the test run itself. So
  delete the Trace_stream that was initialized at the top of main --
  once it's clear we had no load-time errors.

  d) Clean up horribly "Load Recipes" waypoints, combine them with the better
  name, "Mu Prelude".

Putting these together, we have the following manual tests:

  - CFLAGS=-g mu x.mu

    Should not create last_run.

  - CFLAGS=-g mu --trace x.mu

    Should create last_run.
    Should write it out exactly once.

  - CFLAGS=-g mu --trace x.mu  # when x.mu has an error

    Should create last_run.
    Should write it out exactly once.

  - CFLAGS=-g mu --trace test copy_literal  # C test

    Should create last_run.
    Should write it out exactly once.

  - CFLAGS=-g mu --trace test recipe_with_header  # Mu test

    Should create last_run.
    Should write it out exactly once.

I don't know how to automate these scenarios yet. We need a way to run
our build toolchain atop our stack.
Diffstat (limited to '020run.cc')
-rw-r--r--020run.cc43
1 files changed, 7 insertions, 36 deletions
diff --git a/020run.cc b/020run.cc
index 7a4c7020..74012216 100644
--- a/020run.cc
+++ b/020run.cc
@@ -192,11 +192,7 @@ const vector<instruction>& routine::steps() const {
 
 //:: Startup flow
 
-//: Step 1: load all .mu files with numeric prefixes (in order)
-:(before "End Load Recipes")
-// Load Mu Prelude
-//? Save_trace = true;
-//? START_TRACING_UNTIL_END_OF_SCOPE;
+:(before "End Mu Prelude")
 load_file_or_directory("core.mu");
 //? DUMP("");
 //? exit(0);
@@ -204,8 +200,6 @@ load_file_or_directory("core.mu");
 //: Step 2: load any .mu files provided at the commandline
 :(before "End Commandline Parsing")
 // Check For .mu Files
-//? START_TRACING_UNTIL_END_OF_SCOPE
-//? Dump_trace = true;
 if (argc > 1) {
   // skip argv[0]
   ++argv;
@@ -226,9 +220,11 @@ transform_all();
 //? cerr << to_original_string(get(Recipe, get(Recipe_ordinal, "event-loop"))) << '\n';
 //? DUMP("");
 //? exit(0);
-if (trace_contains_errors()) {
-  if (Start_tracing && Trace_stream) Trace_stream->save();
-  return 1;
+if (trace_contains_errors()) return 1;
+if (Trace_stream && Run_tests) {
+  // We'll want a trace per test. Clear the trace.
+  delete Trace_stream;
+  Trace_stream = NULL;
 }
 save_snapshots();
 
@@ -238,14 +234,9 @@ save_snapshots();
 if (!Run_tests && contains_key(Recipe_ordinal, "main") && contains_key(Recipe, get(Recipe_ordinal, "main"))) {
   // Running Main
   reset();
-  if (Start_tracing && Trace_stream == NULL) {
-    Trace_stream = new trace_stream;
-    Save_trace = true;
-  }
   trace(2, "run") << "=== Starting to run" << end();
   assert(Num_calls_to_transform_all == 1);
   run_main(argc, argv);
-  if (Start_tracing && Trace_stream) Trace_stream->save();
 }
 :(code)
 void run_main(int argc, char* argv[]) {
@@ -253,26 +244,6 @@ void run_main(int argc, char* argv[]) {
   if (r) run(r);
 }
 
-//: By default we don't maintain the trace while running main because its
-//: overheads can grow rapidly. However, it's useful when debugging.
-:(before "End Globals")
-bool Start_tracing = false;
-:(before "End Commandline Options(*arg)")
-else if (is_equal(*arg, "--trace")) {
-  Start_tracing = true;
-}
-
-:(code)
-void cleanup_main() {
-  if (!Trace_stream) return;
-  if (Save_trace)
-    Trace_stream->save();
-  delete Trace_stream;
-  Trace_stream = NULL;
-}
-:(before "End One-time Setup")
-atexit(cleanup_main);
-
 :(code)
 void load_file_or_directory(string filename) {
   if (is_directory(filename)) {
@@ -422,7 +393,7 @@ void run(const string& form) {
   transform_all();
   if (tmp.empty()) return;
   if (trace_contains_errors()) {
-    if (Start_tracing && Trace_stream) Trace_stream->save();
+    if (Save_trace && Trace_stream) Trace_stream->save();
     return;
   }
   // if a test defines main, it probably wants to start there regardless of