Skip to content

Rollup of 5 pull requests #59561

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 15 commits into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,7 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
[] ConstEval { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> },
[] ConstEvalRaw { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> },
[] CheckMatch(DefId),
[] SymbolName(DefId),
[] InstanceSymbolName { instance: Instance<'tcx> },
[] SymbolName { instance: Instance<'tcx> },
[] SpecializationGraph(DefId),
[] ObjectSafety(DefId),
[] FulfillObligation { param_env: ParamEnv<'tcx>, trait_ref: PolyTraitRef<'tcx> },
Expand Down
1 change: 0 additions & 1 deletion src/librustc/ty/query/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,6 @@ impl_disk_cacheable_query!(mir_borrowck, |tcx, def_id| {
impl_disk_cacheable_query!(unsafety_check_result, |_, def_id| def_id.is_local());
impl_disk_cacheable_query!(borrowck, |_, def_id| def_id.is_local());
impl_disk_cacheable_query!(check_match, |_, def_id| def_id.is_local());
impl_disk_cacheable_query!(def_symbol_name, |_, _| true);
impl_disk_cacheable_query!(predicates_of, |_, def_id| def_id.is_local());
impl_disk_cacheable_query!(used_trait_imports, |_, def_id| def_id.is_local());
impl_disk_cacheable_query!(codegen_fn_attrs, |_, _| true);
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ rustc_query_append! { [define_queries!][ <'tcx>

[] fn mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx>,

[] fn def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
[] fn symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,

[] fn describe_def: DescribeDef(DefId) -> Option<Def>,
Expand Down Expand Up @@ -727,7 +726,7 @@ fn mir_shim_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>) -> DepConstructo
}

fn symbol_name_dep_node<'tcx>(instance: ty::Instance<'tcx>) -> DepConstructor<'tcx> {
DepConstructor::InstanceSymbolName { instance }
DepConstructor::SymbolName { instance }
}

fn typeck_item_bodies_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
Expand Down
1 change: 0 additions & 1 deletion src/librustc/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ impl<'sess> OnDiskCache<'sess> {
encode_query_results::<borrowck<'_>, _>(tcx, enc, qri)?;
encode_query_results::<mir_borrowck<'_>, _>(tcx, enc, qri)?;
encode_query_results::<mir_const_qualif<'_>, _>(tcx, enc, qri)?;
encode_query_results::<def_symbol_name<'_>, _>(tcx, enc, qri)?;
encode_query_results::<const_is_rvalue_promotable_to_static<'_>, _>(tcx, enc, qri)?;
encode_query_results::<symbol_name<'_>, _>(tcx, enc, qri)?;
encode_query_results::<check_match<'_>, _>(tcx, enc, qri)?;
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ pub fn force_from_dep_node<'tcx>(
DepKind::Layout |
DepKind::ConstEval |
DepKind::ConstEvalRaw |
DepKind::InstanceSymbolName |
DepKind::SymbolName |
DepKind::MirShim |
DepKind::BorrowCheckKrate |
DepKind::Specializes |
Expand Down Expand Up @@ -1304,7 +1304,6 @@ pub fn force_from_dep_node<'tcx>(
DepKind::TypeckTables => { force!(typeck_tables_of, def_id!()); }
DepKind::UsedTraitImports => { force!(used_trait_imports, def_id!()); }
DepKind::HasTypeckTables => { force!(has_typeck_tables, def_id!()); }
DepKind::SymbolName => { force!(def_symbol_name, def_id!()); }
DepKind::SpecializationGraph => { force!(specialization_graph_of, def_id!()); }
DepKind::ObjectSafety => { force!(is_object_safe, def_id!()); }
DepKind::TraitImpls => { force!(trait_impls_of, def_id!()); }
Expand Down Expand Up @@ -1486,7 +1485,6 @@ impl_load_from_cache!(
BorrowCheck => borrowck,
MirBorrowCheck => mir_borrowck,
mir_const_qualif => mir_const_qualif,
SymbolName => def_symbol_name,
ConstIsRvaluePromotableToStatic => const_is_rvalue_promotable_to_static,
CheckMatch => check_match,
type_of => type_of,
Expand Down
18 changes: 17 additions & 1 deletion src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ impl TypeMap<'ll, 'tcx> {
let interner_key = self.unique_id_interner.intern(&enum_variant_type_id);
UniqueTypeId(interner_key)
}

// Get the unique type id string for an enum variant part.
// Variant parts are not types and shouldn't really have their own id,
// but it makes set_members_of_composite_type() simpler.
fn get_unique_type_id_str_of_enum_variant_part<'a>(&mut self,
enum_type_id: UniqueTypeId) -> &str {
let variant_part_type_id = format!("{}_variant_part",
self.get_unique_type_id_as_string(enum_type_id));
let interner_key = self.unique_id_interner.intern(&variant_part_type_id);
self.unique_id_interner.get(interner_key)
}
}

// A description of some recursive type. It can either be already finished (as
Expand Down Expand Up @@ -1689,6 +1700,11 @@ fn prepare_enum_metadata(
},
};

let variant_part_unique_type_id_str = SmallCStr::new(
debug_context(cx).type_map
.borrow_mut()
.get_unique_type_id_str_of_enum_variant_part(unique_type_id)
);
let empty_array = create_DIArray(DIB(cx), &[]);
let variant_part = unsafe {
llvm::LLVMRustDIBuilderCreateVariantPart(
Expand All @@ -1702,7 +1718,7 @@ fn prepare_enum_metadata(
DIFlags::FlagZero,
discriminator_metadata,
empty_array,
unique_type_id_str.as_ptr())
variant_part_unique_type_id_str.as_ptr())
};

// The variant part must be wrapped in a struct according to DWARF.
Expand Down
53 changes: 15 additions & 38 deletions src/librustc_codegen_utils/symbol_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_mir::monomorphize::item::{InstantiationMode, MonoItem, MonoItemExt};
use rustc_mir::monomorphize::Instance;

use syntax_pos::symbol::Symbol;
use syntax_pos::symbol::{Symbol, InternedString};

use log::debug;

Expand All @@ -110,7 +110,6 @@ use std::mem::{self, discriminant};

pub fn provide(providers: &mut Providers<'_>) {
*providers = Providers {
def_symbol_name,
symbol_name,

..*providers
Expand Down Expand Up @@ -222,21 +221,13 @@ fn get_symbol_hash<'a, 'tcx>(
hasher.finish()
}

fn def_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::SymbolName {
SymbolPrinter {
tcx,
path: SymbolPath::new(),
keep_within_component: false,
}.print_def_path(def_id, &[]).unwrap().path.into_interned()
}

fn symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance<'tcx>) -> ty::SymbolName {
fn symbol_name(tcx: TyCtxt<'_, 'tcx, 'tcx>, instance: Instance<'tcx>) -> ty::SymbolName {
ty::SymbolName {
name: Symbol::intern(&compute_symbol_name(tcx, instance)).as_interned_str(),
name: compute_symbol_name(tcx, instance),
}
}

fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance<'tcx>) -> String {
fn compute_symbol_name(tcx: TyCtxt<'_, 'tcx, 'tcx>, instance: Instance<'tcx>) -> InternedString {
let def_id = instance.def_id();
let substs = instance.substs;

Expand All @@ -247,11 +238,13 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
if def_id.is_local() {
if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id) {
let disambiguator = tcx.sess.local_crate_disambiguator();
return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
return Symbol::intern(&tcx.sess.generate_plugin_registrar_symbol(disambiguator))
.as_interned_str();
}
if tcx.proc_macro_decls_static(LOCAL_CRATE) == Some(def_id) {
let disambiguator = tcx.sess.local_crate_disambiguator();
return tcx.sess.generate_proc_macro_decls_symbol(disambiguator);
return Symbol::intern(&tcx.sess.generate_proc_macro_decls_symbol(disambiguator))
.as_interned_str();
}
}

Expand All @@ -268,20 +261,20 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
let attrs = tcx.codegen_fn_attrs(def_id);
if is_foreign {
if let Some(name) = attrs.link_name {
return name.to_string();
return name.as_interned_str();
}
// Don't mangle foreign items.
return tcx.item_name(def_id).to_string();
return tcx.item_name(def_id);
}

if let Some(name) = &attrs.export_name {
// Use provided name
return name.to_string();
return name.as_interned_str();
}

if attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE) {
// Don't mangle
return tcx.item_name(def_id).to_string();
return tcx.item_name(def_id);
}

// We want to compute the "type" of this item. Unfortunately, some
Expand Down Expand Up @@ -321,15 +314,15 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance

let mut printer = SymbolPrinter {
tcx,
path: SymbolPath::from_interned(tcx.def_symbol_name(def_id)),
path: SymbolPath::new(),
keep_within_component: false,
};
}.print_def_path(def_id, &[]).unwrap();

if instance.is_vtable_shim() {
let _ = printer.write_str("{{vtable-shim}}");
}

printer.path.finish(hash)
Symbol::intern(&printer.path.finish(hash)).as_interned_str()
}

// Follow C++ namespace-mangling style, see
Expand Down Expand Up @@ -361,22 +354,6 @@ impl SymbolPath {
result
}

fn from_interned(symbol: ty::SymbolName) -> Self {
let mut result = SymbolPath {
result: String::with_capacity(64),
temp_buf: String::with_capacity(16),
};
result.result.push_str(&symbol.as_str());
result
}

fn into_interned(mut self) -> ty::SymbolName {
self.finalize_pending_component();
ty::SymbolName {
name: Symbol::intern(&self.result).as_interned_str(),
}
}

fn finalize_pending_component(&mut self) {
if !self.temp_buf.is_empty() {
let _ = write!(self.result, "{}{}", self.temp_buf.len(), self.temp_buf);
Expand Down
47 changes: 36 additions & 11 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1619,14 +1619,16 @@ impl LintPass for KeywordIdents {
}
}

struct UnderMacro(bool);

impl KeywordIdents {
fn check_tokens(&mut self, cx: &EarlyContext<'_>, tokens: TokenStream) {
for tt in tokens.into_trees() {
match tt {
TokenTree::Token(span, tok) => match tok.ident() {
// only report non-raw idents
Some((ident, false)) => {
self.check_ident(cx, ast::Ident {
self.check_ident_token(cx, UnderMacro(true), ast::Ident {
span: span.substitute_dummy(ident.span),
..ident
});
Expand All @@ -1639,16 +1641,12 @@ impl KeywordIdents {
}
}
}
}

impl EarlyLintPass for KeywordIdents {
fn check_mac_def(&mut self, cx: &EarlyContext<'_>, mac_def: &ast::MacroDef, _id: ast::NodeId) {
self.check_tokens(cx, mac_def.stream());
}
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) {
self.check_tokens(cx, mac.node.tts.clone().into());
}
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: ast::Ident) {
fn check_ident_token(&mut self,
cx: &EarlyContext<'_>,
UnderMacro(under_macro): UnderMacro,
ident: ast::Ident)
{
let ident_str = &ident.as_str()[..];
let cur_edition = cx.sess.edition();
let is_raw_ident = |ident: ast::Ident| {
Expand All @@ -1657,7 +1655,22 @@ impl EarlyLintPass for KeywordIdents {
let next_edition = match cur_edition {
Edition::Edition2015 => {
match ident_str {
"async" | "try" | "dyn" => Edition::Edition2018,
"async" | "try" => Edition::Edition2018,

// rust-lang/rust#56327: Conservatively do not
// attempt to report occurrences of `dyn` within
// macro definitions or invocations, because `dyn`
// can legitimately occur as a contextual keyword
// in 2015 code denoting its 2018 meaning, and we
// do not want rustfix to inject bugs into working
// code by rewriting such occurrences.
//
// But if we see `dyn` outside of a macro, we know
// its precise role in the parsed AST and thus are
// assured this is truly an attempt to use it as
// an identifier.
"dyn" if !under_macro => Edition::Edition2018,

// Only issue warnings for `await` if the `async_await`
// feature isn't being used. Otherwise, users need
// to keep using `await` for the macro exposed by std.
Expand Down Expand Up @@ -1715,6 +1728,18 @@ impl EarlyLintPass for KeywordIdents {
}
}

impl EarlyLintPass for KeywordIdents {
fn check_mac_def(&mut self, cx: &EarlyContext<'_>, mac_def: &ast::MacroDef, _id: ast::NodeId) {
self.check_tokens(cx, mac_def.stream());
}
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) {
self.check_tokens(cx, mac.node.tts.clone().into());
}
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: ast::Ident) {
self.check_ident_token(cx, UnderMacro(false), ident);
}
}


pub struct ExplicitOutlivesRequirements;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/lower_128bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn check_lang_item_type<'a, 'tcx, D>(
let place_ty = place.ty(local_decls, tcx).to_ty(tcx);
let expected = [lhs_ty, rhs_ty, place_ty];
assert_eq!(sig.inputs_and_output[..], expected,
"lang item {}", tcx.def_symbol_name(did));
"lang item `{}`", tcx.def_path_str(did));
did
}

Expand Down
14 changes: 9 additions & 5 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1769,9 +1769,13 @@ fn get_real_types(
generics: &Generics,
arg: &Type,
cx: &DocContext<'_>,
recurse: i32,
) -> FxHashSet<Type> {
let arg_s = arg.to_string();
let mut res = FxHashSet::default();
if recurse >= 10 { // FIXME: remove this whole recurse thing when the recursion bug is fixed
return res;
}
if arg.is_full_generic() {
if let Some(where_pred) = generics.where_predicates.iter().find(|g| {
match g {
Expand All @@ -1788,7 +1792,7 @@ fn get_real_types(
continue
}
if let Some(ty) = x.get_type(cx) {
let adds = get_real_types(generics, &ty, cx);
let adds = get_real_types(generics, &ty, cx, recurse + 1);
if !adds.is_empty() {
res.extend(adds);
} else if !ty.is_full_generic() {
Expand All @@ -1806,7 +1810,7 @@ fn get_real_types(
}) {
for bound in bound.get_bounds().unwrap_or_else(|| &[]) {
if let Some(ty) = bound.get_trait_type() {
let adds = get_real_types(generics, &ty, cx);
let adds = get_real_types(generics, &ty, cx, recurse + 1);
if !adds.is_empty() {
res.extend(adds);
} else if !ty.is_full_generic() {
Expand All @@ -1820,7 +1824,7 @@ fn get_real_types(
if let Some(gens) = arg.generics() {
for gen in gens.iter() {
if gen.is_full_generic() {
let adds = get_real_types(generics, gen, cx);
let adds = get_real_types(generics, gen, cx, recurse + 1);
if !adds.is_empty() {
res.extend(adds);
}
Expand All @@ -1847,7 +1851,7 @@ pub fn get_all_types(
if arg.type_.is_self_type() {
continue;
}
let args = get_real_types(generics, &arg.type_, cx);
let args = get_real_types(generics, &arg.type_, cx, 0);
if !args.is_empty() {
all_types.extend(args);
} else {
Expand All @@ -1857,7 +1861,7 @@ pub fn get_all_types(

let ret_types = match decl.output {
FunctionRetTy::Return(ref return_type) => {
let mut ret = get_real_types(generics, &return_type, cx);
let mut ret = get_real_types(generics, &return_type, cx, 0);
if ret.is_empty() {
ret.insert(return_type.clone());
}
Expand Down
Loading