Skip to content

Commit 72e74d7

Browse files
committed
Auto merge of #92533 - Aaron1011:variant-symbol, r=petrochenkov
Store a `Symbol` instead of an `Ident` in `VariantDef`/`FieldDef` The field is also renamed from `ident` to `name`. In most cases, we don't actually need the `Span`. A new `ident` method is added to `VariantDef` and `FieldDef`, which constructs the full `Ident` using `tcx.def_ident_span()`. This method is used in the cases where we actually need an `Ident`. This makes incremental compilation properly track changes to the `Span`, without all of the invalidations caused by storing a `Span` directly via an `Ident`.
2 parents 1409c01 + 450ef86 commit 72e74d7

File tree

38 files changed

+120
-107
lines changed

38 files changed

+120
-107
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
372372
} else {
373373
def.non_enum_variant()
374374
};
375-
variant.fields[field.index()].ident.to_string()
375+
variant.fields[field.index()].name.to_string()
376376
}
377377
ty::Tuple(_) => field.index().to_string(),
378378
ty::Ref(_, ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) => {

compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl<'tcx> DebugContext<'tcx> {
174174

175175
field_entry.set(
176176
gimli::DW_AT_name,
177-
AttributeValue::String(field_def.ident.as_str().to_string().into_bytes()),
177+
AttributeValue::String(field_def.name.as_str().to_string().into_bytes()),
178178
);
179179
field_entry.set(
180180
gimli::DW_AT_data_member_location,

compiler/rustc_codegen_gcc/src/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn uncached_gcc_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLa
5757
(layout.ty.kind(), &layout.variants)
5858
{
5959
if def.is_enum() && !def.variants.is_empty() {
60-
write!(&mut name, "::{}", def.variants[index].ident).unwrap();
60+
write!(&mut name, "::{}", def.variants[index].name).unwrap();
6161
}
6262
}
6363
if let (&ty::Generator(_, _, _), &Variants::Single { index }) =

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ impl<'tcx> StructMemberDescriptionFactory<'tcx> {
13001300
let name = if self.variant.ctor_kind == CtorKind::Fn {
13011301
format!("__{}", i)
13021302
} else {
1303-
f.ident.to_string()
1303+
f.name.to_string()
13041304
};
13051305
let field = layout.field(cx, i);
13061306
MemberDescription {
@@ -1480,7 +1480,7 @@ impl<'tcx> UnionMemberDescriptionFactory<'tcx> {
14801480
.map(|(i, f)| {
14811481
let field = self.layout.field(cx, i);
14821482
MemberDescription {
1483-
name: f.ident.to_string(),
1483+
name: f.name.to_string(),
14841484
type_metadata: type_metadata(cx, field.ty, self.span),
14851485
offset: Size::ZERO,
14861486
size: field.size,
@@ -1950,7 +1950,7 @@ enum VariantInfo<'a, 'tcx> {
19501950
impl<'tcx> VariantInfo<'_, 'tcx> {
19511951
fn map_struct_name<R>(&self, f: impl FnOnce(&str) -> R) -> R {
19521952
match self {
1953-
VariantInfo::Adt(variant) => f(variant.ident.as_str()),
1953+
VariantInfo::Adt(variant) => f(variant.name.as_str()),
19541954
VariantInfo::Generator { variant_index, .. } => {
19551955
f(&GeneratorSubsts::variant_name(*variant_index))
19561956
}
@@ -1959,7 +1959,7 @@ impl<'tcx> VariantInfo<'_, 'tcx> {
19591959

19601960
fn variant_name(&self) -> String {
19611961
match self {
1962-
VariantInfo::Adt(variant) => variant.ident.to_string(),
1962+
VariantInfo::Adt(variant) => variant.name.to_string(),
19631963
VariantInfo::Generator { variant_index, .. } => {
19641964
// Since GDB currently prints out the raw discriminant along
19651965
// with every variant, make each variant name be just the value
@@ -1973,7 +1973,7 @@ impl<'tcx> VariantInfo<'_, 'tcx> {
19731973
fn field_name(&self, i: usize) -> String {
19741974
let field_name = match *self {
19751975
VariantInfo::Adt(variant) if variant.ctor_kind != CtorKind::Fn => {
1976-
Some(variant.fields[i].ident.name)
1976+
Some(variant.fields[i].name)
19771977
}
19781978
VariantInfo::Generator {
19791979
generator_layout,
@@ -2063,7 +2063,7 @@ fn prepare_enum_metadata<'ll, 'tcx>(
20632063
let enumerators_metadata: Vec<_> = match enum_type.kind() {
20642064
ty::Adt(def, _) => iter::zip(def.discriminants(tcx), &def.variants)
20652065
.map(|((_, discr), v)| {
2066-
let name = v.ident.as_str();
2066+
let name = v.name.as_str();
20672067
let is_unsigned = match discr.ty.kind() {
20682068
ty::Int(_) => false,
20692069
ty::Uint(_) => true,

compiler/rustc_codegen_llvm/src/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn uncached_llvm_type<'a, 'tcx>(
4949
(layout.ty.kind(), &layout.variants)
5050
{
5151
if def.is_enum() && !def.variants.is_empty() {
52-
write!(&mut name, "::{}", def.variants[index].ident).unwrap();
52+
write!(&mut name, "::{}", def.variants[index].name).unwrap();
5353
}
5454
}
5555
if let (&ty::Generator(_, _, _), &Variants::Single { index }) =

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,14 +409,14 @@ fn push_debuginfo_type_name<'tcx>(
409409
let max = dataful_discriminant_range.end;
410410
let max = tag.value.size(&tcx).truncate(max);
411411

412-
let dataful_variant_name = def.variants[*dataful_variant].ident.as_str();
412+
let dataful_variant_name = def.variants[*dataful_variant].name.as_str();
413413

414414
output.push_str(&format!(", {}, {}, {}", min, max, dataful_variant_name));
415415
} else if let Variants::Single { index: variant_idx } = &layout.variants {
416416
// Uninhabited enums can't be constructed and should never need to be visualized so
417417
// skip this step for them.
418418
if def.variants.len() != 0 {
419-
let variant = def.variants[*variant_idx].ident.as_str();
419+
let variant = def.variants[*variant_idx].name.as_str();
420420

421421
output.push_str(&format!(", {}", variant));
422422
}

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,14 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
267267
match layout.variants {
268268
Variants::Single { index } => {
269269
// Inside a variant
270-
PathElem::Field(def.variants[index].fields[field].ident.name)
270+
PathElem::Field(def.variants[index].fields[field].name)
271271
}
272272
Variants::Multiple { .. } => bug!("we handled variants above"),
273273
}
274274
}
275275

276276
// other ADTs
277-
ty::Adt(def, _) => PathElem::Field(def.non_enum_variant().fields[field].ident.name),
277+
ty::Adt(def, _) => PathElem::Field(def.non_enum_variant().fields[field].name),
278278

279279
// arrays/slices
280280
ty::Array(..) | ty::Slice(..) => PathElem::ArrayElem(field),
@@ -726,7 +726,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
726726
new_op: &OpTy<'tcx, M::PointerTag>,
727727
) -> InterpResult<'tcx> {
728728
let name = match old_op.layout.ty.kind() {
729-
ty::Adt(adt, _) => PathElem::Variant(adt.variants[variant_id].ident.name),
729+
ty::Adt(adt, _) => PathElem::Variant(adt.variants[variant_id].name),
730730
// Generators also have variants
731731
ty::Generator(..) => PathElem::GeneratorState(variant_id),
732732
_ => bug!("Unexpected type with variant: {:?}", old_op.layout.ty),

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
19211921
.fields
19221922
.iter()
19231923
.filter(|field| field.vis.is_accessible_from(field.did, self.tcx))
1924-
.map(|field| (field.ident.name, field.ty(self.tcx, expected_substs)))
1924+
.map(|field| (field.name, field.ty(self.tcx, expected_substs)))
19251925
.find(|(_, ty)| same_type_modulo_infer(ty, exp_found.found))
19261926
{
19271927
if let ObligationCauseCode::Pattern { span: Some(span), .. } = *cause.code() {

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
862862
let ctor_did = data.ctor.map(|index| self.local_def_id(index));
863863

864864
ty::VariantDef::new(
865-
self.item_ident(index, sess),
865+
self.item_ident(index, sess).name,
866866
variant_did,
867867
ctor_did,
868868
data.discr,
@@ -874,7 +874,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
874874
.decode(self)
875875
.map(|index| ty::FieldDef {
876876
did: self.local_def_id(index),
877-
ident: self.item_ident(index, sess),
877+
name: self.item_ident(index, sess).name,
878878
vis: self.get_visibility(index),
879879
})
880880
.collect(),

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
10521052
assert!(f.did.is_local());
10531053
f.did.index
10541054
}));
1055-
self.encode_ident_span(def_id, variant.ident);
1055+
self.encode_ident_span(def_id, variant.ident(tcx));
10561056
self.encode_item_type(def_id);
10571057
if variant.ctor_kind == CtorKind::Fn {
10581058
// FIXME(eddyb) encode signature only in `encode_enum_variant_ctor`.
@@ -1138,7 +1138,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11381138
debug!("EncodeContext::encode_field({:?})", def_id);
11391139

11401140
record!(self.tables.kind[def_id] <- EntryKind::Field);
1141-
self.encode_ident_span(def_id, field.ident);
1141+
self.encode_ident_span(def_id, field.ident(self.tcx));
11421142
self.encode_item_type(def_id);
11431143
}
11441144

0 commit comments

Comments
 (0)