Skip to content

Commit 200e3f7

Browse files
committed
Auto merge of #122037 - oli-obk:more_new_intrinsics, r=Nilstrieb
Move more intrinsics to rustc_intrinsic cc #63585
2 parents f296c16 + a8f71cf commit 200e3f7

File tree

14 files changed

+147
-128
lines changed

14 files changed

+147
-128
lines changed

Diff for: compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

-7
Original file line numberDiff line numberDiff line change
@@ -757,13 +757,6 @@ fn codegen_regular_intrinsic_call<'tcx>(
757757
ret.write_cvalue(fx, val);
758758
}
759759

760-
sym::ptr_guaranteed_cmp => {
761-
intrinsic_args!(fx, args => (a, b); intrinsic);
762-
763-
let val = crate::num::codegen_ptr_binop(fx, BinOp::Eq, a, b).load_scalar(fx);
764-
ret.write_cvalue(fx, CValue::by_val(val, fx.layout_of(fx.tcx.types.u8)));
765-
}
766-
767760
sym::caller_location => {
768761
intrinsic_args!(fx, args => (); intrinsic);
769762

Diff for: compiler/rustc_codegen_ssa/src/back/symbol_export.rs

-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
8181
return library.kind.is_statically_included().then_some(def_id);
8282
}
8383

84-
if tcx.intrinsic(def_id).is_some_and(|i| i.must_be_overridden) {
85-
return None;
86-
}
87-
8884
// Only consider nodes that actually have exported symbols.
8985
match tcx.def_kind(def_id) {
9086
DefKind::Fn | DefKind::Static { .. } => {}

Diff for: compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::operand::{OperandRef, OperandValue};
22
use super::place::PlaceRef;
33
use super::FunctionCx;
4-
use crate::common::IntPredicate;
54
use crate::errors;
65
use crate::errors::InvalidMonomorphization;
76
use crate::meth;
@@ -456,12 +455,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
456455
return Ok(());
457456
}
458457

459-
sym::ptr_guaranteed_cmp => {
460-
let a = args[0].immediate();
461-
let b = args[1].immediate();
462-
bx.icmp(IntPredicate::IntEQ, a, b)
463-
}
464-
465458
sym::ptr_offset_from | sym::ptr_offset_from_unsigned => {
466459
let ty = fn_args.type_at(0);
467460
let pointee_size = bx.layout_of(ty).size;

Diff for: compiler/rustc_hir_analysis/src/check/intrinsic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ pub fn check_intrinsic_type(
441441

442442
sym::ptr_guaranteed_cmp => (
443443
1,
444-
0,
444+
1,
445445
vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))],
446446
tcx.types.u8,
447447
),
@@ -579,7 +579,7 @@ pub fn check_intrinsic_type(
579579

580580
sym::is_val_statically_known => (1, 1, vec![param(0)], tcx.types.bool),
581581

582-
sym::const_eval_select => (4, 0, vec![param(0), param(1), param(2)], param(3)),
582+
sym::const_eval_select => (4, 1, vec![param(0), param(1), param(2)], param(3)),
583583

584584
sym::vtable_size | sym::vtable_align => {
585585
(0, 0, vec![Ty::new_imm_ptr(tcx, Ty::new_unit(tcx))], tcx.types.usize)

Diff for: compiler/rustc_metadata/src/rmeta/encoder.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1067,14 +1067,11 @@ fn should_encode_mir(
10671067
// Full-fledged functions + closures
10681068
DefKind::AssocFn | DefKind::Fn | DefKind::Closure => {
10691069
let generics = tcx.generics_of(def_id);
1070-
let mut opt = tcx.sess.opts.unstable_opts.always_encode_mir
1070+
let opt = tcx.sess.opts.unstable_opts.always_encode_mir
10711071
|| (tcx.sess.opts.output_types.should_codegen()
10721072
&& reachable_set.contains(&def_id)
10731073
&& (generics.requires_monomorphization(tcx)
10741074
|| tcx.cross_crate_inlinable(def_id)));
1075-
if let Some(intrinsic) = tcx.intrinsic(def_id) {
1076-
opt &= !intrinsic.must_be_overridden;
1077-
}
10781075
// The function has a `const` modifier or is in a `#[const_trait]`.
10791076
let is_const_fn = tcx.is_const_fn_raw(def_id.to_def_id())
10801077
|| tcx.is_const_default_method(def_id.to_def_id());

Diff for: compiler/rustc_middle/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#![feature(array_windows)]
3232
#![feature(assert_matches)]
3333
#![feature(box_patterns)]
34+
#![feature(closure_track_caller)]
3435
#![feature(core_intrinsics)]
3536
#![feature(const_type_name)]
3637
#![feature(discriminant_kind)]

Diff for: compiler/rustc_middle/src/ty/context/tls.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ where
8585

8686
/// Allows access to the current `ImplicitCtxt` in a closure if one is available.
8787
#[inline]
88+
#[track_caller]
8889
pub fn with_context_opt<F, R>(f: F) -> R
8990
where
9091
F: for<'a, 'tcx> FnOnce(Option<&ImplicitCtxt<'a, 'tcx>>) -> R,
@@ -147,9 +148,13 @@ where
147148
/// Allows access to the `TyCtxt` in the current `ImplicitCtxt`.
148149
/// The closure is passed None if there is no `ImplicitCtxt` available.
149150
#[inline]
151+
#[track_caller]
150152
pub fn with_opt<F, R>(f: F) -> R
151153
where
152154
F: for<'tcx> FnOnce(Option<TyCtxt<'tcx>>) -> R,
153155
{
154-
with_context_opt(|opt_context| f(opt_context.map(|context| context.tcx)))
156+
with_context_opt(
157+
#[track_caller]
158+
|opt_context| f(opt_context.map(|context| context.tcx)),
159+
)
155160
}

Diff for: compiler/rustc_middle/src/util/bug.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ fn opt_span_bug_fmt<S: Into<MultiSpan>>(
2828
args: fmt::Arguments<'_>,
2929
location: &Location<'_>,
3030
) -> ! {
31-
tls::with_opt(move |tcx| {
32-
let msg = format!("{location}: {args}");
33-
match (tcx, span) {
34-
(Some(tcx), Some(span)) => tcx.dcx().span_bug(span, msg),
35-
(Some(tcx), None) => tcx.dcx().bug(msg),
36-
(None, _) => panic_any(msg),
37-
}
38-
})
31+
tls::with_opt(
32+
#[track_caller]
33+
move |tcx| {
34+
let msg = format!("{location}: {args}");
35+
match (tcx, span) {
36+
(Some(tcx), Some(span)) => tcx.dcx().span_bug(span, msg),
37+
(Some(tcx), None) => tcx.dcx().bug(msg),
38+
(None, _) => panic_any(msg),
39+
}
40+
},
41+
)
3942
}
4043

4144
/// A query to trigger a delayed bug. Clearly, if one has a `tcx` one can already trigger a

Diff for: compiler/rustc_mir_build/src/build/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1013,8 +1013,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10131013
if let Some(source_scope) = scope {
10141014
self.source_scope = source_scope;
10151015
}
1016-
1017-
self.expr_into_dest(Place::return_place(), block, expr_id)
1016+
if self.tcx.intrinsic(self.def_id).is_some_and(|i| i.must_be_overridden) {
1017+
let source_info = self.source_info(rustc_span::DUMMY_SP);
1018+
self.cfg.terminate(block, source_info, TerminatorKind::Unreachable);
1019+
self.cfg.start_new_block().unit()
1020+
} else {
1021+
self.expr_into_dest(Place::return_place(), block, expr_id)
1022+
}
10181023
}
10191024

10201025
fn set_correct_source_scope_for_arg(

Diff for: compiler/rustc_mir_transform/src/cross_crate_inline.rs

-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
2323
return false;
2424
}
2525

26-
if tcx.intrinsic(def_id).is_some_and(|i| i.must_be_overridden) {
27-
return false;
28-
}
29-
3026
// This just reproduces the logic from Instance::requires_inline.
3127
match tcx.def_kind(def_id) {
3228
DefKind::Ctor(..) | DefKind::Closure => return true,

Diff for: compiler/rustc_mir_transform/src/lib.rs

-6
Original file line numberDiff line numberDiff line change
@@ -633,12 +633,6 @@ fn optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> &Body<'_> {
633633
}
634634

635635
fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
636-
if tcx.intrinsic(did).is_some_and(|i| i.must_be_overridden) {
637-
span_bug!(
638-
tcx.def_span(did),
639-
"this intrinsic must be overridden by the codegen backend, it has no meaningful body",
640-
)
641-
}
642636
if tcx.is_constructor(did.to_def_id()) {
643637
// There's no reason to run all of the MIR passes on constructors when
644638
// we can just output the MIR we want directly. This also saves const

Diff for: compiler/rustc_monomorphize/src/collector.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1030,11 +1030,6 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>) ->
10301030
return false;
10311031
}
10321032

1033-
if tcx.intrinsic(def_id).is_some_and(|i| i.must_be_overridden) {
1034-
// These are implemented by backends directly and have no meaningful body.
1035-
return false;
1036-
}
1037-
10381033
if def_id.is_local() {
10391034
// Local items cannot be referred to locally without monomorphizing them locally.
10401035
return true;

0 commit comments

Comments
 (0)