Remove all checks of `IntrinsicDef::must_be_overridden` except for the actual overrides in codegen

This commit is contained in:
Oli Scherer 2024-03-12 16:04:52 +00:00
parent e91084180e
commit a8f71cf289
7 changed files with 11 additions and 32 deletions

View File

@ -81,10 +81,6 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
return library.kind.is_statically_included().then_some(def_id); return library.kind.is_statically_included().then_some(def_id);
} }
if tcx.intrinsic(def_id).is_some_and(|i| i.must_be_overridden) {
return None;
}
// Only consider nodes that actually have exported symbols. // Only consider nodes that actually have exported symbols.
match tcx.def_kind(def_id) { match tcx.def_kind(def_id) {
DefKind::Fn | DefKind::Static { .. } => {} DefKind::Fn | DefKind::Static { .. } => {}

View File

@ -1067,14 +1067,11 @@ fn should_encode_mir(
// Full-fledged functions + closures // Full-fledged functions + closures
DefKind::AssocFn | DefKind::Fn | DefKind::Closure => { DefKind::AssocFn | DefKind::Fn | DefKind::Closure => {
let generics = tcx.generics_of(def_id); let generics = tcx.generics_of(def_id);
let mut opt = tcx.sess.opts.unstable_opts.always_encode_mir let opt = tcx.sess.opts.unstable_opts.always_encode_mir
|| (tcx.sess.opts.output_types.should_codegen() || (tcx.sess.opts.output_types.should_codegen()
&& reachable_set.contains(&def_id) && reachable_set.contains(&def_id)
&& (generics.requires_monomorphization(tcx) && (generics.requires_monomorphization(tcx)
|| tcx.cross_crate_inlinable(def_id))); || tcx.cross_crate_inlinable(def_id)));
if let Some(intrinsic) = tcx.intrinsic(def_id) {
opt &= !intrinsic.must_be_overridden;
}
// The function has a `const` modifier or is in a `#[const_trait]`. // The function has a `const` modifier or is in a `#[const_trait]`.
let is_const_fn = tcx.is_const_fn_raw(def_id.to_def_id()) let is_const_fn = tcx.is_const_fn_raw(def_id.to_def_id())
|| tcx.is_const_default_method(def_id.to_def_id()); || tcx.is_const_default_method(def_id.to_def_id());
@ -1704,10 +1701,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
{ {
for &local_def_id in tcx.mir_keys(()) { for &local_def_id in tcx.mir_keys(()) {
if let DefKind::AssocFn | DefKind::Fn = tcx.def_kind(local_def_id) { if let DefKind::AssocFn | DefKind::Fn = tcx.def_kind(local_def_id) {
if tcx.intrinsic(local_def_id).map_or(true, |i| !i.must_be_overridden) { record_array!(self.tables.deduced_param_attrs[local_def_id.to_def_id()] <-
record_array!(self.tables.deduced_param_attrs[local_def_id.to_def_id()] <- self.tcx.deduced_param_attrs(local_def_id.to_def_id()));
self.tcx.deduced_param_attrs(local_def_id.to_def_id()));
}
} }
} }
} }

View File

@ -1365,9 +1365,7 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
fn visit_impl_item(&mut self, item: &'hir ImplItem<'hir>) { fn visit_impl_item(&mut self, item: &'hir ImplItem<'hir>) {
if associated_body(Node::ImplItem(item)).is_some() { if associated_body(Node::ImplItem(item)).is_some() {
if !self.tcx.has_attr(item.owner_id.def_id, sym::rustc_intrinsic_must_be_overridden) { self.body_owners.push(item.owner_id.def_id);
self.body_owners.push(item.owner_id.def_id);
}
} }
self.impl_items.push(item.impl_item_id()); self.impl_items.push(item.impl_item_id());

View File

@ -1013,8 +1013,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
if let Some(source_scope) = scope { if let Some(source_scope) = scope {
self.source_scope = source_scope; self.source_scope = source_scope;
} }
if self.tcx.intrinsic(self.def_id).is_some_and(|i| i.must_be_overridden) {
self.expr_into_dest(Place::return_place(), block, expr_id) let source_info = self.source_info(rustc_span::DUMMY_SP);
self.cfg.terminate(block, source_info, TerminatorKind::Unreachable);
self.cfg.start_new_block().unit()
} else {
self.expr_into_dest(Place::return_place(), block, expr_id)
}
} }
fn set_correct_source_scope_for_arg( fn set_correct_source_scope_for_arg(

View File

@ -23,10 +23,6 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
return false; return false;
} }
if tcx.intrinsic(def_id).is_some_and(|i| i.must_be_overridden) {
return false;
}
// This just reproduces the logic from Instance::requires_inline. // This just reproduces the logic from Instance::requires_inline.
match tcx.def_kind(def_id) { match tcx.def_kind(def_id) {
DefKind::Ctor(..) | DefKind::Closure => return true, DefKind::Ctor(..) | DefKind::Closure => return true,

View File

@ -633,12 +633,6 @@ fn optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> &Body<'_> {
} }
fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> { fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
if tcx.intrinsic(did).is_some_and(|i| i.must_be_overridden) {
span_bug!(
tcx.def_span(did),
"this intrinsic must be overridden by the codegen backend, it has no meaningful body",
)
}
if tcx.is_constructor(did.to_def_id()) { if tcx.is_constructor(did.to_def_id()) {
// There's no reason to run all of the MIR passes on constructors when // There's no reason to run all of the MIR passes on constructors when
// we can just output the MIR we want directly. This also saves const // we can just output the MIR we want directly. This also saves const

View File

@ -1030,11 +1030,6 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>) ->
return false; return false;
} }
if tcx.intrinsic(def_id).is_some_and(|i| i.must_be_overridden) {
// These are implemented by backends directly and have no meaningful body.
return false;
}
if def_id.is_local() { if def_id.is_local() {
// Local items cannot be referred to locally without monomorphizing them locally. // Local items cannot be referred to locally without monomorphizing them locally.
return true; return true;