Skip to content

Commit fc8581d

Browse files
committed
Auto merge of #59561 - Centril:rollup, r=Centril
Rollup of 5 pull requests Successful merges: - #59343 (rustc(codegen): uncache `def_symbol_name` prefix from `symbol_name`.) - #59380 (Fix invalid DWARF for enums when using ThinLTO) - #59463 (skip dyn keyword lint under macros) - #59539 (Fix infinite recursion) - #59544 (manifest: only include miri on the nightly channel) Failed merges: r? @ghost
2 parents 6c49da4 + 04ffaca commit fc8581d

19 files changed

+590
-66
lines changed

src/librustc/dep_graph/dep_node.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,7 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
500500
[] ConstEval { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> },
501501
[] ConstEvalRaw { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> },
502502
[] CheckMatch(DefId),
503-
[] SymbolName(DefId),
504-
[] InstanceSymbolName { instance: Instance<'tcx> },
503+
[] SymbolName { instance: Instance<'tcx> },
505504
[] SpecializationGraph(DefId),
506505
[] ObjectSafety(DefId),
507506
[] FulfillObligation { param_env: ParamEnv<'tcx>, trait_ref: PolyTraitRef<'tcx> },

src/librustc/ty/query/config.rs

-1
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,6 @@ impl_disk_cacheable_query!(mir_borrowck, |tcx, def_id| {
941941
impl_disk_cacheable_query!(unsafety_check_result, |_, def_id| def_id.is_local());
942942
impl_disk_cacheable_query!(borrowck, |_, def_id| def_id.is_local());
943943
impl_disk_cacheable_query!(check_match, |_, def_id| def_id.is_local());
944-
impl_disk_cacheable_query!(def_symbol_name, |_, _| true);
945944
impl_disk_cacheable_query!(predicates_of, |_, def_id| def_id.is_local());
946945
impl_disk_cacheable_query!(used_trait_imports, |_, def_id| def_id.is_local());
947946
impl_disk_cacheable_query!(codegen_fn_attrs, |_, _| true);

src/librustc/ty/query/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ rustc_query_append! { [define_queries!][ <'tcx>
315315

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

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

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

729728
fn symbol_name_dep_node<'tcx>(instance: ty::Instance<'tcx>) -> DepConstructor<'tcx> {
730-
DepConstructor::InstanceSymbolName { instance }
729+
DepConstructor::SymbolName { instance }
731730
}
732731

733732
fn typeck_item_bodies_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {

src/librustc/ty/query/on_disk_cache.rs

-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ impl<'sess> OnDiskCache<'sess> {
218218
encode_query_results::<borrowck<'_>, _>(tcx, enc, qri)?;
219219
encode_query_results::<mir_borrowck<'_>, _>(tcx, enc, qri)?;
220220
encode_query_results::<mir_const_qualif<'_>, _>(tcx, enc, qri)?;
221-
encode_query_results::<def_symbol_name<'_>, _>(tcx, enc, qri)?;
222221
encode_query_results::<const_is_rvalue_promotable_to_static<'_>, _>(tcx, enc, qri)?;
223222
encode_query_results::<symbol_name<'_>, _>(tcx, enc, qri)?;
224223
encode_query_results::<check_match<'_>, _>(tcx, enc, qri)?;

src/librustc/ty/query/plumbing.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ pub fn force_from_dep_node<'tcx>(
12171217
DepKind::Layout |
12181218
DepKind::ConstEval |
12191219
DepKind::ConstEvalRaw |
1220-
DepKind::InstanceSymbolName |
1220+
DepKind::SymbolName |
12211221
DepKind::MirShim |
12221222
DepKind::BorrowCheckKrate |
12231223
DepKind::Specializes |
@@ -1304,7 +1304,6 @@ pub fn force_from_dep_node<'tcx>(
13041304
DepKind::TypeckTables => { force!(typeck_tables_of, def_id!()); }
13051305
DepKind::UsedTraitImports => { force!(used_trait_imports, def_id!()); }
13061306
DepKind::HasTypeckTables => { force!(has_typeck_tables, def_id!()); }
1307-
DepKind::SymbolName => { force!(def_symbol_name, def_id!()); }
13081307
DepKind::SpecializationGraph => { force!(specialization_graph_of, def_id!()); }
13091308
DepKind::ObjectSafety => { force!(is_object_safe, def_id!()); }
13101309
DepKind::TraitImpls => { force!(trait_impls_of, def_id!()); }
@@ -1486,7 +1485,6 @@ impl_load_from_cache!(
14861485
BorrowCheck => borrowck,
14871486
MirBorrowCheck => mir_borrowck,
14881487
mir_const_qualif => mir_const_qualif,
1489-
SymbolName => def_symbol_name,
14901488
ConstIsRvaluePromotableToStatic => const_is_rvalue_promotable_to_static,
14911489
CheckMatch => check_match,
14921490
type_of => type_of,

src/librustc_codegen_llvm/debuginfo/metadata.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ impl TypeMap<'ll, 'tcx> {
189189
let interner_key = self.unique_id_interner.intern(&enum_variant_type_id);
190190
UniqueTypeId(interner_key)
191191
}
192+
193+
// Get the unique type id string for an enum variant part.
194+
// Variant parts are not types and shouldn't really have their own id,
195+
// but it makes set_members_of_composite_type() simpler.
196+
fn get_unique_type_id_str_of_enum_variant_part<'a>(&mut self,
197+
enum_type_id: UniqueTypeId) -> &str {
198+
let variant_part_type_id = format!("{}_variant_part",
199+
self.get_unique_type_id_as_string(enum_type_id));
200+
let interner_key = self.unique_id_interner.intern(&variant_part_type_id);
201+
self.unique_id_interner.get(interner_key)
202+
}
192203
}
193204

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

1703+
let variant_part_unique_type_id_str = SmallCStr::new(
1704+
debug_context(cx).type_map
1705+
.borrow_mut()
1706+
.get_unique_type_id_str_of_enum_variant_part(unique_type_id)
1707+
);
16921708
let empty_array = create_DIArray(DIB(cx), &[]);
16931709
let variant_part = unsafe {
16941710
llvm::LLVMRustDIBuilderCreateVariantPart(
@@ -1702,7 +1718,7 @@ fn prepare_enum_metadata(
17021718
DIFlags::FlagZero,
17031719
discriminator_metadata,
17041720
empty_array,
1705-
unique_type_id_str.as_ptr())
1721+
variant_part_unique_type_id_str.as_ptr())
17061722
};
17071723

17081724
// The variant part must be wrapped in a struct according to DWARF.

src/librustc_codegen_utils/symbol_names.rs

+15-38
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
101101
use rustc_mir::monomorphize::item::{InstantiationMode, MonoItem, MonoItemExt};
102102
use rustc_mir::monomorphize::Instance;
103103

104-
use syntax_pos::symbol::Symbol;
104+
use syntax_pos::symbol::{Symbol, InternedString};
105105

106106
use log::debug;
107107

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

111111
pub fn provide(providers: &mut Providers<'_>) {
112112
*providers = Providers {
113-
def_symbol_name,
114113
symbol_name,
115114

116115
..*providers
@@ -222,21 +221,13 @@ fn get_symbol_hash<'a, 'tcx>(
222221
hasher.finish()
223222
}
224223

225-
fn def_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::SymbolName {
226-
SymbolPrinter {
227-
tcx,
228-
path: SymbolPath::new(),
229-
keep_within_component: false,
230-
}.print_def_path(def_id, &[]).unwrap().path.into_interned()
231-
}
232-
233-
fn symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance<'tcx>) -> ty::SymbolName {
224+
fn symbol_name(tcx: TyCtxt<'_, 'tcx, 'tcx>, instance: Instance<'tcx>) -> ty::SymbolName {
234225
ty::SymbolName {
235-
name: Symbol::intern(&compute_symbol_name(tcx, instance)).as_interned_str(),
226+
name: compute_symbol_name(tcx, instance),
236227
}
237228
}
238229

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

@@ -247,11 +238,13 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
247238
if def_id.is_local() {
248239
if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id) {
249240
let disambiguator = tcx.sess.local_crate_disambiguator();
250-
return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
241+
return Symbol::intern(&tcx.sess.generate_plugin_registrar_symbol(disambiguator))
242+
.as_interned_str();
251243
}
252244
if tcx.proc_macro_decls_static(LOCAL_CRATE) == Some(def_id) {
253245
let disambiguator = tcx.sess.local_crate_disambiguator();
254-
return tcx.sess.generate_proc_macro_decls_symbol(disambiguator);
246+
return Symbol::intern(&tcx.sess.generate_proc_macro_decls_symbol(disambiguator))
247+
.as_interned_str();
255248
}
256249
}
257250

@@ -268,20 +261,20 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
268261
let attrs = tcx.codegen_fn_attrs(def_id);
269262
if is_foreign {
270263
if let Some(name) = attrs.link_name {
271-
return name.to_string();
264+
return name.as_interned_str();
272265
}
273266
// Don't mangle foreign items.
274-
return tcx.item_name(def_id).to_string();
267+
return tcx.item_name(def_id);
275268
}
276269

277270
if let Some(name) = &attrs.export_name {
278271
// Use provided name
279-
return name.to_string();
272+
return name.as_interned_str();
280273
}
281274

282275
if attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE) {
283276
// Don't mangle
284-
return tcx.item_name(def_id).to_string();
277+
return tcx.item_name(def_id);
285278
}
286279

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

322315
let mut printer = SymbolPrinter {
323316
tcx,
324-
path: SymbolPath::from_interned(tcx.def_symbol_name(def_id)),
317+
path: SymbolPath::new(),
325318
keep_within_component: false,
326-
};
319+
}.print_def_path(def_id, &[]).unwrap();
327320

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

332-
printer.path.finish(hash)
325+
Symbol::intern(&printer.path.finish(hash)).as_interned_str()
333326
}
334327

335328
// Follow C++ namespace-mangling style, see
@@ -361,22 +354,6 @@ impl SymbolPath {
361354
result
362355
}
363356

364-
fn from_interned(symbol: ty::SymbolName) -> Self {
365-
let mut result = SymbolPath {
366-
result: String::with_capacity(64),
367-
temp_buf: String::with_capacity(16),
368-
};
369-
result.result.push_str(&symbol.as_str());
370-
result
371-
}
372-
373-
fn into_interned(mut self) -> ty::SymbolName {
374-
self.finalize_pending_component();
375-
ty::SymbolName {
376-
name: Symbol::intern(&self.result).as_interned_str(),
377-
}
378-
}
379-
380357
fn finalize_pending_component(&mut self) {
381358
if !self.temp_buf.is_empty() {
382359
let _ = write!(self.result, "{}{}", self.temp_buf.len(), self.temp_buf);

src/librustc_lint/builtin.rs

+36-11
Original file line numberDiff line numberDiff line change
@@ -1619,14 +1619,16 @@ impl LintPass for KeywordIdents {
16191619
}
16201620
}
16211621

1622+
struct UnderMacro(bool);
1623+
16221624
impl KeywordIdents {
16231625
fn check_tokens(&mut self, cx: &EarlyContext<'_>, tokens: TokenStream) {
16241626
for tt in tokens.into_trees() {
16251627
match tt {
16261628
TokenTree::Token(span, tok) => match tok.ident() {
16271629
// only report non-raw idents
16281630
Some((ident, false)) => {
1629-
self.check_ident(cx, ast::Ident {
1631+
self.check_ident_token(cx, UnderMacro(true), ast::Ident {
16301632
span: span.substitute_dummy(ident.span),
16311633
..ident
16321634
});
@@ -1639,16 +1641,12 @@ impl KeywordIdents {
16391641
}
16401642
}
16411643
}
1642-
}
16431644

1644-
impl EarlyLintPass for KeywordIdents {
1645-
fn check_mac_def(&mut self, cx: &EarlyContext<'_>, mac_def: &ast::MacroDef, _id: ast::NodeId) {
1646-
self.check_tokens(cx, mac_def.stream());
1647-
}
1648-
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) {
1649-
self.check_tokens(cx, mac.node.tts.clone().into());
1650-
}
1651-
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: ast::Ident) {
1645+
fn check_ident_token(&mut self,
1646+
cx: &EarlyContext<'_>,
1647+
UnderMacro(under_macro): UnderMacro,
1648+
ident: ast::Ident)
1649+
{
16521650
let ident_str = &ident.as_str()[..];
16531651
let cur_edition = cx.sess.edition();
16541652
let is_raw_ident = |ident: ast::Ident| {
@@ -1657,7 +1655,22 @@ impl EarlyLintPass for KeywordIdents {
16571655
let next_edition = match cur_edition {
16581656
Edition::Edition2015 => {
16591657
match ident_str {
1660-
"async" | "try" | "dyn" => Edition::Edition2018,
1658+
"async" | "try" => Edition::Edition2018,
1659+
1660+
// rust-lang/rust#56327: Conservatively do not
1661+
// attempt to report occurrences of `dyn` within
1662+
// macro definitions or invocations, because `dyn`
1663+
// can legitimately occur as a contextual keyword
1664+
// in 2015 code denoting its 2018 meaning, and we
1665+
// do not want rustfix to inject bugs into working
1666+
// code by rewriting such occurrences.
1667+
//
1668+
// But if we see `dyn` outside of a macro, we know
1669+
// its precise role in the parsed AST and thus are
1670+
// assured this is truly an attempt to use it as
1671+
// an identifier.
1672+
"dyn" if !under_macro => Edition::Edition2018,
1673+
16611674
// Only issue warnings for `await` if the `async_await`
16621675
// feature isn't being used. Otherwise, users need
16631676
// to keep using `await` for the macro exposed by std.
@@ -1715,6 +1728,18 @@ impl EarlyLintPass for KeywordIdents {
17151728
}
17161729
}
17171730

1731+
impl EarlyLintPass for KeywordIdents {
1732+
fn check_mac_def(&mut self, cx: &EarlyContext<'_>, mac_def: &ast::MacroDef, _id: ast::NodeId) {
1733+
self.check_tokens(cx, mac_def.stream());
1734+
}
1735+
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) {
1736+
self.check_tokens(cx, mac.node.tts.clone().into());
1737+
}
1738+
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: ast::Ident) {
1739+
self.check_ident_token(cx, UnderMacro(false), ident);
1740+
}
1741+
}
1742+
17181743

17191744
pub struct ExplicitOutlivesRequirements;
17201745

src/librustc_mir/transform/lower_128bit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn check_lang_item_type<'a, 'tcx, D>(
138138
let place_ty = place.ty(local_decls, tcx).to_ty(tcx);
139139
let expected = [lhs_ty, rhs_ty, place_ty];
140140
assert_eq!(sig.inputs_and_output[..], expected,
141-
"lang item {}", tcx.def_symbol_name(did));
141+
"lang item `{}`", tcx.def_path_str(did));
142142
did
143143
}
144144

src/librustdoc/clean/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1769,9 +1769,13 @@ fn get_real_types(
17691769
generics: &Generics,
17701770
arg: &Type,
17711771
cx: &DocContext<'_>,
1772+
recurse: i32,
17721773
) -> FxHashSet<Type> {
17731774
let arg_s = arg.to_string();
17741775
let mut res = FxHashSet::default();
1776+
if recurse >= 10 { // FIXME: remove this whole recurse thing when the recursion bug is fixed
1777+
return res;
1778+
}
17751779
if arg.is_full_generic() {
17761780
if let Some(where_pred) = generics.where_predicates.iter().find(|g| {
17771781
match g {
@@ -1788,7 +1792,7 @@ fn get_real_types(
17881792
continue
17891793
}
17901794
if let Some(ty) = x.get_type(cx) {
1791-
let adds = get_real_types(generics, &ty, cx);
1795+
let adds = get_real_types(generics, &ty, cx, recurse + 1);
17921796
if !adds.is_empty() {
17931797
res.extend(adds);
17941798
} else if !ty.is_full_generic() {
@@ -1806,7 +1810,7 @@ fn get_real_types(
18061810
}) {
18071811
for bound in bound.get_bounds().unwrap_or_else(|| &[]) {
18081812
if let Some(ty) = bound.get_trait_type() {
1809-
let adds = get_real_types(generics, &ty, cx);
1813+
let adds = get_real_types(generics, &ty, cx, recurse + 1);
18101814
if !adds.is_empty() {
18111815
res.extend(adds);
18121816
} else if !ty.is_full_generic() {
@@ -1820,7 +1824,7 @@ fn get_real_types(
18201824
if let Some(gens) = arg.generics() {
18211825
for gen in gens.iter() {
18221826
if gen.is_full_generic() {
1823-
let adds = get_real_types(generics, gen, cx);
1827+
let adds = get_real_types(generics, gen, cx, recurse + 1);
18241828
if !adds.is_empty() {
18251829
res.extend(adds);
18261830
}
@@ -1847,7 +1851,7 @@ pub fn get_all_types(
18471851
if arg.type_.is_self_type() {
18481852
continue;
18491853
}
1850-
let args = get_real_types(generics, &arg.type_, cx);
1854+
let args = get_real_types(generics, &arg.type_, cx, 0);
18511855
if !args.is_empty() {
18521856
all_types.extend(args);
18531857
} else {
@@ -1857,7 +1861,7 @@ pub fn get_all_types(
18571861

18581862
let ret_types = match decl.output {
18591863
FunctionRetTy::Return(ref return_type) => {
1860-
let mut ret = get_real_types(generics, &return_type, cx);
1864+
let mut ret = get_real_types(generics, &return_type, cx, 0);
18611865
if ret.is_empty() {
18621866
ret.insert(return_type.clone());
18631867
}

0 commit comments

Comments
 (0)