Skip to content

Commit 47d2769

Browse files
committed
Update tests
1 parent 2976226 commit 47d2769

30 files changed

Lines changed: 419 additions & 300 deletions

‎tests/unit/out/refcount/12_test.rs‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ pub fn main() {
1111
std::process::exit(main_0());
1212
}
1313
fn main_0() -> i32 {
14-
let v: Value<Vec<Value<Vec<i32>>>> = Rc::new(RefCell::new(Vec::new()));
15-
(v.as_pointer() as Ptr<Vec<Value<Vec<i32>>>>).with_mut(|__v: &mut Vec<Value<Vec<i32>>>| {
16-
__v.push(Rc::new(RefCell::new(
17-
(0..(10_usize) as usize)
18-
.map(|_| <i32>::default())
19-
.collect::<Vec<_>>(),
20-
)))
21-
});
14+
let v: Value<Vec<Vec<i32>>> = Rc::new(RefCell::new(Vec::new()));
15+
{
16+
let __a1 = (0..(10_usize) as usize)
17+
.map(|_| <i32>::default())
18+
.collect::<Vec<_>>();
19+
(*v.borrow_mut()).push(__a1)
20+
};
2221
return 0;
2322
}
2423
pub fn __cpp2rust_init_globals() {}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,33 @@ pub fn main() {
4646
fn main_0() -> i32 {
4747
assert!(
4848
(({
49-
let __idx = (0) as usize;
50-
items_3.with(|rc| rc.borrow()[__idx].clone())
49+
let __idx0 = (0) as usize;
50+
items_3.with(|rc| rc.borrow()[__idx0].clone())
5151
})
5252
.with(|__s| __s.value)
5353
== 1)
5454
);
5555
assert!(
5656
(({
57-
let __idx = (1) as usize;
58-
items_3.with(|rc| rc.borrow()[__idx].clone())
57+
let __idx0 = (1) as usize;
58+
items_3.with(|rc| rc.borrow()[__idx0].clone())
5959
})
6060
.with(|__s| __s.value)
6161
== 2)
6262
);
6363
assert!(({ (*obj_4.with(Value::clone).borrow()).p.clone() }.with(|__s| __s.value) == 42));
6464
assert!(
6565
(({
66-
let __idx = (0) as usize;
67-
cache_5.with(|rc| rc.borrow()[__idx].clone())
66+
let __idx0 = (0) as usize;
67+
cache_5.with(|rc| rc.borrow()[__idx0].clone())
6868
})
6969
.with(|__s| __s.value)
7070
== 1)
7171
);
7272
assert!(
7373
(({
74-
let __idx = (1) as usize;
75-
cache_5.with(|rc| rc.borrow()[__idx].clone())
74+
let __idx0 = (1) as usize;
75+
cache_5.with(|rc| rc.borrow()[__idx0].clone())
7676
})
7777
.with(|__s| __s.value)
7878
== 2)

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

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,36 @@ pub fn main() {
1515
std::process::exit(main_0());
1616
}
1717
fn main_0() -> i32 {
18-
let grid: Value<Box<[Value<Box<[i8]>>]>> = Rc::new(RefCell::new(
18+
let grid: Value<Box<[Box<[i8]>]>> = Rc::new(RefCell::new(
1919
(0..3)
20-
.map(|_| Rc::new(RefCell::new((0..6).map(|_| 0_i8).collect::<Box<[i8]>>())))
21-
.collect::<Box<[Value<Box<[i8]>>]>>(),
20+
.map(|_| (0..6).map(|_| 0_i8).collect::<Box<[i8]>>())
21+
.collect::<Box<[Box<[i8]>]>>(),
2222
));
2323
let mut i: i32 = 0;
2424
'loop_: while (((i < 3) as i32) != 0) {
2525
({
26-
let _row: Ptr<i8> = (((grid.as_pointer() as Ptr<Value<Box<[i8]>>>)
27-
.offset(i)
28-
.read()
29-
.as_pointer()) as Ptr<i8>);
26+
let _row: Ptr<i8> =
27+
(((grid.as_pointer() as Ptr<Box<[i8]>>).offset(i).as_pointer()) as Ptr<i8>);
3028
let _c: i8 = ((('a' as i32) + i) as i8);
3129
fill_row_0(_row, _c)
3230
});
3331
i.postfix_inc();
3432
}
3533
assert!(
36-
(((((*grid.borrow())[(0) as usize].borrow()[(0) as usize] as i32) == ('a' as i32)) as i32)
37-
!= 0)
34+
(((((*grid.borrow())[(0) as usize][(0) as usize] as i32) == ('a' as i32)) as i32) != 0)
3835
);
3936
assert!(
40-
(((((*grid.borrow())[(1) as usize].borrow()[(0) as usize] as i32) == ('b' as i32)) as i32)
41-
!= 0)
37+
(((((*grid.borrow())[(1) as usize][(0) as usize] as i32) == ('b' as i32)) as i32) != 0)
4238
);
4339
assert!(
44-
(((((*grid.borrow())[(2) as usize].borrow()[(0) as usize] as i32) == ('c' as i32)) as i32)
45-
!= 0)
40+
(((((*grid.borrow())[(2) as usize][(0) as usize] as i32) == ('c' as i32)) as i32) != 0)
4641
);
4742
assert!(
48-
(((((*grid.borrow())[(1) as usize].borrow()[(1) as usize] as i32) == ('\0' as i32))
49-
as i32)
50-
!= 0)
43+
(((((*grid.borrow())[(1) as usize][(1) as usize] as i32) == ('\0' as i32)) as i32) != 0)
5144
);
52-
(*grid.borrow())[(2) as usize].borrow_mut()[(5) as usize] = (('z' as i32) as i8);
45+
(*grid.borrow_mut())[(2) as usize][(5) as usize] = (('z' as i32) as i8);
5346
assert!(
54-
(((((*grid.borrow())[(2) as usize].borrow()[(5) as usize] as i32) == ('z' as i32)) as i32)
55-
!= 0)
47+
(((((*grid.borrow())[(2) as usize][(5) as usize] as i32) == ('z' as i32)) as i32) != 0)
5648
);
5749
return 0;
5850
}

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

Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ pub fn shift_points_12(p: Ptr<Point>, mut d: i32) {
8989
pub fn total_len_13(names: Ptr<Ptr<i8>>) -> i32 {
9090
return (({ len5_1((elem!((names), 0).read())) }) + ({ len5_1((elem!((names), 1).read())) }));
9191
}
92+
thread_local!(
93+
pub static kTable_14: Value<Box<[Box<[i32]>]>> = Rc::new(RefCell::new(Box::new([
94+
Box::new([1, 2, 3]),
95+
Box::new([4, 5, 6]),
96+
])));
97+
);
9298
pub fn main() {
9399
__cpp2rust_init_globals();
94100
std::process::exit(main_0());
@@ -136,36 +142,92 @@ fn main_0() -> i32 {
136142
Ptr::<i8>::from_string_literal(b"cde"),
137143
])));
138144
assert!((({ total_len_13(names.as_pointer(),) }) == 5));
139-
let rows: Value<Box<[Value<Box<[i32]>>]>> = Rc::new(RefCell::new(Box::new([
140-
Rc::new(RefCell::new(Box::new([1, 2, 3]))),
141-
Rc::new(RefCell::new(Box::new([4, 5, 6]))),
145+
let rows: Value<Box<[Box<[i32]>]>> = Rc::new(RefCell::new(Box::new([
146+
Box::new([1, 2, 3]),
147+
Box::new([4, 5, 6]),
142148
])));
143-
let mut p: Ptr<Value<Box<[i32]>>> = (rows.as_pointer() as Ptr<Value<Box<[i32]>>>);
149+
let mut p: Ptr<Box<[i32]>> = (rows.as_pointer() as Ptr<Box<[i32]>>);
144150
p.prefix_inc();
145151
assert!(
146-
({ ((p).read().as_pointer() as Ptr::<i32>).clone() } == {
147-
((((rows.as_pointer() as Ptr<Value<Box<[i32]>>>)
152+
({ ((p).as_pointer() as Ptr::<i32>).clone() } == {
153+
((((rows.as_pointer() as Ptr<Box<[i32]>>)
148154
.offset(1)
149-
.read()
150155
.as_pointer()) as Ptr<i32>)
151156
.offset(0))
152157
})
153158
);
154-
let r: Ptr<i32> = ((p).read().as_pointer()).clone();
159+
let r: Ptr<i32> = ((p).as_pointer()).clone();
155160
assert!(((elem!((r), 0).read()) == 4));
156161
assert!((({ sum_2((r).clone(),) }) == 15));
157-
assert!((({ sum_2(((p).read().as_pointer()).clone(),) }) == 15));
158-
let mut q: Ptr<Value<Box<[i32]>>> = (rows.as_pointer() as Ptr<Value<Box<[i32]>>>);
159-
assert!((({ sum_2(q.offset((1) as isize).read().as_pointer(),) }) == 15));
162+
assert!((({ sum_2(((p).as_pointer()).clone(),) }) == 15));
163+
let mut q: Ptr<Box<[i32]>> = (rows.as_pointer() as Ptr<Box<[i32]>>);
164+
assert!((({ sum_2(q.offset((1) as isize).as_pointer(),) }) == 15));
160165
assert!(
161-
({ (q.offset((1) as isize).read().as_pointer() as Ptr::<i32>) } == {
162-
((((rows.as_pointer() as Ptr<Value<Box<[i32]>>>)
166+
({ (q.offset((1) as isize).as_pointer() as Ptr::<i32>) } == {
167+
((((rows.as_pointer() as Ptr<Box<[i32]>>)
163168
.offset(1)
164-
.read()
165169
.as_pointer()) as Ptr<i32>)
166170
.offset(0))
167171
})
168172
);
173+
elem!((q.offset((1) as isize).as_pointer() as Ptr::<i32>), 2).write(8);
174+
assert!(
175+
((*rows.borrow())[(1) as usize][(2) as usize] == 8)
176+
&& ((*rows.borrow())[(0) as usize][(2) as usize] == 3)
177+
);
178+
(*rows.borrow_mut())[(0) as usize][(1) as usize] =
179+
{ (*rows.borrow())[(0) as usize][(2) as usize] };
180+
elem!((q.offset((1) as isize).as_pointer() as Ptr::<i32>), 0)
181+
.write({ (elem!((q.offset((0) as isize).as_pointer() as Ptr::<i32>), 1).read()) });
182+
{
183+
let __rhs = { (elem!((q.offset((0) as isize).as_pointer() as Ptr::<i32>), 2).read()) };
184+
elem!((q.offset((1) as isize).as_pointer() as Ptr::<i32>), 1)
185+
.with_mut(|__v| *__v = *__v + __rhs)
186+
};
187+
assert!(
188+
(((*rows.borrow())[(0) as usize][(1) as usize] == 3)
189+
&& ((*rows.borrow())[(1) as usize][(0) as usize] == 3))
190+
&& ((*rows.borrow())[(1) as usize][(1) as usize] == 8)
191+
);
192+
let key: Value<Box<[i32]>> = Rc::new(RefCell::new(Box::new([0, 4, 5, 6])));
193+
assert!(
194+
((((key.as_pointer() as Ptr<i32>).offset(1)) as Ptr::<i32>)
195+
.to_any()
196+
.memcmp(
197+
&((((kTable_14.with(|v| v.as_pointer()) as Ptr<Box<[i32]>>)
198+
.offset(1)
199+
.as_pointer()) as Ptr::<i32>) as Ptr::<i32>)
200+
.to_any(),
201+
::std::mem::size_of::<[i32; 3]>()
202+
)
203+
== 0)
204+
);
205+
assert!(
206+
((((key.as_pointer() as Ptr<i32>).offset(1)) as Ptr::<i32>)
207+
.to_any()
208+
.memcmp(
209+
&((((kTable_14.with(|v| v.as_pointer()) as Ptr<Box<[i32]>>)
210+
.offset(0)
211+
.as_pointer()) as Ptr::<i32>) as Ptr::<i32>)
212+
.to_any(),
213+
::std::mem::size_of::<[i32; 3]>()
214+
)
215+
!= 0)
216+
);
217+
assert!(
218+
(({
219+
let __idx0 = (1) as usize;
220+
let __idx1 = (2) as usize;
221+
kTable_14.with(|rc| rc.borrow()[__idx0][__idx1])
222+
}) == 6)
223+
&& (({
224+
let __idx0 = (0) as usize;
225+
let __idx1 = (1) as usize;
226+
kTable_14.with(|rc| rc.borrow()[__idx0][__idx1])
227+
}) == 2)
228+
);
169229
return 0;
170230
}
171-
pub fn __cpp2rust_init_globals() {}
231+
pub fn __cpp2rust_init_globals() {
232+
let _ = kTable_14.with(|_| ());
233+
}

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

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -146,44 +146,32 @@ fn main_0() -> i32 {
146146
assert!((v1[(i as usize)] == i));
147147
i.prefix_inc();
148148
}
149-
let m1: Value<Vec<Value<Vec<i32>>>> = Rc::new(RefCell::new(Vec::new()));
149+
let m1: Value<Vec<Vec<i32>>> = Rc::new(RefCell::new(Vec::new()));
150150
let mut i: i32 = 0;
151151
'loop_: while (i < N) {
152-
(m1.as_pointer() as Ptr<Vec<Value<Vec<i32>>>>).with_mut(
153-
|__v: &mut Vec<Value<Vec<i32>>>| {
154-
__v.push(Rc::new(RefCell::new(
155-
(0..(10_usize) as usize)
156-
.map(|_| <i32>::default())
157-
.collect::<Vec<_>>(),
158-
)))
159-
},
160-
);
152+
{
153+
let __a1 = (0..(10_usize) as usize)
154+
.map(|_| <i32>::default())
155+
.collect::<Vec<_>>();
156+
(*m1.borrow_mut()).push(__a1)
157+
};
161158
i.prefix_inc();
162159
}
163-
let m2: Value<Vec<Value<Vec<i32>>>> = Rc::new(RefCell::new(
164-
(*m1.borrow())
165-
.iter()
166-
.map(|inner_vec| Rc::new(RefCell::new(inner_vec.borrow().clone())))
167-
.collect(),
168-
));
160+
let m2: Value<Vec<Vec<i32>>> = Rc::new(RefCell::new((*m1.borrow()).clone()));
169161
let mut i: i32 = 0;
170162
'loop_: while (i < N) {
171163
assert!(
172-
((*((m1.as_pointer() as Ptr<Value<Vec<i32>>>)
164+
((*((m1.as_pointer() as Ptr<Vec<i32>>)
173165
.offset((i as usize))
174-
.upgrade()
175-
.deref()
176166
.as_pointer() as Ptr<Vec<i32>>)
177167
.upgrade()
178168
.deref())
179169
.len()
180170
== 10_usize)
181171
);
182172
assert!(
183-
((*((m2.as_pointer() as Ptr<Value<Vec<i32>>>)
173+
((*((m2.as_pointer() as Ptr<Vec<i32>>)
184174
.offset((i as usize))
185-
.upgrade()
186-
.deref()
187175
.as_pointer() as Ptr<Vec<i32>>)
188176
.upgrade()
189177
.deref())
@@ -194,10 +182,8 @@ fn main_0() -> i32 {
194182
'loop_: while (j < 10) {
195183
assert!(
196184
((elem!(
197-
((m1.as_pointer() as Ptr<Value<Vec<i32>>>)
185+
((m1.as_pointer() as Ptr<Vec<i32>>)
198186
.offset((i as usize))
199-
.upgrade()
200-
.deref()
201187
.as_pointer() as Ptr<i32>),
202188
(j as usize)
203189
)
@@ -206,10 +192,8 @@ fn main_0() -> i32 {
206192
);
207193
assert!(
208194
((elem!(
209-
((m2.as_pointer() as Ptr<Value<Vec<i32>>>)
195+
((m2.as_pointer() as Ptr<Vec<i32>>)
210196
.offset((i as usize))
211-
.upgrade()
212-
.deref()
213197
.as_pointer() as Ptr<i32>),
214198
(j as usize)
215199
)
@@ -225,10 +209,8 @@ fn main_0() -> i32 {
225209
let mut j: i32 = 0;
226210
'loop_: while (j < 10) {
227211
elem!(
228-
((m2.as_pointer() as Ptr<Value<Vec<i32>>>)
212+
((m2.as_pointer() as Ptr<Vec<i32>>)
229213
.offset((i as usize))
230-
.upgrade()
231-
.deref()
232214
.as_pointer() as Ptr<i32>),
233215
(j as usize)
234216
)
@@ -240,21 +222,17 @@ fn main_0() -> i32 {
240222
let mut i: i32 = 0;
241223
'loop_: while (i < N) {
242224
assert!(
243-
((*((m1.as_pointer() as Ptr<Value<Vec<i32>>>)
225+
((*((m1.as_pointer() as Ptr<Vec<i32>>)
244226
.offset((i as usize))
245-
.upgrade()
246-
.deref()
247227
.as_pointer() as Ptr<Vec<i32>>)
248228
.upgrade()
249229
.deref())
250230
.len()
251231
== 10_usize)
252232
);
253233
assert!(
254-
((*((m2.as_pointer() as Ptr<Value<Vec<i32>>>)
234+
((*((m2.as_pointer() as Ptr<Vec<i32>>)
255235
.offset((i as usize))
256-
.upgrade()
257-
.deref()
258236
.as_pointer() as Ptr<Vec<i32>>)
259237
.upgrade()
260238
.deref())
@@ -265,10 +243,8 @@ fn main_0() -> i32 {
265243
'loop_: while (j < 10) {
266244
assert!(
267245
((elem!(
268-
((m1.as_pointer() as Ptr<Value<Vec<i32>>>)
246+
((m1.as_pointer() as Ptr<Vec<i32>>)
269247
.offset((i as usize))
270-
.upgrade()
271-
.deref()
272248
.as_pointer() as Ptr<i32>),
273249
(j as usize)
274250
)
@@ -277,10 +253,8 @@ fn main_0() -> i32 {
277253
);
278254
assert!(
279255
((elem!(
280-
((m2.as_pointer() as Ptr<Value<Vec<i32>>>)
256+
((m2.as_pointer() as Ptr<Vec<i32>>)
281257
.offset((i as usize))
282-
.upgrade()
283-
.deref()
284258
.as_pointer() as Ptr<i32>),
285259
(j as usize)
286260
)

0 commit comments

Comments
 (0)