Skip to content

Commit b01cb10

Browse files
committed
Update tests
1 parent 495291b commit b01cb10

2 files changed

Lines changed: 241 additions & 9 deletions

File tree

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

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,37 @@ pub fn operator_lt_1(a: Ptr<Tracked>, b: Ptr<Tracked>) -> bool {
6464
pub fn greater_2(a: Ptr<Tracked>, b: Ptr<Tracked>) -> bool {
6565
return ({ a.with(|__s| __s.v) } > { b.with(|__s| __s.v) });
6666
}
67+
#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, MoveAssign, Default)]
68+
#[cpp_from(i32, new, value)]
69+
#[byte_size(4)]
70+
pub struct MoveOnly {
71+
#[offset(0)]
72+
pub v: i32,
73+
}
74+
impl MoveOnly {
75+
pub fn new(mut v: i32) -> Self {
76+
Self { v: v }
77+
}
78+
pub fn move_from(_a0: Ptr<MoveOnly>) -> Self {
79+
Self {
80+
v: { (*_a0.upgrade().deref()).v },
81+
}
82+
}
83+
}
84+
impl CppLess for MoveOnly {
85+
fn less(__lhs: &Ptr<Self>, __rhs: &Ptr<Self>) -> bool {
86+
operator_lt_3(__lhs.clone(), __rhs.clone())
87+
}
88+
}
89+
impl CppEq for MoveOnly {
90+
fn equal(__lhs: &Ptr<Self>, __rhs: &Ptr<Self>) -> bool {
91+
!(operator_lt_3(__lhs.clone(), __rhs.clone()))
92+
&& !(operator_lt_3(__rhs.clone(), __lhs.clone()))
93+
}
94+
}
95+
pub fn operator_lt_3(a: Ptr<MoveOnly>, b: Ptr<MoveOnly>) -> bool {
96+
return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) });
97+
}
6798
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)]
6899
#[byte_size(24)]
69100
pub struct Bag {
@@ -80,18 +111,18 @@ impl Bag {
80111
}
81112
impl CppLess for Bag {
82113
fn less(__lhs: &Ptr<Self>, __rhs: &Ptr<Self>) -> bool {
83-
operator_lt_3(__lhs.clone(), __rhs.clone())
114+
operator_lt_4(__lhs.clone(), __rhs.clone())
84115
}
85116
}
86117
impl CppEq for Bag {
87118
fn equal(__lhs: &Ptr<Self>, __rhs: &Ptr<Self>) -> bool {
88-
operator_eq_4(__lhs.clone(), __rhs.clone())
119+
operator_eq_5(__lhs.clone(), __rhs.clone())
89120
}
90121
}
91-
pub fn operator_lt_3(a: Ptr<Bag>, b: Ptr<Bag>) -> bool {
122+
pub fn operator_lt_4(a: Ptr<Bag>, b: Ptr<Bag>) -> bool {
92123
return ({ (*a.upgrade().deref()).items.len() } < { (*b.upgrade().deref()).items.len() });
93124
}
94-
pub fn operator_eq_4(a: Ptr<Bag>, b: Ptr<Bag>) -> bool {
125+
pub fn operator_eq_5(a: Ptr<Bag>, b: Ptr<Bag>) -> bool {
95126
return ({ (*a.upgrade().deref()).items.len() } == { (*b.upgrade().deref()).items.len() });
96127
}
97128
pub fn main() {
@@ -390,6 +421,73 @@ fn main_0() -> i32 {
390421
.with(|__m: &Map<Bag, (Value<Bag>, Value<i32>)>| __m.end())
391422
);
392423
assert!((copies_0.with(|rc| *rc.borrow()) == 0));
424+
let moves: Value<Vec<MoveOnly>> = Rc::new(RefCell::new(Vec::new()));
425+
{
426+
let __init = MoveOnly::new({ 3 });
427+
(*moves.borrow_mut()).push(__init)
428+
};
429+
{
430+
let __init = MoveOnly::new({ 1 });
431+
(*moves.borrow_mut()).push(__init)
432+
};
433+
{
434+
let __init = MoveOnly::new({ 2 });
435+
(*moves.borrow_mut()).push(__init)
436+
};
437+
match ({ moves.decay().begin() },) {
438+
(mut __tmp_11,) => {
439+
let __n = moves.decay().end().iter_distance(&__tmp_11);
440+
let mut __order: Vec<isize> = (0..__n).collect();
441+
__order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_11.iter_at(__x), &__tmp_11.iter_at(__y)));
442+
reorder(__order, |__i| __tmp_11.iter_at(__i));
443+
}
444+
};
445+
assert!(
446+
({
447+
(({ (*moves.borrow())[0_usize].v } == 1) && ({ (*moves.borrow())[1_usize].v } == 2))
448+
&& ({ (*moves.borrow())[2_usize].v } == 3)
449+
})
450+
);
451+
match ({ moves.decay().begin() },) {
452+
(mut __tmp_12,) => {
453+
let __n = moves.decay().end().iter_distance(&__tmp_12);
454+
let mut __order: Vec<isize> = (0..__n).collect();
455+
__order.sort_by(|&__x, &__y| {
456+
let __a = __tmp_12.iter_at(__x);
457+
let __b = __tmp_12.iter_at(__y);
458+
if FnPtr::<fn(Ptr<MoveOnly>, Ptr<MoveOnly>) -> bool>::new(
459+
|a: Ptr<MoveOnly>, b: Ptr<MoveOnly>| -> bool {
460+
{
461+
return ({ a.with(|__s| __s.v) } > { b.with(|__s| __s.v) });
462+
}
463+
},
464+
)
465+
.call(__a.clone(), __b.clone())
466+
{
467+
std::cmp::Ordering::Less
468+
} else if FnPtr::<fn(Ptr<MoveOnly>, Ptr<MoveOnly>) -> bool>::new(
469+
|a: Ptr<MoveOnly>, b: Ptr<MoveOnly>| -> bool {
470+
{
471+
return ({ a.with(|__s| __s.v) } > { b.with(|__s| __s.v) });
472+
}
473+
},
474+
)
475+
.call(__b, __a)
476+
{
477+
std::cmp::Ordering::Greater
478+
} else {
479+
std::cmp::Ordering::Equal
480+
}
481+
});
482+
reorder(__order, |__i| __tmp_12.iter_at(__i));
483+
}
484+
};
485+
assert!(
486+
({
487+
(({ (*moves.borrow())[0_usize].v } == 3) && ({ (*moves.borrow())[1_usize].v } == 2))
488+
&& ({ (*moves.borrow())[2_usize].v } == 1)
489+
})
490+
);
393491
return copies_0.with(|rc| *rc.borrow());
394492
}
395493
pub trait BagImpl {
@@ -406,6 +504,15 @@ impl BagImpl for Ptr<Bag> {
406504
return (*self).clone();
407505
}
408506
}
507+
pub trait MoveOnlyImpl {
508+
fn move_assign(&self, _a0: Ptr<MoveOnly>) -> Ptr<MoveOnly>;
509+
}
510+
impl MoveOnlyImpl for Ptr<MoveOnly> {
511+
fn move_assign(&self, _a0: Ptr<MoveOnly>) -> Ptr<MoveOnly> {
512+
field!((*self), v).write({ { (*_a0.upgrade().deref()).v } });
513+
return (*self).clone();
514+
}
515+
}
409516
pub trait TrackedImpl {
410517
fn copy_assign(&self, o: Ptr<Tracked>) -> Ptr<Tracked>;
411518
fn move_assign(&self, o: Ptr<Tracked>) -> Ptr<Tracked>;

‎tests/unit/out/unsafe/sort_no_copy.rs‎

Lines changed: 130 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,56 @@ pub unsafe fn greater_2(a: *const Tracked, b: *const Tracked) -> bool {
8585
return (((*a).v) > ((*b).v));
8686
}
8787
#[repr(C)]
88+
#[derive(FnPtrArg, MoveCtorUnsafe, CppFromUnsafe, MoveAssignUnsafe, Default)]
89+
#[cpp_from(i32, new, value)]
90+
pub struct MoveOnly {
91+
pub v: i32,
92+
}
93+
impl MoveOnly {
94+
pub unsafe fn new(mut v: i32) -> Self {
95+
let mut this = Self { v: v };
96+
this
97+
}
98+
pub unsafe fn move_from(_a0: *mut MoveOnly) -> Self {
99+
let mut this = Self { v: (*_a0).v };
100+
this
101+
}
102+
pub unsafe fn move_assign(&mut self, _a0: *mut MoveOnly) -> *mut MoveOnly {
103+
self.v = (*_a0).v;
104+
return &mut (*(self as *mut MoveOnly));
105+
}
106+
}
107+
impl std::cmp::Ord for MoveOnly {
108+
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
109+
unsafe {
110+
if operator_lt_3(self as *const MoveOnly, other as *const MoveOnly) {
111+
std::cmp::Ordering::Less
112+
} else if operator_lt_3(other as *const MoveOnly, self as *const MoveOnly) {
113+
std::cmp::Ordering::Greater
114+
} else {
115+
std::cmp::Ordering::Equal
116+
}
117+
}
118+
}
119+
}
120+
impl std::cmp::PartialOrd for MoveOnly {
121+
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
122+
Some(self.cmp(other))
123+
}
124+
}
125+
impl std::cmp::PartialEq for MoveOnly {
126+
fn eq(&self, other: &Self) -> bool {
127+
unsafe {
128+
!(operator_lt_3(self as *const MoveOnly, other as *const MoveOnly))
129+
&& !(operator_lt_3(other as *const MoveOnly, self as *const MoveOnly))
130+
}
131+
}
132+
}
133+
impl std::cmp::Eq for MoveOnly {}
134+
pub unsafe fn operator_lt_3(a: *const MoveOnly, b: *const MoveOnly) -> bool {
135+
return (((*a).v) < ((*b).v));
136+
}
137+
#[repr(C)]
88138
#[derive(Clone, VaArg, FnPtrArg, MoveCtorUnsafe, MoveAssignUnsafe, Default)]
89139
pub struct Bag {
90140
pub items: Vec<Tracked>,
@@ -107,9 +157,9 @@ impl Bag {
107157
impl std::cmp::Ord for Bag {
108158
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
109159
unsafe {
110-
if operator_lt_3(self as *const Bag, other as *const Bag) {
160+
if operator_lt_4(self as *const Bag, other as *const Bag) {
111161
std::cmp::Ordering::Less
112-
} else if operator_lt_3(other as *const Bag, self as *const Bag) {
162+
} else if operator_lt_4(other as *const Bag, self as *const Bag) {
113163
std::cmp::Ordering::Greater
114164
} else {
115165
std::cmp::Ordering::Equal
@@ -124,14 +174,14 @@ impl std::cmp::PartialOrd for Bag {
124174
}
125175
impl std::cmp::PartialEq for Bag {
126176
fn eq(&self, other: &Self) -> bool {
127-
unsafe { operator_eq_4(self as *const Bag, other as *const Bag) }
177+
unsafe { operator_eq_5(self as *const Bag, other as *const Bag) }
128178
}
129179
}
130180
impl std::cmp::Eq for Bag {}
131-
pub unsafe fn operator_lt_3(a: *const Bag, b: *const Bag) -> bool {
181+
pub unsafe fn operator_lt_4(a: *const Bag, b: *const Bag) -> bool {
132182
return (((*a).items.len()) < ((*b).items.len()));
133183
}
134-
pub unsafe fn operator_eq_4(a: *const Bag, b: *const Bag) -> bool {
184+
pub unsafe fn operator_eq_5(a: *const Bag, b: *const Bag) -> bool {
135185
return (((*a).items.len()) == ((*b).items.len()));
136186
}
137187
pub fn main() {
@@ -437,6 +487,81 @@ unsafe fn main_0() -> i32 {
437487
assert!((((*bag_map.find(&bags[(2) as usize]).iter_deref()).1) == (2)));
438488
assert!(bag_map.find(&bags[(1) as usize]) == bag_map.end());
439489
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0)));
490+
let mut moves: Vec<MoveOnly> = Vec::new();
491+
{
492+
let __init = MoveOnly::new({ 3 });
493+
moves.push(__init)
494+
};
495+
{
496+
let __init = MoveOnly::new({ 1 });
497+
moves.push(__init)
498+
};
499+
{
500+
let __init = MoveOnly::new({ 2 });
501+
moves.push(__init)
502+
};
503+
match ({ moves.begin() },) {
504+
(mut __tmp_11,) => {
505+
let __n = moves.end().iter_distance(&__tmp_11);
506+
let mut __order: Vec<isize> = (0..__n).collect();
507+
__order.sort_by(|&__x, &__y| (*__tmp_11.iter_at(__x)).cmp(&*__tmp_11.iter_at(__y)));
508+
let __values: Vec<_> = __order
509+
.iter()
510+
.map(|&__i| std::ptr::read(__tmp_11.iter_at(__i)))
511+
.collect();
512+
for (__i, __v) in (0..__n).zip(__values) {
513+
std::ptr::write(__tmp_11.iter_at(__i), __v);
514+
}
515+
}
516+
};
517+
assert!(
518+
(((moves[(0_usize)].v) == (1)) && ((moves[(1_usize)].v) == (2)))
519+
&& ((moves[(2_usize)].v) == (3))
520+
);
521+
match ({ moves.begin() },) {
522+
(mut __tmp_12,) => {
523+
let __n = moves.end().iter_distance(&__tmp_12);
524+
let mut __order: Vec<isize> = (0..__n).collect();
525+
__order.sort_by(|&__x, &__y| {
526+
let __a = __tmp_12.iter_at(__x) as *const _;
527+
let __b = __tmp_12.iter_at(__y) as *const _;
528+
if FnPtr::<fn(*const MoveOnly, *const MoveOnly) -> bool>::new(
529+
|a: *const MoveOnly, b: *const MoveOnly| -> bool {
530+
unsafe {
531+
return (((*a).v) > ((*b).v));
532+
}
533+
},
534+
)
535+
.call(__a, __b)
536+
{
537+
std::cmp::Ordering::Less
538+
} else if FnPtr::<fn(*const MoveOnly, *const MoveOnly) -> bool>::new(
539+
|a: *const MoveOnly, b: *const MoveOnly| -> bool {
540+
unsafe {
541+
return (((*a).v) > ((*b).v));
542+
}
543+
},
544+
)
545+
.call(__b, __a)
546+
{
547+
std::cmp::Ordering::Greater
548+
} else {
549+
std::cmp::Ordering::Equal
550+
}
551+
});
552+
let __values: Vec<_> = __order
553+
.iter()
554+
.map(|&__i| std::ptr::read(__tmp_12.iter_at(__i)))
555+
.collect();
556+
for (__i, __v) in (0..__n).zip(__values) {
557+
std::ptr::write(__tmp_12.iter_at(__i), __v);
558+
}
559+
}
560+
};
561+
assert!(
562+
(((moves[(0_usize)].v) == (3)) && ((moves[(1_usize)].v) == (2)))
563+
&& ((moves[(2_usize)].v) == (1))
564+
);
440565
return (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0));
441566
}
442567
pub unsafe fn __cpp2rust_init_globals() {

0 commit comments

Comments
 (0)