Skip to content

Rollup of 15 pull requests #48510

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

Merged
merged 47 commits into from
Feb 24, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ae46434
Remove "static item recursion checking" in favor of relying on cycle …
Zoxc Feb 3, 2018
46a3f2f
Change error message for E0391 to "cyclic dependency detected"
Zoxc Feb 9, 2018
335e25f
incr.comp.: Don't keep RefCells in on-disk-cache borrowed in order to…
michaelwoerister Feb 13, 2018
75f72c0
Make nested impl Trait a hard error
cramertj Feb 8, 2018
70e1f4f
Disallow projections from impl Trait types
cramertj Feb 9, 2018
f1fbf79
Amend nested impl Trait error message
cramertj Feb 14, 2018
dbacf0c
Test err on impl Trait projection within dyn Trait
cramertj Feb 14, 2018
d4b8475
incr.comp.: Store DepNode colors in a dense array instead of a hashmap.
michaelwoerister Feb 13, 2018
9e9c55f
Update E0657 stderr to match changed test
cramertj Feb 14, 2018
fe0260f
mir: Gather move at SwitchInt, Assert terminators
fpoli Feb 15, 2018
b9fa2da
Avoid ICE in arg mistmatch error for tuple variants
estebank Feb 15, 2018
10fbdb8
save-analysis: power through bracket mis-counts
nrc Feb 16, 2018
42df8c5
unused_unsafe: don't label irrelevant fns
ExpHP Feb 18, 2018
d5ed655
Use DefId instead of NodeId while generating debuginfo for statics.
michaelwoerister Feb 19, 2018
15ff0ad
Use DefId instead of NodeId in MonoItem::Static.
michaelwoerister Feb 19, 2018
8ff633c
Implement describe_def query for LOCAL_CRATE
michaelwoerister Feb 19, 2018
1be7f96
Rename is_translated_fn query to is_translated_item and make it suppo…
michaelwoerister Feb 19, 2018
89b3ef3
Allow for instantiating statics from upstream crates.
michaelwoerister Feb 19, 2018
1aad320
When encountering invalid token after `unsafe`, mention `{`
estebank Feb 19, 2018
713b05f
rustc_data_structures: add missing #[inline].
eddyb Feb 21, 2018
1eab1b1
support unit tests with return values that implement `Terminaton`
nikomatsakis Feb 8, 2018
0625d4c
begin crate-relative paths with `crate`
nikomatsakis Feb 11, 2018
e446f70
put the "unit test" logic into libtest
nikomatsakis Feb 14, 2018
5f1e78f
move Termination trait to std::process
nikomatsakis Feb 22, 2018
8f35141
remove tokenstream
nikomatsakis Feb 22, 2018
067c2e3
handle `#[bench]` functions better
nikomatsakis Feb 23, 2018
e0ed88d
add test for `fn main() -> !`
nikomatsakis Feb 23, 2018
a0562ec
delete this test file: it also appears as
nikomatsakis Feb 23, 2018
0a5f4ae
move test to the proper directory and test #[bench]
nikomatsakis Feb 23, 2018
068e383
update test -- we now give a slightly different error
nikomatsakis Feb 23, 2018
10f7c11
re-export `assert_test_result` for use when testing libtest itself
nikomatsakis Feb 23, 2018
380e388
do not run MIR type checker twice
nikomatsakis Feb 7, 2018
2370b60
update tests and reference files
nikomatsakis Feb 22, 2018
bcd9968
explain why we don't need to run type-checker when NLL is enabled
nikomatsakis Feb 23, 2018
25ec810
Rollup merge of #47987 - Zoxc:rm-recursion-checking, r=eddyb
Manishearth Feb 24, 2018
a79e5e2
Rollup merge of #48084 - cramertj:impl-trait-errors, r=nikomatsakis
Manishearth Feb 24, 2018
b52b33a
Rollup merge of #48143 - nikomatsakis:termination_trait_in_tests, r=e…
Manishearth Feb 24, 2018
e966993
Rollup merge of #48185 - michaelwoerister:recursive-cache-decoding, r…
Manishearth Feb 24, 2018
111af8f
Rollup merge of #48206 - michaelwoerister:colors-array, r=nikomatsakis
Manishearth Feb 24, 2018
8fdad6f
Rollup merge of #48232 - fpoli:master, r=pnkfelix
Manishearth Feb 24, 2018
387d177
Rollup merge of #48246 - estebank:ice, r=nikomatsakis
Manishearth Feb 24, 2018
b3f85fd
Rollup merge of #48258 - nrc:save-proc-nested, r=eddyb
Manishearth Feb 24, 2018
a1a1409
Rollup merge of #48317 - ExpHP:unused-unsafe-is-no-fn, r=estebank
Manishearth Feb 24, 2018
2483d84
Rollup merge of #48353 - michaelwoerister:monoitem-static-defid, r=eddyb
Manishearth Feb 24, 2018
fc7caed
Rollup merge of #48356 - estebank:unsafe-without-braces, r=nikomatsakis
Manishearth Feb 24, 2018
6ec5dc3
Rollup merge of #48402 - eddyb:y-u-no-inline, r=nikomatsakis
Manishearth Feb 24, 2018
182f882
Rollup merge of #48061 - nikomatsakis:nll-do-not-run-mir-typeck-twice…
Manishearth Feb 24, 2018
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
2 changes: 1 addition & 1 deletion src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ define_dep_nodes!( <'tcx>
[eval_always] CollectAndPartitionTranslationItems,
[] ExportName(DefId),
[] ContainsExternIndicator(DefId),
[] IsTranslatedFunction(DefId),
[] IsTranslatedItem(DefId),
[] CodegenUnit(InternedString),
[] CompileCodegenUnit(InternedString),
[input] OutputFilenames,
Expand Down
98 changes: 98 additions & 0 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use hir::def_id::{CRATE_DEF_INDEX, DefId, LocalDefId, DefIndexAddressSpace};
use syntax::abi::Abi;
use syntax::ast::{self, Name, NodeId, CRATE_NODE_ID};
use syntax::codemap::Spanned;
use syntax::ext::base::MacroKind;
use syntax_pos::Span;

use hir::*;
Expand All @@ -32,13 +33,15 @@ use util::nodemap::{DefIdMap, FxHashMap};
use arena::TypedArena;
use std::cell::RefCell;
use std::io;
use ty::TyCtxt;

pub mod blocks;
mod collector;
mod def_collector;
pub mod definitions;
mod hir_id_validator;


pub const ITEM_LIKE_SPACE: DefIndexAddressSpace = DefIndexAddressSpace::Low;
pub const REGULAR_SPACE: DefIndexAddressSpace = DefIndexAddressSpace::High;

Expand Down Expand Up @@ -373,6 +376,92 @@ impl<'hir> Map<'hir> {
self.definitions.as_local_node_id(def_id.to_def_id()).unwrap()
}

pub fn describe_def(&self, node_id: NodeId) -> Option<Def> {
let node = if let Some(node) = self.find(node_id) {
node
} else {
return None
};

match node {
NodeItem(item) => {
let def_id = || {
self.local_def_id(item.id)
};

match item.node {
ItemStatic(_, m, _) => Some(Def::Static(def_id(),
m == MutMutable)),
ItemConst(..) => Some(Def::Const(def_id())),
ItemFn(..) => Some(Def::Fn(def_id())),
ItemMod(..) => Some(Def::Mod(def_id())),
ItemGlobalAsm(..) => Some(Def::GlobalAsm(def_id())),
ItemTy(..) => Some(Def::TyAlias(def_id())),
ItemEnum(..) => Some(Def::Enum(def_id())),
ItemStruct(..) => Some(Def::Struct(def_id())),
ItemUnion(..) => Some(Def::Union(def_id())),
ItemTrait(..) => Some(Def::Trait(def_id())),
ItemTraitAlias(..) => {
bug!("trait aliases are not yet implemented (see issue #41517)")
},
ItemExternCrate(_) |
ItemUse(..) |
ItemForeignMod(..) |
ItemImpl(..) => None,
}
}
NodeForeignItem(item) => {
let def_id = self.local_def_id(item.id);
match item.node {
ForeignItemFn(..) => Some(Def::Fn(def_id)),
ForeignItemStatic(_, m) => Some(Def::Static(def_id, m)),
ForeignItemType => Some(Def::TyForeign(def_id)),
}
}
NodeTraitItem(item) => {
let def_id = self.local_def_id(item.id);
match item.node {
TraitItemKind::Const(..) => Some(Def::AssociatedConst(def_id)),
TraitItemKind::Method(..) => Some(Def::Method(def_id)),
TraitItemKind::Type(..) => Some(Def::AssociatedTy(def_id)),
}
}
NodeImplItem(item) => {
let def_id = self.local_def_id(item.id);
match item.node {
ImplItemKind::Const(..) => Some(Def::AssociatedConst(def_id)),
ImplItemKind::Method(..) => Some(Def::Method(def_id)),
ImplItemKind::Type(..) => Some(Def::AssociatedTy(def_id)),
}
}
NodeVariant(variant) => {
let def_id = self.local_def_id(variant.node.data.id());
Some(Def::Variant(def_id))
}
NodeField(_) |
NodeExpr(_) |
NodeStmt(_) |
NodeTy(_) |
NodeTraitRef(_) |
NodePat(_) |
NodeBinding(_) |
NodeStructCtor(_) |
NodeLifetime(_) |
NodeVisibility(_) |
NodeBlock(_) => None,
NodeLocal(local) => {
Some(Def::Local(local.id))
}
NodeMacroDef(macro_def) => {
Some(Def::Macro(self.local_def_id(macro_def.id),
MacroKind::Bang))
}
NodeTyParam(param) => {
Some(Def::TyParam(self.local_def_id(param.id)))
}
}
}

fn entry_count(&self) -> usize {
self.map.len()
}
Expand Down Expand Up @@ -1275,3 +1364,12 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
}
}
}

pub fn describe_def(tcx: TyCtxt, def_id: DefId) -> Option<Def> {
if let Some(node_id) = tcx.hir.as_local_node_id(def_id) {
tcx.hir.describe_def(node_id)
} else {
bug!("Calling local describe_def query provider for upstream DefId: {:?}",
def_id)
}
}
6 changes: 6 additions & 0 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use syntax::tokenstream::TokenStream;
use syntax::util::ThinVec;
use syntax::util::parser::ExprPrecedence;
use ty::AdtKind;
use ty::maps::Providers;

use rustc_data_structures::indexed_vec;

Expand Down Expand Up @@ -2204,3 +2205,8 @@ pub type TraitMap = NodeMap<Vec<TraitCandidate>>;
// Map from the NodeId of a glob import to a list of items which are actually
// imported.
pub type GlobMap = NodeMap<FxHashSet<Name>>;


pub fn provide(providers: &mut Providers) {
providers.describe_def = map::describe_def;
}
7 changes: 5 additions & 2 deletions src/librustc/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use hir::def_id::DefId;
use syntax::ast::NodeId;
use syntax::symbol::InternedString;
use ty::{Instance, TyCtxt};
Expand All @@ -21,7 +22,7 @@ use std::hash::Hash;
#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)]
pub enum MonoItem<'tcx> {
Fn(Instance<'tcx>),
Static(NodeId),
Static(DefId),
GlobalAsm(NodeId),
}

Expand Down Expand Up @@ -50,7 +51,9 @@ impl<'tcx> HashStable<StableHashingContext<'tcx>> for MonoItem<'tcx> {
MonoItem::Fn(ref instance) => {
instance.hash_stable(hcx, hasher);
}
MonoItem::Static(node_id) |
MonoItem::Static(def_id) => {
def_id.hash_stable(hcx, hasher);
}
MonoItem::GlobalAsm(node_id) => {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
node_id.hash_stable(hcx, hasher);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/maps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ define_maps! { <'tcx>
[] fn export_name: ExportName(DefId) -> Option<Symbol>,
[] fn contains_extern_indicator: ContainsExternIndicator(DefId) -> bool,
[] fn symbol_export_level: GetSymbolExportLevel(DefId) -> SymbolExportLevel,
[] fn is_translated_function: IsTranslatedFunction(DefId) -> bool,
[] fn is_translated_item: IsTranslatedItem(DefId) -> bool,
[] fn codegen_unit: CodegenUnit(InternedString) -> Arc<CodegenUnit<'tcx>>,
[] fn compile_codegen_unit: CompileCodegenUnit(InternedString) -> Stats,
[] fn output_filenames: output_filenames_node(CrateNum)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/maps/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
DepKind::ContainsExternIndicator => {
force!(contains_extern_indicator, def_id!());
}
DepKind::IsTranslatedFunction => { force!(is_translated_function, def_id!()); }
DepKind::IsTranslatedItem => { force!(is_translated_item, def_id!()); }
DepKind::OutputFilenames => { force!(output_filenames, LOCAL_CRATE); }

DepKind::TargetFeaturesWhitelist => { force!(target_features_whitelist, LOCAL_CRATE); }
Expand Down
1 change: 1 addition & 0 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
}

pub fn default_provide(providers: &mut ty::maps::Providers) {
hir::provide(providers);
borrowck::provide(providers);
mir::provide(providers);
reachable::provide(providers);
Expand Down
12 changes: 5 additions & 7 deletions src/librustc_mir/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let recursion_depth_reset;

match starting_point {
MonoItem::Static(node_id) => {
let def_id = tcx.hir.local_def_id(node_id);
MonoItem::Static(def_id) => {
let instance = Instance::mono(tcx, def_id);

// Sanity check whether this ended up being collected accidentally
Expand Down Expand Up @@ -652,8 +651,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
let tcx = self.tcx;
let instance = Instance::mono(tcx, static_.def_id);
if should_monomorphize_locally(tcx, &instance) {
let node_id = tcx.hir.as_local_node_id(static_.def_id).unwrap();
self.output.push(MonoItem::Static(node_id));
self.output.push(MonoItem::Static(static_.def_id));
}

self.super_static(static_, context, location);
Expand Down Expand Up @@ -946,10 +944,10 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
self.output.push(MonoItem::GlobalAsm(item.id));
}
hir::ItemStatic(..) => {
let def_id = self.tcx.hir.local_def_id(item.id);
debug!("RootCollector: ItemStatic({})",
def_id_to_string(self.tcx,
self.tcx.hir.local_def_id(item.id)));
self.output.push(MonoItem::Static(item.id));
def_id_to_string(self.tcx, def_id));
self.output.push(MonoItem::Static(def_id));
}
hir::ItemConst(..) => {
// const items only generate mono items if they are
Expand Down
16 changes: 7 additions & 9 deletions src/librustc_mir/monomorphize/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug {
fn symbol_name(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ty::SymbolName {
match *self.as_mono_item() {
MonoItem::Fn(instance) => tcx.symbol_name(instance),
MonoItem::Static(node_id) => {
let def_id = tcx.hir.local_def_id(node_id);
MonoItem::Static(def_id) => {
tcx.symbol_name(Instance::mono(tcx, def_id))
}
MonoItem::GlobalAsm(node_id) => {
Expand Down Expand Up @@ -159,7 +158,7 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug {
fn explicit_linkage(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<Linkage> {
let def_id = match *self.as_mono_item() {
MonoItem::Fn(ref instance) => instance.def_id(),
MonoItem::Static(node_id) => tcx.hir.local_def_id(node_id),
MonoItem::Static(def_id) => def_id,
MonoItem::GlobalAsm(..) => return None,
};

Expand Down Expand Up @@ -209,7 +208,7 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug {
debug!("is_instantiable({:?})", self);
let (def_id, substs) = match *self.as_mono_item() {
MonoItem::Fn(ref instance) => (instance.def_id(), instance.substs),
MonoItem::Static(node_id) => (tcx.hir.local_def_id(node_id), Substs::empty()),
MonoItem::Static(def_id) => (def_id, Substs::empty()),
// global asm never has predicates
MonoItem::GlobalAsm(..) => return true
};
Expand All @@ -218,14 +217,11 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug {
}

fn to_string(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> String {
let hir_map = &tcx.hir;

return match *self.as_mono_item() {
MonoItem::Fn(instance) => {
to_string_internal(tcx, "fn ", instance)
},
MonoItem::Static(node_id) => {
let def_id = hir_map.local_def_id(node_id);
MonoItem::Static(def_id) => {
let instance = Instance::new(def_id, tcx.intern_substs(&[]));
to_string_internal(tcx, "static ", instance)
},
Expand All @@ -251,7 +247,9 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug {
MonoItem::Fn(Instance { def, .. }) => {
tcx.hir.as_local_node_id(def.def_id())
}
MonoItem::Static(node_id) |
MonoItem::Static(def_id) => {
tcx.hir.as_local_node_id(def_id)
}
MonoItem::GlobalAsm(node_id) => {
Some(node_id)
}
Expand Down
16 changes: 13 additions & 3 deletions src/librustc_mir/monomorphize/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ pub trait CodegenUnitExt<'tcx> {
}
}
}
MonoItem::Static(node_id) |
MonoItem::Static(def_id) => {
tcx.hir.as_local_node_id(def_id)
}
MonoItem::GlobalAsm(node_id) => {
Some(node_id)
}
Expand Down Expand Up @@ -382,7 +384,15 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
};
(Linkage::External, visibility)
}
MonoItem::Static(node_id) |
MonoItem::Static(def_id) => {
let visibility = if tcx.is_exported_symbol(def_id) {
can_be_internalized = false;
default_visibility(def_id)
} else {
Visibility::Hidden
};
(Linkage::External, visibility)
}
MonoItem::GlobalAsm(node_id) => {
let def_id = tcx.hir.local_def_id(node_id);
let visibility = if tcx.is_exported_symbol(def_id) {
Expand Down Expand Up @@ -643,7 +653,7 @@ fn characteristic_def_id_of_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

Some(def_id)
}
MonoItem::Static(node_id) |
MonoItem::Static(def_id) => Some(def_id),
MonoItem::GlobalAsm(node_id) => Some(tcx.hir.local_def_id(node_id)),
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,7 @@ fn collect_and_partition_translation_items<'a, 'tcx>(
let translation_items: DefIdSet = items.iter().filter_map(|trans_item| {
match *trans_item {
MonoItem::Fn(ref instance) => Some(instance.def_id()),
MonoItem::Static(def_id) => Some(def_id),
_ => None,
}
}).collect();
Expand Down Expand Up @@ -1107,7 +1108,7 @@ impl CrateInfo {
}
}

fn is_translated_function(tcx: TyCtxt, id: DefId) -> bool {
fn is_translated_item(tcx: TyCtxt, id: DefId) -> bool {
let (all_trans_items, _) =
tcx.collect_and_partition_translation_items(LOCAL_CRATE);
all_trans_items.contains(&id)
Expand Down Expand Up @@ -1222,7 +1223,7 @@ pub fn provide(providers: &mut Providers) {
providers.collect_and_partition_translation_items =
collect_and_partition_translation_items;

providers.is_translated_function = is_translated_function;
providers.is_translated_item = is_translated_item;

providers.codegen_unit = |tcx, name| {
let (_, all) = tcx.collect_and_partition_translation_items(LOCAL_CRATE);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub fn get_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
unsafe {
llvm::LLVMRustSetLinkage(llfn, llvm::Linkage::ExternalLinkage);

if cx.tcx.is_translated_function(instance_def_id) {
if cx.tcx.is_translated_item(instance_def_id) {
if instance_def_id.is_local() {
if !cx.tcx.is_exported_symbol(instance_def_id) {
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
Expand Down
Loading