-
Notifications
You must be signed in to change notification settings - Fork 255
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
analyze: assign fresh PointerIds to Ref and AddressOf rvalues #1028
Conversation
… the receiver expr
…ef over Rewrite::AddrOf
// FIXME: The initializers for `r1` and `r2` are rewritten incorrectly. Neither `s` nor the | ||
// `r` field have `Cell` type, and an `&mut T -> &Cell<T>` rewrite is not applied. | ||
// XXXXX: let r1: &core::cell::Cell<(R)> = &((*s).r); | ||
let r1: *mut R = &mut (*s).r; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous rewrite of this code was already broken, so I figured it was okay that the new code also breaks here.
@@ -166,22 +168,41 @@ impl<'tcx> Visitor<'tcx> for ConvertVisitor<'tcx> { | |||
} | |||
}; | |||
|
|||
let expr_rws = take_prefix_while(&mut mir_rws, |x: &DistRewrite| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what invariant does this assume about the ordering of MIR rewrites? what if MirOriginDesc::Expr
is the second rewrite in the list, or they aren't all contiguous and a prefix of mir_rws
? A comment on this and why a prefix is the correct subsequence to grab would be helpful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment: 7c17a85
266e14d
to
60aa23e
Compare
Addressed all comments so far |
Given code like this:
Currently, we produce two
PointerId
s, one onp
and one onq
. The rvalue&mut (*p).field
has the samePointerId
asp
, on the assumption that it must always have the same permissions asp
itself.In the pointee analysis,
p
and&mut (*p).field
will usually have different pointee sets ({S}
and{i32}
respectively). But we'd like to usePointerId
s to identify pointers in the pointee analysis, rather than inventing a whole new labeling system. This requires thatp
and&mut (*p).field
have differentPointerId
s (though in the dataflow analysis, we will add a constraint relating their permissions, so that analysis will still produce identical results).Actually adding
PointerId
s for the necessary rvalues is fairly trivial (see b57fa64). The majority of this PR consists of rewriter improvements to let it handle the newPointerId
s. In particular, it can now apply rewrites to MIR code arising from expr adjustments. For example:This produces the following MIR:
MIR line 1 is the initialization of
arr
. Line 2 applies a borrow adjustment toarr
, line 3 applies an unsizing adjustment, and line 4 actually callsas_ptr
. The MIR code produced is as if the programmer had written(&arr as &[u8]).as_ptr()
rather thanarr.as_ptr()
. Previously, if therewrite::expr::mir_op
module tried to introduce rewrites on lines 2 or 3, it would result in an error; with this PR, those rewrites are correctly lifted to HIR (after materializing the adjustments so there is a place in the source code to apply those rewrites).