mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-11 16:51:53 +03:00
Merge branch 'trunk' into NumBytesTo
This commit is contained in:
commit
1b04ad0535
@ -4673,8 +4673,13 @@ pub fn from_can<'a>(
|
||||
);
|
||||
CapturedSymbols::None
|
||||
}
|
||||
Err(_) => {
|
||||
debug_assert!(captured_symbols.is_empty());
|
||||
Err(e) => {
|
||||
debug_assert!(
|
||||
captured_symbols.is_empty(),
|
||||
"{:?}, {:?}",
|
||||
&captured_symbols,
|
||||
e
|
||||
);
|
||||
CapturedSymbols::None
|
||||
}
|
||||
};
|
||||
|
@ -415,9 +415,10 @@ impl<'a> LambdaSet<'a> {
|
||||
use UnionVariant::*;
|
||||
match variant {
|
||||
Never => Layout::Union(UnionLayout::NonRecursive(&[])),
|
||||
Unit | UnitWithArguments => Layout::Struct(&[]),
|
||||
BoolUnion { .. } => Layout::Builtin(Builtin::Int1),
|
||||
ByteUnion(_) => Layout::Builtin(Builtin::Int8),
|
||||
Unit | UnitWithArguments | BoolUnion { .. } | ByteUnion(_) => {
|
||||
// no useful information to store
|
||||
Layout::Struct(&[])
|
||||
}
|
||||
Newtype {
|
||||
arguments: layouts, ..
|
||||
} => Layout::Struct(layouts.into_bump_slice()),
|
||||
|
@ -2552,3 +2552,108 @@ fn mirror_llvm_alignment_padding() {
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lambda_set_bool() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [ main ] to "./platform"
|
||||
|
||||
p1 = (\u -> u == 97)
|
||||
p2 = (\u -> u == 98)
|
||||
|
||||
main : I64
|
||||
main =
|
||||
oneOfResult = List.map [p1, p2] (\p -> p 42)
|
||||
|
||||
when oneOfResult is
|
||||
_ -> 32
|
||||
|
||||
"#
|
||||
),
|
||||
32,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lambda_set_byte() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [ main ] to "./platform"
|
||||
|
||||
p1 = (\u -> u == 97)
|
||||
p2 = (\u -> u == 98)
|
||||
p3 = (\u -> u == 99)
|
||||
|
||||
main : I64
|
||||
main =
|
||||
oneOfResult = List.map [p1, p2, p3] (\p -> p 42)
|
||||
|
||||
when oneOfResult is
|
||||
_ -> 32
|
||||
|
||||
"#
|
||||
),
|
||||
32,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lambda_set_struct_byte() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [ main ] to "./platform"
|
||||
|
||||
|
||||
main : I64
|
||||
main =
|
||||
r : [ Red, Green, Blue ]
|
||||
r = Red
|
||||
|
||||
p1 = (\u -> r == u)
|
||||
oneOfResult = List.map [p1, p1] (\p -> p Green)
|
||||
|
||||
when oneOfResult is
|
||||
_ -> 32
|
||||
|
||||
"#
|
||||
),
|
||||
32,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lambda_set_enum_byte_byte() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [ main ] to "./platform"
|
||||
|
||||
|
||||
main : I64
|
||||
main =
|
||||
r : [ Red, Green, Blue ]
|
||||
r = Red
|
||||
|
||||
g : [ Red, Green, Blue ]
|
||||
g = Green
|
||||
|
||||
p1 = (\u -> r == u)
|
||||
p2 = (\u -> g == u)
|
||||
oneOfResult = List.map [p1, p2] (\p -> p Green)
|
||||
|
||||
when oneOfResult is
|
||||
_ -> 32
|
||||
|
||||
"#
|
||||
),
|
||||
32,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
@ -276,6 +276,7 @@ macro_rules! assert_llvm_evals_to {
|
||||
|
||||
let transform = |success| {
|
||||
let expected = $expected;
|
||||
#[allow(clippy::redundant_closure_call)]
|
||||
let given = $transform(success);
|
||||
assert_eq!(&given, &expected);
|
||||
};
|
||||
|
@ -1,53 +1,43 @@
|
||||
procedure Num.24 (#Attr.2, #Attr.3):
|
||||
let Test.28 = lowlevel NumAdd #Attr.2 #Attr.3;
|
||||
ret Test.28;
|
||||
let Test.25 = lowlevel NumAdd #Attr.2 #Attr.3;
|
||||
ret Test.25;
|
||||
|
||||
procedure Num.26 (#Attr.2, #Attr.3):
|
||||
let Test.22 = lowlevel NumMul #Attr.2 #Attr.3;
|
||||
ret Test.22;
|
||||
let Test.19 = lowlevel NumMul #Attr.2 #Attr.3;
|
||||
ret Test.19;
|
||||
|
||||
procedure Test.1 ():
|
||||
let Test.30 = 1i64;
|
||||
ret Test.30;
|
||||
let Test.27 = 1i64;
|
||||
ret Test.27;
|
||||
|
||||
procedure Test.2 ():
|
||||
let Test.24 = 2i64;
|
||||
ret Test.24;
|
||||
let Test.21 = 2i64;
|
||||
ret Test.21;
|
||||
|
||||
procedure Test.3 (Test.6):
|
||||
let Test.27 = CallByName Test.1;
|
||||
let Test.26 = CallByName Num.24 Test.6 Test.27;
|
||||
ret Test.26;
|
||||
let Test.24 = CallByName Test.1;
|
||||
let Test.23 = CallByName Num.24 Test.6 Test.24;
|
||||
ret Test.23;
|
||||
|
||||
procedure Test.4 (Test.7):
|
||||
let Test.21 = CallByName Test.2;
|
||||
let Test.20 = CallByName Num.26 Test.7 Test.21;
|
||||
ret Test.20;
|
||||
let Test.18 = CallByName Test.2;
|
||||
let Test.17 = CallByName Num.26 Test.7 Test.18;
|
||||
ret Test.17;
|
||||
|
||||
procedure Test.5 (Test.8, Test.9):
|
||||
joinpoint Test.15 Test.14:
|
||||
ret Test.14;
|
||||
in
|
||||
switch Test.8:
|
||||
case 0:
|
||||
let Test.16 = CallByName Test.3 Test.9;
|
||||
jump Test.15 Test.16;
|
||||
|
||||
default:
|
||||
let Test.17 = CallByName Test.4 Test.9;
|
||||
jump Test.15 Test.17;
|
||||
|
||||
let Test.14 = CallByName Test.3 Test.9;
|
||||
ret Test.14;
|
||||
|
||||
procedure Test.0 ():
|
||||
joinpoint Test.19 Test.12:
|
||||
joinpoint Test.16 Test.12:
|
||||
let Test.13 = 42i64;
|
||||
let Test.11 = CallByName Test.5 Test.12 Test.13;
|
||||
ret Test.11;
|
||||
in
|
||||
let Test.25 = true;
|
||||
if Test.25 then
|
||||
let Test.22 = true;
|
||||
if Test.22 then
|
||||
let Test.3 = Struct {};
|
||||
jump Test.19 Test.3;
|
||||
jump Test.16 Test.3;
|
||||
else
|
||||
let Test.4 = Struct {};
|
||||
jump Test.19 Test.4;
|
||||
jump Test.16 Test.4;
|
||||
|
@ -298,7 +298,87 @@ impl GetSubsSlice<Lowercase> for Subs {
|
||||
|
||||
impl fmt::Debug for Subs {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.utable.fmt(f)
|
||||
writeln!(f)?;
|
||||
for i in 0..self.len() {
|
||||
let var = Variable(i as u32);
|
||||
let desc = self.get_without_compacting(var);
|
||||
|
||||
let root = self.get_root_key_without_compacting(var);
|
||||
|
||||
if var == root {
|
||||
write!(f, "{} => ", i)?;
|
||||
|
||||
subs_fmt_desc(&desc, self, f)?;
|
||||
} else {
|
||||
write!(f, "{} => <{:?}>", i, root)?;
|
||||
}
|
||||
|
||||
writeln!(f)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn subs_fmt_desc(this: &Descriptor, subs: &Subs, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
subs_fmt_content(&this.content, subs, f)?;
|
||||
|
||||
write!(f, " r: {:?}", &this.rank)?;
|
||||
write!(f, " m: {:?}", &this.mark)
|
||||
}
|
||||
|
||||
fn subs_fmt_content(this: &Content, subs: &Subs, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match this {
|
||||
Content::FlexVar(name) => write!(f, "Flex({:?})", name),
|
||||
Content::RigidVar(name) => write!(f, "Rigid({:?})", name),
|
||||
Content::RecursionVar {
|
||||
structure,
|
||||
opt_name,
|
||||
} => write!(f, "Recursion({:?}, {:?})", structure, opt_name),
|
||||
Content::Structure(flat_type) => subs_fmt_flat_type(flat_type, subs, f),
|
||||
Content::Alias(name, arguments, actual) => {
|
||||
write!(f, "Alias({:?}, {:?}, {:?})", name, arguments, actual)
|
||||
}
|
||||
Content::Error => write!(f, "Error"),
|
||||
}
|
||||
}
|
||||
|
||||
fn subs_fmt_flat_type(this: &FlatType, subs: &Subs, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match this {
|
||||
FlatType::Apply(name, arguments) => {
|
||||
let slice = subs.get_subs_slice(*arguments.as_subs_slice());
|
||||
|
||||
write!(f, "Apply({:?}, {:?})", name, slice)
|
||||
}
|
||||
FlatType::Func(arguments, lambda_set, result) => {
|
||||
let slice = subs.get_subs_slice(*arguments.as_subs_slice());
|
||||
write!(f, "Func({:?}, {:?}, {:?})", slice, lambda_set, result)
|
||||
}
|
||||
FlatType::Record(_, _) => todo!(),
|
||||
FlatType::TagUnion(tags, ext) => {
|
||||
write!(f, "[ ")?;
|
||||
|
||||
let (it, new_ext) = tags.sorted_iterator_and_ext(subs, *ext);
|
||||
for (name, slice) in it {
|
||||
write!(f, "{:?} {:?}, ", name, slice)?;
|
||||
}
|
||||
|
||||
write!(f, "]<{:?}>", new_ext)
|
||||
}
|
||||
FlatType::FunctionOrTagUnion(_, _, _) => todo!(),
|
||||
FlatType::RecursiveTagUnion(rec, tags, ext) => {
|
||||
write!(f, "[ ")?;
|
||||
|
||||
let (it, new_ext) = tags.sorted_iterator_and_ext(subs, *ext);
|
||||
for (name, slice) in it {
|
||||
write!(f, "{:?} {:?}, ", name, slice)?;
|
||||
}
|
||||
|
||||
write!(f, "]<{:?}> as <{:?}>", new_ext, rec)
|
||||
}
|
||||
FlatType::Erroneous(e) => write!(f, "Erroneous({:?})", e),
|
||||
FlatType::EmptyRecord => write!(f, "EmptyRecord"),
|
||||
FlatType::EmptyTagUnion => write!(f, "EmptyTagUnion"),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user