Open pandaman64 opened 3 years ago
I believe this is https://github.com/rust-lang/unsafe-code-guidelines/issues/134 / https://github.com/rust-lang/unsafe-code-guidelines/issues/256 / https://github.com/rust-lang/unsafe-code-guidelines/issues/276.
The short version is that ThinArc
stores and works with *mut ArcInner<HeaderSlice<H, [T; 0]>>
but uses it as *mut ArcInner<HeaderSlice<H, [T; {length}]>>
. This might be fixable with some judicious use of ptr::addr_of_mut!
, or it might require more type erasure a la https://lib.rs/crates/erasable.
Taking a glance at the code, though, there are definitely a number of places that need to use ptr::addr_of_mut!
to avoid creating references to uninitialized memory, though; I'll run through and do some first-pass cleanup today or tomorrow.
EDIT: the only computer I have access to at the moment can't run cargo miri
because of this issue 😢
I got another Stacked Borrows violation with GreenNodeBuilder::finish_node
.
Minimal reproduction:
use rowan::{GreenNodeBuilder, SyntaxKind};
fn main() {
let mut builder = GreenNodeBuilder::new();
builder.start_node(SyntaxKind(0));
builder.token(SyntaxKind(1), "foo");
builder.finish_node(); // added this line
}
In this case, the UB occurs inside <HeaderSlice<H, [T; 0]> as Deref>::deref
, which seems to be very relevant to the concern raised in CAD97's comment.
As far as I understand, self: &HeaderSlice<H, [T; 0]>
gives us SharedReadOnly
only for the header part, and we are forging a reference for the entire slice from it.
Yikes, this reliance on &Header
fattening goes deeper than I thought. General temperature is that we would like to allow this pattern (and likely might need to in order to support extern type
), as it's been independently rewritten multiple times and is something people expect to work.
There are two approaches I see towards getting rowan to work under miri again:
GreenNodeData
) and use raw pointers instead (and/or custom handles wrapping raw pointers), or
Hi! I got UB when running Miri with raw pointer tracking enabled (
-Zmiri-track-raw-pointers
) against the invocation ofGreenNodeBuilder::token
. The UB is not reported when running Miri without raw pointer tracking. To reproduce the UB, run the following function withMIRIFLAGS='-Zmiri-track-raw-pointers' cargo +nightly miri run
.Here is the backtrace:
It looks like Miri is not satisfied with
ThinArc
construction.