about summary refs log tree commit diff stats
path: root/057static_dispatch.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-02-21 20:30:02 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-02-21 20:40:06 -0800
commitc4e143d6ea0635cdb164cec1c62afd7461e605ad (patch)
tree06fbb672ce95f1d5152c113cdb40685148b57d0c /057static_dispatch.cc
parentf22250a174d5ad5abf8bf99ad140ced52563aee2 (diff)
downloadmu-c4e143d6ea0635cdb164cec1c62afd7461e605ad.tar.gz
2681 - drop reagent types from reagent properties
All my attempts at staging this change failed with this humongous commit
that took all day and involved debugging three monstrous bugs. Two of
the bugs had to do with forgetting to check the type name in the
implementation of shape-shifting recipes. Bug #2 in particular would
cause core tests in layer 59 to fail -- only when I loaded up edit/! It
got me to just hack directly on mu.cc until I figured out the cause
(snapshot saved in mu.cc.modified). The problem turned out to be that I
accidentally saved a type ingredient in the Type table during
specialization. Now I know that that can be very bad.

I've checked the traces for any stray type numbers (rather than names).

I also found what might be a bug from last November (labeled TODO), but
we'll verify after this commit.
Diffstat (limited to '057static_dispatch.cc')
-rw-r--r--057static_dispatch.cc39
1 files changed, 17 insertions, 22 deletions
diff --git a/057static_dispatch.cc b/057static_dispatch.cc
index 576ef35f..9b1734b0 100644
--- a/057static_dispatch.cc
+++ b/057static_dispatch.cc
@@ -69,12 +69,12 @@ bool all_reagents_match(const recipe& r1, const recipe& r2) {
   if (SIZE(r1.ingredients) != SIZE(r2.ingredients)) return false;
   if (SIZE(r1.products) != SIZE(r2.products)) return false;
   for (long long int i = 0; i < SIZE(r1.ingredients); ++i) {
-    if (!deeply_equal_types(r1.ingredients.at(i), r2.ingredients.at(i))) {
+    if (!deeply_equal_type_names(r1.ingredients.at(i), r2.ingredients.at(i))) {
       return false;
     }
   }
   for (long long int i = 0; i < SIZE(r1.products); ++i) {
-    if (!deeply_equal_types(r1.products.at(i), r2.products.at(i))) {
+    if (!deeply_equal_type_names(r1.products.at(i), r2.products.at(i))) {
       return false;
     }
   }
@@ -87,21 +87,21 @@ set<string> Literal_type_names;
 Literal_type_names.insert("number");
 Literal_type_names.insert("character");
 :(code)
-bool deeply_equal_types(const reagent& a, const reagent& b) {
-  return deeply_equal_types(a.properties.at(0).second, b.properties.at(0).second);
+bool deeply_equal_type_names(const reagent& a, const reagent& b) {
+  return deeply_equal_type_names(a.type, b.type);
 }
-bool deeply_equal_types(const string_tree* a, const string_tree* b) {
+bool deeply_equal_type_names(const type_tree* a, const type_tree* b) {
   if (!a) return !b;
   if (!b) return !a;
-  if (a->value == "literal" && b->value == "literal")
+  if (a->name == "literal" && b->name == "literal")
     return true;
-  if (a->value == "literal")
-    return Literal_type_names.find(b->value) != Literal_type_names.end();
-  if (b->value == "literal")
-    return Literal_type_names.find(a->value) != Literal_type_names.end();
-  return a->value == b->value
-      && deeply_equal_types(a->left, b->left)
-      && deeply_equal_types(a->right, b->right);
+  if (a->name == "literal")
+    return Literal_type_names.find(b->name) != Literal_type_names.end();
+  if (b->name == "literal")
+    return Literal_type_names.find(a->name) != Literal_type_names.end();
+  return a->name == b->name
+      && deeply_equal_type_names(a->left, b->left)
+      && deeply_equal_type_names(a->right, b->right);
 }
 
 string next_unused_recipe_name(const string& recipe_name) {
@@ -130,14 +130,10 @@ recipe test a:number, b:number -> z:number [
 
 //: support recipe headers in a previous transform to fill in missing types
 :(before "End check_or_set_invalid_types")
-for (long long int i = 0; i < SIZE(caller.ingredients); ++i) {
-  check_or_set_invalid_types(caller.ingredients.at(i).type, caller.ingredients.at(i).properties.at(0).second,
-                             maybe(caller.name), "recipe header ingredient");
-}
-for (long long int i = 0; i < SIZE(caller.products); ++i) {
-  check_or_set_invalid_types(caller.products.at(i).type, caller.products.at(i).properties.at(0).second,
-                             maybe(caller.name), "recipe header product");
-}
+for (long long int i = 0; i < SIZE(caller.ingredients); ++i)
+  check_or_set_invalid_types(caller.ingredients.at(i).type, maybe(caller.name), "recipe header ingredient");
+for (long long int i = 0; i < SIZE(caller.products); ++i)
+  check_or_set_invalid_types(caller.products.at(i).type, maybe(caller.name), "recipe header product");
 
 //: after filling in all missing types (because we'll be introducing 'blank' types in this transform in a later layer, for shape-shifting recipes)
 :(after "Transform.push_back(transform_names)")
@@ -156,7 +152,6 @@ list<call> resolve_stack;
 void resolve_ambiguous_calls(recipe_ordinal r) {
   recipe& caller_recipe = get(Recipe, r);
   trace(9991, "transform") << "--- resolve ambiguous calls for recipe " << caller_recipe.name << end();
-//?   cerr << "--- resolve ambiguous calls for recipe " << caller_recipe.name << '\n';
   for (long long int index = 0; index < SIZE(caller_recipe.steps); ++index) {
     instruction& inst = caller_recipe.steps.at(index);
     if (inst.is_label) continue;