@@ -12,39 +12,42 @@ 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 , Default ) ]
16+ #[ byte_size( 8 ) ]
1617pub 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}
2023impl 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 ) ]
7766pub 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}
8174impl 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}
143119pub 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 }
0 commit comments