@@ -12,39 +12,30 @@ thread_local!(
1212thread_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 , MoveCtor , Default ) ]
16+ #[ byte_size( 4 ) ]
1617pub struct Elem {
17- pub v : Value < i32 > ,
18+ #[ offset( 0 ) ]
19+ pub v : i32 ,
1820}
1921impl Elem {
20- pub fn new ( v : i32 ) -> Self {
21- let v: Value < i32 > = Rc :: new ( RefCell :: new ( v) ) ;
22- let __this: Value < Elem > = Rc :: new ( RefCell :: new ( Self {
23- v : Rc :: new ( RefCell :: new ( ( * v. borrow ( ) ) ) ) ,
24- } ) ) ;
25- let this: Ptr < Elem > = __this. as_pointer ( ) ;
26- Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
22+ pub fn new ( mut v : i32 ) -> Self {
23+ Self { v : v }
2724 }
2825 pub fn copy_from ( other : Ptr < Elem > ) -> Self {
29- let __this: Value < Elem > = Rc :: new ( RefCell :: new ( Self {
30- v : Rc :: new ( RefCell :: new (
31- ( ( * ( * other. upgrade ( ) . deref ( ) ) . v . borrow ( ) ) + 100 ) ,
32- ) ) ,
33- } ) ) ;
34- let this: Ptr < Elem > = __this. as_pointer ( ) ;
26+ let __this: Elem = Self {
27+ v : ( other. with ( |__s| __s. v ) + 100 ) ,
28+ } ;
3529 ( * copies_0. with ( Value :: clone) . borrow_mut ( ) ) . prefix_inc ( ) ;
36- Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
30+ __this
3731 }
3832 pub fn move_from ( other : Ptr < Elem > ) -> Self {
39- let __this: Value < Elem > = Rc :: new ( RefCell :: new ( Self {
40- v : Rc :: new ( RefCell :: new (
41- ( ( * ( * other. upgrade ( ) . deref ( ) ) . v . borrow ( ) ) + 1000 ) ,
42- ) ) ,
43- } ) ) ;
44- let this: Ptr < Elem > = __this. as_pointer ( ) ;
45- ( * ( * other. upgrade ( ) . deref ( ) ) . v . borrow_mut ( ) ) = -1_i32 ;
33+ let __this: Elem = Self {
34+ v : ( other. with ( |__s| __s. v ) + 1000 ) ,
35+ } ;
36+ field ! ( other, v) . write ( -1_i32 ) ;
4637 ( * moves_1. with ( Value :: clone) . borrow_mut ( ) ) . prefix_inc ( ) ;
47- Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
38+ __this
4839 }
4940}
5041impl Clone for Elem {
@@ -53,53 +44,20 @@ impl Clone for Elem {
5344 Elem :: copy_from ( __src. as_pointer ( ) )
5445 }
5546}
56- impl ByteRepr for Elem {
57- fn byte_size ( ) -> usize {
58- 4
59- }
60- fn to_bytes ( & self , buf : & mut [ u8 ] ) {
61- ( * self . v . borrow ( ) ) . to_bytes ( & mut buf[ 0 ..4 ] ) ;
62- }
63- fn from_bytes ( buf : & [ u8 ] ) -> Self {
64- Self {
65- v : Rc :: new ( RefCell :: new ( <i32 >:: from_bytes ( & buf[ 0 ..4 ] ) ) ) ,
66- }
67- }
68- }
69- #[ derive( VaArg , FnPtrArg , Default ) ]
47+ #[ derive( Clone , Record , ByteRepr , VaArg , FnPtrArg , Default ) ]
48+ #[ byte_size( 8 ) ]
7049pub struct Two {
71- pub a : Value < Elem > ,
72- pub b : Value < Elem > ,
73- }
74- impl Clone for Two {
75- fn clone ( & self ) -> Self {
76- let __this: Value < Two > = Rc :: new ( RefCell :: new ( Self {
77- a : Rc :: new ( RefCell :: new ( Elem :: copy_from ( { self . a . as_pointer ( ) } ) ) ) ,
78- b : Rc :: new ( RefCell :: new ( Elem :: copy_from ( { self . b . as_pointer ( ) } ) ) ) ,
79- } ) ) ;
80- let this: Ptr < Two > = __this. as_pointer ( ) ;
81- Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
82- }
83- }
84- impl ByteRepr for Two {
85- fn byte_size ( ) -> usize {
86- 8
87- }
88- fn to_bytes ( & self , buf : & mut [ u8 ] ) {
89- ( * self . a . borrow ( ) ) . to_bytes ( & mut buf[ 0 ..4 ] ) ;
90- ( * self . b . borrow ( ) ) . to_bytes ( & mut buf[ 4 ..8 ] ) ;
91- }
92- fn from_bytes ( buf : & [ u8 ] ) -> Self {
93- Self {
94- a : Rc :: new ( RefCell :: new ( <Elem >:: from_bytes ( & buf[ 0 ..4 ] ) ) ) ,
95- b : Rc :: new ( RefCell :: new ( <Elem >:: from_bytes ( & buf[ 4 ..8 ] ) ) ) ,
96- }
97- }
50+ #[ offset( 0 ) ]
51+ #[ byte_size( 4 ) ]
52+ pub a : Elem ,
53+ #[ offset( 4 ) ]
54+ #[ byte_size( 4 ) ]
55+ pub b : Elem ,
9856}
9957pub fn make_two_2 ( ) -> Two {
10058 return Two {
101- a : Rc :: new ( RefCell :: new ( Elem :: new ( { 1 } ) ) ) ,
102- b : Rc :: new ( RefCell :: new ( Elem :: new ( { 2 } ) ) ) ,
59+ a : Elem :: new ( { 1 } ) ,
60+ b : Elem :: new ( { 2 } ) ,
10361 } ;
10462}
10563pub fn main ( ) {
@@ -108,32 +66,32 @@ pub fn main() {
10866}
10967fn main_0 ( ) -> i32 {
11068 let t: Value < Two > = Rc :: new ( RefCell :: new ( Two {
111- a : Rc :: new ( RefCell :: new ( Elem :: new ( { 1 } ) ) ) ,
112- b : Rc :: new ( RefCell :: new ( Elem :: new ( { 2 } ) ) ) ,
69+ a : Elem :: new ( { 1 } ) ,
70+ b : Elem :: new ( { 2 } ) ,
11371 } ) ) ;
114- let base_copies: Value < i32 > = Rc :: new ( RefCell :: new ( copies_0. with ( |rc| * rc. borrow ( ) ) ) ) ;
115- let base_moves: Value < i32 > = Rc :: new ( RefCell :: new ( moves_1. with ( |rc| * rc. borrow ( ) ) ) ) ;
72+ let mut base_copies: i32 = copies_0. with ( |rc| * rc. borrow ( ) ) ;
73+ let mut base_moves: i32 = moves_1. with ( |rc| * rc. borrow ( ) ) ;
11674 let __decomp_3: Value < Two > = Rc :: new ( RefCell :: new ( ( * t. borrow ( ) ) . clone ( ) ) ) ;
117- assert ! ( ( copies_0. with( |rc| * rc. borrow( ) ) == ( ( * base_copies. borrow ( ) ) + 2 ) ) ) ;
118- assert ! ( ( moves_1. with( |rc| * rc. borrow( ) ) == ( * base_moves. borrow ( ) ) ) ) ;
119- assert ! ( ( ( * ( * ( * __decomp_3. borrow( ) ) . a. borrow ( ) ) . v . borrow ( ) ) == 101 ) ) ;
120- assert ! ( ( ( * ( * ( * __decomp_3. borrow( ) ) . b. borrow ( ) ) . v . borrow ( ) ) == 102 ) ) ;
75+ assert ! ( ( copies_0. with( |rc| * rc. borrow( ) ) == ( base_copies + 2 ) ) ) ;
76+ assert ! ( ( moves_1. with( |rc| * rc. borrow( ) ) == base_moves) ) ;
77+ assert ! ( ( { ( * __decomp_3. borrow( ) ) . a. v } == 101 ) ) ;
78+ assert ! ( ( { ( * __decomp_3. borrow( ) ) . b. v } == 102 ) ) ;
12179 let __decomp_4: Ptr < Two > = t. as_pointer ( ) ;
122- assert ! ( ( copies_0. with( |rc| * rc. borrow( ) ) == ( ( * base_copies. borrow ( ) ) + 2 ) ) ) ;
123- assert ! ( ( ( * ( * ( * __decomp_4. upgrade( ) . deref( ) ) . a. borrow ( ) ) . v . borrow ( ) ) == 1 ) ) ;
124- ( * ( * ( * __decomp_4. upgrade ( ) . deref ( ) ) . a . borrow ( ) ) . v . borrow_mut ( ) ) = 50 ;
125- assert ! ( ( ( * ( * ( * t. borrow( ) ) . a. borrow ( ) ) . v . borrow ( ) ) == 50 ) ) ;
80+ assert ! ( ( copies_0. with( |rc| * rc. borrow( ) ) == ( base_copies + 2 ) ) ) ;
81+ assert ! ( ( { ( * __decomp_4. upgrade( ) . deref( ) ) . a. v } == 1 ) ) ;
82+ field ! ( field! ( __decomp_4, a ) , v ) . write ( 50 ) ;
83+ assert ! ( ( { ( * t. borrow( ) ) . a. v } == 50 ) ) ;
12684 let __decomp_5: Value < Two > = Rc :: new ( RefCell :: new ( ( * t. borrow ( ) ) . clone ( ) ) ) ;
127- assert ! ( ( moves_1. with( |rc| * rc. borrow( ) ) == ( ( * base_moves. borrow ( ) ) + 2 ) ) ) ;
128- assert ! ( ( ( * ( * ( * __decomp_5. borrow( ) ) . a. borrow ( ) ) . v . borrow ( ) ) == 1050 ) ) ;
129- assert ! ( ( ( * ( * ( * __decomp_5. borrow( ) ) . b. borrow ( ) ) . v . borrow ( ) ) == 1002 ) ) ;
130- assert ! ( ( ( * ( * ( * t. borrow( ) ) . a. borrow ( ) ) . v . borrow ( ) ) == -1_i32 ) ) ;
131- let before_copies: Value < i32 > = Rc :: new ( RefCell :: new ( copies_0. with ( |rc| * rc. borrow ( ) ) ) ) ;
132- let before_moves: Value < i32 > = Rc :: new ( RefCell :: new ( moves_1. with ( |rc| * rc. borrow ( ) ) ) ) ;
85+ assert ! ( ( moves_1. with( |rc| * rc. borrow( ) ) == ( base_moves + 2 ) ) ) ;
86+ assert ! ( ( { ( * __decomp_5. borrow( ) ) . a. v } == 1050 ) ) ;
87+ assert ! ( ( { ( * __decomp_5. borrow( ) ) . b. v } == 1002 ) ) ;
88+ assert ! ( ( { ( * t. borrow( ) ) . a. v } == -1_i32 ) ) ;
89+ let mut before_copies: i32 = copies_0. with ( |rc| * rc. borrow ( ) ) ;
90+ let mut before_moves: i32 = moves_1. with ( |rc| * rc. borrow ( ) ) ;
13391 let __decomp_6: Value < Two > = Rc :: new ( RefCell :: new ( ( { make_two_2 ( ) } ) ) ) ;
134- assert ! ( ( copies_0. with( |rc| * rc. borrow( ) ) == ( * before_copies. borrow ( ) ) ) ) ;
135- assert ! ( ( moves_1. with( |rc| * rc. borrow( ) ) == ( * before_moves. borrow ( ) ) ) ) ;
136- assert ! ( ( ( * ( * ( * __decomp_6. borrow( ) ) . a. borrow ( ) ) . v . borrow ( ) ) == 1 ) ) ;
92+ assert ! ( ( copies_0. with( |rc| * rc. borrow( ) ) == before_copies) ) ;
93+ assert ! ( ( moves_1. with( |rc| * rc. borrow( ) ) == before_moves) ) ;
94+ assert ! ( ( { ( * __decomp_6. borrow( ) ) . a. v } == 1 ) ) ;
13795 let p: Value < ( Value < Elem > , Value < Elem > ) > = Rc :: new ( RefCell :: new ( (
13896 Rc :: new ( RefCell :: new (
13997 Elem :: new ( { 7 } ) . try_into ( ) . expect ( "failed conversion" ) ,
@@ -142,20 +100,16 @@ fn main_0() -> i32 {
142100 Elem :: new ( { 8 } ) . try_into ( ) . expect ( "failed conversion" ) ,
143101 ) ) ,
144102 ) ) ) ;
145- ( * before_copies. borrow_mut ( ) ) = copies_0. with ( |rc| * rc. borrow ( ) ) ;
103+ before_copies = copies_0. with ( |rc| * rc. borrow ( ) ) ;
146104 let __decomp_7: Value < ( Value < Elem > , Value < Elem > ) > = Rc :: new ( RefCell :: new ( (
147105 Rc :: new ( RefCell :: new ( ( * p. borrow ( ) ) . 0 . borrow ( ) . clone ( ) ) ) ,
148106 Rc :: new ( RefCell :: new ( ( * p. borrow ( ) ) . 1 . borrow ( ) . clone ( ) ) ) ,
149107 ) ) ) ;
150- let x: Ptr < Elem > = ( { get_8 ( ( __decomp_7. as_pointer ( ) ) . clone ( ) ) } ) ;
151- let y: Ptr < Elem > = ( { get_9 ( ( __decomp_7. as_pointer ( ) ) . clone ( ) ) } ) ;
152- assert ! ( ( copies_0. with( |rc| * rc. borrow( ) ) == ( ( * before_copies. borrow( ) ) + 2 ) ) ) ;
153- assert ! (
154- ( ( * ( * x. upgrade( ) . deref( ) ) . v. borrow( ) ) == ( ( * ( * ( * p. borrow( ) ) . 0 . borrow( ) ) . v. borrow( ) ) + 100 ) )
155- ) ;
156- assert ! (
157- ( ( * ( * y. upgrade( ) . deref( ) ) . v. borrow( ) ) == ( ( * ( * ( * p. borrow( ) ) . 1 . borrow( ) ) . v. borrow( ) ) + 100 ) )
158- ) ;
108+ let x: Ptr < Elem > = ( { get_8 ( __decomp_7. as_pointer ( ) ) } ) ;
109+ let y: Ptr < Elem > = ( { get_9 ( __decomp_7. as_pointer ( ) ) } ) ;
110+ assert ! ( ( copies_0. with( |rc| * rc. borrow( ) ) == ( before_copies + 2 ) ) ) ;
111+ assert ! ( ( { ( * x. upgrade( ) . deref( ) ) . v } == ( { ( * ( * p. borrow( ) ) . 0 . borrow( ) ) . v } + 100 ) ) ) ;
112+ assert ! ( ( { ( * y. upgrade( ) . deref( ) ) . v } == ( { ( * ( * p. borrow( ) ) . 1 . borrow( ) ) . v } + 100 ) ) ) ;
159113 return 0 ;
160114}
161115pub fn __cpp2rust_init_globals ( ) {
0 commit comments