Skip to content

Commit bd59ff8

Browse files
Rollup merge of #156872 - cjgillot:skip_move_check_fns, r=oli-obk
Drop skip_move_check_fns query. Looking at the header of the impl block for each method can be just as fast.
2 parents d8a003a + 20d113e commit bd59ff8

3 files changed

Lines changed: 18 additions & 39 deletions

File tree

compiler/rustc_middle/src/queries.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,12 +2710,6 @@ rustc_queries! {
27102710
desc { "monomorphization-time checking" }
27112711
}
27122712

2713-
/// Builds the set of functions that should be skipped for the move-size check.
2714-
query skip_move_check_fns(_: ()) -> &'tcx FxIndexSet<DefId> {
2715-
arena_cache
2716-
desc { "functions to skip for move-size check" }
2717-
}
2718-
27192713
query items_of_instance(key: (ty::Instance<'tcx>, CollectionMode)) -> Result<(&'tcx [Spanned<MonoItem<'tcx>>], &'tcx [Spanned<MonoItem<'tcx>>]), NormalizationErrorInMono> {
27202714
desc { "collecting items used by `{}`", key.0 }
27212715
cache_on_disk

compiler/rustc_monomorphize/src/mono_checks/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,5 @@ fn check_mono_item<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
1515
}
1616

1717
pub(super) fn provide(providers: &mut Providers) {
18-
*providers = Providers {
19-
check_mono_item,
20-
skip_move_check_fns: move_check::skip_move_check_fns,
21-
..*providers
22-
}
18+
*providers = Providers { check_mono_item, ..*providers }
2319
}

compiler/rustc_monomorphize/src/mono_checks/move_check.rs

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use rustc_abi::Size;
2-
use rustc_data_structures::fx::FxIndexSet;
2+
use rustc_hir::def::DefKind;
33
use rustc_hir::def_id::DefId;
44
use rustc_hir::limit::Limit;
55
use rustc_middle::mir::visit::Visitor as MirVisitor;
66
use rustc_middle::mir::{self, Location, traversal};
7-
use rustc_middle::ty::{self, AssocTag, Instance, Ty, TyCtxt, TypeFoldable};
7+
use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable};
88
use rustc_session::lint::builtin::LARGE_ASSIGNMENTS;
9-
use rustc_span::{Ident, Span, Spanned, sym};
9+
use rustc_span::{Span, Spanned, sym};
1010
use tracing::{debug, trace};
1111

1212
use crate::errors::LargeAssignmentsLint;
@@ -98,7 +98,7 @@ impl<'tcx> MoveCheckVisitor<'tcx> {
9898
let ty::FnDef(def_id, _) = *callee_ty.kind() else {
9999
return;
100100
};
101-
if self.tcx.skip_move_check_fns(()).contains(&def_id) {
101+
if should_skip_fn(self.tcx, def_id) {
102102
return;
103103
}
104104

@@ -188,29 +188,18 @@ impl<'tcx> MoveCheckVisitor<'tcx> {
188188
}
189189
}
190190

191-
fn assoc_fn_of_type<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fn_ident: Ident) -> Option<DefId> {
192-
for &impl_def_id in tcx.inherent_impls(def_id) {
193-
if let Some(new) = tcx.associated_items(impl_def_id).find_by_ident_and_kind(
194-
tcx,
195-
fn_ident,
196-
AssocTag::Fn,
197-
def_id,
198-
) {
199-
return Some(new.def_id);
200-
}
191+
/// Return `true` if `def_id` is `Box::new`, `Rc::new` or `Arc::new`.
192+
fn should_skip_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
193+
if let DefKind::AssocFn = tcx.def_kind(def_id)
194+
&& tcx.item_name(def_id) == sym::new
195+
&& let parent = tcx.parent(def_id)
196+
&& let DefKind::Impl { of_trait: false } = tcx.def_kind(parent)
197+
&& let ty::Adt(adt_def, ..) =
198+
tcx.type_of(parent).instantiate_identity().skip_normalization().kind()
199+
{
200+
return Some(adt_def.did()) == tcx.lang_items().owned_box()
201+
|| Some(adt_def.did()) == tcx.get_diagnostic_item(sym::Rc)
202+
|| Some(adt_def.did()) == tcx.get_diagnostic_item(sym::Arc);
201203
}
202-
None
203-
}
204-
205-
pub(crate) fn skip_move_check_fns(tcx: TyCtxt<'_>, _: ()) -> FxIndexSet<DefId> {
206-
let fns = [
207-
(tcx.lang_items().owned_box(), "new"),
208-
(tcx.get_diagnostic_item(sym::Rc), "new"),
209-
(tcx.get_diagnostic_item(sym::Arc), "new"),
210-
];
211-
fns.into_iter()
212-
.filter_map(|(def_id, fn_name)| {
213-
def_id.and_then(|def_id| assoc_fn_of_type(tcx, def_id, Ident::from_str(fn_name)))
214-
})
215-
.collect()
204+
false
216205
}

0 commit comments

Comments
 (0)