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 #73064

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
58ae4a9
de-promote Duration::from_secs
RalfJung May 2, 2020
071f042
linker: Add a linker rerun hack for gcc versions not supporting -stat…
petrochenkov May 28, 2020
7242bda
Be more careful around ty::Error in generators
jonas-schievink May 30, 2020
eaa57cf
`PolyTraitRef::self_ty` returns `Binder<Ty>`
ecstatic-morse May 23, 2020
b4e06b9
Call `skip_binder` or `no_bound_vars` before `self_ty`
ecstatic-morse May 23, 2020
95e9768
test: codegen: skip tests inappropriate for riscv64
tblah May 20, 2020
c872dcf
test: codegen: riscv64-abi: print value numbers for unnamed func args
tblah Jun 4, 2020
37e8e05
test: codegen: Add riscv abi llvm intrinsics test
tblah Jun 4, 2020
08529af
test: codegen: skip catch-unwind on riscv64
tblah Jun 4, 2020
94605b9
run-make regression test for issue #70924.
pnkfelix Jun 3, 2020
b541d3d
Add `-Z span-debug` to allow for easier debugging of proc macros
Aaron1011 May 31, 2020
2764e54
impl ToSocketAddrs for (String, u16)
yoshuawuyts Jun 4, 2020
a9d5dff
Ignore windows in the test.
pnkfelix Jun 5, 2020
32c488f
remove outdated comment
lcnr Jun 6, 2020
1063d8a
Rollup merge of #71796 - RalfJung:from-secs, r=nikomatsakis
RalfJung Jun 6, 2020
6901d34
Rollup merge of #72508 - ecstatic-morse:poly-self-ty, r=nikomatsakis
RalfJung Jun 6, 2020
64defa4
Rollup merge of #72708 - petrochenkov:linkhack, r=cuviper
RalfJung Jun 6, 2020
c8e177b
Rollup merge of #72764 - jonas-schievink:mind-the-tyerr, r=estebank
RalfJung Jun 6, 2020
af8aabf
Rollup merge of #72799 - Aaron1011:feature/span-debug, r=petrochenkov
RalfJung Jun 6, 2020
d99ab70
Rollup merge of #72952 - pnkfelix:regression-test-for-issue-70924, r=…
RalfJung Jun 6, 2020
3b588a6
Rollup merge of #72977 - tblah:riscv-codegen-llvm10, r=nikomatsakis
RalfJung Jun 6, 2020
1873e8d
Rollup merge of #73007 - yoshuawuyts:socketaddr-from-string-u16, r=sf…
RalfJung Jun 6, 2020
5c3bc43
Rollup merge of #73059 - lcnr:outdated-comment, r=matthewjasper
RalfJung Jun 6, 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
1 change: 0 additions & 1 deletion src/libcore/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ impl Duration {
/// ```
#[stable(feature = "duration", since = "1.3.0")]
#[inline]
#[rustc_promotable]
#[rustc_const_stable(feature = "duration_consts", since = "1.32.0")]
pub const fn from_secs(secs: u64) -> Duration {
Duration { secs, nanos: 0 }
Expand Down
65 changes: 57 additions & 8 deletions src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_session::utils::NativeLibKind;
/// need out of the shared crate context before we get rid of it.
use rustc_session::{filesearch, Session};
use rustc_span::symbol::Symbol;
use rustc_target::spec::crt_objects::CrtObjectsFallback;
use rustc_target::spec::crt_objects::{CrtObjects, CrtObjectsFallback};
use rustc_target::spec::{LinkOutputKind, LinkerFlavor, LldFlavor};
use rustc_target::spec::{PanicStrategy, RelocModel, RelroLevel};

Expand All @@ -25,16 +25,10 @@ use crate::{looks_like_rust_object_file, CodegenResults, CrateInfo, METADATA_FIL
use cc::windows_registry;
use tempfile::{Builder as TempFileBuilder, TempDir};

use std::ascii;
use std::char;
use std::env;
use std::ffi::OsString;
use std::fmt;
use std::fs;
use std::io;
use std::path::{Path, PathBuf};
use std::process::{ExitStatus, Output, Stdio};
use std::str;
use std::{ascii, char, env, fmt, fs, io, mem, str};

pub fn remove(sess: &Session, path: &Path) {
if let Err(e) = fs::remove_file(path) {
Expand Down Expand Up @@ -543,6 +537,61 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
continue;
}

// Detect '-static-pie' used with an older version of gcc or clang not supporting it.
// Fallback from '-static-pie' to '-static' in that case.
if sess.target.target.options.linker_is_gnu
&& flavor != LinkerFlavor::Ld
&& (out.contains("unrecognized command line option")
|| out.contains("unknown argument"))
&& (out.contains("-static-pie") || out.contains("--no-dynamic-linker"))
&& cmd.get_args().iter().any(|e| e.to_string_lossy() == "-static-pie")
{
info!("linker output: {:?}", out);
warn!(
"Linker does not support -static-pie command line option. Retrying with -static instead."
);
// Mirror `add_(pre,post)_link_objects` to replace CRT objects.
let fallback = crt_objects_fallback(sess, crate_type);
let opts = &sess.target.target.options;
let pre_objects =
if fallback { &opts.pre_link_objects_fallback } else { &opts.pre_link_objects };
let post_objects =
if fallback { &opts.post_link_objects_fallback } else { &opts.post_link_objects };
let get_objects = |objects: &CrtObjects, kind| {
objects
.get(&kind)
.iter()
.copied()
.flatten()
.map(|obj| get_object_file_path(sess, obj).into_os_string())
.collect::<Vec<_>>()
};
let pre_objects_static_pie = get_objects(pre_objects, LinkOutputKind::StaticPicExe);
let post_objects_static_pie = get_objects(post_objects, LinkOutputKind::StaticPicExe);
let mut pre_objects_static = get_objects(pre_objects, LinkOutputKind::StaticNoPicExe);
let mut post_objects_static = get_objects(post_objects, LinkOutputKind::StaticNoPicExe);
// Assume that we know insertion positions for the replacement arguments from replaced
// arguments, which is true for all supported targets.
assert!(pre_objects_static.is_empty() || !pre_objects_static_pie.is_empty());
assert!(post_objects_static.is_empty() || !post_objects_static_pie.is_empty());
for arg in cmd.take_args() {
if arg.to_string_lossy() == "-static-pie" {
// Replace the output kind.
cmd.arg("-static");
} else if pre_objects_static_pie.contains(&arg) {
// Replace the pre-link objects (replace the first and remove the rest).
cmd.args(mem::take(&mut pre_objects_static));
} else if post_objects_static_pie.contains(&arg) {
// Replace the post-link objects (replace the first and remove the rest).
cmd.args(mem::take(&mut post_objects_static));
} else {
cmd.arg(arg);
}
}
info!("{:?}", &cmd);
continue;
}

// Here's a terribly awful hack that really shouldn't be present in any
// compiler. Here an environment variable is supported to automatically
// retry the linker invocation if the linker looks like it segfaulted.
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_expand/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,7 @@ pub struct ExpansionConfig<'feat> {
pub trace_mac: bool,
pub should_test: bool, // If false, strip `#[test]` nodes
pub keep_macs: bool,
pub span_debug: bool, // If true, use verbose debugging for `proc_macro::Span`
}

impl<'feat> ExpansionConfig<'feat> {
Expand All @@ -1800,6 +1801,7 @@ impl<'feat> ExpansionConfig<'feat> {
trace_mac: false,
should_test: false,
keep_macs: false,
span_debug: false,
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/librustc_expand/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ pub(crate) struct Rustc<'a> {
def_site: Span,
call_site: Span,
mixed_site: Span,
span_debug: bool,
}

impl<'a> Rustc<'a> {
Expand All @@ -362,6 +363,7 @@ impl<'a> Rustc<'a> {
def_site: cx.with_def_site_ctxt(expn_data.def_site),
call_site: cx.with_call_site_ctxt(expn_data.call_site),
mixed_site: cx.with_mixed_site_ctxt(expn_data.call_site),
span_debug: cx.ecfg.span_debug,
}
}

Expand Down Expand Up @@ -646,7 +648,11 @@ impl server::Diagnostic for Rustc<'_> {

impl server::Span for Rustc<'_> {
fn debug(&mut self, span: Self::Span) -> String {
format!("{:?} bytes({}..{})", span.ctxt(), span.lo().0, span.hi().0)
if self.span_debug {
format!("{:?}", span)
} else {
format!("{:?} bytes({}..{})", span.ctxt(), span.lo().0, span.hi().0)
}
}
fn def_site(&mut self) -> Self::Span {
self.def_site
Expand Down
1 change: 1 addition & 0 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ fn configure_and_expand_inner<'a>(
recursion_limit: sess.recursion_limit(),
trace_mac: sess.opts.debugging_opts.trace_macros,
should_test: sess.opts.test,
span_debug: sess.opts.debugging_opts.span_debug,
..rustc_expand::expand::ExpansionConfig::default(crate_name.to_string())
};

Expand Down
1 change: 1 addition & 0 deletions src/librustc_interface/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ fn test_debugging_options_tracking_hash() {
untracked!(save_analysis, true);
untracked!(self_profile, SwitchWithOptPath::Enabled(None));
untracked!(self_profile_events, Some(vec![String::new()]));
untracked!(span_debug, true);
untracked!(span_free_formats, true);
untracked!(strip, Strip::None);
untracked!(terminal_width, Some(80));
Expand Down
8 changes: 2 additions & 6 deletions src/librustc_middle/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,6 @@ impl<'tcx> Binder<&'tcx List<ExistentialPredicate<'tcx>>> {
///
/// Trait references also appear in object types like `Foo<U>`, but in
/// that case the `Self` parameter is absent from the substitutions.
///
/// Note that a `TraitRef` introduces a level of region binding, to
/// account for higher-ranked trait bounds like `T: for<'a> Foo<&'a U>`
/// or higher-ranked object types.
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
#[derive(HashStable, TypeFoldable)]
pub struct TraitRef<'tcx> {
Expand Down Expand Up @@ -765,8 +761,8 @@ impl<'tcx> TraitRef<'tcx> {
pub type PolyTraitRef<'tcx> = Binder<TraitRef<'tcx>>;

impl<'tcx> PolyTraitRef<'tcx> {
pub fn self_ty(&self) -> Ty<'tcx> {
self.skip_binder().self_ty()
pub fn self_ty(&self) -> Binder<Ty<'tcx>> {
self.map_bound_ref(|tr| tr.self_ty())
}

pub fn def_id(&self) -> DefId {
Expand Down
69 changes: 43 additions & 26 deletions src/librustc_mir/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,40 +669,33 @@ fn compute_storage_conflicts(
storage_conflicts
}

fn compute_layout<'tcx>(
/// Validates the typeck view of the generator against the actual set of types retained between
/// yield points.
fn sanitize_witness<'tcx>(
tcx: TyCtxt<'tcx>,
source: MirSource<'tcx>,
body: &Body<'tcx>,
did: DefId,
witness: Ty<'tcx>,
upvars: &Vec<Ty<'tcx>>,
interior: Ty<'tcx>,
always_live_locals: &storage::AlwaysLiveLocals,
movable: bool,
body: &mut Body<'tcx>,
) -> (
FxHashMap<Local, (Ty<'tcx>, VariantIdx, usize)>,
GeneratorLayout<'tcx>,
IndexVec<BasicBlock, Option<BitSet<Local>>>,
retained: &BitSet<Local>,
) {
// Use a liveness analysis to compute locals which are live across a suspension point
let LivenessInfo {
live_locals,
live_locals_at_suspension_points,
storage_conflicts,
storage_liveness,
} = locals_live_across_suspend_points(tcx, body, source, always_live_locals, movable);

// Erase regions from the types passed in from typeck so we can compare them with
// MIR types
let allowed_upvars = tcx.erase_regions(upvars);
let allowed = match interior.kind {
let allowed = match witness.kind {
ty::GeneratorWitness(s) => tcx.erase_late_bound_regions(&s),
_ => bug!(),
_ => {
tcx.sess.delay_span_bug(
body.span,
&format!("unexpected generator witness type {:?}", witness.kind),
);
return;
}
};

let param_env = tcx.param_env(source.def_id());
let param_env = tcx.param_env(did);

for (local, decl) in body.local_decls.iter_enumerated() {
// Ignore locals which are internal or not live
if !live_locals.contains(local) || decl.internal {
// Ignore locals which are internal or not retained between yields.
if !retained.contains(local) || decl.internal {
continue;
}
let decl_ty = tcx.normalize_erasing_regions(param_env, decl.ty);
Expand All @@ -715,10 +708,34 @@ fn compute_layout<'tcx>(
"Broken MIR: generator contains type {} in MIR, \
but typeck only knows about {}",
decl.ty,
interior
witness,
);
}
}
}

fn compute_layout<'tcx>(
tcx: TyCtxt<'tcx>,
source: MirSource<'tcx>,
upvars: &Vec<Ty<'tcx>>,
interior: Ty<'tcx>,
always_live_locals: &storage::AlwaysLiveLocals,
movable: bool,
body: &mut Body<'tcx>,
) -> (
FxHashMap<Local, (Ty<'tcx>, VariantIdx, usize)>,
GeneratorLayout<'tcx>,
IndexVec<BasicBlock, Option<BitSet<Local>>>,
) {
// Use a liveness analysis to compute locals which are live across a suspension point
let LivenessInfo {
live_locals,
live_locals_at_suspension_points,
storage_conflicts,
storage_liveness,
} = locals_live_across_suspend_points(tcx, body, source, always_live_locals, movable);

sanitize_witness(tcx, body, source.def_id(), interior, upvars, &live_locals);

// Gather live local types and their indices.
let mut locals = IndexVec::<GeneratorSavedLocal, _>::new();
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_session/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"make the current crate share its generic instantiations"),
show_span: Option<String> = (None, parse_opt_string, [TRACKED],
"show spans for compiler debugging (expr|pat|ty)"),
span_debug: bool = (false, parse_bool, [UNTRACKED],
"forward proc_macro::Span's `Debug` impl to `Span`"),
// o/w tests have closure@path
span_free_formats: bool = (false, parse_bool, [UNTRACKED],
"exclude spans when debug-printing compiler state (default: no)"),
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_target/spec/tests/tests_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@ impl Target {
assert_eq!(self.options.lld_flavor, LldFlavor::Link);
}
}
assert!(
(self.options.pre_link_objects_fallback.is_empty()
&& self.options.post_link_objects_fallback.is_empty())
|| self.options.crt_objects_fallback.is_some()
);
}
}
32 changes: 21 additions & 11 deletions src/librustc_trait_selection/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
(
Some(format!(
"`?` couldn't convert the error to `{}`",
trait_ref.self_ty(),
trait_ref.skip_binder().self_ty(),
)),
Some(
"the question mark operation (`?`) implicitly performs a \
Expand Down Expand Up @@ -340,7 +340,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
if let Some(ret_span) = self.return_type_span(obligation) {
err.span_label(
ret_span,
&format!("expected `{}` because of this", trait_ref.self_ty()),
&format!(
"expected `{}` because of this",
trait_ref.skip_binder().self_ty()
),
);
}
}
Expand All @@ -353,7 +356,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
"{}the trait `{}` is not implemented for `{}`",
pre_message,
trait_ref.print_only_trait_path(),
trait_ref.self_ty(),
trait_ref.skip_binder().self_ty(),
)
};

Expand Down Expand Up @@ -643,7 +646,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
return;
}

let found_trait_ty = found_trait_ref.self_ty();
let found_trait_ty = match found_trait_ref.self_ty().no_bound_vars() {
Some(ty) => ty,
None => return,
};

let found_did = match found_trait_ty.kind {
ty::Closure(did, _) | ty::Foreign(did) | ty::FnDef(did, _) => Some(did),
Expand Down Expand Up @@ -1360,11 +1366,15 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
) {
let get_trait_impl = |trait_def_id| {
let mut trait_impl = None;
self.tcx.for_each_relevant_impl(trait_def_id, trait_ref.self_ty(), |impl_def_id| {
if trait_impl.is_none() {
trait_impl = Some(impl_def_id);
}
});
self.tcx.for_each_relevant_impl(
trait_def_id,
trait_ref.skip_binder().self_ty(),
|impl_def_id| {
if trait_impl.is_none() {
trait_impl = Some(impl_def_id);
}
},
);
trait_impl
};
let required_trait_path = self.tcx.def_path_str(trait_ref.def_id());
Expand Down Expand Up @@ -1435,7 +1445,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
let mut err = match predicate.kind() {
ty::PredicateKind::Trait(ref data, _) => {
let trait_ref = data.to_poly_trait_ref();
let self_ty = trait_ref.self_ty();
let self_ty = trait_ref.skip_binder().self_ty();
debug!("self_ty {:?} {:?} trait_ref {:?}", self_ty, self_ty.kind, trait_ref);

if predicate.references_error() {
Expand Down Expand Up @@ -1564,7 +1574,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
}
ty::PredicateKind::Projection(ref data) => {
let trait_ref = data.to_poly_trait_ref(self.tcx);
let self_ty = trait_ref.self_ty();
let self_ty = trait_ref.skip_binder().self_ty();
let ty = data.skip_binder().ty;
if predicate.references_error() {
return;
Expand Down
Loading