Skip to content

Commit 45f42b7

Browse files
committed
Make Gc::new() alloc untraceable by default
1 parent fffcbdc commit 45f42b7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

library/alloc/src/gc.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,17 @@ struct GcBox<T: ?Sized>(ManuallyDrop<T>);
222222
impl<T> GcBox<T> {
223223
fn new(value: T) -> *mut GcBox<T> {
224224
let layout = Layout::new::<T>();
225+
226+
#[cfg(bootstrap)]
225227
let ptr = ALLOCATOR.allocate(layout).unwrap().as_ptr() as *mut GcBox<T>;
228+
229+
#[cfg(not(bootstrap))]
230+
let ptr = if core::gc::needs_tracing::<T>() {
231+
ALLOCATOR.allocate(layout).unwrap().as_ptr()
232+
} else {
233+
ALLOCATOR.alloc_untraceable(layout).unwrap().as_ptr()
234+
} as *mut GcBox<T>;
235+
226236
let gcbox = GcBox(ManuallyDrop::new(value));
227237

228238
unsafe {

0 commit comments

Comments
 (0)