mirror of
https://github.com/roc-lang/roc.git
synced 2025-11-13 18:05:28 +00:00
implement expect struct reporting
This commit is contained in:
parent
dbbbc32583
commit
1bfac155ca
3 changed files with 79 additions and 9 deletions
|
|
@ -2608,10 +2608,10 @@ test "getScalarUnsafe" {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn strCloneTo(
|
pub fn strCloneTo(
|
||||||
|
string: RocStr,
|
||||||
ptr: [*]u8,
|
ptr: [*]u8,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
extra_offset: usize,
|
extra_offset: usize,
|
||||||
string: RocStr,
|
|
||||||
) callconv(.C) usize {
|
) callconv(.C) usize {
|
||||||
const WIDTH: usize = @sizeOf(RocStr);
|
const WIDTH: usize = @sizeOf(RocStr);
|
||||||
if (string.isSmallStr()) {
|
if (string.isSmallStr()) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::llvm::bitcode::call_bitcode_fn;
|
use crate::llvm::bitcode::call_str_bitcode_fn;
|
||||||
use crate::llvm::build::{store_roc_value, Env};
|
use crate::llvm::build::{store_roc_value, Env};
|
||||||
use crate::llvm::build_list::{self, incrementing_elem_loop};
|
use crate::llvm::build_list::{self, incrementing_elem_loop};
|
||||||
use crate::llvm::convert::basic_type_from_layout;
|
use crate::llvm::convert::basic_type_from_layout;
|
||||||
|
|
@ -11,7 +11,7 @@ use roc_module::symbol::Symbol;
|
||||||
use roc_mono::layout::{Builtin, Layout, LayoutIds, UnionLayout};
|
use roc_mono::layout::{Builtin, Layout, LayoutIds, UnionLayout};
|
||||||
use roc_region::all::Region;
|
use roc_region::all::Region;
|
||||||
|
|
||||||
use super::build::{load_symbol_and_layout, Scope};
|
use super::build::{load_symbol_and_layout, use_roc_value, Scope};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
struct Cursors<'ctx> {
|
struct Cursors<'ctx> {
|
||||||
|
|
@ -204,13 +204,43 @@ fn build_clone<'a, 'ctx, 'env>(
|
||||||
when_recursive,
|
when_recursive,
|
||||||
),
|
),
|
||||||
|
|
||||||
Layout::Struct {
|
Layout::Struct { field_layouts, .. } => {
|
||||||
field_layouts: _, ..
|
|
||||||
} => {
|
|
||||||
if layout.safe_to_memcpy() {
|
if layout.safe_to_memcpy() {
|
||||||
build_copy(env, ptr, cursors.offset, value)
|
build_copy(env, ptr, cursors.offset, value)
|
||||||
} else {
|
} else {
|
||||||
todo!()
|
let mut cursors = cursors;
|
||||||
|
|
||||||
|
let structure = value.into_struct_value();
|
||||||
|
|
||||||
|
for (i, field_layout) in field_layouts.iter().enumerate() {
|
||||||
|
let field = env
|
||||||
|
.builder
|
||||||
|
.build_extract_value(structure, i as _, "extract")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let field = use_roc_value(env, *field_layout, field, "field");
|
||||||
|
|
||||||
|
let new_extra = build_clone(
|
||||||
|
env,
|
||||||
|
layout_ids,
|
||||||
|
ptr,
|
||||||
|
cursors,
|
||||||
|
field,
|
||||||
|
*field_layout,
|
||||||
|
when_recursive,
|
||||||
|
);
|
||||||
|
|
||||||
|
let field_width = env
|
||||||
|
.ptr_int()
|
||||||
|
.const_int(field_layout.stack_size(env.target_info) as u64, false);
|
||||||
|
|
||||||
|
cursors.extra_offset = new_extra;
|
||||||
|
cursors.offset =
|
||||||
|
env.builder
|
||||||
|
.build_int_add(cursors.offset, field_width, "offset");
|
||||||
|
}
|
||||||
|
|
||||||
|
cursors.extra_offset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -329,14 +359,15 @@ fn build_clone_builtin<'a, 'ctx, 'env>(
|
||||||
Builtin::Str => {
|
Builtin::Str => {
|
||||||
//
|
//
|
||||||
|
|
||||||
call_bitcode_fn(
|
call_str_bitcode_fn(
|
||||||
env,
|
env,
|
||||||
|
&[value],
|
||||||
&[
|
&[
|
||||||
ptr.into(),
|
ptr.into(),
|
||||||
cursors.offset.into(),
|
cursors.offset.into(),
|
||||||
cursors.extra_offset.into(),
|
cursors.extra_offset.into(),
|
||||||
value,
|
|
||||||
],
|
],
|
||||||
|
crate::llvm::bitcode::BitcodeReturns::Basic,
|
||||||
bitcode::STR_CLONE_TO,
|
bitcode::STR_CLONE_TO,
|
||||||
)
|
)
|
||||||
.into_int_value()
|
.into_int_value()
|
||||||
|
|
|
||||||
|
|
@ -479,4 +479,43 @@ mod test {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn struct_with_strings() {
|
||||||
|
run_expect_test(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
app "test" provides [main] to "./platform"
|
||||||
|
|
||||||
|
main = 0
|
||||||
|
|
||||||
|
expect
|
||||||
|
a = {
|
||||||
|
utopia: "Astra mortemque praestare gradatim",
|
||||||
|
brillist: "Profundum et fundamentum",
|
||||||
|
}
|
||||||
|
|
||||||
|
a != a
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
This expectation failed:
|
||||||
|
|
||||||
|
5│> expect
|
||||||
|
6│> a = {
|
||||||
|
7│> utopia: "Astra mortemque praestare gradatim",
|
||||||
|
8│> brillist: "Profundum et fundamentum",
|
||||||
|
9│> }
|
||||||
|
10│>
|
||||||
|
11│> a != a
|
||||||
|
|
||||||
|
When it failed, these variables had these values:
|
||||||
|
|
||||||
|
a : { brillist : Str, utopia : Str }
|
||||||
|
a = { brillist: "Profundum et fundamentum", utopia: "Astra mortemque praestare gradatim" }
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue