Skip to content

Commit

Permalink
Auto merge of #73669 - Manishearth:rollup-0n4u7vq, r=Manishearth
Browse files Browse the repository at this point in the history
Rollup of 11 pull requests

Successful merges:

 - #72780 (Enforce doc alias check)
 - #72876 (Mention that BTreeMap::new() doesn't allocate)
 - #73244 (Check for assignments between non-conflicting generator saved locals)
 - #73488 (code coverage foundation for hash and num_counters)
 - #73523 (Fix -Z unpretty=everybody_loops)
 - #73587 (Move remaining `NodeId` APIs from `Definitions` to `Resolver`)
 - #73601 (Point at the call span when overflow occurs during monomorphization)
 - #73613 (The const propagator cannot trace references.)
 - #73614 (fix `intrinsics::needs_drop` docs)
 - #73630 (Provide context on E0308 involving fn items)
 - #73665 (rustc: Modernize wasm checks for atomics)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Jun 23, 2020
2 parents ff5b446 + 6ed6a84 commit 0c04344
Show file tree
Hide file tree
Showing 62 changed files with 1,217 additions and 536 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4200,6 +4200,7 @@ dependencies = [
"rustc_expand",
"rustc_feature",
"rustc_hir",
"rustc_index",
"rustc_metadata",
"rustc_middle",
"rustc_session",
Expand Down
2 changes: 2 additions & 0 deletions src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ struct MergeIter<K, V, I: Iterator<Item = (K, V)>> {
impl<K: Ord, V> BTreeMap<K, V> {
/// Makes a new empty BTreeMap with a reasonable choice for B.
///
/// Does not allocate anything on its own.
///
/// # Examples
///
/// Basic usage:
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ extern "rust-intrinsic" {
/// implements `Copy`.
///
/// If the actual type neither requires drop glue nor implements
/// `Copy`, then may return `true` or `false`.
/// `Copy`, then the return value of this function is unspecified.
///
/// The stabilized version of this intrinsic is
/// [`std::mem::needs_drop`](../../std/mem/fn.needs_drop.html).
Expand Down
17 changes: 6 additions & 11 deletions src/librustc_ast_lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::ItemKind::Const(ty, body_id)
}
ItemKind::Fn(_, FnSig { ref decl, header }, ref generics, ref body) => {
let fn_def_id = self.resolver.definitions().local_def_id(id);
let fn_def_id = self.resolver.local_def_id(id);
self.with_new_scopes(|this| {
this.current_item = Some(ident.span);

Expand Down Expand Up @@ -342,7 +342,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
self_ty: ref ty,
items: ref impl_items,
} => {
let def_id = self.resolver.definitions().local_def_id(id);
let def_id = self.resolver.local_def_id(id);

// Lower the "impl header" first. This ordering is important
// for in-band lifetimes! Consider `'a` here:
Expand Down Expand Up @@ -646,7 +646,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem<'hir> {
let def_id = self.resolver.definitions().local_def_id(i.id);
let def_id = self.resolver.local_def_id(i.id);
hir::ForeignItem {
hir_id: self.lower_node_id(i.id),
ident: i.ident,
Expand Down Expand Up @@ -747,7 +747,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

fn lower_trait_item(&mut self, i: &AssocItem) -> hir::TraitItem<'hir> {
let trait_item_def_id = self.resolver.definitions().local_def_id(i.id);
let trait_item_def_id = self.resolver.local_def_id(i.id);

let (generics, kind) = match i.kind {
AssocItemKind::Const(_, ref ty, ref default) => {
Expand Down Expand Up @@ -812,7 +812,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

fn lower_impl_item(&mut self, i: &AssocItem) -> hir::ImplItem<'hir> {
let impl_item_def_id = self.resolver.definitions().local_def_id(i.id);
let impl_item_def_id = self.resolver.local_def_id(i.id);

let (generics, kind) = match &i.kind {
AssocItemKind::Const(_, ty, expr) => {
Expand Down Expand Up @@ -1320,12 +1320,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
if let Some(def_id) = def_id.as_local() {
for param in &generics.params {
if let GenericParamKind::Type { .. } = param.kind {
if def_id
== self
.resolver
.definitions()
.local_def_id(param.id)
{
if def_id == self.resolver.local_def_id(param.id) {
add_bounds
.entry(param.id)
.or_default()
Expand Down
52 changes: 38 additions & 14 deletions src/librustc_ast_lowering/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX};
use rustc_hir::definitions::{DefKey, DefPathData, Definitions};
use rustc_hir::intravisit;
use rustc_hir::{ConstArg, GenericArg, ParamName};
use rustc_index::vec::IndexVec;
use rustc_index::vec::{Idx, IndexVec};
use rustc_session::config::nightly_options;
use rustc_session::lint::{builtin::BARE_TRAIT_OBJECTS, BuiltinLintDiagnostics, LintBuffer};
use rustc_session::parse::ParseSess;
Expand Down Expand Up @@ -205,6 +205,19 @@ pub trait Resolver {
fn next_node_id(&mut self) -> NodeId;

fn trait_map(&self) -> &NodeMap<Vec<hir::TraitCandidate>>;

fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId>;

fn local_def_id(&self, node: NodeId) -> LocalDefId;

fn create_def(
&mut self,
parent: LocalDefId,
node_id: ast::NodeId,
data: DefPathData,
expn_id: ExpnId,
span: Span,
) -> LocalDefId;
}

type NtToTokenstream = fn(&Nonterminal, &ParseSess, Span) -> TokenStream;
Expand Down Expand Up @@ -436,7 +449,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
match tree.kind {
UseTreeKind::Simple(_, id1, id2) => {
for &id in &[id1, id2] {
self.lctx.resolver.definitions().create_def_with_parent(
self.lctx.resolver.create_def(
owner,
id,
DefPathData::Misc,
Expand Down Expand Up @@ -488,7 +501,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
| ItemKind::Enum(_, ref generics)
| ItemKind::TyAlias(_, ref generics, ..)
| ItemKind::Trait(_, _, ref generics, ..) => {
let def_id = self.lctx.resolver.definitions().local_def_id(item.id);
let def_id = self.lctx.resolver.local_def_id(item.id);
let count = generics
.params
.iter()
Expand Down Expand Up @@ -564,7 +577,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
.map(|(&k, v)| (self.node_id_to_hir_id[k].unwrap(), v.clone()))
.collect();

self.resolver.definitions().init_node_id_to_hir_id_mapping(self.node_id_to_hir_id);
let mut def_id_to_hir_id = IndexVec::default();

for (node_id, hir_id) in self.node_id_to_hir_id.into_iter_enumerated() {
if let Some(def_id) = self.resolver.opt_local_def_id(node_id) {
if def_id_to_hir_id.len() <= def_id.index() {
def_id_to_hir_id.resize(def_id.index() + 1, None);
}
def_id_to_hir_id[def_id] = hir_id;
}
}

self.resolver.definitions().init_def_id_to_hir_id_mapping(def_id_to_hir_id);

hir::Crate {
item: hir::CrateItem { module, attrs, span: c.span },
Expand Down Expand Up @@ -628,7 +652,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
.item_local_id_counters
.insert(owner, HIR_ID_COUNTER_LOCKED)
.unwrap_or_else(|| panic!("no `item_local_id_counters` entry for {:?}", owner));
let def_id = self.resolver.definitions().local_def_id(owner);
let def_id = self.resolver.local_def_id(owner);
self.current_hir_id_owner.push((def_id, counter));
let ret = f(self);
let (new_def_id, new_counter) = self.current_hir_id_owner.pop().unwrap();
Expand Down Expand Up @@ -671,8 +695,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
debug_assert!(local_id != HIR_ID_COUNTER_LOCKED);

*local_id_counter += 1;
let owner = this.resolver.definitions().opt_local_def_id(owner).expect(
"you forgot to call `create_def_with_parent` or are lowering node-IDs \
let owner = this.resolver.opt_local_def_id(owner).expect(
"you forgot to call `create_def` or are lowering node-IDs \
that do not belong to the current owner",
);

Expand Down Expand Up @@ -800,7 +824,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
};

// Add a definition for the in-band lifetime def.
self.resolver.definitions().create_def_with_parent(
self.resolver.create_def(
parent_def_id,
node_id,
DefPathData::LifetimeNs(str_name),
Expand Down Expand Up @@ -1088,7 +1112,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

let impl_trait_node_id = self.resolver.next_node_id();
let parent_def_id = self.current_hir_id_owner.last().unwrap().0;
self.resolver.definitions().create_def_with_parent(
self.resolver.create_def(
parent_def_id,
impl_trait_node_id,
DefPathData::ImplTrait,
Expand Down Expand Up @@ -1154,7 +1178,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let node_id = self.resolver.next_node_id();

// Add a definition for the in-band const def.
self.resolver.definitions().create_def_with_parent(
self.resolver.create_def(
parent_def_id,
node_id,
DefPathData::AnonConst,
Expand Down Expand Up @@ -1339,7 +1363,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
ImplTraitContext::Universal(in_band_ty_params) => {
// Add a definition for the in-band `Param`.
let def_id = self.resolver.definitions().local_def_id(def_node_id);
let def_id = self.resolver.local_def_id(def_node_id);

let hir_bounds = self.lower_param_bounds(
bounds,
Expand Down Expand Up @@ -1428,7 +1452,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// frequently opened issues show.
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::OpaqueTy, span, None);

let opaque_ty_def_id = self.resolver.definitions().local_def_id(opaque_ty_node_id);
let opaque_ty_def_id = self.resolver.local_def_id(opaque_ty_node_id);

self.allocate_hir_id_counter(opaque_ty_node_id);

Expand Down Expand Up @@ -1620,7 +1644,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let def_node_id = self.context.resolver.next_node_id();
let hir_id =
self.context.lower_node_id_with_owner(def_node_id, self.opaque_ty_id);
self.context.resolver.definitions().create_def_with_parent(
self.context.resolver.create_def(
self.parent,
def_node_id,
DefPathData::LifetimeNs(name.ident().name),
Expand Down Expand Up @@ -1870,7 +1894,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::Async, span, None);

let opaque_ty_def_id = self.resolver.definitions().local_def_id(opaque_ty_node_id);
let opaque_ty_def_id = self.resolver.local_def_id(opaque_ty_node_id);

self.allocate_hir_id_counter(opaque_ty_node_id);

Expand Down
3 changes: 2 additions & 1 deletion src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use rustc_middle::bug;
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{self, Lto, OutputType, Passes, SanitizerSet, SwitchWithOptPath};
use rustc_session::Session;
use rustc_span::symbol::sym;
use rustc_span::InnerSpan;
use rustc_target::spec::{CodeModel, RelocModel};

Expand Down Expand Up @@ -140,7 +141,7 @@ pub fn target_machine_factory(
// lower atomic operations to single-threaded operations.
if singlethread
&& sess.target.target.llvm_target.contains("wasm32")
&& features.iter().any(|s| *s == "+atomics")
&& sess.target_features.contains(&sym::atomics)
{
singlethread = false;
}
Expand Down
35 changes: 14 additions & 21 deletions src/librustc_codegen_llvm/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use rustc_middle::ty::layout::{FnAbiExt, HasTyCtxt};
use rustc_middle::ty::{self, Ty};
use rustc_middle::{bug, span_bug};
use rustc_span::Span;
use rustc_span::Symbol;
use rustc_target::abi::{self, HasDataLayout, LayoutOf, Primitive};
use rustc_target::spec::PanicStrategy;

Expand Down Expand Up @@ -141,26 +140,20 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
self.call(llfn, &[], None)
}
"count_code_region" => {
if let ty::InstanceDef::Item(fn_def_id) = caller_instance.def {
let caller_fn_path = tcx.def_path_str(fn_def_id);
debug!(
"count_code_region to llvm.instrprof.increment(fn_name={})",
caller_fn_path
);

// FIXME(richkadel): (1) Replace raw function name with mangled function name;
// (2) Replace hardcoded `1234` in `hash` with a computed hash (as discussed in)
// the MCP (compiler-team/issues/278); and replace the hardcoded `1` for
// `num_counters` with the actual number of counters per function (when the
// changes are made to inject more than one counter per function).
let (fn_name, _len_val) = self.const_str(Symbol::intern(&caller_fn_path));
let index = args[0].immediate();
let hash = self.const_u64(1234);
let num_counters = self.const_u32(1);
self.instrprof_increment(fn_name, hash, num_counters, index)
} else {
bug!("intrinsic count_code_region: no src.instance");
}
// FIXME(richkadel): The current implementation assumes the MIR for the given
// caller_instance represents a single function. Validate and/or correct if inlining
// and/or monomorphization invalidates these assumptions.
let coverage_data = tcx.coverage_data(caller_instance.def_id());
let mangled_fn = tcx.symbol_name(caller_instance);
let (mangled_fn_name, _len_val) = self.const_str(mangled_fn.name);
let hash = self.const_u64(coverage_data.hash);
let num_counters = self.const_u32(coverage_data.num_counters);
let index = args[0].immediate();
debug!(
"count_code_region to LLVM intrinsic instrprof.increment(fn_name={}, hash={:?}, num_counters={:?}, index={:?})",
mangled_fn.name, hash, num_counters, index
);
self.instrprof_increment(mangled_fn_name, hash, num_counters, index)
}
"va_start" => self.va_start(args[0].immediate()),
"va_end" => self.va_end(args[0].immediate()),
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_codegen_ssa/back/linker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::archive;
use super::command::Command;
use super::symbol_export;
use rustc_span::symbol::sym;

use std::ffi::{OsStr, OsString};
use std::fs::{self, File};
Expand Down Expand Up @@ -1036,9 +1037,7 @@ impl<'a> WasmLd<'a> {
//
// * `--export=*tls*` - when `#[thread_local]` symbols are used these
// symbols are how the TLS segments are initialized and configured.
let atomics = sess.opts.cg.target_feature.contains("+atomics")
|| sess.target.target.options.features.contains("+atomics");
if atomics {
if sess.target_features.contains(&sym::atomics) {
cmd.arg("--shared-memory");
cmd.arg("--max-memory=1073741824");
cmd.arg("--import-memory");
Expand Down
1 change: 1 addition & 0 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ pub fn run_compiler(
compiler.output_file().as_ref().map(|p| &**p),
);
}
trace!("finished pretty-printing");
return early_exit();
}

Expand Down
Loading

0 comments on commit 0c04344

Please sign in to comment.