Merge pull request #4998 from thehabbos007/fn_call

gen_dev: Fix subtle issue with function call building and add bool to array creation in generic64
This commit is contained in:
Folkert de Vries 2023-02-05 01:32:32 +01:00 committed by GitHub
commit 65f8bb3d0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 16 deletions

View file

@ -1850,7 +1850,7 @@ impl<
};
// TODO: Expand to all types.
match self.layout_interner.get(*elem_layout) {
Layout::Builtin(Builtin::Int(IntWidth::I64 | IntWidth::U64)) => {
Layout::Builtin(Builtin::Int(IntWidth::I64 | IntWidth::U64) | Builtin::Bool) => {
let sym_reg = self
.storage_manager
.load_to_general_reg(&mut self.buf, elem_sym);

View file

@ -284,28 +284,31 @@ trait Backend<'a> {
if let LowLevelWrapperType::CanBeReplacedBy(lowlevel) =
LowLevelWrapperType::from_symbol(func_sym.name())
{
self.build_run_low_level(
return self.build_run_low_level(
sym,
&lowlevel,
arguments,
arg_layouts,
ret_layout,
)
} else if self.defined_in_app_module(func_sym.name()) {
let layout_id = LayoutIds::default().get(func_sym.name(), layout);
let fn_name = self.symbol_to_string(func_sym.name(), layout_id);
// Now that the arguments are needed, load them if they are literals.
self.load_literal_symbols(arguments);
self.build_fn_call(sym, fn_name, arguments, arg_layouts, ret_layout)
} else {
self.build_builtin(
);
} else if sym.is_builtin() {
// These builtins can be built through `build_fn_call` as well, but the
// implementation in `build_builtin` inlines some of the symbols.
return self.build_builtin(
sym,
func_sym.name(),
arguments,
arg_layouts,
ret_layout,
)
);
}
let layout_id = LayoutIds::default().get(func_sym.name(), layout);
let fn_name = self.symbol_to_string(func_sym.name(), layout_id);
// Now that the arguments are needed, load them if they are literals.
self.load_literal_symbols(arguments);
self.build_fn_call(sym, fn_name, arguments, arg_layouts, ret_layout)
}
CallType::LowLevel { op: lowlevel, .. } => {
@ -802,7 +805,6 @@ trait Backend<'a> {
arg_layouts: &[InLayout<'a>],
ret_layout: &InLayout<'a>,
) {
self.load_literal_symbols(args);
match func_sym {
Symbol::NUM_IS_ZERO => {
debug_assert_eq!(
@ -816,6 +818,7 @@ trait Backend<'a> {
"NumIsZero: expected to have return layout of type Bool"
);
self.load_literal_symbols(args);
self.load_literal(
&Symbol::DEV_TMP,
&arg_layouts[0],
@ -843,11 +846,13 @@ trait Backend<'a> {
let bool_layout = Layout::BOOL;
self.load_literal(&Symbol::DEV_TMP, &bool_layout, &Literal::Bool(true));
self.return_symbol(&Symbol::DEV_TMP, &bool_layout);
self.free_symbol(&Symbol::DEV_TMP)
}
Symbol::BOOL_FALSE => {
let bool_layout = Layout::BOOL;
self.load_literal(&Symbol::DEV_TMP, &bool_layout, &Literal::Bool(false));
self.return_symbol(&Symbol::DEV_TMP, &bool_layout);
self.free_symbol(&Symbol::DEV_TMP)
}
_ => todo!("the function, {:?}", func_sym),
}

View file

@ -52,7 +52,7 @@ fn int_list_literal() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn bool_list_literal() {
assert_evals_to!(
indoc!(
@ -84,7 +84,45 @@ fn bool_list_literal() {
RocList::from_slice(&[false; 1]),
RocList<bool>
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn bool_list_concat() {
assert_evals_to!(
indoc!(
r#"
List.concat [Bool.true, Bool.false] [Bool.false, Bool.true]
"#
),
RocList::from_slice(&[true, false, false, true]),
RocList<bool>
);
assert_evals_to!(
indoc!(
r#"
List.concat [] [Bool.false, Bool.true]
"#
),
RocList::from_slice(&[false, true]),
RocList<bool>
);
assert_evals_to!(
indoc!(
r#"
List.concat [Bool.true, Bool.false] []
"#
),
RocList::from_slice(&[true, false]),
RocList<bool>
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bool_list_literal_repeat() {
assert_evals_to!(
indoc!(
r#"
@ -726,7 +764,7 @@ fn list_append_to_empty_list_of_int() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_append_bools() {
assert_evals_to!(
"List.append [Bool.true, Bool.false] Bool.true",
@ -789,7 +827,7 @@ fn list_prepend_str() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_prepend_bools() {
assert_evals_to!(
"List.prepend [Bool.true, Bool.false] Bool.true",