-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Large array literal causes slow compilation #37155
Comments
You can absolutely transmute if you use an #![feature(const_fn, integer_atomics)]
use std::cell::UnsafeCell;
use std::sync::atomic::AtomicU64;
pub struct SyncCell<T>(UnsafeCell<T>);
unsafe impl<T: Sync> Sync for SyncCell<T> {}
static XYZ: SyncCell<[u64; 1024*512]> =
SyncCell(UnsafeCell::new([0; 1024*512]));
pub fn get_xyz() -> &'static [AtomicU64; 1024*512] {
unsafe {&*(XYZ.0.get() as *mut _)}
}
fn main() {} |
That's much better, thanks! I'll leave the issue open for now, since this indicates a bottleneck in translation, but it's no longer an immediate problem. |
https://gist.github.com/Mark-Simulacrum/a83196ed84920c37804654ec39a7ebe9 is the full time-passes log from today, with the relevant passes:
|
See #52868 (comment) for a quick test case demonstrating that compile time scales quadratically with array size. |
Triage: Still reproduces with nightly-2023-11-17 using the following reproducer taken from #58523. pub fn main() {
let mut _buf = vec![0u8; 1 << 32];
(&[0u8; (1 << 32) - 8]);
} |
I have a large array of the form
where
LARGE_NUMBER = 512 * 1024
.ATOMIC_U64_INIT
is notCopy
, so it's not obvious how to express this differently. I don't even think I even legally can use a[u64; LARGE_NUMBER]
and transmute on use becauseu64
has aliasing guarantees thatAtomicU64
breaks.This ends up adding more than 10s to my compile times.
time-passes
, filtering out passes that take <0.1s above their baseline, showsThere's a full version available elsewhere, but it's not really more interesting.
The text was updated successfully, but these errors were encountered: