Skip to content

Rollup of 4 pull requests #64461

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

Closed
wants to merge 19 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d86516d
Stabilise weak_ptr_eq
Thomasdezeeuw Aug 25, 2019
307804a
Update {rc, sync}::Weak::ptr_eq doc about comparing Weak::new
Thomasdezeeuw Aug 25, 2019
417b5f1
[const-prop] Replace `eval_place()` with use of `InterpCx`
wesleywiser Sep 4, 2019
600b9d1
[const-prop] Replace `Use` handling with use of `InterpCx`
wesleywiser Sep 6, 2019
1befe27
[const-prop] Replace `Cast` handling with use of `InterpCx`
wesleywiser Sep 6, 2019
c97347d
[const-prop] Replace `NullaryOp` handling with use of `InterpCx`
wesleywiser Sep 6, 2019
ec15579
[const-prop] Replace most `UnaryOp` handling with use of `InterpCx`
wesleywiser Sep 6, 2019
b5c28e0
[const-prop] Replace `CheckedBinaryOp` handling with use of `InterpCx`
wesleywiser Sep 9, 2019
a1053a9
[const-prop] Replace some `Binaryp` handling with use of `InterpCx`
wesleywiser Sep 10, 2019
72050c8
[const-prop] Replace `Ref` handling with use of `InterpCx`
wesleywiser Sep 11, 2019
fe323d4
Don't run the ConstProp MIR pass on generators
wesleywiser Sep 13, 2019
039fc48
Respond to code review feedback and fix tidy
wesleywiser Sep 13, 2019
0b333ef
Move Ref-from-arg checking from `step.rs` to `const_prop.rs`
wesleywiser Sep 14, 2019
b7f20d0
Provide a span if main function is not present in crate
Mark-Simulacrum Sep 8, 2019
7b3adc2
Ban non-extern rust intrinsics
Mark-Simulacrum Sep 12, 2019
2286a45
Rollup merge of #61797 - Thomasdezeeuw:stablise-weak_ptr_eq, r=RalfJung
Centril Sep 14, 2019
30b46ef
Rollup merge of #64290 - Mark-Simulacrum:span-no-main, r=estebank
Centril Sep 14, 2019
1fb2f4a
Rollup merge of #64406 - Mark-Simulacrum:error-unknown-intrinsic, r=C…
Centril Sep 14, 2019
8e00329
Rollup merge of #64419 - wesleywiser:const_prop_use_ecx, r=oli-obk
Centril Sep 14, 2019
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
[const-prop] Replace most UnaryOp handling with use of InterpCx
  • Loading branch information
wesleywiser committed Sep 14, 2019
commit ec15579b6535d2358c93a593fbe19fb647575429
45 changes: 17 additions & 28 deletions src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,39 +325,28 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
},

Rvalue::UnaryOp(op, ref arg) => {
let def_id = if self.tcx.is_closure(self.source.def_id()) {
self.tcx.closure_base_def_id(self.source.def_id())
} else {
self.source.def_id()
};
let generics = self.tcx.generics_of(def_id);
if generics.requires_monomorphization(self.tcx) {
// FIXME: can't handle code with generics
return None;
}
let overflow_check = self.tcx.sess.overflow_checks();

let arg = self.eval_operand(arg, source_info)?;
let oflo_check = self.tcx.sess.overflow_checks();
let val = self.use_ecx(source_info, |this| {
let prim = this.ecx.read_immediate(arg)?;
match op {
UnOp::Neg => {
// We check overflow in debug mode already
// so should only check in release mode.
if !oflo_check
&& prim.layout.ty.is_signed()
&& prim.to_bits()? == (1 << (prim.layout.size.bits() - 1)) {
self.use_ecx(source_info, |this| {
// We check overflow in debug mode already
// so should only check in release mode.
if op == UnOp::Neg && !overflow_check {
let ty = arg.ty(&this.local_decls, this.tcx);

if ty.is_integral() {
let arg = this.ecx.eval_operand(arg, None)?;
let prim = this.ecx.read_immediate(arg)?;
// Need to do overflow check here: For actual CTFE, MIR
// generation emits code that does this before calling the op.
if prim.to_bits()? == (1 << (prim.layout.size.bits() - 1)) {
throw_panic!(OverflowNeg)
}
}
UnOp::Not => {
// Cannot overflow
}
}
// Now run the actual operation.
this.ecx.unary_op(op, prim)
})?;
Some(val.into())

this.ecx.eval_rvalue_into_place(rvalue, place)?;
this.ecx.eval_place_to_op(place, Some(place_layout))
})
}
Rvalue::CheckedBinaryOp(op, ref left, ref right) |
Rvalue::BinaryOp(op, ref left, ref right) => {
Expand Down