mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 08:17:40 +03:00
mono: generate Eq functions for Boxed layout
This commit is contained in:
parent
817ffba982
commit
7c7e450756
@ -1671,7 +1671,8 @@ impl<'a> LowLevelCall<'a> {
|
||||
Layout::Builtin(Builtin::Dict(_, _) | Builtin::Set(_) | Builtin::List(_))
|
||||
| Layout::Struct { .. }
|
||||
| Layout::Union(_)
|
||||
| Layout::LambdaSet(_) => {
|
||||
| Layout::LambdaSet(_)
|
||||
| Layout::Boxed(_) => {
|
||||
// Don't want Zig calling convention here, we're calling internal Roc functions
|
||||
backend
|
||||
.storage
|
||||
@ -1689,8 +1690,6 @@ impl<'a> LowLevelCall<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
Layout::Boxed(_) => todo!(),
|
||||
|
||||
Layout::RecursivePointer => {
|
||||
internal_error!(
|
||||
"Tried to apply `==` to RecursivePointer values {:?}",
|
||||
|
@ -530,12 +530,43 @@ fn eq_tag_fields<'a>(
|
||||
}
|
||||
|
||||
fn eq_boxed<'a>(
|
||||
_root: &mut CodeGenHelp<'a>,
|
||||
_ident_ids: &mut IdentIds,
|
||||
_ctx: &mut Context<'a>,
|
||||
_inner_layout: &'a Layout<'a>,
|
||||
root: &mut CodeGenHelp<'a>,
|
||||
ident_ids: &mut IdentIds,
|
||||
ctx: &mut Context<'a>,
|
||||
inner_layout: &'a Layout<'a>,
|
||||
) -> Stmt<'a> {
|
||||
todo!()
|
||||
let a = root.create_symbol(ident_ids, "a");
|
||||
let b = root.create_symbol(ident_ids, "b");
|
||||
let result = root.create_symbol(ident_ids, "result");
|
||||
|
||||
let a_expr = Expr::ExprUnbox { symbol: ARG_1 };
|
||||
let b_expr = Expr::ExprUnbox { symbol: ARG_2 };
|
||||
let eq_call_expr = root
|
||||
.call_specialized_op(ident_ids, ctx, *inner_layout, root.arena.alloc([a, b]))
|
||||
.unwrap();
|
||||
|
||||
Stmt::Let(
|
||||
a,
|
||||
a_expr,
|
||||
*inner_layout,
|
||||
root.arena.alloc(
|
||||
//
|
||||
Stmt::Let(
|
||||
b,
|
||||
b_expr,
|
||||
*inner_layout,
|
||||
root.arena.alloc(
|
||||
//
|
||||
Stmt::Let(
|
||||
result,
|
||||
eq_call_expr,
|
||||
LAYOUT_BOOL,
|
||||
root.arena.alloc(Stmt::Ret(result)),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
/// List equality
|
||||
|
@ -286,11 +286,11 @@ impl<'a> CodeGenHelp<'a> {
|
||||
&mut self,
|
||||
ident_ids: &mut IdentIds,
|
||||
ctx: &mut Context<'a>,
|
||||
layout: Layout<'a>,
|
||||
orig_layout: Layout<'a>,
|
||||
) -> Symbol {
|
||||
use HelperOp::*;
|
||||
|
||||
let layout = self.replace_rec_ptr(ctx, layout);
|
||||
let layout = self.replace_rec_ptr(ctx, orig_layout);
|
||||
|
||||
let found = self
|
||||
.specializations
|
||||
@ -450,7 +450,9 @@ impl<'a> CodeGenHelp<'a> {
|
||||
layout
|
||||
}
|
||||
|
||||
Layout::Boxed(inner) => self.replace_rec_ptr(ctx, *inner),
|
||||
Layout::Boxed(inner) => {
|
||||
Layout::Boxed(self.arena.alloc(self.replace_rec_ptr(ctx, *inner)))
|
||||
}
|
||||
|
||||
Layout::LambdaSet(lambda_set) => {
|
||||
self.replace_rec_ptr(ctx, lambda_set.runtime_representation())
|
||||
|
@ -672,3 +672,25 @@ fn compare_nullable_recursive_union_same_content() {
|
||||
bool
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn boxed_eq_int() {
|
||||
assert_evals_to!("Box.box 1 == Box.box 1", true, bool);
|
||||
assert_evals_to!("Box.box 2 == Box.box 1", false, bool);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn boxed_eq_str() {
|
||||
assert_evals_to!(
|
||||
"Box.box \"Hello, world\" == Box.box \"Hello, world\"",
|
||||
true,
|
||||
bool
|
||||
);
|
||||
assert_evals_to!(
|
||||
"Box.box \"Hello, world\" == Box.box \"Hello, stranger\"",
|
||||
false,
|
||||
bool
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user