Skip to content

Commit cee562c

Browse files
authored
Rollup merge of #143361 - cjgillot:split-disambig, r=oli-obk
Stop passing resolver disambiguator state to AST lowering. AST->HIR lowering can use a disjoint set of `DefPathData` as the resolver, so we don't need to pass the disambiguator state. r? `@oli-obk`
2 parents e4407c0 + b67453f commit cee562c

File tree

10 files changed

+46
-14
lines changed

10 files changed

+46
-14
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_data_structures::stack::ensure_sufficient_stack;
77
use rustc_hir as hir;
88
use rustc_hir::attrs::AttributeKind;
99
use rustc_hir::def::{DefKind, Res};
10+
use rustc_hir::definitions::DefPathData;
1011
use rustc_hir::{HirId, Target, find_attr};
1112
use rustc_middle::span_bug;
1213
use rustc_middle::ty::TyCtxt;
@@ -461,7 +462,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
461462
for (idx, arg) in args.iter().cloned().enumerate() {
462463
if legacy_args_idx.contains(&idx) {
463464
let node_id = self.next_node_id();
464-
self.create_def(node_id, None, DefKind::AnonConst, f.span);
465+
self.create_def(
466+
node_id,
467+
None,
468+
DefKind::AnonConst,
469+
DefPathData::LateAnonConst,
470+
f.span,
471+
);
465472
let mut visitor = WillCreateDefIdsVisitor {};
466473
let const_value = if let ControlFlow::Break(span) = visitor.visit_expr(&arg) {
467474
Box::new(Expr {

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use rustc_data_structures::tagged_ptr::TaggedRef;
5151
use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle};
5252
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
5353
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId};
54+
use rustc_hir::definitions::{DefPathData, DisambiguatorState};
5455
use rustc_hir::lints::DelayedLint;
5556
use rustc_hir::{
5657
self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LifetimeSource,
@@ -93,6 +94,7 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
9394
struct LoweringContext<'a, 'hir> {
9495
tcx: TyCtxt<'hir>,
9596
resolver: &'a mut ResolverAstLowering,
97+
disambiguator: DisambiguatorState,
9698

9799
/// Used to allocate HIR nodes.
98100
arena: &'hir hir::Arena<'hir>,
@@ -155,6 +157,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
155157
// Pseudo-globals.
156158
tcx,
157159
resolver,
160+
disambiguator: DisambiguatorState::new(),
158161
arena: tcx.hir_arena,
159162

160163
// HirId handling.
@@ -546,6 +549,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
546549
node_id: ast::NodeId,
547550
name: Option<Symbol>,
548551
def_kind: DefKind,
552+
def_path_data: DefPathData,
549553
span: Span,
550554
) -> LocalDefId {
551555
let parent = self.current_hir_id_owner.def_id;
@@ -561,7 +565,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
561565
let def_id = self
562566
.tcx
563567
.at(span)
564-
.create_def(parent, name, def_kind, None, &mut self.resolver.disambiguator)
568+
.create_def(parent, name, def_kind, Some(def_path_data), &mut self.disambiguator)
565569
.def_id();
566570

567571
debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
@@ -846,6 +850,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
846850
param,
847851
Some(kw::UnderscoreLifetime),
848852
DefKind::LifetimeParam,
853+
DefPathData::DesugaredAnonymousLifetime,
849854
ident.span,
850855
);
851856
debug!(?_def_id);
@@ -2290,7 +2295,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22902295
// We're lowering a const argument that was originally thought to be a type argument,
22912296
// so the def collector didn't create the def ahead of time. That's why we have to do
22922297
// it here.
2293-
let def_id = self.create_def(node_id, None, DefKind::AnonConst, span);
2298+
let def_id = self.create_def(
2299+
node_id,
2300+
None,
2301+
DefKind::AnonConst,
2302+
DefPathData::LateAnonConst,
2303+
span,
2304+
);
22942305
let hir_id = self.lower_node_id(node_id);
22952306

22962307
let path_expr = Expr {

compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::sync::Arc;
33
use rustc_ast::*;
44
use rustc_data_structures::stack::ensure_sufficient_stack;
55
use rustc_hir::def::{DefKind, Res};
6+
use rustc_hir::definitions::DefPathData;
67
use rustc_hir::{self as hir, LangItem, Target};
78
use rustc_middle::span_bug;
89
use rustc_span::source_map::{Spanned, respan};
@@ -527,7 +528,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
527528
// We're generating a range end that didn't exist in the AST,
528529
// so the def collector didn't create the def ahead of time. That's why we have to do
529530
// it here.
530-
let def_id = self.create_def(node_id, None, DefKind::AnonConst, span);
531+
let def_id =
532+
self.create_def(node_id, None, DefKind::AnonConst, DefPathData::LateAnonConst, span);
531533
let hir_id = self.lower_node_id(node_id);
532534

533535
let unstable_span = self.mark_span_with_reason(

compiler/rustc_hir/src/definitions.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ pub enum DefPathData {
302302
Ctor,
303303
/// A constant expression (see `{ast,hir}::AnonConst`).
304304
AnonConst,
305+
/// A constant expression created during AST->HIR lowering..
306+
LateAnonConst,
307+
/// A fresh anonymous lifetime created by desugaring elided lifetimes.
308+
DesugaredAnonymousLifetime,
305309
/// An existential `impl Trait` type node.
306310
/// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name.
307311
OpaqueTy,
@@ -454,6 +458,8 @@ impl DefPathData {
454458
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name)
455459
| OpaqueLifetime(name) => Some(name),
456460

461+
DesugaredAnonymousLifetime => Some(kw::UnderscoreLifetime),
462+
457463
Impl
458464
| ForeignMod
459465
| CrateRoot
@@ -462,6 +468,7 @@ impl DefPathData {
462468
| Closure
463469
| Ctor
464470
| AnonConst
471+
| LateAnonConst
465472
| OpaqueTy
466473
| AnonAssocTy(..)
467474
| SyntheticCoroutineBody
@@ -475,6 +482,8 @@ impl DefPathData {
475482
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) | AnonAssocTy(name)
476483
| OpaqueLifetime(name) => Some(name),
477484

485+
DesugaredAnonymousLifetime => Some(kw::UnderscoreLifetime),
486+
478487
Impl
479488
| ForeignMod
480489
| CrateRoot
@@ -483,6 +492,7 @@ impl DefPathData {
483492
| Closure
484493
| Ctor
485494
| AnonConst
495+
| LateAnonConst
486496
| OpaqueTy
487497
| SyntheticCoroutineBody
488498
| NestedStatic => None,
@@ -502,7 +512,8 @@ impl DefPathData {
502512
GlobalAsm => DefPathDataName::Anon { namespace: sym::global_asm },
503513
Closure => DefPathDataName::Anon { namespace: sym::closure },
504514
Ctor => DefPathDataName::Anon { namespace: sym::constructor },
505-
AnonConst => DefPathDataName::Anon { namespace: sym::constant },
515+
AnonConst | LateAnonConst => DefPathDataName::Anon { namespace: sym::constant },
516+
DesugaredAnonymousLifetime => DefPathDataName::Named(kw::UnderscoreLifetime),
506517
OpaqueTy => DefPathDataName::Anon { namespace: sym::opaque },
507518
AnonAssocTy(..) => DefPathDataName::Anon { namespace: sym::anon_assoc },
508519
SyntheticCoroutineBody => DefPathDataName::Anon { namespace: sym::synthetic },

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use rustc_errors::{Diag, ErrorGuaranteed, LintBuffer};
3737
use rustc_hir::attrs::{AttributeKind, StrippedCfgItem};
3838
use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res};
3939
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap};
40-
use rustc_hir::definitions::DisambiguatorState;
4140
use rustc_hir::{LangItem, attrs as attr, find_attr};
4241
use rustc_index::IndexVec;
4342
use rustc_index::bit_set::BitMatrix;
@@ -211,8 +210,6 @@ pub struct ResolverAstLowering {
211210

212211
pub node_id_to_def_id: NodeMap<LocalDefId>,
213212

214-
pub disambiguator: DisambiguatorState,
215-
216213
pub trait_map: NodeMap<Vec<hir::TraitCandidate>>,
217214
/// List functions and methods for which lifetime elision was successful.
218215
pub lifetime_elision_allowed: FxHashSet<ast::NodeId>,

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,7 @@ fn guess_def_namespace(tcx: TyCtxt<'_>, def_id: DefId) -> Namespace {
21562156

21572157
DefPathData::ValueNs(..)
21582158
| DefPathData::AnonConst
2159+
| DefPathData::LateAnonConst
21592160
| DefPathData::Closure
21602161
| DefPathData::Ctor => Namespace::ValueNS,
21612162

compiler/rustc_resolve/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1791,7 +1791,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17911791
.into_items()
17921792
.map(|(k, f)| (k, f.key()))
17931793
.collect(),
1794-
disambiguator: self.disambiguator,
17951794
trait_map: self.trait_map,
17961795
lifetime_elision_allowed: self.lifetime_elision_allowed,
17971796
lint_buffer: Steal::new(self.lint_buffer),

compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,8 @@ fn encode_ty_name(tcx: TyCtxt<'_>, def_id: DefId) -> String {
712712
hir::definitions::DefPathData::ValueNs(..) => "v",
713713
hir::definitions::DefPathData::Closure => "C",
714714
hir::definitions::DefPathData::Ctor => "c",
715-
hir::definitions::DefPathData::AnonConst => "k",
715+
hir::definitions::DefPathData::AnonConst => "K",
716+
hir::definitions::DefPathData::LateAnonConst => "k",
716717
hir::definitions::DefPathData::OpaqueTy => "i",
717718
hir::definitions::DefPathData::SyntheticCoroutineBody => "s",
718719
hir::definitions::DefPathData::NestedStatic => "n",
@@ -722,6 +723,7 @@ fn encode_ty_name(tcx: TyCtxt<'_>, def_id: DefId) -> String {
722723
| hir::definitions::DefPathData::MacroNs(..)
723724
| hir::definitions::DefPathData::OpaqueLifetime(..)
724725
| hir::definitions::DefPathData::LifetimeNs(..)
726+
| hir::definitions::DefPathData::DesugaredAnonymousLifetime
725727
| hir::definitions::DefPathData::AnonAssocTy(..) => {
726728
bug!("encode_ty_name: unexpected `{:?}`", disambiguated_data.data);
727729
}

compiler/rustc_symbol_mangling/src/v0.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,8 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> {
877877
DefPathData::ValueNs(_) => 'v',
878878
DefPathData::Closure => 'C',
879879
DefPathData::Ctor => 'c',
880-
DefPathData::AnonConst => 'k',
880+
DefPathData::AnonConst => 'K',
881+
DefPathData::LateAnonConst => 'k',
881882
DefPathData::OpaqueTy => 'i',
882883
DefPathData::SyntheticCoroutineBody => 's',
883884
DefPathData::NestedStatic => 'n',
@@ -889,6 +890,7 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> {
889890
| DefPathData::Impl
890891
| DefPathData::MacroNs(_)
891892
| DefPathData::LifetimeNs(_)
893+
| DefPathData::DesugaredAnonymousLifetime
892894
| DefPathData::OpaqueLifetime(_)
893895
| DefPathData::AnonAssocTy(..) => {
894896
bug!("symbol_names: unexpected DefPathData: {:?}", disambiguated_data.data)

tests/codegen-llvm/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-paths.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ pub fn foo12(_: &Type4, _: &Type4, _: &Type4) {}
7878
// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo11{{[{}][{}]}}closure{{[}][}]}}3FooEE"}
7979
// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo11{{[{}][{}]}}closure{{[}][}]}}3FooES0_E"}
8080
// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo11{{[{}][{}]}}closure{{[}][}]}}3FooES0_S0_E"}
81-
// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooEE"}
82-
// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooES0_E"}
83-
// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooES0_S0_E"}
81+
// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNKNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooEE"}
82+
// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNKNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooES0_E"}
83+
// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NtNKNvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo12{{[{}][{}]}}constant{{[}][}]}}3FooES0_S0_E"}
8484
// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo8{{[{}][{}]}}impl{{[}][}]}}3barEE"}
8585
// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo8{{[{}][{}]}}impl{{[}][}]}}3barES0_E"}
8686
// CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFvu3refIu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_{{[[:print:]]+}}3foo8{{[{}][{}]}}impl{{[}][}]}}3barES0_S0_E"}

0 commit comments

Comments
 (0)