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 1 commit
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
Prev Previous commit
Next Next commit
Use DefId instead of NodeId in MonoItem::Static.
  • Loading branch information
michaelwoerister committed Feb 19, 2018
commit 15ff0adcde77776e2947d147a756d4289aa42e59
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
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
26 changes: 13 additions & 13 deletions src/librustc_trans/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc::hir::map as hir_map;
use rustc::middle::const_val::ConstEvalErr;
use debuginfo;
use base;
use monomorphize::{MonoItem, MonoItemExt};
use monomorphize::MonoItem;
use common::{CodegenCx, val_ty};
use declare;
use monomorphize::Instance;
Expand Down Expand Up @@ -110,21 +110,24 @@ pub fn get_static(cx: &CodegenCx, def_id: DefId) -> ValueRef {
return g;
}

let defined_in_current_codegen_unit = cx.codegen_unit
.items()
.contains_key(&MonoItem::Static(def_id));
assert!(!defined_in_current_codegen_unit,
"consts::get_static() should always hit the cache for \
statics defined in the same CGU, but did not for `{:?}`",
def_id);

let ty = instance.ty(cx.tcx);
let sym = cx.tcx.symbol_name(instance);

let g = if let Some(id) = cx.tcx.hir.as_local_node_id(def_id) {

let llty = cx.layout_of(ty).llvm_type(cx);
let (g, attrs) = match cx.tcx.hir.get(id) {
hir_map::NodeItem(&hir::Item {
ref attrs, span, node: hir::ItemStatic(..), ..
}) => {
let sym = MonoItem::Static(id).symbol_name(cx.tcx);

let defined_in_current_codegen_unit = cx.codegen_unit
.items()
.contains_key(&MonoItem::Static(id));
assert!(!defined_in_current_codegen_unit);

if declare::get_declared_value(cx, &sym[..]).is_some() {
span_bug!(span, "trans: Conflicting symbol names for static?");
}
Expand All @@ -143,7 +146,7 @@ pub fn get_static(cx: &CodegenCx, def_id: DefId) -> ValueRef {
hir_map::NodeForeignItem(&hir::ForeignItem {
ref attrs, span, node: hir::ForeignItemStatic(..), ..
}) => {
let sym = cx.tcx.symbol_name(instance);

let g = if let Some(name) =
attr::first_attr_value_str_by_name(&attrs, "linkage") {
// If this is a static with a linkage specified, then we need to handle
Expand Down Expand Up @@ -203,8 +206,6 @@ pub fn get_static(cx: &CodegenCx, def_id: DefId) -> ValueRef {

g
} else {
let sym = cx.tcx.symbol_name(instance);

// FIXME(nagisa): perhaps the map of externs could be offloaded to llvm somehow?
// FIXME(nagisa): investigate whether it can be changed into define_global
let g = declare::declare_global(cx, &sym, cx.layout_of(ty).llvm_type(cx));
Expand Down Expand Up @@ -246,11 +247,10 @@ pub fn get_static(cx: &CodegenCx, def_id: DefId) -> ValueRef {

pub fn trans_static<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
m: hir::Mutability,
id: ast::NodeId,
def_id: DefId,
attrs: &[ast::Attribute])
-> Result<ValueRef, ConstEvalErr<'tcx>> {
unsafe {
let def_id = cx.tcx.hir.local_def_id(id);
let g = get_static(cx, def_id);

let v = ::mir::trans_static_initializer(cx, def_id)?;
Expand Down
28 changes: 21 additions & 7 deletions src/librustc_trans/trans_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ use llvm;
use monomorphize::Instance;
use type_of::LayoutLlvmExt;
use rustc::hir;
use rustc::hir::def_id::DefId;
use rustc::mir::mono::{Linkage, Visibility};
use rustc::ty::TypeFoldable;
use rustc::ty::layout::LayoutOf;
use syntax::ast;
use syntax::attr;
use std::fmt;

Expand All @@ -44,11 +44,18 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug + BaseMonoItemExt<'a, 'tcx> {
cx.codegen_unit.name());

match *self.as_mono_item() {
MonoItem::Static(node_id) => {
MonoItem::Static(def_id) => {
let tcx = cx.tcx;
let node_id = match tcx.hir.as_local_node_id(def_id) {
Some(node_id) => node_id,
None => {
bug!("MonoItemExt::define() called for non-local \
static `{:?}`.", def_id)
}
};
let item = tcx.hir.expect_item(node_id);
if let hir::ItemStatic(_, m, _) = item.node {
match consts::trans_static(&cx, m, item.id, &item.attrs) {
match consts::trans_static(&cx, m, def_id, &item.attrs) {
Ok(_) => { /* Cool, everything's alright. */ },
Err(err) => {
err.report(tcx, item.span, "static");
Expand Down Expand Up @@ -91,8 +98,8 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug + BaseMonoItemExt<'a, 'tcx> {
debug!("symbol {}", &symbol_name);

match *self.as_mono_item() {
MonoItem::Static(node_id) => {
predefine_static(cx, node_id, linkage, visibility, &symbol_name);
MonoItem::Static(def_id) => {
predefine_static(cx, def_id, linkage, visibility, &symbol_name);
}
MonoItem::Fn(instance) => {
predefine_fn(cx, instance, linkage, visibility, &symbol_name);
Expand Down Expand Up @@ -126,11 +133,18 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug + BaseMonoItemExt<'a, 'tcx> {
impl<'a, 'tcx> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {}

fn predefine_static<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
node_id: ast::NodeId,
def_id: DefId,
linkage: Linkage,
visibility: Visibility,
symbol_name: &str) {
let def_id = cx.tcx.hir.local_def_id(node_id);
let node_id = match cx.tcx.hir.as_local_node_id(def_id) {
Some(node_id) => node_id,
None => {
bug!("MonoItemExt::predefine() called for non-local static `{:?}`.",
def_id)
}
};

let instance = Instance::mono(cx.tcx, def_id);
let ty = instance.ty(cx.tcx);
let llty = cx.layout_of(ty).llvm_type(cx);
Expand Down