Skip to content

Provide slightly better notes when tracking a pointer tag #1945

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

Merged
merged 1 commit into from
Dec 21, 2021

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Dec 19, 2021

I slapped this in as a sort of advanced println-based debugging when trying to figure out a track-raw-pointers finding in smallvec. Perhaps this looks like a good idea to you all?

EDIT: User scenario

Run MIRIFLAGS=-Ztag-raw-pointers cargo miri test, get a diagnostic that looks like

error: Undefined Behavior: trying to reborrow for SharedReadOnly at alloc99465+0x9, but parent tag <265507> does not have an appropriate item in the borrow stack

So now run MIRIFLAGS=-Ztag-raw-pointers -Zmiri-track-pointer-tag=265507 cargo miri test
Old:

note: tracking was triggered
   --> src/lib.rs:822:36
    |
822 |                 vec: NonNull::from(self),
    |                                    ^^^^ popped tracked tag for item [SharedReadOnly for <265507>]

New:

note: tracking was triggered
   --> src/lib.rs:822:36
    |
822 |                 vec: NonNull::from(self),
    |                                    ^^^^ popped tracked tag for item [SharedReadOnly for <265507>] due to Write access for <265356>

So that if a user is now beginning to question their sanity because they don't really understand SB yet, they can then track the tag which caused the parent tag to be removed from the stack to be sure what's going on here:

   --> src/lib.rs:792:5
    |
792 | /     pub fn drain<R>(&mut self, range: R) -> Drain<'_, A>
793 | |     where
794 | |         R: RangeBounds<usize>,
795 | |     {
...   |
824 | |         }
825 | |     }
    | |_____^ created tag 265356

The existing diagnostic can tell you where the tag you'd need was invalidated, but it cannot tell you what and why that tag was invalidated.

@RalfJung
Copy link
Member

RalfJung commented Dec 20, 2021

What does the new output look like, compared to the old one? An example would be nice, to make it easier to evaluate the change.

@saethlin saethlin requested a review from RalfJung December 21, 2021 00:55
@saethlin saethlin force-pushed the better-sb-tracking branch 2 times, most recently from 28bf160 to b5b2526 Compare December 21, 2021 00:57
@saethlin
Copy link
Member Author

I've cleaned up the nomenclature a bit and elaborated on the user experience that made me want this in the opening comment.

@RalfJung
Copy link
Member

I've cleaned up the nomenclature a bit and elaborated on the user experience that made me want this in the opening comment.

Ah I see, this is a case where it's also not clear from the code whether this is a read or write access. (NonNull::from(&*self) would possibly avoid invalidating the tag, if I guessed the involved types correctly.)

@saethlin
Copy link
Member Author

Ah I see, this is a case where it's also not clear from the code whether this is a read or write access. (NonNull::from(&*self) would possibly avoid invalidating the tag, if I guessed the involved types correctly.)

Yup! I'm now understanding my own thinking a bit more: A lot of my use of Miri has been squinting at a diagnostic and trying to understand what exactly is causing there to be no borrow in the stack for a tag. The only way I could confirm my guess is by altering the code, and if Miri then passes, I just assume that my understanding was correct.

@saethlin saethlin requested a review from RalfJung December 21, 2021 17:16
@RalfJung
Copy link
Member

Looks good, thanks. :)
@bors r+

@bors
Copy link
Contributor

bors commented Dec 21, 2021

📌 Commit cd69219 has been approved by RalfJung

@bors
Copy link
Contributor

bors commented Dec 21, 2021

⌛ Testing commit cd69219 with merge 6f3061b...

@bors
Copy link
Contributor

bors commented Dec 21, 2021

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing 6f3061b to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants