File tree Expand file tree Collapse file tree 4 files changed +10
-6
lines changed
starlark/src/values/layout Expand file tree Collapse file tree 4 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -163,11 +163,12 @@ pub(crate) trait AValue<'v>: StarlarkValueDyn<'v> + Sized {
163
163
Self :: offset_of_extra( ) % mem:: align_of:: <Self :: ExtraElem >( ) == 0 ,
164
164
"extra must be aligned"
165
165
) ;
166
- cmp:: max (
166
+ let size = cmp:: max (
167
167
mem:: size_of :: < Self :: StarlarkValue > ( ) ,
168
168
// Content is not necessarily aligned to end of `A`.
169
169
Self :: offset_of_extra ( ) + ( mem:: size_of :: < Self :: ExtraElem > ( ) * extra_len) ,
170
- )
170
+ ) ;
171
+ AValueHeader :: align_up ( size)
171
172
}
172
173
173
174
unsafe fn heap_freeze (
Original file line number Diff line number Diff line change @@ -132,8 +132,6 @@ impl<'c> Iterator for ChunkIter<'c> {
132
132
let or_forward = & * ( self . chunk . as_ptr ( ) as * const AValueOrForward ) ;
133
133
let n = or_forward. alloc_size ( ) ;
134
134
debug_assert ! ( n <= self . chunk. len( ) ) ;
135
- let n = AValueHeader :: align_up ( n) ;
136
- let n = cmp:: min ( n, self . chunk . len ( ) ) ;
137
135
self . chunk = self . chunk . split_at ( n) . 1 ;
138
136
Some ( or_forward)
139
137
}
@@ -174,6 +172,7 @@ impl Arena {
174
172
mem:: size_of :: < AValueHeader > ( ) + T :: memory_size_for_extra_len ( extra_len) ,
175
173
MIN_ALLOC ,
176
174
) ;
175
+ debug_assert ! ( size % AValueHeader :: ALIGN == 0 ) ;
177
176
let layout = Layout :: from_size_align ( size, mem:: align_of :: < AValueHeader > ( ) ) . unwrap ( ) ;
178
177
let p = bump. alloc_layout ( layout) . as_ptr ( ) ;
179
178
unsafe {
Original file line number Diff line number Diff line change @@ -179,7 +179,9 @@ impl AValueOrForward {
179
179
}
180
180
} ;
181
181
let n = mem:: size_of :: < AValueHeader > ( ) + n;
182
- cmp:: max ( n, MIN_ALLOC )
182
+ let size = cmp:: max ( n, MIN_ALLOC ) ;
183
+ debug_assert ! ( size % AValueHeader :: ALIGN == 0 ) ;
184
+ size
183
185
}
184
186
}
185
187
Original file line number Diff line number Diff line change @@ -223,7 +223,9 @@ pub(crate) struct AValueDyn<'v> {
223
223
impl < ' v > AValueDyn < ' v > {
224
224
#[ inline]
225
225
pub ( crate ) fn memory_size ( self ) -> usize {
226
- ( self . vtable . memory_size ) ( self . value as * const ( ) )
226
+ let size = ( self . vtable . memory_size ) ( self . value as * const ( ) ) ;
227
+ debug_assert ! ( size % AValueHeader :: ALIGN == 0 ) ;
228
+ size
227
229
}
228
230
229
231
pub ( crate ) fn total_memory ( self ) -> usize {
You can’t perform that action at this time.
0 commit comments