-
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
Boxes with custom allocators break several underlying assumptions in Miri (and MIR more broadly) #95453
Comments
Thanks for the report! Something went very wrong a bit before this error occurred... a ScalarPair value should never have Scalar layout. |
smaller repro from glacier: #![feature(allocator_api)]
fn main() {
Box::new_in(&[0, 1], &std::alloc::Global);
} |
@matthiaskrgr Indeed, I get a similar error when I run that code under Miri:
This is with the latest nightly:
But that ICE is marked as fixed. Should this be closed as a duplicate and #78459 reopened? |
#78459 was fixed by doing something in the codegen backend, this here is about the interpreter. It think it is a separate, albeit related, problem. |
I see, that explains why it wasn't caught as a regression. |
I suspect this has something to do with dereferencing a Honestly that sounds like a pretty bad way to encode this all. The way allocators were added to Cc @rust-lang/wg-mir-opt (there is no WG-MIR I think?) @rust-lang/wg-allocators |
Here's a way to cause even more fun ICEs in Miri, by making And indeed, we have
|
" The proper fix-for-all-time is to stop making How practical that is in the short/medium term, though, is a different question. However, it's probably required to let |
I got things to work for the example, and for a nasty variant of the example that makes As you can see, various random places throughout the interpreter need to be aware of this -- the hallmark of non-compositional design. Stacked Borrows will ignore such Boxes (so if they are Also, this does not entirely fix the problem; this example still ICEs because the casting and unsizing code assumes that it will only be called with regular pointer types. I've run out of steam for fixing that; it would probably require special treatment around here. There are probably more places I missed, it is very hard to be sure since this is breaking some very fundamental assumptions. |
Yeah, I don't have a good alternative idea either. Borrow checking works on MIR and needs to treat these things as primitive pointers. We could have a MIR transformation run after borrowck to remove Having primitive types that are also generic and contain arbitrary user-defined data, however, is clearly also bad. Having |
Cc @bjorn3 since I didn't see cranelift handle this (but I might have missed it). |
I have already mostly fixed it on the cg_clif side. I was made aware of these changes because some rustc tests started to fail. Thanks for the ping anyway. |
cc @drmeepster who I think is fixing this in a way that will solve it for all backends in #95576 |
When I next update that PR, I'll test this issue to make sure it's resolved. However, even that is still just a hacky solution. After it merges, I'm going to try to remove Box derefs from the MIR too, and in a general way that can be built on to implement DerefMove in the future. |
I'm really happy to see progress on this! (both #95576 and any plans for some kind of I remember removing the special-casing of In fact, looking back at fa67abd, that allowed to refer to |
@drmeepster that's amazing. :-) |
I think using the same type #95576 helps, but Miri handles |
That there are issues remaining is also shown by the fact that #98510 fails -- we still are deref'ing |
I aggressively agree with the point here, but there's something important left unspecified here: Is it the compiler-understood primitive Obviously |
It cannot be Maybe it should be So maybe it is a new type "between" Box and Unique? I am not sure. |
While this is a great idea and would fix the unsizing issue, it wouldn't solve the failures in #98510. The ICE there comes from validity checking code which needs to be special cased for box anyway to give good diagnostics. |
Actually I think we can easily solve the unsizing issue by implementing |
I think validity checking only needs to special-case the "inner" |
With rust-lang/miri#2323, the relevant testcase should pass in Miri. However, this still requires some gross hacks so we should keep an issue open to track finding a proper solution for this. |
Turns out yes we (used to) add |
…ler-errors interpret, codegen: tweak some comments and checks regarding Box with custom allocator Cc rust-lang#95453
Rollup merge of rust-lang#129812 - RalfJung:box-custom-alloc, r=compiler-errors interpret, codegen: tweak some comments and checks regarding Box with custom allocator Cc rust-lang#95453
interpret, codegen: tweak some comments and checks regarding Box with custom allocator Cc rust-lang/rust#95453
interpret, codegen: tweak some comments and checks regarding Box with custom allocator Cc rust-lang/rust#95453
@RalfJung . Some notes.
|
We won't remove all special casing for Box anytime soon. That doesn't mean we can't remove some of the more surprising special cases like the validity invariant not allowing aliasing. |
This error got turned into a general design issue for
Box
as a language primitive vsBox
having an 'allocator' field. See original bug report below. Also see a further testcase at rust-lang/miri#2072.This is minimized from an error I ran into while implementing the
Allocator
API in my crate, bump-into, and trying to test the implementation with Miri:Code
Meta
rustc --version --verbose
:Error output
Backtrace
The text was updated successfully, but these errors were encountered: