Skip to content

Commit

Permalink
Test trait implementations with arc-ed fields
Browse files Browse the repository at this point in the history
Ensure that the fields are handled as if the field was not boxed.
  • Loading branch information
jvff committed Dec 20, 2024
1 parent a2ab2c9 commit 532da70
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
3 changes: 2 additions & 1 deletion linera-witty/tests/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//! Dummy types used in tests.
use std::rc::Rc;
use std::{rc::Rc, sync::Arc};

use linera_witty::{WitLoad, WitStore, WitType};

Expand Down Expand Up @@ -76,4 +76,5 @@ pub enum SpecializedGenericEnum<A, B> {
pub struct StructWithHeapFields {
pub boxed: Box<SimpleWrapper>,
pub rced: Rc<Leaf>,
pub arced: Arc<Enum>,
}
17 changes: 16 additions & 1 deletion linera-witty/tests/wit_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,16 @@ fn test_heap_allocated_fields() {
first: false,
second: 0x201f_1e1d_1c1b_1a19_1817_1615_1413_1211_u128,
}),
arced: Arc::new(Enum::SmallerVariantWithStrictAlignment {
inner: 0x2f2e_2d2c_2b2a_2928,
}),
};

test_load_from_memory(
&[
1, 2, 3, 4, 5, 6, 7, 8, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32,
25, 26, 27, 28, 29, 30, 31, 32, 2, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
46, 47, 48,
],
expected.clone(),
);
Expand All @@ -332,6 +336,17 @@ fn test_heap_allocated_fields() {
0_i32,
0x1817_1615_1413_1211_i64,
0x201f_1e1d_1c1b_1a19_i64,
2_i32,
0x2f2e_2d2c_2b2a_2928_i64,
0_i32,
0_i32,
0_i32,
0_i32,
0_i32,
0_i32,
0_i32,
0_i32,
0_i32,
],
expected,
&[],
Expand Down
17 changes: 16 additions & 1 deletion linera-witty/tests/wit_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,17 @@ fn test_heap_allocated_fields() {
first: true,
second: 0x7071_7273_7475_7677_7879_7a7b_7c7d_7e7f_u128,
}),
arced: Arc::new(Enum::SmallerVariantWithStrictAlignment {
inner: 0x4041_4243_4445_4647_u64,
}),
};

test_store_in_memory(
data.clone(),
&[
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a,
0x79, 0x78, 0x77, 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x70,
0x79, 0x78, 0x77, 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x70, 2, 0, 0, 0, 0, 0, 0, 0,
0x47, 0x46, 0x45, 0x44, 0x43, 0x42, 0x41, 0x40, 0, 0, 0, 0, 0, 0, 0, 0,
],
&[],
);
Expand All @@ -380,6 +384,17 @@ fn test_heap_allocated_fields() {
1_i32,
0x7879_7a7b_7c7d_7e7f_i64,
0x7071_7273_7475_7677_i64,
2_i32,
0x4041_4243_4445_4647_i64,
0,
0,
0,
0,
0,
0,
0,
0,
0,
],
&[],
);
Expand Down
12 changes: 10 additions & 2 deletions linera-witty/tests/wit_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,17 @@ fn test_specialized_generic_enum_type() {
#[test]
fn test_heap_allocated_fields() {
test_wit_type_implementation::<StructWithHeapFields>(ExpectedMetadata {
size: 32,
size: 56,
alignment: 8,
flat_layout_length: 4,
flat_layout_length: 15,
declaration: concat!(
" variant enum {\n",
" empty,\n",
" large-variant-with-loose-alignment(\
tuple<s8, s8, s8, s8, s8, s8, s8, s8, s8, s8>\
),\n",
" smaller-variant-with-strict-alignment(u64),\n",
" }\n\n",
" record leaf {\n",
" first: bool,\n",
" second: u128,\n",
Expand All @@ -195,6 +202,7 @@ fn test_heap_allocated_fields() {
" record struct-with-heap-fields {\n",
" boxed: simple-wrapper,\n",
" rced: leaf,\n",
" arced: enum,\n",
" }\n\n",
" type u128 = tuple<u64, u64>;\n",
),
Expand Down

0 comments on commit 532da70

Please sign in to comment.