Skip to content

Rollup of 7 pull requests #108325

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

Merged
merged 26 commits into from
Feb 22, 2023
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c13d5f1
Make sure test_type_match doesn't ICE with late-bound types
compiler-errors Feb 18, 2023
cb35a7b
add BorrowckInferCtxt
b-naber Nov 7, 2022
2f79f73
collect region contexts during mir renumbering
b-naber Nov 8, 2022
960ebaf
collect existentials and placeholders
b-naber Nov 9, 2022
e2bf960
sccs info
b-naber Nov 9, 2022
46bd77a
some conditional imports
b-naber Nov 9, 2022
2d2bccf
rebase
b-naber Nov 10, 2022
aefc5ec
remove cfgs
b-naber Dec 9, 2022
0725d0c
add some cfgs back
b-naber Feb 19, 2023
4a75995
Move state fixup into a different method.
cjgillot Feb 8, 2023
d0934f1
Merge if-let and match.
cjgillot Feb 8, 2023
f02d6c4
Remove use_ecx.
cjgillot Feb 10, 2023
c9843d6
remove cfg attributes
b-naber Feb 20, 2023
a58682d
Specify what 'this' actually is
compiler-errors Feb 21, 2023
1397a5e
compiletest: bump miow crate
klensy Feb 21, 2023
6e34e65
Fix compiletest crash when test file path does not exist
chenyukang Feb 21, 2023
58e7470
replace lazy_static with once_cell
klensy Feb 21, 2023
b483816
hir-analysis: make one diagnostic translatable
tshepang Feb 21, 2023
8252a6e
address review
b-naber Feb 21, 2023
314fe4d
Rollup merge of #104239 - b-naber:sccs-info, r=jackh726
matthiaskrgr Feb 21, 2023
8a5843f
Rollup merge of #108202 - compiler-errors:non_lifetime_binders-type-m…
matthiaskrgr Feb 21, 2023
ae01430
Rollup merge of #108295 - compiler-errors:wtf-is-this, r=cjgillot
matthiaskrgr Feb 21, 2023
c292def
Rollup merge of #108306 - klensy:compiletest-up, r=wesleywiser
matthiaskrgr Feb 21, 2023
c21b7f6
Rollup merge of #108313 - chenyukang:yukang/fix-only-modified, r=oli-obk
matthiaskrgr Feb 21, 2023
82dc2eb
Rollup merge of #108322 - cjgillot:clean-const-prop, r=oli-obk
matthiaskrgr Feb 21, 2023
d39fc21
Rollup merge of #108323 - tshepang:translatable-hir-analysis, r=compi…
matthiaskrgr Feb 21, 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
Merge if-let and match.
  • Loading branch information
cjgillot committed Feb 20, 2023
commit d0934f14c7fd95c0517c98a2c0dc549ec40b03e7
130 changes: 63 additions & 67 deletions compiler/rustc_mir_transform/src/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -917,84 +917,80 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
trace!("visit_statement: {:?}", statement);
let source_info = statement.source_info;
self.source_info = Some(source_info);
if let StatementKind::Assign(box (place, ref mut rval)) = statement.kind {
let can_const_prop = self.ecx.machine.can_const_prop[place.local];
if let Some(()) = self.const_prop(rval, place) {
// This will return None if the above `const_prop` invocation only "wrote" a
// type whose creation requires no write. E.g. a generator whose initial state
// consists solely of uninitialized memory (so it doesn't capture any locals).
if let Some(ref value) = self.get_const(place) && self.should_const_prop(value) {
trace!("replacing {:?} with {:?}", rval, value);
self.replace_with_const(rval, value, source_info);
if can_const_prop == ConstPropMode::FullConstProp
|| can_const_prop == ConstPropMode::OnlyInsideOwnBlock
{
trace!("propagated into {:?}", place);
match statement.kind {
StatementKind::Assign(box (place, ref mut rval)) => {
let can_const_prop = self.ecx.machine.can_const_prop[place.local];
if let Some(()) = self.const_prop(rval, place) {
// This will return None if the above `const_prop` invocation only "wrote" a
// type whose creation requires no write. E.g. a generator whose initial state
// consists solely of uninitialized memory (so it doesn't capture any locals).
if let Some(ref value) = self.get_const(place) && self.should_const_prop(value) {
trace!("replacing {:?} with {:?}", rval, value);
self.replace_with_const(rval, value, source_info);
if can_const_prop == ConstPropMode::FullConstProp
|| can_const_prop == ConstPropMode::OnlyInsideOwnBlock
{
trace!("propagated into {:?}", place);
}
}
}
match can_const_prop {
ConstPropMode::OnlyInsideOwnBlock => {
trace!(
"found local restricted to its block. \
match can_const_prop {
ConstPropMode::OnlyInsideOwnBlock => {
trace!(
"found local restricted to its block. \
Will remove it from const-prop after block is finished. Local: {:?}",
place.local
);
}
ConstPropMode::OnlyPropagateInto | ConstPropMode::NoPropagation => {
trace!("can't propagate into {:?}", place);
if place.local != RETURN_PLACE {
Self::remove_const(&mut self.ecx, place.local);
place.local
);
}
}
ConstPropMode::FullConstProp => {}
}
} else {
// Const prop failed, so erase the destination, ensuring that whatever happens
// from here on, does not know about the previous value.
// This is important in case we have
// ```rust
// let mut x = 42;
// x = SOME_MUTABLE_STATIC;
// // x must now be uninit
// ```
// FIXME: we overzealously erase the entire local, because that's easier to
// implement.
trace!(
"propagation into {:?} failed.
Nuking the entire site from orbit, it's the only way to be sure",
place,
);
Self::remove_const(&mut self.ecx, place.local);
}
} else {
match statement.kind {
StatementKind::SetDiscriminant { ref place, .. } => {
match self.ecx.machine.can_const_prop[place.local] {
ConstPropMode::FullConstProp | ConstPropMode::OnlyInsideOwnBlock => {
if self.use_ecx(|this| this.ecx.statement(statement)).is_some() {
trace!("propped discriminant into {:?}", place);
} else {
ConstPropMode::OnlyPropagateInto | ConstPropMode::NoPropagation => {
trace!("can't propagate into {:?}", place);
if place.local != RETURN_PLACE {
Self::remove_const(&mut self.ecx, place.local);
}
}
ConstPropMode::OnlyPropagateInto | ConstPropMode::NoPropagation => {
Self::remove_const(&mut self.ecx, place.local);
}
ConstPropMode::FullConstProp => {}
}
} else {
// Const prop failed, so erase the destination, ensuring that whatever happens
// from here on, does not know about the previous value.
// This is important in case we have
// ```rust
// let mut x = 42;
// x = SOME_MUTABLE_STATIC;
// // x must now be uninit
// ```
// FIXME: we overzealously erase the entire local, because that's easier to
// implement.
trace!(
"propagation into {:?} failed.
Nuking the entire site from orbit, it's the only way to be sure",
place,
);
Self::remove_const(&mut self.ecx, place.local);
}
StatementKind::StorageLive(local) | StatementKind::StorageDead(local) => {
let frame = self.ecx.frame_mut();
frame.locals[local].value =
if let StatementKind::StorageLive(_) = statement.kind {
LocalValue::Live(interpret::Operand::Immediate(
interpret::Immediate::Uninit,
))
}
StatementKind::SetDiscriminant { ref place, .. } => {
match self.ecx.machine.can_const_prop[place.local] {
ConstPropMode::FullConstProp | ConstPropMode::OnlyInsideOwnBlock => {
if self.use_ecx(|this| this.ecx.statement(statement)).is_some() {
trace!("propped discriminant into {:?}", place);
} else {
LocalValue::Dead
};
Self::remove_const(&mut self.ecx, place.local);
}
}
ConstPropMode::OnlyPropagateInto | ConstPropMode::NoPropagation => {
Self::remove_const(&mut self.ecx, place.local);
}
}
_ => {}
}
StatementKind::StorageLive(local) | StatementKind::StorageDead(local) => {
let frame = self.ecx.frame_mut();
frame.locals[local].value = if let StatementKind::StorageLive(_) = statement.kind {
LocalValue::Live(interpret::Operand::Immediate(interpret::Immediate::Uninit))
} else {
LocalValue::Dead
};
}
_ => {}
}

self.super_statement(statement, location);
Expand Down