Skip to content

[WIP] Misc incr comp improvements around span hashing invalidation #92204

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

Closed
wants to merge 6 commits into from
Closed
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
7 changes: 4 additions & 3 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let tcx = self.tcx();

match *ak {
AggregateKind::Adt(def, variant_index, substs, _, active_field_index) => {
AggregateKind::Adt(adt_did, variant_index, substs, _, active_field_index) => {
let def = tcx.adt_def(adt_did);
let variant = &def.variants[variant_index];
let adj_field_index = active_field_index.unwrap_or(field_index);
if let Some(field) = variant.fields.get(adj_field_index) {
Expand Down Expand Up @@ -2621,8 +2622,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
);

let (def_id, instantiated_predicates) = match aggregate_kind {
AggregateKind::Adt(def, _, substs, _, _) => {
(def.did, tcx.predicates_of(def.did).instantiate(tcx, substs))
AggregateKind::Adt(adt_did, _, substs, _, _) => {
(*adt_did, tcx.predicates_of(*adt_did).instantiate(tcx, substs))
}

// For closures, we have some **extra requirements** we
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

mir::Rvalue::Aggregate(ref kind, ref operands) => {
let (dest, active_field_index) = match **kind {
mir::AggregateKind::Adt(adt_def, variant_index, _, _, active_field_index) => {
mir::AggregateKind::Adt(adt_did, variant_index, _, _, active_field_index) => {
dest.codegen_set_discr(&mut bx, variant_index);
if adt_def.is_enum() {
if bx.tcx().adt_def(adt_did).is_enum() {
(dest.project_downcast(&mut bx, variant_index), active_field_index)
} else {
(dest, active_field_index)
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
Aggregate(ref kind, ref operands) => {
// active_field_index is for union initialization.
let (dest, active_field_index) = match **kind {
mir::AggregateKind::Adt(adt_def, variant_index, _, _, active_field_index) => {
mir::AggregateKind::Adt(adt_did, variant_index, _, _, active_field_index) => {
self.write_discriminant(variant_index, &dest)?;
if adt_def.is_enum() {
if self.tcx.adt_def(adt_did).is_enum() {
assert!(active_field_index.is_none());
(self.place_downcast(&dest, variant_index)?, None)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ where
Rvalue::Aggregate(kind, operands) => {
// Return early if we know that the struct or enum being constructed is always
// qualified.
if let AggregateKind::Adt(def, _, substs, ..) = **kind {
if let AggregateKind::Adt(adt_did, _, substs, ..) = **kind {
let def = cx.tcx.adt_def(adt_did);
if Q::in_adt_inherently(cx, def, substs) {
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_const_eval/src/util/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ pub fn expand_aggregate<'tcx>(
) -> impl Iterator<Item = Statement<'tcx>> + TrustedLen {
let mut set_discriminant = None;
let active_field_index = match kind {
AggregateKind::Adt(adt_def, variant_index, _, _, active_field_index) => {
AggregateKind::Adt(adt_did, variant_index, _, _, active_field_index) => {
let adt_def = tcx.adt_def(adt_did);
if adt_def.is_enum() {
set_discriminant = Some(Statement {
kind: StatementKind::SetDiscriminant { place: Box::new(lhs), variant_index },
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ impl Path<'_> {
#[derive(Debug, HashStable_Generic)]
pub struct PathSegment<'hir> {
/// The identifier portion of this path segment.
#[stable_hasher(project(name))]
pub ident: Ident,
// `id` and `res` are optional. We currently only use these in save-analysis,
// any path segments without these will not have save-analysis info and
Expand Down Expand Up @@ -850,7 +849,6 @@ pub struct PatField<'hir> {
#[stable_hasher(ignore)]
pub hir_id: HirId,
/// The identifier for the field.
#[stable_hasher(project(name))]
pub ident: Ident,
/// The pattern the field is destructured to.
pub pat: &'hir Pat<'hir>,
Expand Down Expand Up @@ -2113,7 +2111,6 @@ pub const FN_OUTPUT_NAME: Symbol = sym::Output;
#[derive(Debug, HashStable_Generic)]
pub struct TypeBinding<'hir> {
pub hir_id: HirId,
#[stable_hasher(project(name))]
pub ident: Ident,
pub gen_args: &'hir GenericArgs<'hir>,
pub kind: TypeBindingKind<'hir>,
Expand Down Expand Up @@ -2501,7 +2498,6 @@ pub struct EnumDef<'hir> {
#[derive(Debug, HashStable_Generic)]
pub struct Variant<'hir> {
/// Name of the variant.
#[stable_hasher(project(name))]
pub ident: Ident,
/// Id of the variant (not the constructor, see `VariantData::ctor_hir_id()`).
pub id: HirId,
Expand Down Expand Up @@ -2591,7 +2587,6 @@ impl VisibilityKind<'_> {
#[derive(Debug, HashStable_Generic)]
pub struct FieldDef<'hir> {
pub span: Span,
#[stable_hasher(project(name))]
pub ident: Ident,
pub vis: Visibility<'hir>,
pub hir_id: HirId,
Expand Down Expand Up @@ -2850,7 +2845,6 @@ impl ItemKind<'_> {
#[derive(Encodable, Debug, HashStable_Generic)]
pub struct TraitItemRef {
pub id: TraitItemId,
#[stable_hasher(project(name))]
pub ident: Ident,
pub kind: AssocItemKind,
pub span: Span,
Expand All @@ -2866,7 +2860,6 @@ pub struct TraitItemRef {
#[derive(Debug, HashStable_Generic)]
pub struct ImplItemRef {
pub id: ImplItemId,
#[stable_hasher(project(name))]
pub ident: Ident,
pub kind: AssocItemKind,
pub span: Span,
Expand Down Expand Up @@ -2905,7 +2898,6 @@ impl ForeignItemId {
#[derive(Debug, HashStable_Generic)]
pub struct ForeignItemRef {
pub id: ForeignItemId,
#[stable_hasher(project(name))]
pub ident: Ident,
pub span: Span,
}
Expand Down
32 changes: 15 additions & 17 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,7 @@ pub enum AggregateKind<'tcx> {
/// active field number and is present only for union expressions
/// -- e.g., for a union expression `SomeUnion { c: .. }`, the
/// active field index would identity the field `c`
Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>),
Adt(DefId, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>),

Closure(DefId, SubstsRef<'tcx>),
Generator(DefId, SubstsRef<'tcx>, hir::Movability),
Expand Down Expand Up @@ -2427,28 +2427,26 @@ impl<'tcx> Debug for Rvalue<'tcx> {
}
}

AggregateKind::Adt(adt_def, variant, substs, _user_ty, _) => {
let variant_def = &adt_def.variants[variant];

let name = ty::tls::with(|tcx| {
AggregateKind::Adt(adt_did, variant, substs, _user_ty, _) => {
ty::tls::with(|tcx| {
let mut name = String::new();
let variant_def = &tcx.adt_def(adt_did).variants[variant];
let substs = tcx.lift(substs).expect("could not lift for printing");
FmtPrinter::new(tcx, &mut name, Namespace::ValueNS)
.print_def_path(variant_def.def_id, substs)?;
Ok(name)
})?;

match variant_def.ctor_kind {
CtorKind::Const => fmt.write_str(&name),
CtorKind::Fn => fmt_tuple(fmt, &name),
CtorKind::Fictive => {
let mut struct_fmt = fmt.debug_struct(&name);
for (field, place) in iter::zip(&variant_def.fields, places) {
struct_fmt.field(field.ident.as_str(), place);

match variant_def.ctor_kind {
CtorKind::Const => fmt.write_str(&name),
CtorKind::Fn => fmt_tuple(fmt, &name),
CtorKind::Fictive => {
let mut struct_fmt = fmt.debug_struct(&name);
for (field, place) in iter::zip(&variant_def.fields, places) {
struct_fmt.field(field.ident.as_str(), place);
}
struct_fmt.finish()
}
struct_fmt.finish()
}
}
})
}

AggregateKind::Closure(def_id, substs) => ty::tls::with(|tcx| {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl<'tcx> Rvalue<'tcx> {
Rvalue::Aggregate(ref ak, ref ops) => match **ak {
AggregateKind::Array(ty) => tcx.mk_array(ty, ops.len() as u64),
AggregateKind::Tuple => tcx.mk_tup(ops.iter().map(|op| op.ty(local_decls, tcx))),
AggregateKind::Adt(def, _, substs, _, _) => tcx.type_of(def.did).subst(tcx, substs),
AggregateKind::Adt(did, _, substs, _, _) => tcx.type_of(did).subst(tcx, substs),
AggregateKind::Closure(did, substs) => tcx.mk_closure(did, substs),
AggregateKind::Generator(did, substs, movability) => {
tcx.mk_generator(did, substs, movability)
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,11 @@ rustc_queries! {
cache_on_disk_if { true }
}

/// DO NOT call this directly - always use `symbol_name`
query symbol_name_for_plain_item(def_id: DefId) -> ty::SymbolName<'tcx> {
desc { "computing the symbol name for plain item `{}`", tcx.def_path_str(def_id) }
}

query opt_def_kind(def_id: DefId) -> Option<DefKind> {
desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
separate_provide_extern
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/ty/assoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ impl AssocItemContainer {
#[derive(Copy, Clone, Debug, PartialEq, HashStable, Eq, Hash)]
pub struct AssocItem {
pub def_id: DefId,
#[stable_hasher(project(name))]
pub ident: Ident,
pub kind: AssocKind,
pub vis: Visibility,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,6 @@ pub struct VariantDef {
/// If this variant is a struct variant, then this is `None`.
pub ctor_def_id: Option<DefId>,
/// Variant or struct name.
#[stable_hasher(project(name))]
pub ident: Ident,
/// Discriminant of this variant.
pub discr: VariantDiscr,
Expand Down Expand Up @@ -1598,7 +1597,6 @@ pub enum VariantDiscr {
#[derive(Debug, HashStable, TyEncodable, TyDecodable)]
pub struct FieldDef {
pub did: DefId,
#[stable_hasher(project(name))]
pub ident: Ident,
pub vis: Visibility,
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
})
});
let adt = Box::new(AggregateKind::Adt(
adt_def,
adt_def.did,
variant_index,
substs,
user_ty,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> {
match rvalue {
Rvalue::Aggregate(box ref aggregate, _) => match aggregate {
&AggregateKind::Array(..) | &AggregateKind::Tuple => {}
&AggregateKind::Adt(ref def, ..) => {
match self.tcx.layout_scalar_valid_range(def.did) {
&AggregateKind::Adt(adt_did, ..) => {
match self.tcx.layout_scalar_valid_range(adt_did) {
(Bound::Unbounded, Bound::Unbounded) => {}
_ => self.require_unsafe(
UnsafetyViolationKind::General,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl<'tcx> TransformVisitor<'tcx> {
val: Operand<'tcx>,
source_info: SourceInfo,
) -> impl Iterator<Item = Statement<'tcx>> {
let kind = AggregateKind::Adt(self.state_adt_ref, idx, self.state_substs, None, None);
let kind = AggregateKind::Adt(self.state_adt_ref.did, idx, self.state_substs, None, None);
assert_eq!(self.state_adt_ref.variants[idx].fields.len(), 1);
let ty = self
.tcx
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
adt_def.variants[variant_index].fields.iter().enumerate().map(|(idx, field_def)| {
(Operand::Move(Place::from(Local::new(idx + 1))), field_def.ty(tcx, substs))
}),
AggregateKind::Adt(adt_def, variant_index, substs, None, None),
AggregateKind::Adt(adt_def.did, variant_index, substs, None, None),
source_info,
tcx,
)
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_query_system/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl std::convert::From<DepNodeIndex> for QueryInvocationId {
}
}

#[derive(PartialEq)]
#[derive(PartialEq, Debug)]
pub enum DepNodeColor {
Red,
Green(DepNodeIndex),
Expand Down Expand Up @@ -285,6 +285,7 @@ impl<K: DepKind> DepGraph<K> {
key
);

tracing::info!("Inserting color: {:?} {:?}", key, color);
data.colors.insert(prev_index, color);
}

Expand Down Expand Up @@ -1156,6 +1157,7 @@ impl DepNodeColorMap {
}

fn insert(&self, index: SerializedDepNodeIndex, color: DepNodeColor) {
tracing::info!("Actually storing: {:?} {:?}", index, color);
self.values[index].store(
match color {
DepNodeColor::Red => COMPRESSED_RED,
Expand Down
42 changes: 38 additions & 4 deletions compiler/rustc_symbol_mangling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ use rustc_hir::Node;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::mono::{InstantiationMode, MonoItem};
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
use rustc_middle::ty::{self, Instance, InstanceDef, Ty, TyCtxt, WithOptConstParam};
use rustc_session::config::SymbolManglingVersion;
use rustc_span::def_id::DefId;
use rustc_target::abi::call::FnAbi;

use tracing::debug;
Expand All @@ -124,13 +125,46 @@ pub fn symbol_name_for_instance_in_crate<'tcx>(
}

pub fn provide(providers: &mut Providers) {
*providers = Providers { symbol_name: symbol_name_provider, ..*providers };
*providers = Providers {
symbol_name: symbol_name_provider,
symbol_name_for_plain_item: symbol_name_for_plain_item_provider,
..*providers
};
}

fn symbol_name_for_plain_item_provider<'tcx>(
tcx: TyCtxt<'tcx>,
def_id: DefId,
) -> ty::SymbolName<'tcx> {
symbol_name_provider_body(
tcx,
Instance {
def: InstanceDef::Item(WithOptConstParam::unknown(def_id)),
substs: InternalSubsts::empty(),
},
)
}

fn symbol_name_provider<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::SymbolName<'tcx> {
if let Instance {
def: InstanceDef::Item(WithOptConstParam { did: def_id, const_param_did: None }),
substs,
} = instance
{
if substs.is_empty() {
return tcx.symbol_name_for_plain_item(def_id);
}
}
symbol_name_provider_body(tcx, instance)
}

// The `symbol_name` query provides the symbol name for calling a given
// instance from the local crate. In particular, it will also look up the
// correct symbol name of instances from upstream crates.
fn symbol_name_provider<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::SymbolName<'tcx> {
fn symbol_name_provider_body<'tcx>(
tcx: TyCtxt<'tcx>,
instance: Instance<'tcx>,
) -> ty::SymbolName<'tcx> {
let symbol_name = compute_symbol_name(tcx, instance, || {
// This closure determines the instantiating crate for instances that
// need an instantiating-crate-suffix for their symbol name, in order
Expand Down
Loading