-
Notifications
You must be signed in to change notification settings - Fork 64
Stacked Borrows: How precise should UnsafeCell be tracked? #236
Copy link
Copy link
Open
Labels
A-SB-vs-TBTopic: Design questions where SB and TB are opposite sides of the design axisTopic: Design questions where SB and TB are opposite sides of the design axisA-aliasing-modelTopic: Related to the aliasing model (e.g. Stacked/Tree Borrows)Topic: Related to the aliasing model (e.g. Stacked/Tree Borrows)C-open-questionCategory: An open question that we should revisitCategory: An open question that we should revisitS-pending-designStatus: Resolving this issue requires addressing some open design questionsStatus: Resolving this issue requires addressing some open design questions
Metadata
Metadata
Assignees
Labels
A-SB-vs-TBTopic: Design questions where SB and TB are opposite sides of the design axisTopic: Design questions where SB and TB are opposite sides of the design axisA-aliasing-modelTopic: Related to the aliasing model (e.g. Stacked/Tree Borrows)Topic: Related to the aliasing model (e.g. Stacked/Tree Borrows)C-open-questionCategory: An open question that we should revisitCategory: An open question that we should revisitS-pending-designStatus: Resolving this issue requires addressing some open design questionsStatus: Resolving this issue requires addressing some open design questions
Type
Fields
Give feedbackNo fields configured for issues without a type.
Currently, when looking for
UnsafeCellbehind shared references, Miri descends through arrays, structs and the like, but does not descend throughenums. Instead, when it sees anenum, it checks ifT: Freeze, and if not, treats the entireenumas anUnsafeCell.The benefit of this is that finding
UnsafeCelldoes not require reading from memory (rust-lang/miri#931), which makes formal reasoning about Stacked Borrows a lot simpler. Accessing memory duringUnsafeCellsearch opens all sorts of nasty questions, such as whether those accesses are themselves subject to Stacked Borrows rules or not (and if yes, which tag they use). Not reading enum discriminants also avoids potential confusion from Stacked Borrows partially checking the validity invariant of the referenced data.On the other hand, being more precise with
UnsafeCellsearch could help optimizations. When a function works on&Result<Cell<i32>, i32>, and the compiler somehow can know that theErrvariant is active, we would be able to rely on this shared reference being read-only -- currently, that is not an assumption that the compiler can make. (But note that once a shared reference gets created to thei32in theErrvariant, that is already guaranteed to be read-only.)This is somewhat related to #204.
Some posts with useful datapoints (not exhaustive):
Other parts of this question:
T?UnsafeCellinsidePhantomDatahave any effect?