Multimorphic lambdas capture another lambda

This commit is contained in:
Ayaz Hafiz 2022-06-28 18:28:15 -04:00 committed by ayazhafiz
parent b69d538ea0
commit 28c1cf46a3
No known key found for this signature in database
GPG key ID: B443F7A3030C9AED
5 changed files with 175 additions and 63 deletions

View file

@ -0,0 +1,85 @@
procedure #Multimorphic.0 (Test.29, #Attr.12):
let Test.8 : {} = UnionAtIndex (Id 0) (Index 1) #Attr.12;
let Test.7 : {} = UnionAtIndex (Id 0) (Index 0) #Attr.12;
let Test.49 : {} = Struct {};
let Test.48 : Str = CallByName Test.16 Test.49;
let Test.45 : {Str} = CallByName Test.4 Test.48;
let Test.47 : {} = Struct {};
let Test.46 : Str = CallByName Test.13 Test.47 Test.45;
ret Test.46;
procedure #Multimorphic.1 (Test.29, #Attr.12):
let Test.8 : {} = UnionAtIndex (Id 1) (Index 1) #Attr.12;
let Test.7 : {} = UnionAtIndex (Id 1) (Index 0) #Attr.12;
let Test.35 : {} = Struct {};
let Test.34 : Str = CallByName Test.15 Test.35;
let Test.31 : {} = CallByName Test.3 Test.34;
dec Test.34;
let Test.33 : {} = Struct {};
let Test.32 : Str = CallByName Test.11 Test.33;
ret Test.32;
procedure Test.11 (Test.37):
let Test.38 : Str = "";
ret Test.38;
procedure Test.13 (Test.51, #Attr.12):
let Test.12 : Str = StructAtIndex 0 #Attr.12;
inc Test.12;
dec #Attr.12;
ret Test.12;
procedure Test.15 (Test.39):
let Test.40 : Str = "";
ret Test.40;
procedure Test.16 (Test.54):
let Test.56 : Str = "s1";
ret Test.56;
procedure Test.2 (Test.7, Test.8):
let Test.9 : [C {} {}, C {} {}] = ClosureTag(#Multimorphic.0) Test.7 Test.8;
ret Test.9;
procedure Test.2 (Test.7, Test.8):
let Test.9 : [C {} {}, C {} {}] = ClosureTag(#Multimorphic.1) Test.7 Test.8;
ret Test.9;
procedure Test.3 (Test.17):
let Test.36 : {} = Struct {};
ret Test.36;
procedure Test.4 (Test.18):
let Test.50 : {Str} = Struct {Test.18};
ret Test.50;
procedure Test.0 ():
let Test.5 : Int1 = true;
joinpoint Test.25 Test.6:
let Test.20 : {} = Struct {};
let Test.21 : U8 = GetTagId Test.6;
joinpoint Test.22 Test.19:
ret Test.19;
in
switch Test.21:
case 0:
let Test.23 : Str = CallByName #Multimorphic.0 Test.20 Test.6;
jump Test.22 Test.23;
default:
let Test.24 : Str = CallByName #Multimorphic.1 Test.20 Test.6;
jump Test.22 Test.24;
in
let Test.57 : Int1 = true;
let Test.58 : Int1 = lowlevel Eq Test.57 Test.5;
if Test.58 then
let Test.27 : {} = Struct {};
let Test.28 : {} = Struct {};
let Test.26 : [C {} {}, C {} {}] = CallByName Test.2 Test.27 Test.28;
jump Test.25 Test.26;
else
let Test.42 : {} = Struct {};
let Test.43 : {} = Struct {};
let Test.41 : [C {} {}, C {} {}] = CallByName Test.2 Test.42 Test.43;
jump Test.25 Test.41;

View file

@ -1600,3 +1600,32 @@ fn multimorphic_lambdas_with_non_capturing_function() {
"#
)
}
#[mono_test]
fn multimorphic_lambdas_have_captured_function_in_closure() {
indoc!(
r#"
Lazy a : {} -> a
after : Lazy a, (a -> Lazy b) -> Lazy b
after = \effect, map ->
thunk = \{} ->
when map (effect {}) is
b -> b {}
thunk
f = \_ -> \_ -> ""
g = \{ s1 } -> \_ -> s1
x : [True, False]
x = True
fun =
when x is
True -> after (\{} -> "") f
False -> after (\{} -> {s1: "s1"}) g
fun {}
"#
)
}