Switched order of checking layout and list length for list reverse implementation

This commit is contained in:
Chad Stearns 2020-07-12 17:11:26 -04:00
parent fdf11689b6
commit 1221ef3c76

View file

@ -1649,6 +1649,8 @@ fn run_low_level<'a, 'ctx, 'env>(
let (list, list_layout) = &args[0]; let (list, list_layout) = &args[0];
match list_layout {
Layout::Builtin(Builtin::List(elem_layout)) => {
let wrapper_struct = let wrapper_struct =
build_expr(env, layout_ids, scope, parent, list).into_struct_value(); build_expr(env, layout_ids, scope, parent, list).into_struct_value();
@ -1668,8 +1670,6 @@ fn run_low_level<'a, 'ctx, 'env>(
); );
let build_then = || { let build_then = || {
match list_layout {
Layout::Builtin(Builtin::List(elem_layout)) => {
// Allocate space for the new array that we'll copy into. // Allocate space for the new array that we'll copy into.
let elem_type = let elem_type =
basic_type_from_layout(env.arena, ctx, elem_layout, env.ptr_bytes); basic_type_from_layout(env.arena, ctx, elem_layout, env.ptr_bytes);
@ -1785,12 +1785,6 @@ fn run_low_level<'a, 'ctx, 'env>(
collection(ctx, ptr_bytes), collection(ctx, ptr_bytes),
"cast_collection", "cast_collection",
) )
}
Layout::Builtin(Builtin::EmptyList) => empty_list(env),
_ => {
unreachable!("Invalid List layout for List.get: {:?}", list_layout);
}
}
}; };
let build_else = || empty_list(env); let build_else = || empty_list(env);
@ -1806,6 +1800,12 @@ fn run_low_level<'a, 'ctx, 'env>(
BasicTypeEnum::StructType(struct_type), BasicTypeEnum::StructType(struct_type),
) )
} }
Layout::Builtin(Builtin::EmptyList) => empty_list(env),
_ => {
unreachable!("Invalid List layout for List.reverse {:?}", list_layout);
}
}
}
ListPush => { ListPush => {
// List.push List elem, elem -> List elem // List.push List elem, elem -> List elem
debug_assert_eq!(args.len(), 2); debug_assert_eq!(args.len(), 2);