Description
For efficiency reasons, but also others, it would be nice to change how MIR represents the Place
data structure. Right now we have a tree-like structure:
Lines 1694 to 1709 in fefe816
But this is not the most convenient and it can be an efficiency hazard. Instead, I propose a structure like this (inspired by something @eddyb said, and I imagine that they will have suggestions too):
struct Place<'tcx> {
base: PlaceBase<'tcx>,
elem: &'tcx Slice<ProjectionElem<'tcx>>,
}
enum PlaceBase<'tcx> {
/// local variable
Local(Local),
/// static or static mut variable
Static(Box<Static<'tcx>>),
/// Constant code promoted to an injected static
Promoted(Box<(Promoted, Ty<'tcx>)>),
}
where ProjectionElem
is basically the same type as today:
Lines 1734 to 1770 in fefe816
In other words, instead of representing a.b.c
as
.c
.b
.a
we would represent it as (a, [b, c])
(here, [b, c]
would be an interned slice).
The advantages of this setup:
Place
is nowCopy
, which is always nice- You can figure out very quickly that
a.b.c
is disjoint fromd.e.f
- Right now we have to use these
unroll_place
calls
- Right now we have to use these
And it is a building block, I think, for other improvements to NLL performance.
cc @eddyb