Add projections check to EUV for escape analysis

This commit is contained in:
flip1995 2019-11-29 12:57:10 +01:00
parent b2523afae4
commit 604e6ba0e2
No known key found for this signature in database
GPG Key ID: 693086869D506637

View File

@ -106,14 +106,13 @@ fn is_argument(map: &hir::map::Map<'_>, id: HirId) -> bool {
impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
fn consume(&mut self, cmt: &Place<'tcx>, mode: ConsumeMode) {
if cmt.projections.is_empty() {
if let PlaceBase::Local(lid) = cmt.base {
if let ConsumeMode::Move = mode {
// moved out or in. clearly can't be localized
self.set.remove(&lid);
}
}
let map = &self.cx.tcx.hir();
if let PlaceBase::Local(lid) = cmt.base {
if let Some(Node::Binding(_)) = map.find(cmt.hir_id) {
if self.set.contains(&lid) {
// let y = x where x is known
@ -124,14 +123,18 @@ fn consume(&mut self, cmt: &Place<'tcx>, mode: ConsumeMode) {
}
}
}
}
fn borrow(&mut self, cmt: &Place<'tcx>, _: ty::BorrowKind) {
if cmt.projections.is_empty() {
if let PlaceBase::Local(lid) = cmt.base {
self.set.remove(&lid);
}
}
}
fn mutate(&mut self, cmt: &Place<'tcx>) {
if cmt.projections.is_empty() {
let map = &self.cx.tcx.hir();
if is_argument(map, cmt.hir_id) {
// Skip closure arguments
@ -146,6 +149,7 @@ fn mutate(&mut self, cmt: &Place<'tcx>) {
return;
}
}
}
}
impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {