Appropriately substitute symbols in switch conditions

Closes #4557
This commit is contained in:
Ayaz Hafiz 2022-12-27 12:28:04 -06:00
parent 4dbe90db93
commit 23fc7f1413
No known key found for this signature in database
GPG Key ID: 0E2A37416A25EF58
3 changed files with 81 additions and 3 deletions

View File

@ -7079,10 +7079,18 @@ fn substitute_in_stmt_help<'a>(
default_branch,
ret_layout,
} => {
let opt_default = substitute_in_stmt_help(arena, default_branch.1, subs);
let mut did_change = false;
let cond_symbol = match substitute(subs, *cond_symbol) {
Some(s) => {
did_change = true;
s
}
None => *cond_symbol,
};
let opt_default = substitute_in_stmt_help(arena, default_branch.1, subs);
let opt_branches = Vec::from_iter_in(
branches.iter().map(|(label, info, branch)| {
match substitute_in_stmt_help(arena, branch, subs) {
@ -7119,7 +7127,7 @@ fn substitute_in_stmt_help<'a>(
};
Some(arena.alloc(Switch {
cond_symbol: *cond_symbol,
cond_symbol,
cond_layout: *cond_layout,
default_branch,
branches,

View File

@ -0,0 +1,56 @@
procedure Bool.11 (#Attr.2, #Attr.3):
let Bool.24 : Int1 = lowlevel Eq #Attr.2 #Attr.3;
ret Bool.24;
procedure Bool.4 (#Attr.2, #Attr.3):
let Bool.23 : Int1 = lowlevel Or #Attr.2 #Attr.3;
ret Bool.23;
procedure Test.1 (Test.2, Test.3):
let Test.17 : {Int1, Int1} = Struct {Test.2, Test.3};
let Test.34 : Int1 = StructAtIndex 0 Test.17;
let Test.33 : Int1 = StructAtIndex 1 Test.17;
let Test.19 : Int1 = CallByName Test.1 Test.33 Test.34;
let Test.27 : {} = Struct {};
joinpoint Test.28 Test.21:
let Test.23 : {} = Struct {};
joinpoint Test.24 Test.22:
let Test.20 : Int1 = CallByName Bool.11 Test.21 Test.22;
dec Test.22;
dec Test.21;
let Test.18 : Int1 = CallByName Bool.4 Test.19 Test.20;
ret Test.18;
in
switch Test.33:
case 0:
let Test.25 : Str = CallByName Test.9 Test.23;
jump Test.24 Test.25;
default:
let Test.26 : Str = CallByName Test.11 Test.23;
jump Test.24 Test.26;
in
switch Test.34:
case 0:
let Test.29 : Str = CallByName Test.9 Test.27;
jump Test.28 Test.29;
default:
let Test.30 : Str = CallByName Test.11 Test.27;
jump Test.28 Test.30;
procedure Test.11 (Test.36):
let Test.37 : Str = "a";
ret Test.37;
procedure Test.9 (Test.39):
let Test.40 : Str = "a";
ret Test.40;
procedure Test.0 ():
let Test.38 : Int1 = false;
let Test.35 : Int1 = true;
let Test.13 : Int1 = CallByName Test.1 Test.38 Test.35;
ret Test.13;

View File

@ -2242,3 +2242,17 @@ fn lambda_set_with_imported_toplevels_issue_4733() {
"###
)
}
#[mono_test]
fn issue_4557() {
indoc!(
r###"
app "test" provides [main] to "./platform"
isEqQ = \q1, q2 -> when T q1 q2 is
T (U f1) (U f2) -> Bool.or (isEqQ (U f2) (U f1)) (f1 {} == f2 {})
main = isEqQ (U \{} -> "a") (U \{} -> "a")
"###
)
}