-
Notifications
You must be signed in to change notification settings - Fork 254
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: add pointee_type analysis #1029
Conversation
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] | ||
pub enum CTy<'tcx> { | ||
Ty(LTy<'tcx>), | ||
/// An inference variable. Note that inference variables are scoped to the local function; |
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 is an inference variable?
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.
is it the state of some variable before its equivalence to a type is determined?
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.
It's a unification variable as used in type inference.
|
||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] | ||
pub enum Constraint<'tcx> { | ||
/// The set of types for pointer `.0` must contain type `.1`. This is used for "uses" of a |
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's the notation .N
?
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.
Referring to the anonymous fields of this enum variant, similar to field access in tuples and tuple structs (e.g. let foo = (1, 2); return foo.0;
)
AllTypesCompatible(PointerId), | ||
|
||
/// The set of types for pointer `.0` must be a subset of the set of types for pointer `.1`. | ||
/// This is used for pointer assignments like `p = q`, among other things. |
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.
I know it's apparent to those with dataflow familiarity but I think it's worth equating .0
and q
and .1
and p
in the documentation somehow
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.
Adjusted comment: 763e88f
is this doing equality saturation? it looks very familiar to the approach |
self.visit_place(pl); | ||
} | ||
Rvalue::Aggregate(_, ref ops) => { | ||
// TODO |
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.
make TODO more specfic please, i'm not sure what's left to be done
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.
Made these a little more specific: 5f1a2a1
It's a little difficult for me to review this for correctness, especially given there are no tests. How can I be most useful to you here as a reviewer? One of my concerns is that it's all hand-made with no reference to a standard equivalence constraint solving algorithm. We do this in a few places and it seems repetitious and error-prone; please tell me if my concerns are overblown. |
2ab998c
to
faeed96
Compare
This branch adds an analysis that computes a set of possible pointee types for each pointer. It includes only the analysis; the analysis results aren't used to drive any rewriting yet. On
algo_md5
, the analysis correctly identifies that the_input
argument toMD5_Update
should actually point tou8
s, that thememset
inli_MD5Transform
operates onu32
s, and that thememset
inMD5_Final
operates on anMD5_CTX
.The next step after this will be to use the analysis results in rewriting. We need to rewrite pointer types to use the inferred pointees (such as changing
_input: &c_void
to_input: &[u8]
), replacememcpy
andmemset
with safe operations, and (optionally) delete casts that are now no-ops (such asinput = _input as *const c_uchar
, onceinput
and_input
are both rewritten to&[u8]
). This may also require some changes to our currentvoid*
cast handling.