Skip to content

Commit 082d50d

Browse files
committed
Return a struct from query intrinsic to be able to add another field in the next commit
1 parent 562ea68 commit 082d50d

File tree

14 files changed

+33
-26
lines changed

14 files changed

+33
-26
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
16681668
// (Eventually this should use const-generics, but those are not up for the task yet:
16691669
// https://github.com/rust-lang/rust/issues/85229.)
16701670
if let Some(name @ (sym::simd_shuffle | sym::simd_insert | sym::simd_extract)) =
1671-
self.tcx().intrinsic(def_id)
1671+
self.tcx().intrinsic(def_id).map(|i| i.name)
16721672
{
16731673
let idx = match name {
16741674
sym::simd_shuffle => 2,

compiler/rustc_codegen_ssa/src/mir/block.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, ValidityRequirement};
1717
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
1818
use rustc_middle::ty::{self, Instance, Ty};
1919
use rustc_session::config::OptLevel;
20-
use rustc_span::{source_map::Spanned, sym, Span, Symbol};
20+
use rustc_span::{source_map::Spanned, sym, Span};
2121
use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode, Reg};
2222
use rustc_target::abi::{self, HasDataLayout, WrappingRange};
2323
use rustc_target::spec::abi::Abi;
@@ -672,7 +672,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
672672
&mut self,
673673
helper: &TerminatorCodegenHelper<'tcx>,
674674
bx: &mut Bx,
675-
intrinsic: Option<Symbol>,
675+
intrinsic: Option<ty::IntrinsicDef>,
676676
instance: Option<Instance<'tcx>>,
677677
source_info: mir::SourceInfo,
678678
target: Option<mir::BasicBlock>,
@@ -682,7 +682,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
682682
// Emit a panic or a no-op for `assert_*` intrinsics.
683683
// These are intrinsics that compile to panics so that we can get a message
684684
// which mentions the offending type, even from a const context.
685-
let panic_intrinsic = intrinsic.and_then(|s| ValidityRequirement::from_intrinsic(s));
685+
let panic_intrinsic = intrinsic.and_then(|i| ValidityRequirement::from_intrinsic(i.name));
686686
if let Some(requirement) = panic_intrinsic {
687687
let ty = instance.unwrap().args.type_at(0);
688688

@@ -818,7 +818,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
818818
// The arguments we'll be passing. Plus one to account for outptr, if used.
819819
let arg_count = fn_abi.args.len() + fn_abi.ret.is_indirect() as usize;
820820

821-
if intrinsic == Some(sym::caller_location) {
821+
if matches!(intrinsic, Some(ty::IntrinsicDef { name: sym::caller_location, .. })) {
822822
return if let Some(target) = target {
823823
let location =
824824
self.get_caller_location(bx, mir::SourceInfo { span: fn_span, ..source_info });
@@ -838,7 +838,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
838838
}
839839

840840
let instance = match intrinsic {
841-
None | Some(sym::drop_in_place) => instance,
841+
None | Some(ty::IntrinsicDef { name: sym::drop_in_place, .. }) => instance,
842842
Some(intrinsic) => {
843843
let mut llargs = Vec::with_capacity(1);
844844
let ret_dest = self.make_return_dest(
@@ -865,7 +865,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
865865
// The indices passed to simd_shuffle in the
866866
// third argument must be constant. This is
867867
// checked by the type-checker.
868-
if i == 2 && intrinsic == sym::simd_shuffle {
868+
if i == 2 && intrinsic.name == sym::simd_shuffle {
869869
if let mir::Operand::Constant(constant) = &arg.node {
870870
let (llval, ty) = self.simd_shuffle_indices(bx, constant);
871871
return OperandRef {

compiler/rustc_hir_analysis/src/check/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -527,12 +527,12 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
527527
check_enum(tcx, def_id);
528528
}
529529
DefKind::Fn => {
530-
if let Some(name) = tcx.intrinsic(def_id) {
530+
if let Some(i) = tcx.intrinsic(def_id) {
531531
intrinsic::check_intrinsic_type(
532532
tcx,
533533
def_id,
534534
tcx.def_ident_span(def_id).unwrap(),
535-
name,
535+
i.name,
536536
Abi::Rust,
537537
)
538538
}

compiler/rustc_metadata/src/rmeta/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1749,7 +1749,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
17491749
self.root.tables.attr_flags.get(self, index)
17501750
}
17511751

1752-
fn get_intrinsic(self, index: DefIndex) -> Option<Symbol> {
1752+
fn get_intrinsic(self, index: DefIndex) -> Option<ty::IntrinsicDef> {
17531753
self.root.tables.intrinsic.get(self, index).map(|d| d.decode(self))
17541754
}
17551755

compiler/rustc_metadata/src/rmeta/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ macro_rules! define_tables {
375375

376376
define_tables! {
377377
- defaulted:
378-
intrinsic: Table<DefIndex, Option<LazyValue<Symbol>>>,
378+
intrinsic: Table<DefIndex, Option<LazyValue<ty::IntrinsicDef>>>,
379379
is_macro_rules: Table<DefIndex, bool>,
380380
is_type_alias_impl_trait: Table<DefIndex, bool>,
381381
type_alias_is_lazy: Table<DefIndex, bool>,

compiler/rustc_middle/src/query/erase.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ trivial! {
241241
Option<rustc_target::abi::FieldIdx>,
242242
Option<rustc_target::spec::PanicStrategy>,
243243
Option<usize>,
244-
Option<rustc_span::Symbol>,
244+
Option<rustc_middle::ty::IntrinsicDef>,
245245
Result<(), rustc_errors::ErrorGuaranteed>,
246246
Result<(), rustc_middle::traits::query::NoSolution>,
247247
Result<rustc_middle::traits::EvaluationResult, rustc_middle::traits::OverflowError>,

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@ rustc_queries! {
17601760
separate_provide_extern
17611761
}
17621762
/// Whether the function is an intrinsic
1763-
query intrinsic(def_id: DefId) -> Option<Symbol> {
1763+
query intrinsic(def_id: DefId) -> Option<rustc_middle::ty::IntrinsicDef> {
17641764
desc { |tcx| "fetch intrinsic name if `{}` is an intrinsic", tcx.def_path_str(def_id) }
17651765
separate_provide_extern
17661766
}

compiler/rustc_middle/src/ty/intrinsic.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ use rustc_span::{def_id::DefId, Symbol};
22

33
use super::TyCtxt;
44

5+
#[derive(Copy, Clone, Debug, Decodable, Encodable, HashStable)]
6+
pub struct IntrinsicDef {
7+
pub name: Symbol,
8+
}
9+
510
impl TyCtxt<'_> {
611
pub fn is_intrinsic(self, def_id: DefId, name: Symbol) -> bool {
712
let Some(i) = self.intrinsic(def_id) else { return false };
8-
i == name
13+
i.name == name
914
}
1015
}

compiler/rustc_middle/src/ty/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub use adt::*;
3030
pub use assoc::*;
3131
pub use generic_args::*;
3232
pub use generics::*;
33+
pub use intrinsic::IntrinsicDef;
3334
use rustc_ast as ast;
3435
use rustc_ast::node_id::NodeMap;
3536
use rustc_attr as attr;

compiler/rustc_middle/src/ty/parameterized.rs

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ trivially_parameterized_over_tcx! {
7575
ty::Visibility<DefIndex>,
7676
ty::adjustment::CoerceUnsizedInfo,
7777
ty::fast_reject::SimplifiedType,
78+
ty::IntrinsicDef,
7879
rustc_ast::Attribute,
7980
rustc_ast::DelimArgs,
8081
rustc_ast::expand::StrippedCfgItem<rustc_hir::def_id::DefIndex>,

compiler/rustc_middle/src/ty/util.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
1919
use rustc_index::bit_set::GrowableBitSet;
2020
use rustc_macros::HashStable;
2121
use rustc_session::Limit;
22-
use rustc_span::{sym, Symbol};
22+
use rustc_span::sym;
2323
use rustc_target::abi::{Integer, IntegerType, Primitive, Size};
2424
use rustc_target::spec::abi::Abi;
2525
use smallvec::SmallVec;
@@ -1641,12 +1641,12 @@ pub fn is_doc_notable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
16411641
.any(|items| items.iter().any(|item| item.has_name(sym::notable_trait)))
16421642
}
16431643

1644-
/// Determines whether an item is an intrinsic by Abi. or by whether it has a `rustc_intrinsic` attribute
1645-
pub fn intrinsic(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<Symbol> {
1644+
/// Determines whether an item is an intrinsic (which may be via Abi or via the `rustc_intrinsic` attribute)
1645+
pub fn intrinsic(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::IntrinsicDef> {
16461646
if matches!(tcx.fn_sig(def_id).skip_binder().abi(), Abi::RustIntrinsic | Abi::PlatformIntrinsic)
16471647
|| tcx.has_attr(def_id, sym::rustc_intrinsic)
16481648
{
1649-
Some(tcx.item_name(def_id.into()))
1649+
Some(ty::IntrinsicDef { name: tcx.item_name(def_id.into()) })
16501650
} else {
16511651
None
16521652
}

compiler/rustc_mir_dataflow/src/rustc_peek.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl PeekCall {
202202
&terminator.kind
203203
{
204204
if let ty::FnDef(def_id, fn_args) = *func.const_.ty().kind() {
205-
if tcx.intrinsic(def_id)? != sym::rustc_peek {
205+
if tcx.intrinsic(def_id)?.name != sym::rustc_peek {
206206
return None;
207207
}
208208

compiler/rustc_mir_transform/src/instsimplify.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ fn resolve_rust_intrinsic<'tcx>(
323323
func_ty: Ty<'tcx>,
324324
) -> Option<(Symbol, GenericArgsRef<'tcx>)> {
325325
if let ty::FnDef(def_id, args) = *func_ty.kind() {
326-
let name = tcx.intrinsic(def_id)?;
327-
return Some((name, args));
326+
let intrinsic = tcx.intrinsic(def_id)?;
327+
return Some((intrinsic.name, args));
328328
}
329329
None
330330
}

compiler/rustc_mir_transform/src/lower_intrinsics.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
1414
if let TerminatorKind::Call { func, args, destination, target, .. } =
1515
&mut terminator.kind
1616
&& let ty::FnDef(def_id, generic_args) = *func.ty(local_decls, tcx).kind()
17-
&& let Some(intrinsic_name) = tcx.intrinsic(def_id)
17+
&& let Some(intrinsic) = tcx.intrinsic(def_id)
1818
{
19-
match intrinsic_name {
19+
match intrinsic.name {
2020
sym::unreachable => {
2121
terminator.kind = TerminatorKind::Unreachable;
2222
}
@@ -105,7 +105,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
105105
lhs = args.next().unwrap();
106106
rhs = args.next().unwrap();
107107
}
108-
let bin_op = match intrinsic_name {
108+
let bin_op = match intrinsic.name {
109109
sym::wrapping_add => BinOp::Add,
110110
sym::wrapping_sub => BinOp::Sub,
111111
sym::wrapping_mul => BinOp::Mul,
@@ -136,7 +136,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
136136
lhs = args.next().unwrap();
137137
rhs = args.next().unwrap();
138138
}
139-
let bin_op = match intrinsic_name {
139+
let bin_op = match intrinsic.name {
140140
sym::add_with_overflow => BinOp::Add,
141141
sym::sub_with_overflow => BinOp::Sub,
142142
sym::mul_with_overflow => BinOp::Mul,
@@ -155,7 +155,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
155155
sym::size_of | sym::min_align_of => {
156156
if let Some(target) = *target {
157157
let tp_ty = generic_args.type_at(0);
158-
let null_op = match intrinsic_name {
158+
let null_op = match intrinsic.name {
159159
sym::size_of => NullOp::SizeOf,
160160
sym::min_align_of => NullOp::AlignOf,
161161
_ => bug!("unexpected intrinsic"),

0 commit comments

Comments
 (0)