about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-01-27 19:59:29 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-01-27 19:59:29 -0800
commit0d3f30c21164b9fd722455e9fc60cdb0add2a866 (patch)
treec8b87736fd7c330f2b305923cb992998266f459f
parent50689bff2ed59814a67e74e90a33717552d69df0 (diff)
downloadmu-0d3f30c21164b9fd722455e9fc60cdb0add2a866.tar.gz
2610 - warn when recipes don't use default-space
Somehow this never transferred over from the Arc version until now.
-rw-r--r--020run.cc2
-rw-r--r--043space.cc44
-rw-r--r--050scenario.cc7
-rw-r--r--edit/005-sandbox.mu21
-rw-r--r--edit/010-warnings.mu7
-rw-r--r--sandbox/005-sandbox.mu1
-rw-r--r--sandbox/010-warnings.mu3
7 files changed, 74 insertions, 11 deletions
diff --git a/020run.cc b/020run.cc
index be3c69c1..90147e67 100644
--- a/020run.cc
+++ b/020run.cc
@@ -133,6 +133,7 @@ inline bool routine::completed() const {
 
 //: Step 1: load all .mu files with numeric prefixes (in order)
 :(before "End Load Recipes")
+// Load .mu Core
 //? Trace_file = "interactive";
 //? START_TRACING_UNTIL_END_OF_SCOPE;
 load_permanently("core.mu");
@@ -162,6 +163,7 @@ if (argc > 1) {
 //: start running it.
 :(before "End Main")
 if (!Run_tests && contains_key(Recipe_ordinal, "main") && contains_key(Recipe, get(Recipe_ordinal, "main"))) {
+  // Running Main
   setup();
 //?   Trace_file = "interactive";
 //?   START_TRACING_UNTIL_END_OF_SCOPE;
diff --git a/043space.cc b/043space.cc
index 662e7527..5bbda699 100644
--- a/043space.cc
+++ b/043space.cc
@@ -243,3 +243,47 @@ void rewrite_default_space_instruction(instruction& curr) {
     raise_error << "new-default-space can't take any results\n" << end();
   curr.products.push_back(reagent("default-space:address:shared:array:location"));
 }
+
+//:: all recipes must set default-space one way or another
+
+:(before "End Globals")
+bool Warn_on_missing_default_space = false;
+:(before "End Checks")
+Transform.push_back(check_default_space);  // idempotent
+:(code)
+void check_default_space(const recipe_ordinal r) {
+  if (!Warn_on_missing_default_space) return;  // skip previous core tests; this is only for mu code
+  const recipe& caller = get(Recipe, r);
+  // skip scenarios (later layer)
+  // user code should never create recipes with underscores in their names
+  if (caller.name.find("scenario_") == 0) return;  // skip mu scenarios which will use raw memory locations
+  if (caller.name.find("run_") == 0) return;  // skip calls to 'run', which should be in scenarios and will also use raw memory locations
+  // assume recipes with only numeric addresses know what they're doing (usually tests)
+  if (!contains_non_special_name(r)) return;
+  trace(9991, "transform") << "--- check that recipe " << caller.name << " sets default-space" << end();
+  if (caller.steps.empty()) return;
+  if (caller.steps.at(0).products.empty()
+      || caller.steps.at(0).products.at(0).name != "default-space") {
+    raise << maybe(caller.name) << " does not seem to start with default-space or local-scope\n" << end();
+//?     cerr << maybe(caller.name) << " does not seem to start with default-space or local-scope\n" << '\n';
+  }
+}
+:(after "Load .mu Core")
+Warn_on_missing_default_space = true;
+:(after "Test Runs")
+Warn_on_missing_default_space = false;
+:(after "Running Main")
+Warn_on_missing_default_space = true;
+
+:(code)
+bool contains_non_special_name(const recipe_ordinal r) {
+  for (map<string, long long int>::iterator p = Name[r].begin(); p != Name[r].end(); ++p) {
+    if (p->first.empty()) continue;
+    if (p->first.find("stash_") == 0) continue;  // generated by rewrite_stashes_to_text
+    if (!is_special_name(p->first)) {
+//?       cerr << "  " << Recipe[r].name << ": " << p->first << '\n';
+      return true;
+    }
+  }
+  return false;
+}
diff --git a/050scenario.cc b/050scenario.cc
index 768c2f7c..63c446ef 100644
--- a/050scenario.cc
+++ b/050scenario.cc
@@ -111,6 +111,7 @@ long long int Num_core_mu_tests = 0;
 :(after "Check For .mu Files")
 Num_core_mu_tests = SIZE(Scenarios);
 :(before "End Tests")
+Warn_on_missing_default_space = true;
 time_t mu_time; time(&mu_time);
 cerr << "\nMu tests: " << ctime(&mu_time);
 for (long long int i = 0; i < SIZE(Scenarios); ++i) {
@@ -145,7 +146,7 @@ void run_mu_scenario(const scenario& s) {
     Trace_stream = new trace_stream;
     setup();
   }
-  vector<recipe_ordinal> tmp = load("recipe scenario-"+s.name+" [ "+s.to_run+" ]");
+  vector<recipe_ordinal> tmp = load("recipe scenario_"+s.name+" [ "+s.to_run+" ]");
   bind_special_scenario_names(tmp.at(0));
   transform_all();
   run(tmp.front());
@@ -202,8 +203,10 @@ case RUN: {
 }
 :(before "End Primitive Recipe Implementations")
 case RUN: {
+  assert(Name[Next_recipe_ordinal].empty());
   ostringstream tmp;
-  tmp << "recipe run" << Next_recipe_ordinal << " [ " << current_instruction().ingredients.at(0).name << " ]";
+  tmp << "recipe run_" << Next_recipe_ordinal << " [ " << current_instruction().ingredients.at(0).name << " ]";
+//?   cerr << tmp.str() << '\n';
 //?   cerr << "before load\n";
   vector<recipe_ordinal> tmp_recipe = load(tmp.str());
 //?   cerr << "before bind\n";
diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu
index 568c7cb1..244c24f6 100644
--- a/edit/005-sandbox.mu
+++ b/edit/005-sandbox.mu
@@ -446,6 +446,7 @@ scenario run-updates-results [
   # define a recipe (no indent for the 'add' line below so column numbers are more obvious)
   1:address:shared:array:character <- new [ 
 recipe foo [
+local-scope
 z:number <- add 2, 2
 reply z
 ]]
@@ -461,15 +462,16 @@ reply z
     .                                                                                 run (F4)           .
     .                                                  ┊                                                 .
     .recipe foo [                                      ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
-    .z:number <- add 2, 2                              ┊0                                               x.
-    .reply z                                           ┊foo                                              .
-    .]                                                 ┊4                                                .
-    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
+    .local-scope                                       ┊0                                               x.
+    .z:number <- add 2, 2                              ┊foo                                              .
+    .reply z                                           ┊4                                                .
+    .]                                                 ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
+    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊                                                 .
     .                                                  ┊                                                 .
   ]
   # make a change (incrementing one of the args to 'add'), then rerun
   assume-console [
-    left-click 3, 28  # one past the value of the second arg
+    left-click 4, 28  # one past the value of the second arg
     press backspace
     type [3]
     press F4
@@ -482,10 +484,11 @@ reply z
     .                                                                                 run (F4)           .
     .                                                  ┊                                                 .
     .recipe foo [                                      ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
-    .z:number <- add 2, 3                              ┊0                                               x.
-    .reply z                                           ┊foo                                              .
-    .]                                                 ┊5                                                .
-    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
+    .local-scope                                       ┊0                                               x.
+    .z:number <- add 2, 3                              ┊foo                                              .
+    .reply z                                           ┊5                                                .
+    .]                                                 ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
+    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊                                                 .
     .                                                  ┊                                                 .
   ]
 ]
diff --git a/edit/010-warnings.mu b/edit/010-warnings.mu
index c37e31e2..5220ad3e 100644
--- a/edit/010-warnings.mu
+++ b/edit/010-warnings.mu
@@ -415,6 +415,7 @@ scenario run-shows-get-on-non-container-warnings [
   assume-screen 100/width, 15/height
   1:address:shared:array:character <- new [ 
 recipe foo [
+  local-scope
   x:address:shared:point <- new point:type
   get x:address:shared:point, 1:offset
 ]]
@@ -430,6 +431,7 @@ recipe foo [
     .  errors found                                                                   run (F4)           .
     .                                                  ┊foo                                              .
     .recipe foo [                                      ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
+    .  local-scope                                     ┊                                                 .
     .  x:address:shared:point <- new point:type        ┊                                                 .
     .  get x:address:shared:point, 1:offset            ┊                                                 .
     .]                                                 ┊                                                 .
@@ -445,6 +447,7 @@ scenario run-shows-non-literal-get-argument-warnings [
   assume-screen 100/width, 15/height
   1:address:shared:array:character <- new [ 
 recipe foo [
+  local-scope
   x:number <- copy 0
   y:address:shared:point <- new point:type
   get *y:address:shared:point, x:number
@@ -461,6 +464,7 @@ recipe foo [
     .  errors found                                                                   run (F4)           .
     .                                                  ┊foo                                              .
     .recipe foo [                                      ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
+    .  local-scope                                     ┊                                                 .
     .  x:number <- copy 0                              ┊                                                 .
     .  y:address:shared:point <- new point:type        ┊                                                 .
     .  get *y:address:shared:point, x:number           ┊                                                 .
@@ -480,6 +484,7 @@ scenario run-shows-warnings-everytime [
   assume-screen 100/width, 15/height
   1:address:shared:array:character <- new [ 
 recipe foo [
+  local-scope
   x:number <- copy y:number
 ]]
   2:address:shared:array:character <- new [foo]
@@ -492,6 +497,7 @@ recipe foo [
     .  errors found                                                                   run (F4)           .
     .                                                  ┊foo                                              .
     .recipe foo [                                      ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
+    .  local-scope                                     ┊                                                 .
     .  x:number <- copy y:number                       ┊                                                 .
     .]                                                 ┊                                                 .
     .foo: use before set: y                            ┊                                                 .
@@ -509,6 +515,7 @@ recipe foo [
     .  errors found                                                                   run (F4)           .
     .                                                  ┊foo                                              .
     .recipe foo [                                      ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
+    .  local-scope                                     ┊                                                 .
     .  x:number <- copy y:number                       ┊                                                 .
     .]                                                 ┊                                                 .
     .foo: use before set: y                            ┊                                                 .
diff --git a/sandbox/005-sandbox.mu b/sandbox/005-sandbox.mu
index 35d53beb..08bdf37f 100644
--- a/sandbox/005-sandbox.mu
+++ b/sandbox/005-sandbox.mu
@@ -459,6 +459,7 @@ reply z
   # make a change (incrementing one of the args to 'add'), then rerun
   1:address:shared:array:character <- new [ 
 recipe foo [
+local-scope
 z:number <- add 2, 3
 reply z
 ]]
diff --git a/sandbox/010-warnings.mu b/sandbox/010-warnings.mu
index 7f725097..f4651db5 100644
--- a/sandbox/010-warnings.mu
+++ b/sandbox/010-warnings.mu
@@ -425,6 +425,7 @@ scenario run-shows-get-on-non-container-warnings [
   assume-screen 50/width, 20/height
   1:address:shared:array:character <- new [ 
 recipe foo [
+  local-scope
   x:address:shared:point <- new point:type
   get x:address:shared:point, 1:offset
 ]]
@@ -450,6 +451,7 @@ scenario run-shows-non-literal-get-argument-warnings [
   assume-screen 50/width, 20/height
   1:address:shared:array:character <- new [ 
 recipe foo [
+  local-scope
   x:number <- copy 0
   y:address:shared:point <- new point:type
   get *y:address:shared:point, x:number
@@ -477,6 +479,7 @@ scenario run-shows-warnings-everytime [
   # try to run a file with an error
   1:address:shared:array:character <- new [ 
 recipe foo [
+  local-scope
   x:number <- copy y:number
 ]]
   2:address:shared:array:character <- new [foo]