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 7 pull requests #66924

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
8f158bc
Replace .unwrap() with ? in std::os::unix::net
linkmauve Nov 12, 2019
3a2da71
Return Ok(()) in docstrings in std::os::unix::net
linkmauve Nov 13, 2019
aff7942
Also fix the signature of main in std::sys::unix::ext
linkmauve Nov 24, 2019
cdfb5cb
Add missing semicolons and question marks
linkmauve Nov 24, 2019
be18a22
Add missing main() and return value
linkmauve Nov 24, 2019
3e7a5a4
handle diverging functions forwarding their return place
RalfJung Nov 27, 2019
2869aba
comment
RalfJung Nov 27, 2019
f2bee66
Add missing check
GuillaumeGomez Nov 27, 2019
27f4d6b
Remove minification on search-index.js file
GuillaumeGomez Nov 27, 2019
baeea4e
minify theme.js as well
GuillaumeGomez Nov 27, 2019
7171060
rustc: hide HirId's fmt::Debug output from -Z span_free_formats.
eddyb Nov 28, 2019
30a9978
rustc: move MIR source_scope_local_data's ClearCrossCrate to be aroun…
eddyb Nov 26, 2019
78d85fc
rustc_mir: fix inliner to also copy over source_scope_local_data.
eddyb Nov 26, 2019
a9976d8
rustc: move mir::SourceScopeLocalData to a field of SourceScopeData.
eddyb Nov 26, 2019
02b66a1
libunwind_panic: adjust miri panic hack
RalfJung Nov 27, 2019
9034efe
rustc: don't just show raw DefIndex's in BrNamed's fmt::Debug impl.
eddyb Nov 30, 2019
507a020
Rollup merge of #66346 - linkmauve:try-in-docstring, r=Dylan-DPC
Centril Dec 1, 2019
455fdb4
Rollup merge of #66789 - eddyb:mir-source-scope-local-data, r=oli-obk
Centril Dec 1, 2019
b215445
Rollup merge of #66822 - RalfJung:miri-panic, r=oli-obk
Centril Dec 1, 2019
66284c3
Rollup merge of #66827 - RalfJung:miri-missing-ret-place, r=oli-obk
Centril Dec 1, 2019
ac8a402
Rollup merge of #66828 - GuillaumeGomez:less-minification, r=kinnison
Centril Dec 1, 2019
77aed00
Rollup merge of #66850 - eddyb:span-free-formats, r=oli-obk
Centril Dec 1, 2019
1569dab
Rollup merge of #66907 - eddyb:br-nicer-named, r=oli-obk
Centril Dec 1, 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
4 changes: 3 additions & 1 deletion src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1348,9 +1348,11 @@ extern "rust-intrinsic" {
pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;

/// Internal hook used by Miri to implement unwinding.
/// Compiles to a NOP during non-Miri codegen.
///
/// Perma-unstable: do not use
#[cfg(not(bootstrap))]
pub fn miri_start_panic(data: *mut (dyn crate::any::Any + crate::marker::Send)) -> !;
pub fn miri_start_panic(data: *mut (dyn crate::any::Any + crate::marker::Send)) -> ();
}

// Some functions are defined here because they accidentally got made
Expand Down
16 changes: 11 additions & 5 deletions src/libpanic_unwind/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ use core::raw;
use core::panic::BoxMeUp;

cfg_if::cfg_if! {
if #[cfg(miri)] {
#[path = "miri.rs"]
mod imp;
} else if #[cfg(target_os = "emscripten")] {
if #[cfg(target_os = "emscripten")] {
#[path = "emcc.rs"]
mod imp;
} else if #[cfg(target_arch = "wasm32")] {
Expand Down Expand Up @@ -94,5 +91,14 @@ pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
#[unwind(allowed)]
pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 {
let payload = payload as *mut &mut dyn BoxMeUp;
imp::panic(Box::from_raw((*payload).take_box()))
let payload = (*payload).take_box();

// Miri panic support: cfg'd out of normal builds just to be sure.
// When going through normal codegen, `miri_start_panic` is a NOP, so the
// Miri-enabled sysroot still supports normal unwinding. But when executed in
// Miri, this line initiates unwinding.
#[cfg(miri)]
core::intrinsics::miri_start_panic(payload);

imp::panic(Box::from_raw(payload))
}
42 changes: 0 additions & 42 deletions src/libpanic_unwind/miri.rs

This file was deleted.

25 changes: 17 additions & 8 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ pub struct Body<'tcx> {
/// and used for debuginfo. Indexed by a `SourceScope`.
pub source_scopes: IndexVec<SourceScope, SourceScopeData>,

/// Crate-local information for each source scope, that can't (and
/// needn't) be tracked across crates.
pub source_scope_local_data: ClearCrossCrate<IndexVec<SourceScope, SourceScopeLocalData>>,

/// The yield type of the function, if it is a generator.
pub yield_ty: Option<Ty<'tcx>>,

Expand Down Expand Up @@ -167,7 +163,6 @@ impl<'tcx> Body<'tcx> {
pub fn new(
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
source_scopes: IndexVec<SourceScope, SourceScopeData>,
source_scope_local_data: ClearCrossCrate<IndexVec<SourceScope, SourceScopeLocalData>>,
local_decls: LocalDecls<'tcx>,
user_type_annotations: CanonicalUserTypeAnnotations<'tcx>,
arg_count: usize,
Expand All @@ -188,7 +183,6 @@ impl<'tcx> Body<'tcx> {
phase: MirPhase::Build,
basic_blocks,
source_scopes,
source_scope_local_data,
yield_ty: None,
generator_drop: None,
generator_layout: None,
Expand Down Expand Up @@ -435,6 +429,13 @@ pub enum ClearCrossCrate<T> {
}

impl<T> ClearCrossCrate<T> {
pub fn as_ref(&'a self) -> ClearCrossCrate<&'a T> {
match self {
ClearCrossCrate::Clear => ClearCrossCrate::Clear,
ClearCrossCrate::Set(v) => ClearCrossCrate::Set(v),
}
}

pub fn assert_crate_local(self) -> T {
match self {
ClearCrossCrate::Clear => bug!("unwrapping cross-crate data"),
Expand Down Expand Up @@ -2027,6 +2028,10 @@ rustc_index::newtype_index! {
pub struct SourceScopeData {
pub span: Span,
pub parent_scope: Option<SourceScope>,

/// Crate-local information for this source scope, that can't (and
/// needn't) be tracked across crates.
pub local_data: ClearCrossCrate<SourceScopeLocalData>,
}

#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
Expand Down Expand Up @@ -2308,10 +2313,14 @@ impl<'tcx> Debug for Rvalue<'tcx> {
}
}

AggregateKind::Closure(def_id, _) => ty::tls::with(|tcx| {
AggregateKind::Closure(def_id, substs) => ty::tls::with(|tcx| {
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
let name = if tcx.sess.opts.debugging_opts.span_free_formats {
format!("[closure@{:?}]", hir_id)
let substs = tcx.lift(&substs).unwrap();
format!(
"[closure@{}]",
tcx.def_path_str_with_substs(def_id, substs),
)
} else {
format!("[closure@{:?}]", tcx.hir().span(hir_id))
};
Expand Down
1 change: 1 addition & 0 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ macro_rules! make_mir_visitor {
let SourceScopeData {
span,
parent_scope,
local_data: _,
} = scope_data;

self.visit_span(span);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ pub trait PrettyPrinter<'tcx>:
// FIXME(eddyb) should use `def_span`.
if let Some(hir_id) = self.tcx().hir().as_local_hir_id(did) {
if self.tcx().sess.opts.debugging_opts.span_free_formats {
p!(write("@{:?}", hir_id));
p!(write("@"), print_def_path(did, substs));
} else {
p!(write("@{:?}", self.tcx().hir().span(hir_id)));
}
Expand Down
8 changes: 6 additions & 2 deletions src/librustc/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! hand, though we've recently added some macros and proc-macros to help with the tedium.

use crate::hir::def::Namespace;
use crate::hir::def_id::CRATE_DEF_INDEX;
use crate::mir::ProjectionKind;
use crate::mir::interpret;
use crate::ty::{self, Lift, Ty, TyCtxt, InferConst};
Expand Down Expand Up @@ -95,8 +96,11 @@ impl fmt::Debug for ty::BoundRegion {
match *self {
ty::BrAnon(n) => write!(f, "BrAnon({:?})", n),
ty::BrNamed(did, name) => {
write!(f, "BrNamed({:?}:{:?}, {})",
did.krate, did.index, name)
if did.index == CRATE_DEF_INDEX {
write!(f, "BrNamed({})", name)
} else {
write!(f, "BrNamed({:?}, {})", did, name)
}
}
ty::BrEnv => write!(f, "BrEnv"),
}
Expand Down
15 changes: 4 additions & 11 deletions src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,18 +528,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
_ => FnAbi::new(&bx, sig, &extra_args)
};

// This should never be reachable at runtime:
// We should only emit a call to this intrinsic in #[cfg(miri)] mode,
// which means that we will never actually use the generate object files
// (we will just be interpreting the MIR)
//
// Note that we still need to be able to codegen *something* for this intrisnic:
// Miri currently uses Xargo to build a special libstd. As a side effect,
// we generate normal object files for libstd - while these are never used,
// we still need to be able to build them.
// For normal codegen, this Miri-specific intrinsic is just a NOP.
if intrinsic == Some("miri_start_panic") {
bx.abort();
bx.unreachable();
let target = destination.as_ref().unwrap().1;
helper.maybe_sideeffect(self.mir, &mut bx, &[target]);
helper.funclet_br(self, &mut bx, target);
return;
}

Expand Down
67 changes: 34 additions & 33 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,10 @@ fn do_mir_borrowck<'a, 'tcx>(
let mut initial_diag =
mbcx.report_conflicting_borrow(location, (&place, span), bk, &borrow);

let lint_root = if let ClearCrossCrate::Set(ref vsi) = mbcx.body.source_scope_local_data {
let scope = mbcx.body.source_info(location).scope;
vsi[scope].lint_root
} else {
id
let scope = mbcx.body.source_info(location).scope;
let lint_root = match &mbcx.body.source_scopes[scope].local_data {
ClearCrossCrate::Set(data) => data.lint_root,
_ => id,
};

// Span and message don't matter; we overwrite them below anyway
Expand Down Expand Up @@ -338,38 +337,40 @@ fn do_mir_borrowck<'a, 'tcx>(
debug!("mbcx.used_mut: {:?}", mbcx.used_mut);
let used_mut = mbcx.used_mut;
for local in mbcx.body.mut_vars_and_args_iter().filter(|local| !used_mut.contains(local)) {
if let ClearCrossCrate::Set(ref vsi) = mbcx.body.source_scope_local_data {
let local_decl = &mbcx.body.local_decls[local];

// Skip over locals that begin with an underscore or have no name
match mbcx.local_names[local] {
Some(name) => if name.as_str().starts_with("_") {
continue;
},
None => continue,
}
let local_decl = &mbcx.body.local_decls[local];
let lint_root = match &mbcx.body.source_scopes[local_decl.source_info.scope].local_data {
ClearCrossCrate::Set(data) => data.lint_root,
_ => continue,
};

let span = local_decl.source_info.span;
if span.desugaring_kind().is_some() {
// If the `mut` arises as part of a desugaring, we should ignore it.
// Skip over locals that begin with an underscore or have no name
match mbcx.local_names[local] {
Some(name) => if name.as_str().starts_with("_") {
continue;
}
},
None => continue,
}

let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);
tcx.struct_span_lint_hir(
UNUSED_MUT,
vsi[local_decl.source_info.scope].lint_root,
span,
"variable does not need to be mutable",
)
.span_suggestion_short(
mut_span,
"remove this `mut`",
String::new(),
Applicability::MachineApplicable,
)
.emit();
let span = local_decl.source_info.span;
if span.desugaring_kind().is_some() {
// If the `mut` arises as part of a desugaring, we should ignore it.
continue;
}

let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);
tcx.struct_span_lint_hir(
UNUSED_MUT,
lint_root,
span,
"variable does not need to be mutable",
)
.span_suggestion_short(
mut_span,
"remove this `mut`",
String::new(),
Applicability::MachineApplicable,
)
.emit();
}

// Buffer any move errors that we collected and de-duplicated.
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_mir/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ struct Builder<'a, 'tcx> {
/// The vector of all scopes that we have created thus far;
/// we track this for debuginfo later.
source_scopes: IndexVec<SourceScope, SourceScopeData>,
source_scope_local_data: IndexVec<SourceScope, SourceScopeLocalData>,
source_scope: SourceScope,

/// The guard-context: each time we build the guard expression for
Expand Down Expand Up @@ -704,7 +703,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block_context: BlockContext::new(),
source_scopes: IndexVec::new(),
source_scope: OUTERMOST_SOURCE_SCOPE,
source_scope_local_data: IndexVec::new(),
guard_context: vec![],
push_unsafe_count: 0,
unpushed_unsafe: safety,
Expand Down Expand Up @@ -741,7 +739,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Body::new(
self.cfg.basic_blocks,
self.source_scopes,
ClearCrossCrate::Set(self.source_scope_local_data),
self.local_decls,
self.canonical_user_type_annotations,
self.arg_count,
Expand Down Expand Up @@ -942,7 +939,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.hir.root_lint_level
);
let parent_root = tcx.maybe_lint_level_root_bounded(
self.source_scope_local_data[original_source_scope].lint_root,
self.source_scopes[original_source_scope]
.local_data
.as_ref()
.assert_crate_local()
.lint_root,
self.hir.root_lint_level,
);
if current_root != parent_root {
Expand Down
23 changes: 13 additions & 10 deletions src/librustc_mir/build/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// We estimate the true lint roots here to avoid creating a lot of source scopes.

let parent_root = tcx.maybe_lint_level_root_bounded(
self.source_scope_local_data[source_scope].lint_root,
self.source_scopes[source_scope]
.local_data
.as_ref()
.assert_crate_local()
.lint_root,
self.hir.root_lint_level,
);
let current_root = tcx.maybe_lint_level_root_bounded(
Expand Down Expand Up @@ -654,23 +658,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let parent = self.source_scope;
debug!("new_source_scope({:?}, {:?}, {:?}) - parent({:?})={:?}",
span, lint_level, safety,
parent, self.source_scope_local_data.get(parent));
let scope = self.source_scopes.push(SourceScopeData {
span,
parent_scope: Some(parent),
});
parent, self.source_scopes.get(parent));
let scope_local_data = SourceScopeLocalData {
lint_root: if let LintLevel::Explicit(lint_root) = lint_level {
lint_root
} else {
self.source_scope_local_data[parent].lint_root
self.source_scopes[parent].local_data.as_ref().assert_crate_local().lint_root
},
safety: safety.unwrap_or_else(|| {
self.source_scope_local_data[parent].safety
self.source_scopes[parent].local_data.as_ref().assert_crate_local().safety
})
};
self.source_scope_local_data.push(scope_local_data);
scope
self.source_scopes.push(SourceScopeData {
span,
parent_scope: Some(parent),
local_data: ClearCrossCrate::Set(scope_local_data),
})
}

/// Given a span and the current source scope, make a SourceInfo.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
} else {
block.terminator().source_info
};
match body.source_scope_local_data {
mir::ClearCrossCrate::Set(ref ivs) => Some(ivs[source_info.scope].lint_root),
match &body.source_scopes[source_info.scope].local_data {
mir::ClearCrossCrate::Set(data) => Some(data.lint_root),
mir::ClearCrossCrate::Clear => None,
}
});
Expand Down
Loading