-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Internal compiler error librustc/ty/layout.rs:1627:25 #50371
Comments
Thanks for reporting this issue! Can you post here the code that crashes the compiler? |
It is a larger project I cannot share yet, I tried to isolate the relevant code but failed. Can you tell me how to find out which files/types are causing this issue? That would help me create a reproducer. |
Repro I think: use std::ptr::write_volatile;
fn main() {
let mut a = Some(1usize);
unsafe {
write_volatile(&mut a, None);
}
} |
@kennytm Thank you, that is a reproducer. To further narrow down, code does work properly with
|
@eun-ice Thanks! I'm running a bisect between the two nightlies you linked, should be ready in a few minutes. |
It gets even weirder. The reproducer by @kennytm works fine with nightly-2018-04-18 but fails with current nightly. The following also fails with nightly-2018-04-18 and current nightly, but works fin with nightly-2018-02-17 So clearly the commit you isolated cannot be the only problem? use std::ptr::write_volatile;
enum Some {
A,
B,
}
trait FooTrait<T> {
fn get(&mut self) -> Option<T>;
}
struct FooStruct<T> {
some: Option<T>
}
impl<T> FooTrait<T> for FooStruct<T> {
fn get(&mut self) -> Option<T> {
self.some.take()
}
}
fn main() {
let foo: Box<FooTrait<Some>> = Box::new(FooStruct { some: Some(Some::A) });
let mut a = Some(foo);
unsafe {
write_volatile(&mut a, None);
}
} |
This is an actual bug, in the implementation of the |
Actually, I would rather say the bug is in the layout itself, should we have a field for the other part of the pair? |
Sorry, I do not have a meaningful answer to this, as I am just a humble Rust user. Maybe @pietroalbini @kennytm can chime in? On a side note: Is write_volatile/read_volatile even needed or can I just use write/read. I guard access to the memory cell using an atomic with Ordering::Acquire/Ordering::Release anyways? |
@eun-ice I've nominated this to be discussed at the next compiler team meeting (and they're way more experienced than me). Since this is a regression, we'll get this fixed before the 1.27 release ;) |
The implementation of @eun-ice AFAIK |
@eddyb thanks for your response. So if I guard pure memory access (no memmaps or anything) using an AtomicBool like this fn write(&self) {
if self.guard.compare_and_swap(false, true, Ordering::Acquire) == false {
ptr:write_volatile(...)
self.guard.store(false, Ordering::Release);
}
}
fn read(&self) {
if self.guard.compare_and_swap(false, true, Ordering::Acquire) == false {
ptr:read_volatile(...)
self.guard.store(false, Ordering::Release);
}
} Is ptr::read/ptr::write sufficient here or do I need ptr::read_volatile/ptr::write_volatile? From what I heard in theory the write_volatile makes sure the compiler does not reorder this instruction. Especially if the compiler chose to move the read/write after the Release it would be a problem. But I haven't found any documentation on how Rust does this (besides the hint that Rust does not yet have a defined memory model yet) |
@eun-ice I'm not well-versed in synchronization primitives, I just know |
@eun-ice You could use |
@eun-ice If the |
@Amanieu thank you for your comment. Do you think the compiler fence is needed to prevent Rust from ordering the read/write after the release of the guard? |
@eun-ice That's not necessary, the |
@Amanieu I am so grateful, thank you. |
triage: P-high This looks like a severe problem, @eddyb will fix. |
(@nox expressed interest in working on this) |
Fix volatile_store and nontemporal_store Fixes #50371.
I cannot isolate what exactly makes rustc crash, but I get an internal compiler error on Mac OSX and Linux.
The code compiles fine with an older nightly:
But it doesn't work with the current nightly:
The error is
The text was updated successfully, but these errors were encountered: