about summary refs log tree commit diff stats
path: root/042name.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-11-10 21:39:02 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-11-10 21:39:02 -0800
commit93d4cc937ee480952cb93f21e5a04a96296c8302 (patch)
tree99018782ac8bd84e1eae1f0650b89d2f72989dd2 /042name.cc
parentdc80c7b92a9c5e576436f5c877fa9ecc6883d152 (diff)
downloadmu-93d4cc937ee480952cb93f21e5a04a96296c8302.tar.gz
3663 - fix a refcounting bug: '(type)' != 'type'
This was a large commit, and most of it is a follow-up to commit 3309,
undoing what is probably the final ill-considered optimization I added
to s-expressions in Mu: I was always representing (a b c) as (a b . c),
etc. That is now gone.

Why did I need to take it out? The key problem was the error silently
ignored in layer 30. That was causing size_of("(type)") to silently
return garbage rather than loudly complain (assuming 'type' was a simple
type).

But to take it out I had to modify types_strictly_match (layer 21) to
actually strictly match and not just do a prefix match.

In the process of removing the prefix match, I had to make extracting
recipe types from recipe headers more robust. So far it only matched the
first element of each ingredient's type; these matched:

  (recipe address:number -> address:number)
  (recipe address -> address)

I didn't notice because the dotted notation optimization was actually
representing this as:

  (recipe address:number -> address number)

---

One final little thing in this commit: I added an alias for 'assert'
called 'assert_for_now', to indicate that I'm not sure something's
really an invariant, that it might be triggered by (invalid) user
programs, and so require more thought on error handling down the road.

But this may well be an ill-posed distinction. It may be overwhelmingly
uneconomic to continually distinguish between model invariants and error
states for input. I'm starting to grow sympathetic to Google Analytics's
recent approach of just banning assertions altogether. We'll see..
Diffstat (limited to '042name.cc')
-rw-r--r--042name.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/042name.cc b/042name.cc
index 1fc2f201..48f2bfea 100644
--- a/042name.cc
+++ b/042name.cc
@@ -121,9 +121,13 @@ type_ordinal skip_addresses(type_tree* type) {
   while (type && is_compound_type_starting_with(type, "address"))
     type = type->right;
   if (!type) return -1;  // error handled elsewhere
+  if (type->atom) return type->value;
   const type_tree* base_type = type;
   // Update base_type in skip_addresses
-  return base_type->value;
+  if (base_type->atom)
+    return base_type->value;
+  assert(base_type->left->atom);
+  return base_type->left->value;
 }
 
 int find_element_name(const type_ordinal t, const string& name, const string& recipe_name) {