about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-04-13 22:04:52 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-04-13 22:04:52 -0700
commitf404eb55720ce5bcfe9e78b74933a0a2b69badef (patch)
tree2ad1e781f376dc6f7296ad3fe35ba2bc95c79085
parentad05221de91b9ec058de36319c617e7ac771e950 (diff)
downloadmu-f404eb55720ce5bcfe9e78b74933a0a2b69badef.tar.gz
3819
Yet another attempt at trying to clean up commit 3216. I think this solution
might finally let me stop agonizing over the problem. State variables for
distinguishing call-sites are a reasonable mechanism, orthogonal to waypoints
and the hook functions to hold them.
-rw-r--r--020run.cc7
-rw-r--r--036refcount.cc14
-rw-r--r--043space.cc11
-rw-r--r--072scheduler.cc2
4 files changed, 18 insertions, 16 deletions
diff --git a/020run.cc b/020run.cc
index 39168588..892800f4 100644
--- a/020run.cc
+++ b/020run.cc
@@ -91,7 +91,8 @@ void run_current_routine() {
         cout << "not a primitive op: " << current_instruction().operation << '\n';
       }
     }
-    // Write Products of Instruction
+    //: used by a later layer
+    Writing_products_of_instruction = true;
     if (SIZE(products) < SIZE(current_instruction().products)) {
       raise << SIZE(products) << " vs " << SIZE(current_instruction().products) << ": failed to write to all products in '" << to_original_string(current_instruction()) << "'\n" << end();
     }
@@ -99,13 +100,15 @@ void run_current_routine() {
       for (int i = 0;  i < SIZE(current_instruction().products);  ++i)
         write_memory(current_instruction().products.at(i), products.at(i));
     }
-    // End Write Products of Instruction
+    Writing_products_of_instruction = false;
     // End Running One Instruction
     finish_instruction:;
     ++current_step_index();
   }
   stop_running_current_routine:;
 }
+:(before "End Globals")
+bool Writing_products_of_instruction = false;
 
 //: hook replaced in a later layer
 bool should_continue_running(const routine* current_routine) {
diff --git a/036refcount.cc b/036refcount.cc
index 10d451ab..8297c4ed 100644
--- a/036refcount.cc
+++ b/036refcount.cc
@@ -17,20 +17,22 @@ def main [
 +run: {2: ("address" "number")} <- copy {0: "literal"}
 +mem: decrementing refcount of 1000: 1 -> 0
 
-:(before "End Globals")
-//: escape hatch for a later layer
-bool Update_refcounts_in_write_memory = true;
-
 :(before "End write_memory(x) Special-cases")
-if (Update_refcounts_in_write_memory)
-  update_any_refcounts(x, data);
+update_any_refcounts(x, data);
 
 :(code)
 void update_any_refcounts(const reagent& canonized_x, const vector<double>& data) {
+  if (!should_update_refcounts()) return;
   increment_any_refcounts(canonized_x, data);  // increment first so we don't reclaim on x <- copy x
   decrement_any_refcounts(canonized_x);
 }
 
+//: escape hatch for a later layer
+bool should_update_refcounts() {
+  // End should_update_refcounts() Special-cases
+  return true;
+}
+
 void increment_any_refcounts(const reagent& canonized_x, const vector<double>& data) {
   if (is_mu_address(canonized_x)) {
     assert(scalar(data));
diff --git a/043space.cc b/043space.cc
index a07d2528..1562c11f 100644
--- a/043space.cc
+++ b/043space.cc
@@ -286,14 +286,10 @@ bool escaping(const reagent& r) {
 //: since we don't decrement refcounts for escaping values above, make sure we
 //: don't increment them when the caller saves them either
 
-:(after "Write Products of Instruction")
-Update_refcounts_in_write_memory = should_update_refcounts_in_write_memory();
-:(before "End Write Products of Instruction")
-Update_refcounts_in_write_memory = true;
-:(code)
-bool should_update_refcounts_in_write_memory() {
+:(before "End should_update_refcounts() Special-cases")
+if (Writing_products_of_instruction) {
   const instruction& inst = current_instruction();
-  // End should_update_refcounts_in_write_memory Special-cases For Primitives
+  // should_update_refcounts() Special-cases When Writing Products Of Primitive Instructions
   if (inst.operation < MAX_PRIMITIVE_RECIPES) return true;
   if (!contains_key(Recipe, inst.operation)) return true;
   const recipe& callee = get(Recipe, inst.operation);
@@ -301,6 +297,7 @@ bool should_update_refcounts_in_write_memory() {
   return callee.steps.at(0).name_before_rewrite != "local-scope";  // callees that call local-scope are already dealt with before return
 }
 
+:(code)
 bool caller_uses_product(int product_index) {
   assert(Current_routine);  // run-time only
   assert(!Current_routine->calls.empty());
diff --git a/072scheduler.cc b/072scheduler.cc
index ad79bace..3dad805c 100644
--- a/072scheduler.cc
+++ b/072scheduler.cc
@@ -289,7 +289,7 @@ def new-routine n:&:num [
 increment_any_refcounts(ingredient, ingredients.at(i));
 :(before "End Populate start-running Ingredient")
 increment_any_refcounts(ingredient, ingredients.at(i));
-:(before "End should_update_refcounts_in_write_memory Special-cases For Primitives")
+:(after "should_update_refcounts() Special-cases When Writing Products Of Primitive Instructions")
 if (inst.operation == NEXT_INGREDIENT || inst.operation == NEXT_INGREDIENT_WITHOUT_TYPECHECKING) {
   if (space_index(inst.products.at(0)) > 0) return true;
   if (has_property(inst.products.at(0), "raw")) return true;