Skip to content
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

Rollup of 9 pull requests #111476

Closed
wants to merge 23 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2198fae
Make `NonUseContext::AscribeUserTy` carry `ty::Variance`
obeis May 8, 2023
b64e911
Add test.
cjgillot May 10, 2023
d0d4e02
Iteratively replace pointers.
cjgillot May 10, 2023
aeac555
Do not see through copies of mutable pointers.
cjgillot May 10, 2023
9fb1c73
Avoid shadowing.
cjgillot May 10, 2023
a2fe993
Only warn single-use lifetime when the binders match.
cjgillot May 10, 2023
ccd8ad7
Note base types of coercion
compiler-errors May 11, 2023
eadf3bb
Update cargo
heiher May 11, 2023
616fb42
Update browser-ui-test version to 0.16.0
GuillaumeGomez May 10, 2023
0630283
Migrate to 0.16.0 browser-ui-test version
GuillaumeGomez May 10, 2023
8e55400
Convert some GUI tests color checks to use original format
GuillaumeGomez May 11, 2023
cac7e42
Fix backtrace normalization in ice-bug-report-url.rs
uweigand May 10, 2023
3851a4b
Improve error for `self: Box<self>`
clubby789 May 11, 2023
90ce53a
Usage of atomic counters for llvm code coverage
Dushistov May 11, 2023
e1746af
Rollup merge of #111366 - obeis:ascribe-user-type-variance, r=lcnr
matthiaskrgr May 11, 2023
1c5586a
Rollup merge of #111439 - uweigand:backtrace-normalize, r=compiler-er…
matthiaskrgr May 11, 2023
e4444d1
Rollup merge of #111441 - cjgillot:issue-111422, r=JakobDegen
matthiaskrgr May 11, 2023
2651fff
Rollup merge of #111444 - cjgillot:issue-111400, r=oli-obk
matthiaskrgr May 11, 2023
41ab9c8
Rollup merge of #111451 - compiler-errors:note-cast-origin, r=b-naber
matthiaskrgr May 11, 2023
c58dd49
Rollup merge of #111456 - loongarch-rs:bump-cargo, r=weihanglo
matthiaskrgr May 11, 2023
3a5077c
Rollup merge of #111459 - GuillaumeGomez:update-browser-ui-test, r=no…
matthiaskrgr May 11, 2023
ae2f6f2
Rollup merge of #111460 - clubby789:lowercase-box-self, r=compiler-er…
matthiaskrgr May 11, 2023
b203279
Rollup merge of #111469 - Dushistov:fix-coverage-data-race, r=wesleyw…
matthiaskrgr May 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Iteratively replace pointers.
cjgillot committed May 10, 2023
commit d0d4e0237ff708c4d41070ef946679819125a0d5
79 changes: 54 additions & 25 deletions compiler/rustc_mir_transform/src/ref_prop.rs
Original file line number Diff line number Diff line change
@@ -85,7 +85,9 @@ fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let ssa = SsaLocals::new(body);

let mut replacer = compute_replacement(tcx, body, &ssa);
debug!(?replacer.targets, ?replacer.allowed_replacements, ?replacer.storage_to_remove);
debug!(?replacer.targets);
debug!(?replacer.allowed_replacements);
debug!(?replacer.storage_to_remove);

replacer.visit_body_preserves_cfg(body);

@@ -190,8 +192,11 @@ fn compute_replacement<'tcx>(
continue;
}

// Whether the current local is subject to the uniqueness rule.
let needs_unique = ty.is_mutable_ptr();

// If this a mutable reference that we cannot fully replace, mark it as unknown.
if ty.is_mutable_ptr() && !fully_replacable_locals.contains(local) {
if needs_unique && !fully_replacable_locals.contains(local) {
debug!("not fully replaceable");
continue;
}
@@ -217,18 +222,18 @@ fn compute_replacement<'tcx>(
let mut place = *place;
// Try to see through `place` in order to collapse reborrow chains.
if place.projection.first() == Some(&PlaceElem::Deref)
&& let Value::Pointer(target, refmut) = targets[place.local]
&& let Value::Pointer(target, needs_unique) = targets[place.local]
// Only see through immutable reference and pointers, as we do not know yet if
// mutable references are fully replaced.
&& !refmut
&& !needs_unique
// Only collapse chain if the pointee is definitely live.
&& can_perform_opt(target, location)
{
place = target.project_deeper(&place.projection[1..], tcx);
}
assert_ne!(place.local, local);
if is_constant_place(place) {
targets[local] = Value::Pointer(place, ty.is_mutable_ptr());
targets[local] = Value::Pointer(place, needs_unique);
}
}
// We do not know what to do, so keep as not-a-pointer.
@@ -276,16 +281,35 @@ fn compute_replacement<'tcx>(
return;
}

if let Value::Pointer(target, refmut) = self.targets[place.local]
&& place.projection.first() == Some(&PlaceElem::Deref)
{
let perform_opt = (self.can_perform_opt)(target, loc);
if perform_opt {
self.allowed_replacements.insert((target.local, loc));
} else if refmut {
// This mutable reference is not fully replacable, so drop it.
self.targets[place.local] = Value::Unknown;
if place.projection.first() != Some(&PlaceElem::Deref) {
// This is not a dereference, nothing to do.
return;
}

let mut place = place.as_ref();
loop {
if let Value::Pointer(target, needs_unique) = self.targets[place.local] {
let perform_opt = (self.can_perform_opt)(target, loc);
debug!(?place, ?target, ?needs_unique, ?perform_opt);

// This a reborrow chain, recursively allow the replacement.
//
// This also allows to detect cases where `target.local` is not replacable,
// and mark it as such.
if let &[PlaceElem::Deref] = &target.projection[..] {
assert!(perform_opt);
self.allowed_replacements.insert((target.local, loc));
place.local = target.local;
continue;
} else if perform_opt {
self.allowed_replacements.insert((target.local, loc));
} else if needs_unique {
// This mutable reference is not fully replacable, so drop it.
self.targets[place.local] = Value::Unknown;
}
}

break;
}
}
}
@@ -326,18 +350,23 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
}

fn visit_place(&mut self, place: &mut Place<'tcx>, ctxt: PlaceContext, loc: Location) {
if let Value::Pointer(target, _) = self.targets[place.local]
&& place.projection.first() == Some(&PlaceElem::Deref)
{
let perform_opt = matches!(ctxt, PlaceContext::NonUse(_))
|| self.allowed_replacements.contains(&(target.local, loc));

if perform_opt {
*place = target.project_deeper(&place.projection[1..], self.tcx);
self.any_replacement = true;
if place.projection.first() != Some(&PlaceElem::Deref) {
return;
}

loop {
if let Value::Pointer(target, _) = self.targets[place.local] {
let perform_opt = matches!(ctxt, PlaceContext::NonUse(_))
|| self.allowed_replacements.contains(&(target.local, loc));

if perform_opt {
*place = target.project_deeper(&place.projection[1..], self.tcx);
self.any_replacement = true;
continue;
}
}
} else {
self.super_place(place, ctxt, loc);

break;
}
}

Original file line number Diff line number Diff line change
@@ -41,8 +41,7 @@
- StorageLive(_5); // scope 2 at $DIR/reference_prop.rs:+3:16: +3:26
- _5 = &mut (*_2); // scope 2 at $DIR/reference_prop.rs:+3:16: +3:26
- _4 = &raw mut (*_5); // scope 2 at $DIR/reference_prop.rs:+3:16: +3:26
+ _5 = &mut _1; // scope 2 at $DIR/reference_prop.rs:+3:16: +3:26
+ _4 = &raw mut (*_2); // scope 2 at $DIR/reference_prop.rs:+3:16: +3:26
+ _4 = &raw mut _1; // scope 2 at $DIR/reference_prop.rs:+3:16: +3:26
_3 = _4; // scope 2 at $DIR/reference_prop.rs:+3:16: +3:36
- StorageDead(_5); // scope 2 at $DIR/reference_prop.rs:+3:36: +3:37
StorageDead(_4); // scope 2 at $DIR/reference_prop.rs:+3:36: +3:37
@@ -55,8 +54,8 @@
- (*_3) = const 4_i32; // scope 6 at $DIR/reference_prop.rs:+7:14: +7:23
- _8 = const (); // scope 6 at $DIR/reference_prop.rs:+7:5: +7:26
- StorageDead(_8); // scope 5 at $DIR/reference_prop.rs:+7:25: +7:26
+ _7 = (*_2); // scope 4 at $DIR/reference_prop.rs:+6:13: +6:18
+ (*_5) = const 4_i32; // scope 6 at $DIR/reference_prop.rs:+7:14: +7:23
+ _7 = _1; // scope 4 at $DIR/reference_prop.rs:+6:13: +6:18
+ _1 = const 4_i32; // scope 6 at $DIR/reference_prop.rs:+7:14: +7:23
StorageLive(_9); // scope 5 at $DIR/reference_prop.rs:+8:6: +8:7
_9 = _7; // scope 5 at $DIR/reference_prop.rs:+8:6: +8:7
StorageLive(_10); // scope 5 at $DIR/reference_prop.rs:+8:9: +8:10
Original file line number Diff line number Diff line change
@@ -9,15 +9,14 @@
let mut _5: *mut usize; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL

bb0: {
_2 = &mut (*_1); // scope 0 at $DIR/reference_prop.rs:+10:13: +10:25
- _2 = &mut (*_1); // scope 0 at $DIR/reference_prop.rs:+10:13: +10:25
- _3 = &mut (*_2); // scope 0 at $DIR/reference_prop.rs:+11:13: +11:26
- _4 = &raw mut (*_2); // scope 0 at $DIR/reference_prop.rs:+12:13: +12:30
- _5 = &raw mut (*_3); // scope 0 at $DIR/reference_prop.rs:+13:13: +13:30
- _0 = (*_4); // scope 0 at $DIR/reference_prop.rs:+15:13: +15:22
- _0 = (*_5); // scope 0 at $DIR/reference_prop.rs:+16:13: +16:22
+ _3 = &mut (*_1); // scope 0 at $DIR/reference_prop.rs:+11:13: +11:26
+ _0 = (*_2); // scope 0 at $DIR/reference_prop.rs:+15:13: +15:22
+ _0 = (*_3); // scope 0 at $DIR/reference_prop.rs:+16:13: +16:22
+ _0 = (*_1); // scope 0 at $DIR/reference_prop.rs:+15:13: +15:22
+ _0 = (*_1); // scope 0 at $DIR/reference_prop.rs:+16:13: +16:22
return; // scope 0 at $DIR/reference_prop.rs:+17:13: +17:21
}
}