Skip to content

Commit

Permalink
Remove all checks of IntrinsicDef::must_be_overridden except for th…
Browse files Browse the repository at this point in the history
…e actual overrides in codegen
  • Loading branch information
oli-obk committed Mar 14, 2024
1 parent 2d8c6ff commit ff12979
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 32 deletions.
4 changes: 0 additions & 4 deletions compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Expand Up @@ -81,10 +81,6 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
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.
match tcx.def_kind(def_id) {
DefKind::Fn | DefKind::Static { .. } => {}
Expand Down
11 changes: 3 additions & 8 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Expand Up @@ -1067,14 +1067,11 @@ fn should_encode_mir(
// Full-fledged functions + closures
DefKind::AssocFn | DefKind::Fn | DefKind::Closure => {
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()
&& reachable_set.contains(&def_id)
&& (generics.requires_monomorphization(tcx)
|| 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]`.
let is_const_fn = tcx.is_const_fn_raw(def_id.to_def_id())
|| tcx.is_const_default_method(def_id.to_def_id());
Expand Down Expand Up @@ -1704,10 +1701,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
{
for &local_def_id in tcx.mir_keys(()) {
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()] <-
self.tcx.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()));
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_middle/src/hir/map/mod.rs
Expand Up @@ -1372,9 +1372,7 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {

fn visit_impl_item(&mut self, item: &'hir ImplItem<'hir>) {
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());
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_mir_build/src/build/mod.rs
Expand Up @@ -1006,8 +1006,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
if let Some(source_scope) = scope {
self.source_scope = source_scope;
}

self.expr_into_dest(Place::return_place(), block, expr_id)
if self.tcx.intrinsic(self.def_id).is_some_and(|i| i.must_be_overridden) {
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(
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_mir_transform/src/cross_crate_inline.rs
Expand Up @@ -23,10 +23,6 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
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.
match tcx.def_kind(def_id) {
DefKind::Ctor(..) | DefKind::Closure => return true,
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_mir_transform/src/lib.rs
Expand Up @@ -632,12 +632,6 @@ fn 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()) {
// 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
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_monomorphize/src/collector.rs
Expand Up @@ -1024,11 +1024,6 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>) ->
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() {
// Local items cannot be referred to locally without monomorphizing them locally.
return true;
Expand Down

0 comments on commit ff12979

Please sign in to comment.