-
Notifications
You must be signed in to change notification settings - Fork 7
Make hir::Place projections more precise #1
Comments
Some details on how HIR Places are constructed. They are defined and built in the mem categorization module. This code takes a HIR Expression, which represents the syntax for an expression, and tries to create a HIR Place from it. The name "mem categorization" is somewhat old, but it comes from the idea that we are "categorizing" what "memory" the expression refers to (e.g., a local variable, or a field of some local variable -- this is precisely what we now call a "place"). Mem categorization doesn't just take the HIR Expression as input, it also takes some information produced by the type checker, which tells us e.g. the type of the expression along with some implicit things like derefs (that is, an expression like As a starting point, consider the You can see that it looks at "what kind of expression is this" by a big match. So, if we are going to introduce more precision, this is where we start. e.g., if we wanted to isolate out a |
Looking more closely at the code for
|
There's also this match for patterns that will also need updating. |
So a first step might be to modify crate fn cat_projection<N: HirNode>(
&self,
node: &N,
base_place: Place<'tcx>,
ty: Ty<'tcx>,
projection: Projection<'tcx>,
) -> Place<'tcx> { so that we can adjust the calls one by one (e.g., the field could pass in a new field variant, etc). |
This commit also categorizing access as Field, Index, or Subslice. Ideas are taken from `mir::ProjectionElem`. Proposed changes: https://github.com/rust-lang/project-rfc-2229/blob/master/hir-place-target.md Closes: rust-lang/project-rfc-2229#1, rust-lang/project-rfc-2229#2 Co-authored-by: Aman Arora <me@aman-arora.com> Co-authored-by: Chris Pardy <chrispardy36@gmail.com> Co-authored-by: Dhruv Jauhar <dhruvjhr@gmail.com>
This commit also categorizing access as Field, Index, or Subslice. Ideas are taken from `mir::ProjectionElem`. Proposed changes: https://github.com/rust-lang/project-rfc-2229/blob/master/hir-place-target.md Closes: rust-lang/project-rfc-2229#1, rust-lang/project-rfc-2229#2 Co-authored-by: Aman Arora <me@aman-arora.com> Co-authored-by: Chris Pardy <chrispardy36@gmail.com> Co-authored-by: Dhruv Jauhar <dhruvjhr@gmail.com>
This commit also categorizing access as Field, Index, or Subslice. Ideas are taken from `mir::ProjectionElem`. Proposed changes: https://github.com/rust-lang/project-rfc-2229/blob/master/hir-place-target.md Closes: rust-lang/project-rfc-2229#1, rust-lang/project-rfc-2229#2 Co-authored-by: Aman Arora <me@aman-arora.com> Co-authored-by: Chris Pardy <chrispardy36@gmail.com> Co-authored-by: Dhruv Jauhar <dhruvjhr@gmail.com>
This commit also categorizing access as Field, Index, or Subslice. Ideas are taken from `mir::ProjectionElem`. Proposed changes: https://github.com/rust-lang/project-rfc-2229/blob/master/hir-place-target.md Closes: rust-lang/project-rfc-2229#1, rust-lang/project-rfc-2229#2 Co-authored-by: Aman Arora <me@aman-arora.com> Co-authored-by: Chris Pardy <chrispardy36@gmail.com> Co-authored-by: Dhruv Jauhar <dhruvjhr@gmail.com>
…, r=nikomatsakis Make hir ProjectionKind more precise This commit also categorizing access as Field, Index, or Subslice. Ideas are taken from `mir::ProjectionElem`. Proposed changes: https://github.com/rust-lang/project-rfc-2229/blob/master/hir-place-target.md Closes: rust-lang/project-rfc-2229#1, Closes: rust-lang/project-rfc-2229#2 r? @nikomatsakis @matthewjasper
…, r=nikomatsakis Make hir ProjectionKind more precise This commit also categorizing access as Field, Index, or Subslice. Ideas are taken from `mir::ProjectionElem`. Proposed changes: https://github.com/rust-lang/project-rfc-2229/blob/master/hir-place-target.md Closes: rust-lang/project-rfc-2229#1, Closes: rust-lang/project-rfc-2229#2 r? @nikomatsakis @matthewjasper
…, r=nikomatsakis Make hir ProjectionKind more precise This commit also categorizing access as Field, Index, or Subslice. Ideas are taken from `mir::ProjectionElem`. Proposed changes: https://github.com/rust-lang/project-rfc-2229/blob/master/hir-place-target.md Closes: rust-lang/project-rfc-2229#1, Closes: rust-lang/project-rfc-2229#2 r? @nikomatsakis @matthewjasper
The current HIR Place data structure includes only two kinds of projections:
If you compare that to the MIR Place, you can see that the MIR version has a lot more kinds of projections. I'm making a list of them below. We may not need to add them all to HIR Place, but we probably want most of them. For each one, there is a check-box, and in some cases I may link to additional issues that give more details about how to make a change.
Within the HIR we don't need to be as precise as the MIR.
Field(u32, VariantIdx)
where theu32
is for the field within a struct.Index
.ConstIndex
is used for some special cases where we know the index is a fixed constant -- mostly pattern matching likelet [a, b, _] = some_array
. The compiler is (sometimes) smart enough to see that these moves are distinct from (say)let [_, _, c] = some_array
, but to be that smart, it needs to know the indices as constants. We are just going to capture the entire array for now, so we don't care for now.The text was updated successfully, but these errors were encountered: