Skip to content

Commit f6fea83

Browse files
committed
Effects cleanup
- removed extra bits from predicates queries that are no longer needed in the new system - removed the need for `non_erasable_generics` to take in tcx and DefId, removed unused arguments in callers
1 parent c1db4dc commit f6fea83

File tree

23 files changed

+40
-97
lines changed

23 files changed

+40
-97
lines changed

compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ impl DebugContext {
210210
type_names::push_generic_params(
211211
tcx,
212212
tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), args),
213-
enclosing_fn_def_id,
214213
&mut name,
215214
);
216215

compiler/rustc_codegen_gcc/src/callee.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>)
9898
// whether we are sharing generics or not. The important thing here is
9999
// that the visibility we apply to the declaration is the same one that
100100
// has been applied to the definition (wherever that definition may be).
101-
let is_generic =
102-
instance.args.non_erasable_generics(tcx, instance.def_id()).next().is_some();
101+
let is_generic = instance.args.non_erasable_generics().next().is_some();
103102

104103
if is_generic {
105104
// This is a monomorphization. Its expected visibility depends

compiler/rustc_codegen_llvm/src/callee.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
9898
unsafe {
9999
llvm::LLVMRustSetLinkage(llfn, llvm::Linkage::ExternalLinkage);
100100

101-
let is_generic =
102-
instance.args.non_erasable_generics(tcx, instance.def_id()).next().is_some();
101+
let is_generic = instance.args.non_erasable_generics().next().is_some();
103102

104103
let is_hidden = if is_generic {
105104
// This is a monomorphization of a generic function.

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
350350
type_names::push_generic_params(
351351
tcx,
352352
tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), args),
353-
enclosing_fn_def_id,
354353
&mut name,
355354
);
356355

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ fn exported_symbols_provider_local(
312312

313313
match *mono_item {
314314
MonoItem::Fn(Instance { def: InstanceKind::Item(def), args }) => {
315-
if args.non_erasable_generics(tcx, def).next().is_some() {
315+
if args.non_erasable_generics().next().is_some() {
316316
let symbol = ExportedSymbol::Generic(def, args);
317317
symbols.push((symbol, SymbolExportInfo {
318318
level: SymbolExportLevel::Rust,
@@ -321,27 +321,21 @@ fn exported_symbols_provider_local(
321321
}));
322322
}
323323
}
324-
MonoItem::Fn(Instance { def: InstanceKind::DropGlue(def_id, Some(ty)), args }) => {
324+
MonoItem::Fn(Instance { def: InstanceKind::DropGlue(_, Some(ty)), args }) => {
325325
// A little sanity-check
326-
assert_eq!(
327-
args.non_erasable_generics(tcx, def_id).next(),
328-
Some(GenericArgKind::Type(ty))
329-
);
326+
assert_eq!(args.non_erasable_generics().next(), Some(GenericArgKind::Type(ty)));
330327
symbols.push((ExportedSymbol::DropGlue(ty), SymbolExportInfo {
331328
level: SymbolExportLevel::Rust,
332329
kind: SymbolExportKind::Text,
333330
used: false,
334331
}));
335332
}
336333
MonoItem::Fn(Instance {
337-
def: InstanceKind::AsyncDropGlueCtorShim(def_id, Some(ty)),
334+
def: InstanceKind::AsyncDropGlueCtorShim(_, Some(ty)),
338335
args,
339336
}) => {
340337
// A little sanity-check
341-
assert_eq!(
342-
args.non_erasable_generics(tcx, def_id).next(),
343-
Some(GenericArgKind::Type(ty))
344-
);
338+
assert_eq!(args.non_erasable_generics().next(), Some(GenericArgKind::Type(ty)));
345339
symbols.push((ExportedSymbol::AsyncDropGlueCtorShim(ty), SymbolExportInfo {
346340
level: SymbolExportLevel::Rust,
347341
kind: SymbolExportKind::Text,

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ fn push_debuginfo_type_name<'tcx>(
110110
ty_and_layout,
111111
&|output, visited| {
112112
push_item_name(tcx, def.did(), true, output);
113-
push_generic_params_internal(tcx, args, def.did(), output, visited);
113+
push_generic_params_internal(tcx, args, output, visited);
114114
},
115115
output,
116116
visited,
117117
);
118118
} else {
119119
push_item_name(tcx, def.did(), qualified, output);
120-
push_generic_params_internal(tcx, args, def.did(), output, visited);
120+
push_generic_params_internal(tcx, args, output, visited);
121121
}
122122
}
123123
ty::Tuple(component_types) => {
@@ -251,13 +251,8 @@ fn push_debuginfo_type_name<'tcx>(
251251
let principal =
252252
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), principal);
253253
push_item_name(tcx, principal.def_id, qualified, output);
254-
let principal_has_generic_params = push_generic_params_internal(
255-
tcx,
256-
principal.args,
257-
principal.def_id,
258-
output,
259-
visited,
260-
);
254+
let principal_has_generic_params =
255+
push_generic_params_internal(tcx, principal.args, output, visited);
261256

262257
let projection_bounds: SmallVec<[_; 4]> = trait_data
263258
.projection_bounds()
@@ -538,13 +533,7 @@ pub fn compute_debuginfo_vtable_name<'tcx>(
538533
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), trait_ref);
539534
push_item_name(tcx, trait_ref.def_id, true, &mut vtable_name);
540535
visited.clear();
541-
push_generic_params_internal(
542-
tcx,
543-
trait_ref.args,
544-
trait_ref.def_id,
545-
&mut vtable_name,
546-
&mut visited,
547-
);
536+
push_generic_params_internal(tcx, trait_ref.args, &mut vtable_name, &mut visited);
548537
} else {
549538
vtable_name.push('_');
550539
}
@@ -647,12 +636,11 @@ fn push_unqualified_item_name(
647636
fn push_generic_params_internal<'tcx>(
648637
tcx: TyCtxt<'tcx>,
649638
args: GenericArgsRef<'tcx>,
650-
def_id: DefId,
651639
output: &mut String,
652640
visited: &mut FxHashSet<Ty<'tcx>>,
653641
) -> bool {
654642
assert_eq!(args, tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), args));
655-
let mut args = args.non_erasable_generics(tcx, def_id).peekable();
643+
let mut args = args.non_erasable_generics().peekable();
656644
if args.peek().is_none() {
657645
return false;
658646
}
@@ -736,12 +724,11 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
736724
pub fn push_generic_params<'tcx>(
737725
tcx: TyCtxt<'tcx>,
738726
args: GenericArgsRef<'tcx>,
739-
def_id: DefId,
740727
output: &mut String,
741728
) {
742729
let _prof = tcx.prof.generic_activity("compute_debuginfo_type_name");
743730
let mut visited = FxHashSet::default();
744-
push_generic_params_internal(tcx, args, def_id, output, &mut visited);
731+
push_generic_params_internal(tcx, args, output, &mut visited);
745732
}
746733

747734
fn push_closure_or_coroutine_name<'tcx>(
@@ -786,7 +773,7 @@ fn push_closure_or_coroutine_name<'tcx>(
786773
// FIXME(async_closures): This is probably not going to be correct w.r.t.
787774
// multiple coroutine flavors. Maybe truncate to (parent + 1)?
788775
let args = args.truncate_to(tcx, generics);
789-
push_generic_params_internal(tcx, args, enclosing_fn_def_id, output, visited);
776+
push_generic_params_internal(tcx, args, output, visited);
790777
}
791778

792779
fn push_close_angle_bracket(cpp_like_debuginfo: bool, output: &mut String) {

compiler/rustc_hir_analysis/src/bounds.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Bounds are restrictions applied to some types after they've been lowered from the HIR to the
22
//! [`rustc_middle::ty`] form.
33
4-
use rustc_data_structures::fx::FxIndexMap;
54
use rustc_hir::LangItem;
65
use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
76
use rustc_span::Span;
@@ -25,7 +24,6 @@ use rustc_span::Span;
2524
#[derive(Default, PartialEq, Eq, Clone, Debug)]
2625
pub(crate) struct Bounds<'tcx> {
2726
clauses: Vec<(ty::Clause<'tcx>, Span)>,
28-
effects_min_tys: FxIndexMap<Ty<'tcx>, Span>,
2927
}
3028

3129
impl<'tcx> Bounds<'tcx> {
@@ -96,15 +94,7 @@ impl<'tcx> Bounds<'tcx> {
9694
}
9795
}
9896

99-
pub(crate) fn clauses(
100-
&self,
101-
// FIXME(effects): remove tcx
102-
_tcx: TyCtxt<'tcx>,
103-
) -> impl Iterator<Item = (ty::Clause<'tcx>, Span)> + '_ {
97+
pub(crate) fn clauses(&self) -> impl Iterator<Item = (ty::Clause<'tcx>, Span)> + '_ {
10498
self.clauses.iter().cloned()
10599
}
106-
107-
pub(crate) fn effects_min_tys(&self) -> impl Iterator<Item = Ty<'tcx>> + '_ {
108-
self.effects_min_tys.keys().copied()
109-
}
110100
}

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn associated_type_bounds<'tcx>(
6767
)
6868
});
6969

70-
let all_bounds = tcx.arena.alloc_from_iter(bounds.clauses(tcx).chain(bounds_from_parent));
70+
let all_bounds = tcx.arena.alloc_from_iter(bounds.clauses().chain(bounds_from_parent));
7171
debug!(
7272
"associated_type_bounds({}) = {:?}",
7373
tcx.def_path_str(assoc_item_def_id.to_def_id()),
@@ -339,7 +339,7 @@ fn opaque_type_bounds<'tcx>(
339339
}
340340
debug!(?bounds);
341341

342-
tcx.arena.alloc_from_iter(bounds.clauses(tcx))
342+
tcx.arena.alloc_from_iter(bounds.clauses())
343343
})
344344
}
345345

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
106106
return ty::GenericPredicates {
107107
parent: Some(tcx.parent(def_id.to_def_id())),
108108
predicates: tcx.arena.alloc_from_iter(predicates),
109-
effects_min_tys: ty::List::empty(),
110109
};
111110
}
112111

@@ -128,7 +127,6 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
128127
return ty::GenericPredicates {
129128
parent: Some(impl_def_id),
130129
predicates: tcx.arena.alloc_from_iter(impl_predicates),
131-
effects_min_tys: ty::List::empty(),
132130
};
133131
}
134132

@@ -154,7 +152,6 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
154152
// We use an `IndexSet` to preserve order of insertion.
155153
// Preserving the order of insertion is important here so as not to break UI tests.
156154
let mut predicates: FxIndexSet<(ty::Clause<'_>, Span)> = FxIndexSet::default();
157-
let mut effects_min_tys = Vec::new();
158155

159156
let hir_generics = node.generics().unwrap_or(NO_GENERICS);
160157
if let Node::Item(item) = node {
@@ -189,8 +186,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
189186
ty::List::empty(),
190187
PredicateFilter::All,
191188
);
192-
predicates.extend(bounds.clauses(tcx));
193-
effects_min_tys.extend(bounds.effects_min_tys());
189+
predicates.extend(bounds.clauses());
194190
}
195191

196192
// In default impls, we can assume that the self type implements
@@ -223,7 +219,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
223219
param.span,
224220
);
225221
trace!(?bounds);
226-
predicates.extend(bounds.clauses(tcx));
222+
predicates.extend(bounds.clauses());
227223
trace!(?predicates);
228224
}
229225
hir::GenericParamKind::Const { .. } => {
@@ -275,8 +271,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
275271
bound_vars,
276272
PredicateFilter::All,
277273
);
278-
predicates.extend(bounds.clauses(tcx));
279-
effects_min_tys.extend(bounds.effects_min_tys());
274+
predicates.extend(bounds.clauses());
280275
}
281276

282277
hir::WherePredicate::RegionPredicate(region_pred) => {
@@ -348,7 +343,6 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
348343
ty::GenericPredicates {
349344
parent: generics.parent,
350345
predicates: tcx.arena.alloc_from_iter(predicates),
351-
effects_min_tys: tcx.mk_type_list(&effects_min_tys),
352346
}
353347
}
354348

@@ -499,7 +493,6 @@ pub(super) fn explicit_predicates_of<'tcx>(
499493
ty::GenericPredicates {
500494
parent: predicates_and_bounds.parent,
501495
predicates: tcx.arena.alloc_slice(&predicates),
502-
effects_min_tys: predicates_and_bounds.effects_min_tys,
503496
}
504497
}
505498
} else {
@@ -551,7 +544,6 @@ pub(super) fn explicit_predicates_of<'tcx>(
551544
return GenericPredicates {
552545
parent: parent_preds.parent,
553546
predicates: { tcx.arena.alloc_from_iter(filtered_predicates) },
554-
effects_min_tys: parent_preds.effects_min_tys,
555547
};
556548
}
557549
gather_explicit_predicates_of(tcx, def_id)
@@ -630,7 +622,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
630622

631623
// Combine the two lists to form the complete set of superbounds:
632624
let implied_bounds =
633-
&*tcx.arena.alloc_from_iter(bounds.clauses(tcx).chain(where_bounds_that_match));
625+
&*tcx.arena.alloc_from_iter(bounds.clauses().chain(where_bounds_that_match));
634626
debug!(?implied_bounds);
635627

636628
// Now require that immediate supertraits are lowered, which will, in
@@ -874,7 +866,7 @@ impl<'tcx> ItemCtxt<'tcx> {
874866
);
875867
}
876868

877-
bounds.clauses(self.tcx).collect()
869+
bounds.clauses().collect()
878870
}
879871
}
880872

@@ -966,7 +958,7 @@ pub(super) fn const_conditions<'tcx>(
966958

967959
ty::ConstConditions {
968960
parent: has_parent.then(|| tcx.local_parent(def_id).to_def_id()),
969-
predicates: tcx.arena.alloc_from_iter(bounds.clauses(tcx).map(|(clause, span)| {
961+
predicates: tcx.arena.alloc_from_iter(bounds.clauses().map(|(clause, span)| {
970962
(
971963
clause.kind().map_bound(|clause| match clause {
972964
ty::ClauseKind::HostEffect(ty::HostEffectPredicate {

compiler/rustc_hir_analysis/src/delegation.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,6 @@ impl<'tcx> PredicatesBuilder<'tcx> {
278278
ty::GenericPredicates {
279279
parent: self.parent,
280280
predicates: self.tcx.arena.alloc_from_iter(preds),
281-
// FIXME(fn_delegation): Support effects.
282-
effects_min_tys: ty::List::empty(),
283281
}
284282
}
285283
}

0 commit comments

Comments
 (0)