Skip to content

Commit df17bbb

Browse files
committed
Update tests
1 parent 61c16cf commit df17bbb

5 files changed

Lines changed: 120 additions & 224 deletions

File tree

‎tests/unit/out/refcount/structured_binding_copy_ctor.rs‎

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,29 @@ use std::rc::{Rc, Weak};
99
thread_local!(
1010
pub static copies_0: Value<i32> = Rc::new(RefCell::new(0));
1111
);
12-
#[derive(VaArg, FnPtrArg, Default)]
12+
#[derive(Record, ByteRepr, VaArg, FnPtrArg, Default)]
13+
#[byte_size(8)]
1314
pub struct Counted {
14-
pub x: Value<i32>,
15-
pub y: Value<i32>,
15+
#[offset(0)]
16+
pub x: i32,
17+
#[offset(4)]
18+
pub y: i32,
1619
}
1720
impl Counted {
1821
pub fn new(x: i32, y: i32) -> Self {
1922
let x: Value<i32> = Rc::new(RefCell::new(x));
2023
let y: Value<i32> = Rc::new(RefCell::new(y));
2124
let __this: Value<Counted> = Rc::new(RefCell::new(Self {
22-
x: Rc::new(RefCell::new((*x.borrow()))),
23-
y: Rc::new(RefCell::new((*y.borrow()))),
25+
x: (*x.borrow()),
26+
y: (*y.borrow()),
2427
}));
2528
let this: Ptr<Counted> = __this.as_pointer();
2629
Rc::try_unwrap(__this).ok().unwrap().into_inner()
2730
}
2831
pub fn copy_from(other: Ptr<Counted>) -> Self {
2932
let __this: Value<Counted> = Rc::new(RefCell::new(Self {
30-
x: Rc::new(RefCell::new(((*(*other.upgrade().deref()).x.borrow()) * 2))),
31-
y: Rc::new(RefCell::new(((*(*other.upgrade().deref()).y.borrow()) * 2))),
33+
x: (other.with(|__s| __s.x) * 2),
34+
y: (other.with(|__s| __s.y) * 2),
3235
}));
3336
let this: Ptr<Counted> = __this.as_pointer();
3437
(*copies_0.with(Value::clone).borrow_mut()).prefix_inc();
@@ -44,21 +47,6 @@ impl Clone for Counted {
4447
Counted::copy_from(__src.as_pointer())
4548
}
4649
}
47-
impl ByteRepr for Counted {
48-
fn byte_size() -> usize {
49-
8
50-
}
51-
fn to_bytes(&self, buf: &mut [u8]) {
52-
(*self.x.borrow()).to_bytes(&mut buf[0..4]);
53-
(*self.y.borrow()).to_bytes(&mut buf[4..8]);
54-
}
55-
fn from_bytes(buf: &[u8]) -> Self {
56-
Self {
57-
x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
58-
y: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))),
59-
}
60-
}
61-
}
6250
pub fn make_counted_1() -> Counted {
6351
return Counted::new({ 5 }, { 6 });
6452
}
@@ -70,19 +58,19 @@ fn main_0() -> i32 {
7058
let s: Value<Counted> = Rc::new(RefCell::new(Counted::new({ 1 }, { 2 })));
7159
let __decomp_2: Value<Counted> = Rc::new(RefCell::new(Counted::copy_from({ s.as_pointer() })));
7260
assert!((copies_0.with(|rc| *rc.borrow()) == 1));
73-
assert!(((*(*__decomp_2.borrow()).x.borrow()) == 2));
74-
assert!(((*(*__decomp_2.borrow()).y.borrow()) == 4));
61+
assert!(({ (*__decomp_2.borrow()).x } == 2));
62+
assert!(({ (*__decomp_2.borrow()).y } == 4));
7563
let __decomp_3: Ptr<Counted> = s.as_pointer();
7664
assert!((copies_0.with(|rc| *rc.borrow()) == 1));
77-
assert!(((*(*__decomp_3.upgrade().deref()).x.borrow()) == 1));
78-
assert!(((*(*__decomp_3.upgrade().deref()).y.borrow()) == 2));
65+
assert!((__decomp_3.with(|__s| __s.x) == 1));
66+
assert!((__decomp_3.with(|__s| __s.y) == 2));
7967
let __decomp_4: Ptr<Counted> = s.as_pointer();
8068
assert!((copies_0.with(|rc| *rc.borrow()) == 1));
81-
assert!(((*(*__decomp_4.upgrade().deref()).x.borrow()) == 1));
69+
assert!((__decomp_4.with(|__s| __s.x) == 1));
8270
let __decomp_5: Value<Counted> = Rc::new(RefCell::new(({ make_counted_1() })));
8371
assert!((copies_0.with(|rc| *rc.borrow()) == 1));
84-
assert!(((*(*__decomp_5.borrow()).x.borrow()) == 5));
85-
assert!(((*(*__decomp_5.borrow()).y.borrow()) == 6));
72+
assert!(({ (*__decomp_5.borrow()).x } == 5));
73+
assert!(({ (*__decomp_5.borrow()).y } == 6));
8674
return 0;
8775
}
8876
pub fn __cpp2rust_init_globals() {

‎tests/unit/out/refcount/structured_binding_move_ctor.rs‎

Lines changed: 33 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,42 @@ thread_local!(
1212
thread_local!(
1313
pub static moves_1: Value<i32> = Rc::new(RefCell::new(0));
1414
);
15-
#[derive(VaArg, FnPtrArg, Default)]
15+
#[derive(Record, ByteRepr, VaArg, FnPtrArg, Default)]
16+
#[byte_size(8)]
1617
pub struct Movable {
17-
pub x: Value<i32>,
18-
pub y: Value<i32>,
18+
#[offset(0)]
19+
pub x: i32,
20+
#[offset(4)]
21+
pub y: i32,
1922
}
2023
impl Movable {
2124
pub fn new(x: i32, y: i32) -> Self {
2225
let x: Value<i32> = Rc::new(RefCell::new(x));
2326
let y: Value<i32> = Rc::new(RefCell::new(y));
2427
let __this: Value<Movable> = Rc::new(RefCell::new(Self {
25-
x: Rc::new(RefCell::new((*x.borrow()))),
26-
y: Rc::new(RefCell::new((*y.borrow()))),
28+
x: (*x.borrow()),
29+
y: (*y.borrow()),
2730
}));
2831
let this: Ptr<Movable> = __this.as_pointer();
2932
Rc::try_unwrap(__this).ok().unwrap().into_inner()
3033
}
3134
pub fn copy_from(other: Ptr<Movable>) -> Self {
3235
let __this: Value<Movable> = Rc::new(RefCell::new(Self {
33-
x: Rc::new(RefCell::new((*(*other.upgrade().deref()).x.borrow()))),
34-
y: Rc::new(RefCell::new((*(*other.upgrade().deref()).y.borrow()))),
36+
x: other.with(|__s| __s.x),
37+
y: other.with(|__s| __s.y),
3538
}));
3639
let this: Ptr<Movable> = __this.as_pointer();
3740
(*copies_0.with(Value::clone).borrow_mut()).prefix_inc();
3841
Rc::try_unwrap(__this).ok().unwrap().into_inner()
3942
}
4043
pub fn move_from(other: Ptr<Movable>) -> Self {
4144
let __this: Value<Movable> = Rc::new(RefCell::new(Self {
42-
x: Rc::new(RefCell::new((*(*other.upgrade().deref()).x.borrow()))),
43-
y: Rc::new(RefCell::new((*(*other.upgrade().deref()).y.borrow()))),
45+
x: other.with(|__s| __s.x),
46+
y: other.with(|__s| __s.y),
4447
}));
4548
let this: Ptr<Movable> = __this.as_pointer();
46-
(*(*other.upgrade().deref()).x.borrow_mut()) = 0;
47-
(*(*other.upgrade().deref()).y.borrow_mut()) = 0;
49+
field!(other, x).write(0);
50+
field!(other, y).write(0);
4851
(*moves_1.with(Value::clone).borrow_mut()).prefix_inc();
4952
Rc::try_unwrap(__this).ok().unwrap().into_inner()
5053
}
@@ -58,48 +61,21 @@ impl Clone for Movable {
5861
Movable::copy_from(__src.as_pointer())
5962
}
6063
}
61-
impl ByteRepr for Movable {
62-
fn byte_size() -> usize {
63-
8
64-
}
65-
fn to_bytes(&self, buf: &mut [u8]) {
66-
(*self.x.borrow()).to_bytes(&mut buf[0..4]);
67-
(*self.y.borrow()).to_bytes(&mut buf[4..8]);
68-
}
69-
fn from_bytes(buf: &[u8]) -> Self {
70-
Self {
71-
x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
72-
y: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))),
73-
}
74-
}
75-
}
76-
#[derive(VaArg, FnPtrArg, Default)]
64+
#[derive(Record, ByteRepr, VaArg, FnPtrArg, Default)]
65+
#[byte_size(48)]
7766
pub struct Holder {
67+
#[offset(0)]
68+
#[byte_size(24)]
7869
pub xs: Value<Vec<i32>>,
70+
#[offset(24)]
71+
#[byte_size(24)]
7972
pub ys: Value<Vec<i32>>,
8073
}
8174
impl Clone for Holder {
8275
fn clone(&self) -> Self {
83-
let __this: Value<Holder> = Rc::new(RefCell::new(Self {
76+
Self {
8477
xs: Rc::new(RefCell::new((*self.xs.borrow()).clone())),
8578
ys: Rc::new(RefCell::new((*self.ys.borrow()).clone())),
86-
}));
87-
let this: Ptr<Holder> = __this.as_pointer();
88-
Rc::try_unwrap(__this).ok().unwrap().into_inner()
89-
}
90-
}
91-
impl ByteRepr for Holder {
92-
fn byte_size() -> usize {
93-
48
94-
}
95-
fn to_bytes(&self, buf: &mut [u8]) {
96-
(*self.xs.borrow()).to_bytes(&mut buf[0..24]);
97-
(*self.ys.borrow()).to_bytes(&mut buf[24..48]);
98-
}
99-
fn from_bytes(buf: &[u8]) -> Self {
100-
Self {
101-
xs: Rc::new(RefCell::new(<Vec<i32>>::from_bytes(&buf[0..24]))),
102-
ys: Rc::new(RefCell::new(<Vec<i32>>::from_bytes(&buf[24..48]))),
10379
}
10480
}
10581
}
@@ -112,32 +88,32 @@ fn main_0() -> i32 {
11288
let __decomp_2: Value<Movable> = Rc::new(RefCell::new(Movable::move_from({ m.as_pointer() })));
11389
assert!((moves_1.with(|rc| *rc.borrow()) == 1));
11490
assert!((copies_0.with(|rc| *rc.borrow()) == 0));
115-
assert!(((*(*__decomp_2.borrow()).x.borrow()) == 3));
116-
assert!(((*(*__decomp_2.borrow()).y.borrow()) == 4));
117-
assert!(((*(*m.borrow()).x.borrow()) == 0));
118-
assert!(((*(*m.borrow()).y.borrow()) == 0));
91+
assert!(({ (*__decomp_2.borrow()).x } == 3));
92+
assert!(({ (*__decomp_2.borrow()).y } == 4));
93+
assert!(({ (*m.borrow()).x } == 0));
94+
assert!(({ (*m.borrow()).y } == 0));
11995
let h: Value<Holder> = Rc::new(RefCell::new(Holder {
12096
xs: Rc::new(RefCell::new(vec![1, 2, 3])),
12197
ys: Rc::new(RefCell::new(vec![4, 5])),
12298
}));
12399
let __decomp_3: Value<Holder> =
124100
Rc::new(RefCell::new(({ HolderImpl::extract(&h.as_pointer()) })));
125-
assert!(((*(*__decomp_3.borrow()).xs.borrow()).len() == 3_usize));
126-
assert!(((*(*__decomp_3.borrow()).ys.borrow()).len() == 2_usize));
101+
assert!(((*{ (*__decomp_3.borrow()).xs.clone() }.borrow()).len() == 3_usize));
102+
assert!(((*{ (*__decomp_3.borrow()).ys.clone() }.borrow()).len() == 2_usize));
127103
assert!(
128-
((((*__decomp_3.borrow()).xs.as_pointer() as Ptr<i32>)
104+
((({ (*__decomp_3.borrow()).xs.clone() }.as_pointer() as Ptr<i32>)
129105
.offset(2_usize)
130106
.read())
131107
== 3)
132108
);
133109
assert!(
134-
((((*__decomp_3.borrow()).ys.as_pointer() as Ptr<i32>)
110+
((({ (*__decomp_3.borrow()).ys.clone() }.as_pointer() as Ptr<i32>)
135111
.offset(0_usize)
136112
.read())
137113
== 4)
138114
);
139-
assert!((*(*h.borrow()).xs.borrow()).is_empty());
140-
assert!((*(*h.borrow()).ys.borrow()).is_empty());
115+
assert!((*{ (*h.borrow()).xs.clone() }.borrow()).is_empty());
116+
assert!((*{ (*h.borrow()).ys.clone() }.borrow()).is_empty());
141117
return 0;
142118
}
143119
pub trait HolderImpl {
@@ -147,10 +123,10 @@ impl HolderImpl for Ptr<Holder> {
147123
fn extract(&self) -> Holder {
148124
return Holder {
149125
xs: Rc::new(RefCell::new(std::mem::take(
150-
&mut (*(*(*self).upgrade().deref()).xs.borrow_mut()),
126+
&mut (*(*self).with(|__s| __s.xs.clone()).borrow_mut()),
151127
))),
152128
ys: Rc::new(RefCell::new(std::mem::take(
153-
&mut (*(*(*self).upgrade().deref()).ys.borrow_mut()),
129+
&mut (*(*self).with(|__s| __s.ys.clone()).borrow_mut()),
154130
))),
155131
};
156132
}

‎tests/unit/out/refcount/structured_binding_range_for.rs‎

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,13 @@ use std::io::prelude::*;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
9-
#[derive(VaArg, FnPtrArg, Default)]
9+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
10+
#[byte_size(8)]
1011
pub struct Pair {
11-
pub first: Value<i32>,
12-
pub second: Value<i32>,
13-
}
14-
impl Clone for Pair {
15-
fn clone(&self) -> Self {
16-
let __this: Value<Pair> = Rc::new(RefCell::new(Self {
17-
first: Rc::new(RefCell::new((*self.first.borrow()))),
18-
second: Rc::new(RefCell::new((*self.second.borrow()))),
19-
}));
20-
let this: Ptr<Pair> = __this.as_pointer();
21-
Rc::try_unwrap(__this).ok().unwrap().into_inner()
22-
}
23-
}
24-
impl ByteRepr for Pair {
25-
fn byte_size() -> usize {
26-
8
27-
}
28-
fn to_bytes(&self, buf: &mut [u8]) {
29-
(*self.first.borrow()).to_bytes(&mut buf[0..4]);
30-
(*self.second.borrow()).to_bytes(&mut buf[4..8]);
31-
}
32-
fn from_bytes(buf: &[u8]) -> Self {
33-
Self {
34-
first: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
35-
second: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))),
36-
}
37-
}
12+
#[offset(0)]
13+
pub first: i32,
14+
#[offset(4)]
15+
pub second: i32,
3816
}
3917
pub fn main() {
4018
__cpp2rust_init_globals();
@@ -43,35 +21,37 @@ pub fn main() {
4321
fn main_0() -> i32 {
4422
let arr: Value<Box<[Pair]>> = Rc::new(RefCell::new(Box::new([
4523
Pair {
46-
first: Rc::new(RefCell::new(1)),
47-
second: Rc::new(RefCell::new(2)),
24+
first: 1,
25+
second: 2,
4826
},
4927
Pair {
50-
first: Rc::new(RefCell::new(3)),
51-
second: Rc::new(RefCell::new(4)),
28+
first: 3,
29+
second: 4,
5230
},
5331
Pair {
54-
first: Rc::new(RefCell::new(5)),
55-
second: Rc::new(RefCell::new(6)),
32+
first: 5,
33+
second: 6,
5634
},
5735
])));
5836
'loop_: for mut __decomp_0 in arr.as_pointer() as Ptr<Pair> {
59-
(*(*__decomp_0.upgrade().deref()).first.borrow_mut()) +=
60-
(*(*__decomp_0.upgrade().deref()).second.borrow());
37+
{
38+
let _ptr = field!(__decomp_0, first);
39+
_ptr.write(_ptr.read() + __decomp_0.with(|__s| __s.second))
40+
};
6141
}
62-
assert!(((*(*arr.borrow())[(0) as usize].first.borrow()) == 3));
63-
assert!(((*(*arr.borrow())[(2) as usize].first.borrow()) == 11));
42+
assert!(({ (*arr.borrow())[(0) as usize].first } == 3));
43+
assert!(({ (*arr.borrow())[(2) as usize].first } == 11));
6444
'loop_: for mut __decomp_1 in arr.as_pointer() as Ptr<Pair> {
6545
let __decomp_1: Value<Pair> = Rc::new(RefCell::new(__decomp_1.upgrade().deref().clone()));
66-
(*(*__decomp_1.borrow()).first.borrow_mut()) = 0;
67-
(*(*__decomp_1.borrow()).second.borrow_mut()) = 0;
46+
(*__decomp_1.borrow_mut()).first = 0;
47+
(*__decomp_1.borrow_mut()).second = 0;
6848
}
69-
assert!(((*(*arr.borrow())[(1) as usize].first.borrow()) == 7));
70-
assert!(((*(*arr.borrow())[(1) as usize].second.borrow()) == 4));
49+
assert!(({ (*arr.borrow())[(1) as usize].first } == 7));
50+
assert!(({ (*arr.borrow())[(1) as usize].second } == 4));
7151
let sum: Value<i32> = Rc::new(RefCell::new(0));
7252
'loop_: for mut __decomp_2 in arr.as_pointer() as Ptr<Pair> {
73-
(*sum.borrow_mut()) += ((*(*__decomp_2.upgrade().deref()).first.borrow())
74-
* (*(*__decomp_2.upgrade().deref()).second.borrow()));
53+
(*sum.borrow_mut()) +=
54+
(__decomp_2.with(|__s| __s.first) * __decomp_2.with(|__s| __s.second));
7555
}
7656
assert!(((*sum.borrow()) == (((3 * 2) + (7 * 4)) + (11 * 6))));
7757
return 0;

0 commit comments

Comments
 (0)