Skip to content

Commit 707fa49

Browse files
committed
Avoid computing function type for intrinsic instances
1 parent 2bd5807 commit 707fa49

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_codegen_ssa::traits::{
2323
use rustc_middle::bug;
2424
#[cfg(feature = "master")]
2525
use rustc_middle::ty::layout::FnAbiOf;
26-
use rustc_middle::ty::layout::{HasTypingEnv, LayoutOf};
26+
use rustc_middle::ty::layout::LayoutOf;
2727
use rustc_middle::ty::{self, Instance, Ty};
2828
use rustc_span::{Span, Symbol, sym};
2929
use rustc_target::callconv::{ArgAbi, PassMode};
@@ -205,15 +205,10 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
205205
span: Span,
206206
) -> Result<(), Instance<'tcx>> {
207207
let tcx = self.tcx;
208-
let callee_ty = instance.ty(tcx, self.typing_env());
209208

210-
let (def_id, fn_args) = match *callee_ty.kind() {
211-
ty::FnDef(def_id, fn_args) => (def_id, fn_args),
212-
_ => bug!("expected fn item type, found {}", callee_ty),
213-
};
214-
215-
let name = tcx.item_name(def_id);
209+
let name = tcx.item_name(instance.def_id());
216210
let name_str = name.as_str();
211+
let fn_args = instance.args;
217212

218213
let simple = get_simple_intrinsic(self, name);
219214
let simple_func = get_simple_function(self, name);

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,9 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
169169
span: Span,
170170
) -> Result<(), ty::Instance<'tcx>> {
171171
let tcx = self.tcx;
172-
let callee_ty = instance.ty(tcx, self.typing_env());
173172

174-
let ty::FnDef(def_id, fn_args) = *callee_ty.kind() else {
175-
bug!("expected fn item type, found {}", callee_ty);
176-
};
177-
178-
let name = tcx.item_name(def_id);
173+
let name = tcx.item_name(instance.def_id());
174+
let fn_args = instance.args;
179175

180176
let simple = get_simple_intrinsic(self, name);
181177
let llval = match name {

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_abi::WrappingRange;
2+
use rustc_middle::bug;
23
use rustc_middle::mir::SourceInfo;
34
use rustc_middle::ty::{self, Ty, TyCtxt};
4-
use rustc_middle::{bug, span_bug};
55
use rustc_session::config::OptLevel;
66
use rustc_span::sym;
77

@@ -60,14 +60,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
6060
source_info: SourceInfo,
6161
) -> Result<(), ty::Instance<'tcx>> {
6262
let span = source_info.span;
63-
let callee_ty = instance.ty(bx.tcx(), bx.typing_env());
6463

65-
let ty::FnDef(def_id, fn_args) = *callee_ty.kind() else {
66-
span_bug!(span, "expected fn item type, found {}", callee_ty);
67-
};
68-
69-
let name = bx.tcx().item_name(def_id);
64+
let name = bx.tcx().item_name(instance.def_id());
7065
let name_str = name.as_str();
66+
let fn_args = instance.args;
7167

7268
// If we're swapping something that's *not* an `OperandValue::Ref`,
7369
// then we can do it directly and avoid the alloca.
@@ -126,7 +122,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
126122
sym::vtable_align => ty::COMMON_VTABLE_ENTRIES_ALIGN,
127123
_ => bug!(),
128124
};
129-
let value = meth::VirtualIndex::from_index(idx).get_usize(bx, vtable, callee_ty);
125+
let value = meth::VirtualIndex::from_index(idx).get_usize(
126+
bx,
127+
vtable,
128+
instance.ty(bx.tcx(), bx.typing_env()),
129+
);
130130
match name {
131131
// Size is always <= isize::MAX.
132132
sym::vtable_size => {

0 commit comments

Comments
 (0)