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

[beta] backports #73766

Merged
merged 11 commits into from
Jun 27, 2020
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl<'a> Linker for GccLinker<'a> {
fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path) {
match output_kind {
LinkOutputKind::DynamicNoPicExe => {
if !self.is_ld {
if !self.is_ld && self.sess.target.target.options.linker_is_gnu {
self.cmd.arg("-no-pie");
}
}
Expand All @@ -291,7 +291,7 @@ impl<'a> Linker for GccLinker<'a> {
LinkOutputKind::StaticNoPicExe => {
// `-static` works for both gcc wrapper and ld.
self.cmd.arg("-static");
if !self.is_ld {
if !self.is_ld && self.sess.target.target.options.linker_is_gnu {
self.cmd.arg("-no-pie");
}
}
Expand Down
11 changes: 1 addition & 10 deletions src/librustc_middle/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,16 +508,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
debug!("{}.super_relate_consts(a = {:?}, b = {:?})", relation.tag(), a, b);
let tcx = relation.tcx();

let eagerly_eval = |x: &'tcx ty::Const<'tcx>| {
// FIXME(eddyb) this doesn't account for lifetime inference variables
// being erased by `eval`, *nor* for the polymorphic aspect of `eval`.
// That is, we could always use `eval` and it will just return the
// old value back if it doesn't succeed.
if !x.val.needs_infer() {
return x.eval(tcx, relation.param_env()).val;
}
x.val
};
let eagerly_eval = |x: &'tcx ty::Const<'tcx>| x.eval(tcx, relation.param_env()).val;

// FIXME(eddyb) doesn't look like everything below checks that `a.ty == b.ty`.
// We could probably always assert it early, as `const` generic parameters
Expand Down
8 changes: 8 additions & 0 deletions src/librustc_mir/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,14 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
self.output.push(create_fn_mono_item(instance));
}
}
mir::Rvalue::ThreadLocalRef(def_id) => {
assert!(self.tcx.is_thread_local_static(def_id));
let instance = Instance::mono(self.tcx, def_id);
if should_monomorphize_locally(self.tcx, &instance) {
trace!("collecting thread-local static {:?}", def_id);
self.output.push(MonoItem::Static(def_id));
}
}
_ => { /* not interesting */ }
}

Expand Down
6 changes: 5 additions & 1 deletion src/librustc_mir/transform/simplify_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,11 @@ fn optimization_applies<'tcx>(
}

impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity {
fn run_pass(&self, _: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) {
fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) {
if tcx.sess.opts.debugging_opts.mir_opt_level < 2 {
return;
}

trace!("running SimplifyArmIdentity on {:?}", source);
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
for bb in basic_blocks {
Expand Down
48 changes: 25 additions & 23 deletions src/librustc_mir_build/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard};
use crate::build::{BlockAnd, BlockAndExtension, Builder};
use crate::build::{GuardFrame, GuardFrameLocal, LocalsForNode};
use crate::hair::{self, *};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::{fx::{FxHashMap, FxHashSet}, stack::ensure_sufficient_stack};
use rustc_hir::HirId;
use rustc_index::bit_set::BitSet;
use rustc_middle::middle::region;
Expand Down Expand Up @@ -909,30 +909,32 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
split_or_candidate |= self.simplify_candidate(candidate);
}

if split_or_candidate {
// At least one of the candidates has been split into subcandidates.
// We need to change the candidate list to include those.
let mut new_candidates = Vec::new();
ensure_sufficient_stack(|| {
if split_or_candidate {
// At least one of the candidates has been split into subcandidates.
// We need to change the candidate list to include those.
let mut new_candidates = Vec::new();

for candidate in candidates {
candidate.visit_leaves(|leaf_candidate| new_candidates.push(leaf_candidate));
for candidate in candidates {
candidate.visit_leaves(|leaf_candidate| new_candidates.push(leaf_candidate));
}
self.match_simplified_candidates(
span,
start_block,
otherwise_block,
&mut *new_candidates,
fake_borrows,
);
} else {
self.match_simplified_candidates(
span,
start_block,
otherwise_block,
candidates,
fake_borrows,
);
}
self.match_simplified_candidates(
span,
start_block,
otherwise_block,
&mut *new_candidates,
fake_borrows,
);
} else {
self.match_simplified_candidates(
span,
start_block,
otherwise_block,
candidates,
fake_borrows,
);
};
});
}

fn match_simplified_candidates(
Expand Down
9 changes: 8 additions & 1 deletion src/librustc_mir_build/hair/pattern/const_to_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,15 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
cv.ty, structural
);

// This can occur because const qualification treats all associated constants as
// opaque, whereas `search_for_structural_match_violation` tries to monomorphize them
// before it runs.
//
// FIXME(#73448): Find a way to bring const qualification into parity with
// `search_for_structural_match_violation`.
if structural.is_none() && mir_structural_match_violation {
bug!("MIR const-checker found novel structural match violation");
warn!("MIR const-checker found novel structural match violation. See #73448.");
return inlined_const_as_pat;
}

if let Some(non_sm_ty) = structural {
Expand Down
18 changes: 18 additions & 0 deletions src/librustc_trait_selection/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// who might care about this case, like coherence, should use
// that function).
if candidates.is_empty() {
// If there's an error type, 'downgrade' our result from
// `Err(Unimplemented)` to `Ok(None)`. This helps us avoid
// emitting additional spurious errors, since we're guaranteed
// to have emitted at least one.
if stack.obligation.references_error() {
debug!("no results for error type, treating as ambiguous");
return Ok(None);
}
return Err(Unimplemented);
}

Expand Down Expand Up @@ -1697,6 +1705,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
) -> Result<(), SelectionError<'tcx>> {
debug!("assemble_candidates_from_impls(obligation={:?})", obligation);

// Essentially any user-written impl will match with an error type,
// so creating `ImplCandidates` isn't useful. However, we might
// end up finding a candidate elsewhere (e.g. a `BuiltinCandidate` for `Sized)
// This helps us avoid overflow: see issue #72839
// Since compilation is already guaranteed to fail, this is just
// to try to show the 'nicest' possible errors to the user.
if obligation.references_error() {
return Ok(());
}

self.tcx().for_each_relevant_impl(
obligation.predicate.def_id(),
obligation.predicate.skip_binder().trait_ref.self_ty(),
Expand Down
17 changes: 8 additions & 9 deletions src/test/mir-opt/simplify-arm/rustc.id.SimplifyArmIdentity.diff
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
}

bb3: {
- StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15
- _3 = ((_1 as Some).0: u8); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15
- StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26
- _4 = _3; // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26
- ((_0 as Some).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
- discriminant(_0) = 1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
- StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:11:26: 11:27
- StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:11:27: 11:28
+ _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15
_3 = ((_1 as Some).0: u8); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15
StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26
_4 = _3; // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26
((_0 as Some).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
discriminant(_0) = 1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:11:26: 11:27
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:11:27: 11:28
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@
}

bb3: {
_0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15
_3 = ((_1 as Some).0: u8); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15
StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26
_4 = _3; // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26
((_0 as Some).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
discriminant(_0) = 1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:11:26: 11:27
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:11:27: 11:28
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
}

bb1: {
- StorageLive(_5); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14
- _5 = ((_1 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14
- StorageLive(_6); // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24
- _6 = _5; // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24
- ((_0 as Err).0: i32) = move _6; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
- discriminant(_0) = 1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
- StorageDead(_6); // scope 2 at $DIR/simplify-arm.rs:19:24: 19:25
- StorageDead(_5); // scope 0 at $DIR/simplify-arm.rs:19:25: 19:26
+ _0 = move _1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
StorageLive(_5); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14
_5 = ((_1 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14
StorageLive(_6); // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24
_6 = _5; // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24
((_0 as Err).0: i32) = move _6; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
discriminant(_0) = 1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
StorageDead(_6); // scope 2 at $DIR/simplify-arm.rs:19:24: 19:25
StorageDead(_5); // scope 0 at $DIR/simplify-arm.rs:19:25: 19:26
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
}

Expand All @@ -39,15 +38,14 @@
}

bb3: {
- StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13
- _3 = ((_1 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13
- StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22
- _4 = _3; // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22
- ((_0 as Ok).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
- discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
- StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:18:22: 18:23
- StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:18:23: 18:24
+ _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13
_3 = ((_1 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13
StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22
_4 = _3; // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22
((_0 as Ok).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:18:22: 18:23
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:18:23: 18:24
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,38 @@

bb0: {
_2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14
- switchInt(move _2) -> [0isize: bb3, 1isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14
+ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14
switchInt(move _2) -> [0isize: bb3, 1isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14
}

bb1: {
- _0 = move _1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
- }
-
- bb2: {
- unreachable; // scope 0 at $DIR/simplify-arm.rs:17:11: 17:12
- }
-
- bb3: {
_0 = move _1; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
+ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
StorageLive(_5); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14
_5 = ((_1 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14
StorageLive(_6); // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24
_6 = _5; // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24
((_0 as Err).0: i32) = move _6; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
discriminant(_0) = 1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
StorageDead(_6); // scope 2 at $DIR/simplify-arm.rs:19:24: 19:25
StorageDead(_5); // scope 0 at $DIR/simplify-arm.rs:19:25: 19:26
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
}

- bb4: {
+ bb2: {
bb2: {
unreachable; // scope 0 at $DIR/simplify-arm.rs:17:11: 17:12
}

bb3: {
StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13
_3 = ((_1 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13
StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22
_4 = _3; // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22
((_0 as Ok).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:18:22: 18:23
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:18:23: 18:24
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
}

bb4: {
return; // scope 0 at $DIR/simplify-arm.rs:21:2: 21:2
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,16 @@
}

bb2: {
- StorageLive(_10); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
- _10 = ((_3 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
- _2 = _10; // scope 5 at $DIR/simplify-arm.rs:24:13: 24:15
- StorageDead(_10); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
+ _0 = move _3; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
StorageLive(_10); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
_10 = ((_3 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
_2 = _10; // scope 5 at $DIR/simplify-arm.rs:24:13: 24:15
StorageDead(_10); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16
- StorageLive(_11); // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9
- _11 = _2; // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9
- ((_0 as Ok).0: u8) = move _11; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
- discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
- StorageDead(_11); // scope 1 at $DIR/simplify-arm.rs:25:9: 25:10
StorageLive(_11); // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9
_11 = _2; // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9
((_0 as Ok).0: u8) = move _11; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
StorageDead(_11); // scope 1 at $DIR/simplify-arm.rs:25:9: 25:10
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
goto -> bb5; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@
}

bb2: {
_0 = move _3; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
StorageLive(_10); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
_10 = ((_3 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
_2 = _10; // scope 5 at $DIR/simplify-arm.rs:24:13: 24:15
StorageDead(_10); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16
StorageLive(_11); // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9
_11 = _2; // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9
((_0 as Ok).0: u8) = move _11; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
StorageDead(_11); // scope 1 at $DIR/simplify-arm.rs:25:9: 25:10
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
goto -> bb5; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
}
Expand Down
Loading