From 987b630476eff43467905299d936c388f28d3fc6 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 13 Apr 2017 22:26:25 -0700 Subject: 3820 --- html/054static_dispatch.cc.html | 893 +++++++++++++++++++++------------------- 1 file changed, 471 insertions(+), 422 deletions(-) (limited to 'html/054static_dispatch.cc.html') diff --git a/html/054static_dispatch.cc.html b/html/054static_dispatch.cc.html index c3f2c8cc..5ba08ee0 100644 --- a/html/054static_dispatch.cc.html +++ b/html/054static_dispatch.cc.html @@ -224,7 +224,7 @@ if ('onhashchange' in window) { 159 for (int index = 0; index < SIZE(caller_recipe.steps); ++index) { 160 ¦ instruction& inst = caller_recipe.steps.at(index); 161 ¦ if (inst.is_label) continue; -162 ¦ if (non_ghost_size(get_or_insert(Recipe_variants, inst.name)) == 0) continue; +162 ¦ if (non_ghost_size(get_or_insert(Recipe_variants, inst.name)) == 0) continue; 163 ¦ trace(9992, "transform") << "instruction " << inst.original_string << end(); 164 ¦ Resolve_stack.push_front(call(r)); 165 ¦ Resolve_stack.front().running_step_index = index; @@ -242,11 +242,11 @@ if ('onhashchange' in window) { 177 vector<recipe_ordinal> candidates; 178 179 // Static Dispatch Phase 1 -180 candidates = strictly_matching_variants(inst, variants); +180 candidates = strictly_matching_variants(inst, variants); 181 if (!candidates.empty()) return best_variant(inst, candidates).name; 182 183 // Static Dispatch Phase 2 -184 candidates = strictly_matching_variants_except_literal_against_address_or_boolean(inst, variants); +184 candidates = strictly_matching_variants_except_literal_against_address_or_boolean(inst, variants); 185 if (!candidates.empty()) return best_variant(inst, candidates).name; 186 187 // Static Dispatch Phase 3 @@ -254,440 +254,489 @@ if ('onhashchange' in window) { 189 // End Static Dispatch Phase 3 190 191 // Static Dispatch Phase 4 -192 candidates = matching_variants(inst, variants); +192 candidates = matching_variants(inst, variants); 193 if (!candidates.empty()) return best_variant(inst, candidates).name; 194 195 // error messages 196 if (get(Recipe_ordinal, inst.name) >= MAX_PRIMITIVE_RECIPES) { // we currently don't check types for primitive variants -197 ¦ raise << maybe(caller_recipe.name) << "failed to find a matching call for '" << inst.original_string << "'\n" << end(); -198 ¦ for (list<call>::iterator p = /*skip*/++Resolve_stack.begin(); p != Resolve_stack.end(); ++p) { -199 ¦ ¦ const recipe& specializer_recipe = get(Recipe, p->running_recipe); -200 ¦ ¦ const instruction& specializer_inst = specializer_recipe.steps.at(p->running_step_index); -201 ¦ ¦ if (specializer_recipe.name != "interactive") -202 ¦ ¦ ¦ raise << " (from '" << to_original_string(specializer_inst) << "' in " << specializer_recipe.name << ")\n" << end(); -203 ¦ ¦ else -204 ¦ ¦ ¦ raise << " (from '" << to_original_string(specializer_inst) << "')\n" << end(); -205 ¦ ¦ // One special-case to help with the rewrite_stash transform. (cross-layer) -206 ¦ ¦ if (specializer_inst.products.at(0).name.find("stash_") == 0) { -207 ¦ ¦ ¦ instruction stash_inst; -208 ¦ ¦ ¦ if (next_stash(*p, &stash_inst)) { -209 ¦ ¦ ¦ ¦ if (specializer_recipe.name != "interactive") -210 ¦ ¦ ¦ ¦ ¦ raise << " (part of '" << stash_inst.original_string << "' in " << specializer_recipe.name << ")\n" << end(); -211 ¦ ¦ ¦ ¦ else -212 ¦ ¦ ¦ ¦ ¦ raise << " (part of '" << stash_inst.original_string << "')\n" << end(); -213 ¦ ¦ ¦ } -214 ¦ ¦ } -215 ¦ } -216 } -217 return ""; -218 } -219 -220 // phase 1 -221 vector<recipe_ordinal> strictly_matching_variants(const instruction& inst, vector<recipe_ordinal>& variants) { -222 vector<recipe_ordinal> result; -223 for (int i = 0; i < SIZE(variants); ++i) { -224 ¦ if (variants.at(i) == -1) continue; -225 ¦ trace(9992, "transform") << "checking variant (strict) " << i << ": " << header_label(variants.at(i)) << end(); -226 ¦ if (all_header_reagents_strictly_match(inst, get(Recipe, variants.at(i)))) -227 ¦ ¦ result.push_back(variants.at(i)); -228 } -229 return result; -230 } -231 -232 bool all_header_reagents_strictly_match(const instruction& inst, const recipe& variant) { -233 for (int i = 0; i < min(SIZE(inst.ingredients), SIZE(variant.ingredients)); ++i) { -234 ¦ if (!types_strictly_match(variant.ingredients.at(i), inst.ingredients.at(i))) { -235 ¦ ¦ trace(9993, "transform") << "strict match failed: ingredient " << i << end(); -236 ¦ ¦ return false; -237 ¦ } -238 } -239 for (int i = 0; i < min(SIZE(inst.products), SIZE(variant.products)); ++i) { -240 ¦ if (is_dummy(inst.products.at(i))) continue; -241 ¦ if (!types_strictly_match(variant.products.at(i), inst.products.at(i))) { -242 ¦ ¦ trace(9993, "transform") << "strict match failed: product " << i << end(); -243 ¦ ¦ return false; -244 ¦ } -245 } -246 return true; -247 } -248 -249 // phase 2 -250 vector<recipe_ordinal> strictly_matching_variants_except_literal_against_address_or_boolean(const instruction& inst, vector<recipe_ordinal>& variants) { -251 vector<recipe_ordinal> result; -252 for (int i = 0; i < SIZE(variants); ++i) { -253 ¦ if (variants.at(i) == -1) continue; -254 ¦ trace(9992, "transform") << "checking variant (strict except literal-against-boolean) " << i << ": " << header_label(variants.at(i)) << end(); -255 ¦ if (all_header_reagents_strictly_match_except_literal_against_address_or_boolean(inst, get(Recipe, variants.at(i)))) -256 ¦ ¦ result.push_back(variants.at(i)); -257 } -258 return result; -259 } -260 -261 bool all_header_reagents_strictly_match_except_literal_against_address_or_boolean(const instruction& inst, const recipe& variant) { -262 for (int i = 0; i < min(SIZE(inst.ingredients), SIZE(variant.ingredients)); ++i) { -263 ¦ if (!types_strictly_match_except_literal_against_address_or_boolean(variant.ingredients.at(i), inst.ingredients.at(i))) { -264 ¦ ¦ trace(9993, "transform") << "match failed: ingredient " << i << end(); -265 ¦ ¦ return false; -266 ¦ } -267 } -268 for (int i = 0; i < min(SIZE(variant.products), SIZE(inst.products)); ++i) { -269 ¦ if (is_dummy(inst.products.at(i))) continue; -270 ¦ if (!types_strictly_match_except_literal_against_address_or_boolean(variant.products.at(i), inst.products.at(i))) { -271 ¦ ¦ trace(9993, "transform") << "match failed: product " << i << end(); -272 ¦ ¦ return false; -273 ¦ } -274 } -275 return true; -276 } -277 -278 bool types_strictly_match_except_literal_against_address_or_boolean(const reagent& to, const reagent& from) { -279 if (is_literal(from) && is_mu_boolean(to)) -280 ¦ return from.name == "0" || from.name == "1"; -281 // Match Literal Zero Against Address { -282 if (is_literal(from) && is_mu_address(to)) -283 ¦ return from.name == "0"; -284 // } -285 return types_strictly_match(to, from); -286 } -287 -288 // phase 4 -289 vector<recipe_ordinal> matching_variants(const instruction& inst, vector<recipe_ordinal>& variants) { -290 vector<recipe_ordinal> result; -291 for (int i = 0; i < SIZE(variants); ++i) { -292 ¦ if (variants.at(i) == -1) continue; -293 ¦ trace(9992, "transform") << "checking variant " << i << ": " << header_label(variants.at(i)) << end(); -294 ¦ if (all_header_reagents_match(inst, get(Recipe, variants.at(i)))) -295 ¦ ¦ result.push_back(variants.at(i)); -296 } -297 return result; -298 } -299 -300 bool all_header_reagents_match(const instruction& inst, const recipe& variant) { -301 for (int i = 0; i < min(SIZE(inst.ingredients), SIZE(variant.ingredients)); ++i) { -302 ¦ if (!types_match(variant.ingredients.at(i), inst.ingredients.at(i))) { -303 ¦ ¦ trace(9993, "transform") << "match failed: ingredient " << i << end(); -304 ¦ ¦ return false; -305 ¦ } -306 } -307 for (int i = 0; i < min(SIZE(variant.products), SIZE(inst.products)); ++i) { -308 ¦ if (is_dummy(inst.products.at(i))) continue; -309 ¦ if (!types_match(variant.products.at(i), inst.products.at(i))) { -310 ¦ ¦ trace(9993, "transform") << "match failed: product " << i << end(); -311 ¦ ¦ return false; -312 ¦ } -313 } -314 return true; -315 } -316 -317 // tie-breaker for each phase -318 const recipe& best_variant(const instruction& inst, vector<recipe_ordinal>& candidates) { -319 assert(!candidates.empty()); -320 int min_score = 999; -321 int min_index = 0; -322 for (int i = 0; i < SIZE(candidates); ++i) { -323 ¦ const recipe& candidate = get(Recipe, candidates.at(i)); -324 ¦ // prefer functions without extra or missing ingredients or products -325 ¦ int score = abs(SIZE(candidate.products)-SIZE(inst.products)) -326 ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ + abs(SIZE(candidate.ingredients)-SIZE(inst.ingredients)); -327 ¦ // prefer functions with non-address ingredients or products -328 ¦ for (int j = 0; j < SIZE(candidate.ingredients); ++j) { -329 ¦ ¦ if (is_mu_address(candidate.ingredients.at(j))) -330 ¦ ¦ ¦ ++score; -331 ¦ } -332 ¦ for (int j = 0; j < SIZE(candidate.products); ++j) { -333 ¦ ¦ if (is_mu_address(candidate.products.at(j))) -334 ¦ ¦ ¦ ++score; -335 ¦ } -336 ¦ assert(score < 999); -337 ¦ if (score < min_score) { -338 ¦ ¦ min_score = score; -339 ¦ ¦ min_index = i; -340 ¦ } -341 } -342 return get(Recipe, candidates.at(min_index)); -343 } -344 -345 int non_ghost_size(vector<recipe_ordinal>& variants) { -346 int result = 0; -347 for (int i = 0; i < SIZE(variants); ++i) -348 ¦ if (variants.at(i) != -1) ++result; -349 return result; -350 } -351 -352 bool next_stash(const call& c, instruction* stash_inst) { -353 const recipe& specializer_recipe = get(Recipe, c.running_recipe); -354 int index = c.running_step_index; -355 for (++index; index < SIZE(specializer_recipe.steps); ++index) { -356 ¦ const instruction& inst = specializer_recipe.steps.at(index); -357 ¦ if (inst.name == "stash") { -358 ¦ ¦ *stash_inst = inst; -359 ¦ ¦ return true; -360 ¦ } -361 } -362 return false; +197 ¦ if (SIZE(variants) == 1) { +198 ¦ ¦ raise << maybe(caller_recipe.name) << "instruction '" << inst.original_string << "' does not match '" << header_label(get(Recipe, variants.at(0))) << "'\n" << end(); +199 ¦ ¦ raise << " instruction expands to '" << to_string(inst) << "'\n" << end(); +200 ¦ } +201 ¦ else { +202 ¦ ¦ raise << maybe(caller_recipe.name) << "failed to find a matching call for '" << inst.original_string << "'\n" << end(); +203 ¦ ¦ raise << " which expands to:\n" << end(); +204 ¦ ¦ raise << " " << to_string(inst) << '\n' << end(); +205 ¦ ¦ raise << " available variants are:\n" << end(); +206 ¦ ¦ for (int i = 0; i < SIZE(variants); ++i) { +207 ¦ ¦ ¦ const recipe& curr = get(Recipe, variants.at(i)); +208 ¦ ¦ ¦ raise << " " << header_label(curr) << '\n' << end(); +209 ¦ ¦ } +210 ¦ } +211 ¦ for (list<call>::iterator p = /*skip*/++Resolve_stack.begin(); p != Resolve_stack.end(); ++p) { +212 ¦ ¦ const recipe& specializer_recipe = get(Recipe, p->running_recipe); +213 ¦ ¦ const instruction& specializer_inst = specializer_recipe.steps.at(p->running_step_index); +214 ¦ ¦ if (specializer_recipe.name != "interactive") +215 ¦ ¦ ¦ raise << " (from '" << to_original_string(specializer_inst) << "' in " << specializer_recipe.name << ")\n" << end(); +216 ¦ ¦ else +217 ¦ ¦ ¦ raise << " (from '" << to_original_string(specializer_inst) << "')\n" << end(); +218 ¦ ¦ // One special-case to help with the rewrite_stash transform. (cross-layer) +219 ¦ ¦ if (specializer_inst.products.at(0).name.find("stash_") == 0) { +220 ¦ ¦ ¦ instruction stash_inst; +221 ¦ ¦ ¦ if (next_stash(*p, &stash_inst)) { +222 ¦ ¦ ¦ ¦ if (specializer_recipe.name != "interactive") +223 ¦ ¦ ¦ ¦ ¦ raise << " (part of '" << stash_inst.original_string << "' in " << specializer_recipe.name << ")\n" << end(); +224 ¦ ¦ ¦ ¦ else +225 ¦ ¦ ¦ ¦ ¦ raise << " (part of '" << stash_inst.original_string << "')\n" << end(); +226 ¦ ¦ ¦ } +227 ¦ ¦ } +228 ¦ } +229 } +230 return ""; +231 } +232 +233 // phase 1 +234 vector<recipe_ordinal> strictly_matching_variants(const instruction& inst, vector<recipe_ordinal>& variants) { +235 vector<recipe_ordinal> result; +236 for (int i = 0; i < SIZE(variants); ++i) { +237 ¦ if (variants.at(i) == -1) continue; +238 ¦ trace(9992, "transform") << "checking variant (strict) " << i << ": " << header_label(variants.at(i)) << end(); +239 ¦ if (all_header_reagents_strictly_match(inst, get(Recipe, variants.at(i)))) +240 ¦ ¦ result.push_back(variants.at(i)); +241 } +242 return result; +243 } +244 +245 bool all_header_reagents_strictly_match(const instruction& inst, const recipe& variant) { +246 for (int i = 0; i < min(SIZE(inst.ingredients), SIZE(variant.ingredients)); ++i) { +247 ¦ if (!types_strictly_match(variant.ingredients.at(i), inst.ingredients.at(i))) { +248 ¦ ¦ trace(9993, "transform") << "strict match failed: ingredient " << i << end(); +249 ¦ ¦ return false; +250 ¦ } +251 } +252 for (int i = 0; i < min(SIZE(inst.products), SIZE(variant.products)); ++i) { +253 ¦ if (is_dummy(inst.products.at(i))) continue; +254 ¦ if (!types_strictly_match(variant.products.at(i), inst.products.at(i))) { +255 ¦ ¦ trace(9993, "transform") << "strict match failed: product " << i << end(); +256 ¦ ¦ return false; +257 ¦ } +258 } +259 return true; +260 } +261 +262 // phase 2 +263 vector<recipe_ordinal> strictly_matching_variants_except_literal_against_address_or_boolean(const instruction& inst, vector<recipe_ordinal>& variants) { +264 vector<recipe_ordinal> result; +265 for (int i = 0; i < SIZE(variants); ++i) { +266 ¦ if (variants.at(i) == -1) continue; +267 ¦ trace(9992, "transform") << "checking variant (strict except literal-against-boolean) " << i << ": " << header_label(variants.at(i)) << end(); +268 ¦ if (all_header_reagents_strictly_match_except_literal_against_address_or_boolean(inst, get(Recipe, variants.at(i)))) +269 ¦ ¦ result.push_back(variants.at(i)); +270 } +271 return result; +272 } +273 +274 bool all_header_reagents_strictly_match_except_literal_against_address_or_boolean(const instruction& inst, const recipe& variant) { +275 for (int i = 0; i < min(SIZE(inst.ingredients), SIZE(variant.ingredients)); ++i) { +276 ¦ if (!types_strictly_match_except_literal_against_address_or_boolean(variant.ingredients.at(i), inst.ingredients.at(i))) { +277 ¦ ¦ trace(9993, "transform") << "match failed: ingredient " << i << end(); +278 ¦ ¦ return false; +279 ¦ } +280 } +281 for (int i = 0; i < min(SIZE(variant.products), SIZE(inst.products)); ++i) { +282 ¦ if (is_dummy(inst.products.at(i))) continue; +283 ¦ if (!types_strictly_match_except_literal_against_address_or_boolean(variant.products.at(i), inst.products.at(i))) { +284 ¦ ¦ trace(9993, "transform") << "match failed: product " << i << end(); +285 ¦ ¦ return false; +286 ¦ } +287 } +288 return true; +289 } +290 +291 bool types_strictly_match_except_literal_against_address_or_boolean(const reagent& to, const reagent& from) { +292 if (is_literal(from) && is_mu_boolean(to)) +293 ¦ return from.name == "0" || from.name == "1"; +294 // Match Literal Zero Against Address { +295 if (is_literal(from) && is_mu_address(to)) +296 ¦ return from.name == "0"; +297 // } +298 return types_strictly_match(to, from); +299 } +300 +301 // phase 4 +302 vector<recipe_ordinal> matching_variants(const instruction& inst, vector<recipe_ordinal>& variants) { +303 vector<recipe_ordinal> result; +304 for (int i = 0; i < SIZE(variants); ++i) { +305 ¦ if (variants.at(i) == -1) continue; +306 ¦ trace(9992, "transform") << "checking variant " << i << ": " << header_label(variants.at(i)) << end(); +307 ¦ if (all_header_reagents_match(inst, get(Recipe, variants.at(i)))) +308 ¦ ¦ result.push_back(variants.at(i)); +309 } +310 return result; +311 } +312 +313 bool all_header_reagents_match(const instruction& inst, const recipe& variant) { +314 for (int i = 0; i < min(SIZE(inst.ingredients), SIZE(variant.ingredients)); ++i) { +315 ¦ if (!types_match(variant.ingredients.at(i), inst.ingredients.at(i))) { +316 ¦ ¦ trace(9993, "transform") << "match failed: ingredient " << i << end(); +317 ¦ ¦ return false; +318 ¦ } +319 } +320 for (int i = 0; i < min(SIZE(variant.products), SIZE(inst.products)); ++i) { +321 ¦ if (is_dummy(inst.products.at(i))) continue; +322 ¦ if (!types_match(variant.products.at(i), inst.products.at(i))) { +323 ¦ ¦ trace(9993, "transform") << "match failed: product " << i << end(); +324 ¦ ¦ return false; +325 ¦ } +326 } +327 return true; +328 } +329 +330 // tie-breaker for each phase +331 const recipe& best_variant(const instruction& inst, vector<recipe_ordinal>& candidates) { +332 assert(!candidates.empty()); +333 int min_score = 999; +334 int min_index = 0; +335 for (int i = 0; i < SIZE(candidates); ++i) { +336 ¦ const recipe& candidate = get(Recipe, candidates.at(i)); +337 ¦ // prefer functions without extra or missing ingredients or products +338 ¦ int score = abs(SIZE(candidate.products)-SIZE(inst.products)) +339 ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ + abs(SIZE(candidate.ingredients)-SIZE(inst.ingredients)); +340 ¦ // prefer functions with non-address ingredients or products +341 ¦ for (int j = 0; j < SIZE(candidate.ingredients); ++j) { +342 ¦ ¦ if (is_mu_address(candidate.ingredients.at(j))) +343 ¦ ¦ ¦ ++score; +344 ¦ } +345 ¦ for (int j = 0; j < SIZE(candidate.products); ++j) { +346 ¦ ¦ if (is_mu_address(candidate.products.at(j))) +347 ¦ ¦ ¦ ++score; +348 ¦ } +349 ¦ assert(score < 999); +350 ¦ if (score < min_score) { +351 ¦ ¦ min_score = score; +352 ¦ ¦ min_index = i; +353 ¦ } +354 } +355 return get(Recipe, candidates.at(min_index)); +356 } +357 +358 int non_ghost_size(vector<recipe_ordinal>& variants) { +359 int result = 0; +360 for (int i = 0; i < SIZE(variants); ++i) +361 ¦ if (variants.at(i) != -1) ++result; +362 return result; 363 } 364 -365 :(scenario static_dispatch_disabled_in_recipe_without_variants) -366 def main [ -367 1:num <- test 3 -368 ] -369 def test [ -370 2:num <- next-ingredient # ensure no header -371 return 34 -372 ] -373 +mem: storing 34 in location 1 -374 -375 :(scenario static_dispatch_disabled_on_headerless_definition) -376 % Hide_errors = true; -377 def test a:num -> z:num [ -378 z <- copy 1 -379 ] -380 def test [ -381 return 34 -382 ] -383 +error: redefining recipe test -384 -385 :(scenario static_dispatch_disabled_on_headerless_definition_2) -386 % Hide_errors = true; -387 def test [ -388 return 34 -389 ] +365 bool next_stash(const call& c, instruction* stash_inst) { +366 const recipe& specializer_recipe = get(Recipe, c.running_recipe); +367 int index = c.running_step_index; +368 for (++index; index < SIZE(specializer_recipe.steps); ++index) { +369 ¦ const instruction& inst = specializer_recipe.steps.at(index); +370 ¦ if (inst.name == "stash") { +371 ¦ ¦ *stash_inst = inst; +372 ¦ ¦ return true; +373 ¦ } +374 } +375 return false; +376 } +377 +378 :(scenario static_dispatch_disabled_in_recipe_without_variants) +379 def main [ +380 1:num <- test 3 +381 ] +382 def test [ +383 2:num <- next-ingredient # ensure no header +384 return 34 +385 ] +386 +mem: storing 34 in location 1 +387 +388 :(scenario static_dispatch_disabled_on_headerless_definition) +389 % Hide_errors = true; 390 def test a:num -> z:num [ 391 z <- copy 1 392 ] -393 +error: redefining recipe test -394 -395 :(scenario static_dispatch_on_primitive_names) -396 def main [ -397 1:num <- copy 34 -398 2:num <- copy 34 -399 3:bool <- equal 1:num, 2:num -400 4:bool <- copy 0/false -401 5:bool <- copy 0/false -402 6:bool <- equal 4:bool, 5:bool -403 ] -404 # temporarily hardcode number equality to always fail -405 def equal x:num, y:num -> z:bool [ -406 local-scope -407 load-ingredients -408 z <- copy 0/false -409 ] -410 # comparing numbers used overload -411 +mem: storing 0 in location 3 -412 # comparing booleans continues to use primitive -413 +mem: storing 1 in location 6 -414 -415 :(scenario static_dispatch_works_with_dummy_results_for_containers) -416 def main [ -417 _ <- test 3, 4 -418 ] -419 def test a:num -> z:point [ -420 local-scope -421 load-ingredients -422 z <- merge a, 0 -423 ] -424 def test a:num, b:num -> z:point [ -425 local-scope -426 load-ingredients -427 z <- merge a, b -428 ] -429 $error: 0 -430 -431 :(scenario static_dispatch_works_with_compound_type_containing_container_defined_after_first_use) -432 def main [ -433 x:&:foo <- new foo:type -434 test x -435 ] -436 container foo [ -437 x:num -438 ] -439 def test a:&:foo -> z:num [ -440 local-scope -441 load-ingredients -442 z:num <- get *a, x:offset -443 ] -444 $error: 0 -445 -446 :(scenario static_dispatch_works_with_compound_type_containing_container_defined_after_second_use) -447 def main [ -448 x:&:foo <- new foo:type -449 test x -450 ] -451 def test a:&:foo -> z:num [ -452 local-scope -453 load-ingredients -454 z:num <- get *a, x:offset -455 ] -456 container foo [ -457 x:num -458 ] -459 $error: 0 -460 -461 :(scenario static_dispatch_prefers_literals_to_be_numbers_rather_than_addresses) -462 def main [ -463 1:num <- foo 0 -464 ] -465 def foo x:&:num -> y:num [ -466 return 34 -467 ] -468 def foo x:num -> y:num [ -469 return 35 -470 ] -471 +mem: storing 35 in location 1 -472 -473 :(scenario static_dispatch_prefers_literals_to_be_numbers_rather_than_addresses_2) -474 def main [ -475 1:num <- foo 0 0 -476 ] -477 # Both variants need to bind 0 to address in first ingredient. -478 # We still want to prefer the variant with a number rather than address for -479 # _subsequent_ ingredients. -480 def foo x:&:num y:&:num -> z:num [ # put the bad match before the good one -481 return 34 -482 ] -483 def foo x:&:num y:num -> z:num [ -484 return 35 -485 ] -486 +mem: storing 35 in location 1 -487 -488 :(scenario static_dispatch_on_non_literal_character_ignores_variant_with_numbers) -489 % Hide_errors = true; -490 def main [ -491 local-scope -492 x:char <- copy 10/newline -493 1:num/raw <- foo x -494 ] -495 def foo x:num -> y:num [ -496 load-ingredients -497 return 34 +393 def test [ +394 return 34 +395 ] +396 +error: redefining recipe test +397 +398 :(scenario static_dispatch_disabled_on_headerless_definition_2) +399 % Hide_errors = true; +400 def test [ +401 return 34 +402 ] +403 def test a:num -> z:num [ +404 z <- copy 1 +405 ] +406 +error: redefining recipe test +407 +408 :(scenario static_dispatch_on_primitive_names) +409 def main [ +410 1:num <- copy 34 +411 2:num <- copy 34 +412 3:bool <- equal 1:num, 2:num +413 4:bool <- copy 0/false +414 5:bool <- copy 0/false +415 6:bool <- equal 4:bool, 5:bool +416 ] +417 # temporarily hardcode number equality to always fail +418 def equal x:num, y:num -> z:bool [ +419 local-scope +420 load-ingredients +421 z <- copy 0/false +422 ] +423 # comparing numbers used overload +424 +mem: storing 0 in location 3 +425 # comparing booleans continues to use primitive +426 +mem: storing 1 in location 6 +427 +428 :(scenario static_dispatch_works_with_dummy_results_for_containers) +429 def main [ +430 _ <- test 3, 4 +431 ] +432 def test a:num -> z:point [ +433 local-scope +434 load-ingredients +435 z <- merge a, 0 +436 ] +437 def test a:num, b:num -> z:point [ +438 local-scope +439 load-ingredients +440 z <- merge a, b +441 ] +442 $error: 0 +443 +444 :(scenario static_dispatch_works_with_compound_type_containing_container_defined_after_first_use) +445 def main [ +446 x:&:foo <- new foo:type +447 test x +448 ] +449 container foo [ +450 x:num +451 ] +452 def test a:&:foo -> z:num [ +453 local-scope +454 load-ingredients +455 z:num <- get *a, x:offset +456 ] +457 $error: 0 +458 +459 :(scenario static_dispatch_works_with_compound_type_containing_container_defined_after_second_use) +460 def main [ +461 x:&:foo <- new foo:type +462 test x +463 ] +464 def test a:&:foo -> z:num [ +465 local-scope +466 load-ingredients +467 z:num <- get *a, x:offset +468 ] +469 container foo [ +470 x:num +471 ] +472 $error: 0 +473 +474 :(scenario static_dispatch_prefers_literals_to_be_numbers_rather_than_addresses) +475 def main [ +476 1:num <- foo 0 +477 ] +478 def foo x:&:num -> y:num [ +479 return 34 +480 ] +481 def foo x:num -> y:num [ +482 return 35 +483 ] +484 +mem: storing 35 in location 1 +485 +486 :(scenario static_dispatch_prefers_literals_to_be_numbers_rather_than_addresses_2) +487 def main [ +488 1:num <- foo 0 0 +489 ] +490 # Both variants need to bind 0 to address in first ingredient. +491 # We still want to prefer the variant with a number rather than address for +492 # _subsequent_ ingredients. +493 def foo x:&:num y:&:num -> z:num [ # put the bad match before the good one +494 return 34 +495 ] +496 def foo x:&:num y:num -> z:num [ +497 return 35 498 ] -499 +error: main: ingredient 0 has the wrong type at '1:num/raw <- foo x' -500 -mem: storing 34 in location 1 -501 -502 :(scenario static_dispatch_dispatches_literal_to_boolean_before_character) +499 +mem: storing 35 in location 1 +500 +501 :(scenario static_dispatch_on_non_literal_character_ignores_variant_with_numbers) +502 % Hide_errors = true; 503 def main [ -504 1:num/raw <- foo 0 # valid literal for boolean -505 ] -506 def foo x:char -> y:num [ -507 local-scope -508 load-ingredients -509 return 34 -510 ] -511 def foo x:bool -> y:num [ -512 local-scope -513 load-ingredients -514 return 35 -515 ] -516 # boolean variant is preferred -517 +mem: storing 35 in location 1 -518 -519 :(scenario static_dispatch_dispatches_literal_to_character_when_out_of_boolean_range) -520 def main [ -521 1:num/raw <- foo 97 # not a valid literal for boolean -522 ] -523 def foo x:char -> y:num [ -524 local-scope -525 load-ingredients -526 return 34 -527 ] -528 def foo x:bool -> y:num [ -529 local-scope -530 load-ingredients -531 return 35 -532 ] -533 # character variant is preferred -534 +mem: storing 34 in location 1 -535 -536 :(scenario static_dispatch_dispatches_literal_to_number_if_at_all_possible) -537 def main [ -538 1:num/raw <- foo 97 -539 ] -540 def foo x:char -> y:num [ -541 local-scope -542 load-ingredients -543 return 34 -544 ] -545 def foo x:num -> y:num [ -546 local-scope -547 load-ingredients -548 return 35 -549 ] -550 # number variant is preferred -551 +mem: storing 35 in location 1 -552 -553 :(code) -554 string header_label(const recipe_ordinal r) { -555 return header_label(get(Recipe, r)); -556 } -557 string header_label(const recipe& caller) { -558 ostringstream out; -559 out << "recipe " << caller.name; -560 for (int i = 0; i < SIZE(caller.ingredients); ++i) -561 ¦ out << ' ' << to_string(caller.ingredients.at(i)); -562 if (!caller.products.empty()) out << " ->"; -563 for (int i = 0; i < SIZE(caller.products); ++i) -564 ¦ out << ' ' << to_string(caller.products.at(i)); -565 return out.str(); -566 } -567 -568 :(scenario reload_variant_retains_other_variants) -569 def main [ -570 1:num <- copy 34 -571 2:num <- foo 1:num -572 ] -573 def foo x:num -> y:num [ -574 local-scope -575 load-ingredients -576 return 34 -577 ] -578 def foo x:&:num -> y:num [ -579 local-scope -580 load-ingredients -581 return 35 -582 ] -583 def! foo x:&:num -> y:num [ -584 local-scope -585 load-ingredients -586 return 36 -587 ] -588 +mem: storing 34 in location 2 -589 $error: 0 -590 -591 :(scenario dispatch_errors_come_after_unknown_name_errors) -592 % Hide_errors = true; -593 def main [ -594 y:num <- foo x +504 local-scope +505 x:char <- copy 10/newline +506 1:num/raw <- foo x +507 ] +508 def foo x:num -> y:num [ +509 load-ingredients +510 return 34 +511 ] +512 +error: main: ingredient 0 has the wrong type at '1:num/raw <- foo x' +513 -mem: storing 34 in location 1 +514 +515 :(scenario static_dispatch_dispatches_literal_to_boolean_before_character) +516 def main [ +517 1:num/raw <- foo 0 # valid literal for boolean +518 ] +519 def foo x:char -> y:num [ +520 local-scope +521 load-ingredients +522 return 34 +523 ] +524 def foo x:bool -> y:num [ +525 local-scope +526 load-ingredients +527 return 35 +528 ] +529 # boolean variant is preferred +530 +mem: storing 35 in location 1 +531 +532 :(scenario static_dispatch_dispatches_literal_to_character_when_out_of_boolean_range) +533 def main [ +534 1:num/raw <- foo 97 # not a valid literal for boolean +535 ] +536 def foo x:char -> y:num [ +537 local-scope +538 load-ingredients +539 return 34 +540 ] +541 def foo x:bool -> y:num [ +542 local-scope +543 load-ingredients +544 return 35 +545 ] +546 # character variant is preferred +547 +mem: storing 34 in location 1 +548 +549 :(scenario static_dispatch_dispatches_literal_to_number_if_at_all_possible) +550 def main [ +551 1:num/raw <- foo 97 +552 ] +553 def foo x:char -> y:num [ +554 local-scope +555 load-ingredients +556 return 34 +557 ] +558 def foo x:num -> y:num [ +559 local-scope +560 load-ingredients +561 return 35 +562 ] +563 # number variant is preferred +564 +mem: storing 35 in location 1 +565 +566 :(code) +567 string header_label(const recipe_ordinal r) { +568 return header_label(get(Recipe, r)); +569 } +570 string header_label(const recipe& caller) { +571 ostringstream out; +572 out << "recipe " << caller.name; +573 for (int i = 0; i < SIZE(caller.ingredients); ++i) +574 ¦ out << ' ' << to_string(caller.ingredients.at(i)); +575 if (!caller.products.empty()) out << " ->"; +576 for (int i = 0; i < SIZE(caller.products); ++i) +577 ¦ out << ' ' << to_string(caller.products.at(i)); +578 return out.str(); +579 } +580 +581 :(scenario reload_variant_retains_other_variants) +582 def main [ +583 1:num <- copy 34 +584 2:num <- foo 1:num +585 ] +586 def foo x:num -> y:num [ +587 local-scope +588 load-ingredients +589 return 34 +590 ] +591 def foo x:&:num -> y:num [ +592 local-scope +593 load-ingredients +594 return 35 595 ] -596 def foo a:num -> b:num [ +596 def! foo x:&:num -> y:num [ 597 local-scope 598 load-ingredients -599 return 34 +599 return 36 600 ] -601 def foo a:bool -> b:num [ -602 local-scope -603 load-ingredients -604 return 35 -605 ] -606 +error: main: missing type for 'x' in 'y:num <- foo x' -607 +error: main: failed to find a matching call for 'y:num <- foo x' -608 -609 :(scenario override_methods_with_type_abbreviations) -610 def main [ -611 local-scope -612 s:text <- new [abc] -613 1:num/raw <- foo s -614 ] -615 def foo a:address:array:character -> result:number [ -616 return 34 -617 ] -618 # identical to previous variant once you take type abbreviations into account -619 def! foo a:text -> result:num [ -620 return 35 -621 ] -622 +mem: storing 35 in location 1 -623 -624 :(before "End Includes") -625 using std::abs; +601 +mem: storing 34 in location 2 +602 $error: 0 +603 +604 :(scenario dispatch_errors_come_after_unknown_name_errors) +605 % Hide_errors = true; +606 def main [ +607 y:num <- foo x +608 ] +609 def foo a:num -> b:num [ +610 local-scope +611 load-ingredients +612 return 34 +613 ] +614 def foo a:bool -> b:num [ +615 local-scope +616 load-ingredients +617 return 35 +618 ] +619 +error: main: missing type for 'x' in 'y:num <- foo x' +620 +error: main: failed to find a matching call for 'y:num <- foo x' +621 +622 :(scenario override_methods_with_type_abbreviations) +623 def main [ +624 local-scope +625 s:text <- new [abc] +626 1:num/raw <- foo s +627 ] +628 def foo a:address:array:character -> result:number [ +629 return 34 +630 ] +631 # identical to previous variant once you take type abbreviations into account +632 def! foo a:text -> result:num [ +633 return 35 +634 ] +635 +mem: storing 35 in location 1 +636 +637 :(scenario ignore_static_dispatch_in_type_errors_without_overloading) +638 % Hide_errors = true; +639 def main [ +640 local-scope +641 x:&:num <- copy 0 +642 foo x +643 ] +644 def foo x:&:char [ +645 local-scope +646 load-ingredients +647 ] +648 +error: main: instruction 'foo x' does not match 'recipe foo {x: ("address" "character")}' +649 +error: instruction expands to 'foo {x: ("address" "number")}' +650 +651 :(scenario show_available_variants_in_dispatch_errors) +652 % Hide_errors = true; +653 def main [ +654 local-scope +655 x:&:num <- copy 0 +656 foo x +657 ] +658 def foo x:&:char [ +659 local-scope +660 load-ingredients +661 ] +662 def foo x:&:bool [ +663 local-scope +664 load-ingredients +665 ] +666 +error: main: failed to find a matching call for 'foo x' +667 +error: which expands to: +668 +error: foo {x: ("address" "number")} +669 +error: available variants are: +670 +error: recipe foo {x: ("address" "character")} +671 +error: recipe foo_2 {x: ("address" "boolean")} +672 +673 :(before "End Includes") +674 using std::abs; -- cgit 1.4.1-2-gfad0