Skip to content

Commit d5aa795

Browse files
committed
std: Add cfg(test) to UnsafeArc assertions
This is a ubiquitous type in concurrent code, and the assertions are causing significant code bloat for simple operations such as reading the pointer (injecting a failure point, etc). I am testing executable sizes with no I/O implementations (everything stubbed out to return nothing), and this took the size of a libnative executable from 328K to 207K (37% reduction in size), so I think that this is one assertion that's well worth configuring off for now.
1 parent f01a9a8 commit d5aa795

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/libstd/sync/arc.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ impl<T: Send> UnsafeArc<T> {
8080
#[inline]
8181
pub fn get(&self) -> *mut T {
8282
unsafe {
83-
assert!((*self.data).count.load(Relaxed) > 0);
83+
// FIXME(#12049): this needs some sort of debug assertion
84+
if cfg!(test) { assert!((*self.data).count.load(Relaxed) > 0); }
8485
return &mut (*self.data).data as *mut T;
8586
}
8687
}
@@ -90,7 +91,8 @@ impl<T: Send> UnsafeArc<T> {
9091
#[inline]
9192
pub fn get_immut(&self) -> *T {
9293
unsafe {
93-
assert!((*self.data).count.load(Relaxed) > 0);
94+
// FIXME(#12049): this needs some sort of debug assertion
95+
if cfg!(test) { assert!((*self.data).count.load(Relaxed) > 0); }
9496
return &(*self.data).data as *T;
9597
}
9698
}
@@ -109,7 +111,8 @@ impl<T: Send> Clone for UnsafeArc<T> {
109111
unsafe {
110112
// This barrier might be unnecessary, but I'm not sure...
111113
let old_count = (*self.data).count.fetch_add(1, Acquire);
112-
assert!(old_count >= 1);
114+
// FIXME(#12049): this needs some sort of debug assertion
115+
if cfg!(test) { assert!(old_count >= 1); }
113116
return UnsafeArc { data: self.data };
114117
}
115118
}
@@ -127,7 +130,8 @@ impl<T> Drop for UnsafeArc<T>{
127130
// Must be acquire+release, not just release, to make sure this
128131
// doesn't get reordered to after the unwrapper pointer load.
129132
let old_count = (*self.data).count.fetch_sub(1, SeqCst);
130-
assert!(old_count >= 1);
133+
// FIXME(#12049): this needs some sort of debug assertion
134+
if cfg!(test) { assert!(old_count >= 1); }
131135
if old_count == 1 {
132136
let _: ~ArcData<T> = cast::transmute(self.data);
133137
}

0 commit comments

Comments
 (0)