From 93d4cc937ee480952cb93f21e5a04a96296c8302 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 10 Nov 2016 21:39:02 -0800 Subject: 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.. --- 021check_instruction.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to '021check_instruction.cc') diff --git a/021check_instruction.cc b/021check_instruction.cc index 93ce5427..2a8ef70f 100644 --- a/021check_instruction.cc +++ b/021check_instruction.cc @@ -102,6 +102,7 @@ bool types_coercible(const reagent& to, const reagent& from) { if (is_mu_address(from) && is_mu_number(to)) return true; if (is_mu_boolean(from) && is_mu_number(to)) return true; if (is_mu_number(from) && is_mu_boolean(to)) return true; + // End types_coercible Special-cases return false; } @@ -136,14 +137,12 @@ bool types_strictly_match(reagent/*copy*/ to, reagent/*copy*/ from) { return types_strictly_match(to.type, from.type); } -// two types match if the second begins like the first -// (trees perform the same check recursively on each subtree) bool types_strictly_match(const type_tree* to, const type_tree* from) { if (from == to) return true; + if (!to) return false; if (!from) return to->atom && to->value == 0; - if (to->atom && !from->atom) return from->left->atom && from->left->name == to->name; + if (from->atom != to->atom) return false; if (from->atom) { - if (!to->atom) return false; if (from->value == -1) return from->name == to->name; return from->value == to->value; } -- cgit 1.4.1-2-gfad0