Skip to content
Closed
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5c20ef4
bootstrap: Configurable musl libdir
tmiasko Jun 17, 2020
7cac209
add missing doc links
RalfJung Jun 21, 2020
55d207a
tweak wording
RalfJung Jun 21, 2020
cb8c94c
improve grammar
RalfJung Jun 21, 2020
f44b8b9
Document the Self keyword
poliorcetics Jun 24, 2020
5232e20
Document the super keyword
poliorcetics Jun 25, 2020
8b368db
Bootstrap: fallback detection of Windows
ajpaverd Jun 25, 2020
1a355a2
Document some invariants correctly/more
oli-obk Jun 25, 2020
42062a5
Shortcuts for min/max on ordinary BTreeMap/BTreeSet iterators
ssomers Jun 22, 2020
6f8bec9
Warn if linking to a private item
jyn514 May 13, 2020
20552c8
Generate docs for links to private items when passed --document-private
jyn514 May 30, 2020
6742382
Fix debug messages
jyn514 Jun 26, 2020
cb152ea
Remove blank line
kraai Jun 26, 2020
8ec8776
Rollup merge of #72771 - jyn514:rustdoc, r=Manishearth
Manishearth Jun 26, 2020
eca643d
Rollup merge of #73456 - tmiasko:musl-libdir, r=Mark-Simulacrum
Manishearth Jun 26, 2020
0633d28
Rollup merge of #73579 - RalfJung:doc-missing-links, r=shepmaster
Manishearth Jun 26, 2020
b3c2a4a
Rollup merge of #73627 - ssomers:btree_iter_min_max, r=Mark-Simulacrum
Manishearth Jun 26, 2020
eff76f3
Rollup merge of #73691 - ajpaverd:bootstrap-windows-73689, r=Mark-Sim…
Manishearth Jun 26, 2020
f52542a
Rollup merge of #73694 - poliorcetics:self-upper-keyword, r=Mark-Simu…
Manishearth Jun 26, 2020
050ebb0
Rollup merge of #73718 - poliorcetics:super-keyword, r=shepmaster
Manishearth Jun 26, 2020
8675c3b
Rollup merge of #73728 - oli-obk:const_prop_cleanup, r=wesleywiser
Manishearth Jun 26, 2020
657ad9e
Rollup merge of #73765 - kraai:remove-blank-line, r=jonas-schievink
Manishearth Jun 26, 2020
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
19 changes: 13 additions & 6 deletions src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,20 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
}

fn get_const(&self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {
let op = self.ecx.eval_place_to_op(place, None).ok();
let op = match self.ecx.eval_place_to_op(place, None) {
Ok(op) => op,
Err(e) => {
trace!("get_const failed: {}", e);
return None;
}
};

// Try to read the local as an immediate so that if it is representable as a scalar, we can
// handle it as such, but otherwise, just return the value as is.
match op.map(|ret| self.ecx.try_read_immediate(ret)) {
Some(Ok(Ok(imm))) => Some(imm.into()),
Some(match self.ecx.try_read_immediate(op) {
Ok(Ok(imm)) => imm.into(),
_ => op,
}
})
}

/// Remove `local` from the pool of `Locals`. Allows writing to them,
Expand Down Expand Up @@ -857,8 +863,9 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
if let Ok(place_layout) = self.tcx.layout_of(self.param_env.and(place_ty)) {
let can_const_prop = self.can_const_prop[place.local];
if let Some(()) = self.const_prop(rval, place_layout, source_info, place) {
// This will return None for variables that are from other blocks,
// so it should be okay to propagate from here on down.
// 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(value) = self.get_const(place) {
if self.should_const_prop(value) {
trace!("replacing {:?} with {:?}", rval, value);
Expand Down