2015-08-06 11:29:26 -07:00
|
|
|
//! Type-checking for the rust-intrinsic and platform-intrinsic
|
|
|
|
//! intrinsics that the compiler exposes.
|
|
|
|
|
2020-08-27 20:09:22 +10:00
|
|
|
use crate::errors::{
|
2021-09-11 14:47:28 +00:00
|
|
|
UnrecognizedAtomicOperation, UnrecognizedIntrinsicFunction,
|
2021-07-01 13:52:44 +02:00
|
|
|
WrongNumberOfGenericArgumentsToIntrinsic,
|
2020-08-27 20:09:22 +10:00
|
|
|
};
|
2019-02-08 22:30:58 +09:00
|
|
|
use crate::require_same_types;
|
2019-12-31 21:25:16 +01:00
|
|
|
|
2022-08-17 13:43:59 +02:00
|
|
|
use hir::def_id::DefId;
|
2022-09-09 16:38:33 +02:00
|
|
|
use rustc_errors::{struct_span_err, DiagnosticMessage};
|
2020-03-29 17:19:48 +02:00
|
|
|
use rustc_hir as hir;
|
2020-03-29 16:41:09 +02:00
|
|
|
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
|
2023-07-05 20:13:26 +01:00
|
|
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
2020-06-28 12:58:20 +02:00
|
|
|
use rustc_span::symbol::{kw, sym, Symbol};
|
2018-04-25 19:30:39 +03:00
|
|
|
use rustc_target::spec::abi::Abi;
|
2015-08-06 11:29:26 -07:00
|
|
|
|
2019-06-11 23:35:39 +03:00
|
|
|
fn equate_intrinsic_type<'tcx>(
|
2019-06-14 00:48:52 +03:00
|
|
|
tcx: TyCtxt<'tcx>,
|
2019-11-28 20:18:29 +01:00
|
|
|
it: &hir::ForeignItem<'_>,
|
2018-08-22 15:56:37 +02:00
|
|
|
n_tps: usize,
|
2021-06-08 20:38:43 +02:00
|
|
|
n_lts: usize,
|
2020-12-16 22:36:14 -05:00
|
|
|
sig: ty::PolyFnSig<'tcx>,
|
2018-08-22 15:56:37 +02:00
|
|
|
) {
|
2021-07-01 13:52:44 +02:00
|
|
|
let (own_counts, span) = match &it.kind {
|
2021-06-08 20:38:43 +02:00
|
|
|
hir::ForeignItemKind::Fn(.., generics) => {
|
2022-10-27 14:02:18 +11:00
|
|
|
let own_counts = tcx.generics_of(it.owner_id.to_def_id()).own_counts();
|
2021-07-01 13:52:44 +02:00
|
|
|
(own_counts, generics.span)
|
2021-06-08 20:38:43 +02:00
|
|
|
}
|
2017-05-13 17:11:52 +03:00
|
|
|
_ => {
|
2017-06-29 21:03:19 +02:00
|
|
|
struct_span_err!(tcx.sess, it.span, E0622, "intrinsic must be a function")
|
2017-05-13 17:11:52 +03:00
|
|
|
.span_label(it.span, "expected a function")
|
|
|
|
.emit();
|
|
|
|
return;
|
|
|
|
}
|
2021-06-08 20:38:43 +02:00
|
|
|
};
|
2016-02-16 18:36:41 +02:00
|
|
|
|
2021-07-01 13:52:44 +02:00
|
|
|
let gen_count_ok = |found: usize, expected: usize, descr: &str| -> bool {
|
|
|
|
if found != expected {
|
|
|
|
tcx.sess.emit_err(WrongNumberOfGenericArgumentsToIntrinsic {
|
|
|
|
span,
|
|
|
|
found,
|
|
|
|
expected,
|
|
|
|
descr,
|
|
|
|
});
|
|
|
|
false
|
|
|
|
} else {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
};
|
2016-08-25 01:24:49 +02:00
|
|
|
|
2021-07-01 13:52:44 +02:00
|
|
|
if gen_count_ok(own_counts.lifetimes, n_lts, "lifetime")
|
|
|
|
&& gen_count_ok(own_counts.types, n_tps, "type")
|
|
|
|
&& gen_count_ok(own_counts.consts, 0, "const")
|
|
|
|
{
|
2023-07-05 20:13:26 +01:00
|
|
|
let fty = Ty::new_fn_ptr(tcx, sig);
|
2023-01-15 12:58:46 +01:00
|
|
|
let it_def_id = it.owner_id.def_id;
|
|
|
|
let cause = ObligationCause::new(it.span, it_def_id, ObligationCauseCode::IntrinsicType);
|
2023-01-18 16:52:47 -07:00
|
|
|
require_same_types(
|
|
|
|
tcx,
|
|
|
|
&cause,
|
2023-03-14 14:19:06 +01:00
|
|
|
ty::ParamEnv::empty(), // FIXME: do all intrinsics have an empty param env?
|
2023-07-11 22:35:29 +01:00
|
|
|
Ty::new_fn_ptr(tcx, tcx.fn_sig(it.owner_id).instantiate_identity()),
|
2023-01-18 16:52:47 -07:00
|
|
|
fty,
|
|
|
|
);
|
2015-08-06 14:52:40 -07:00
|
|
|
}
|
|
|
|
}
|
2015-08-06 11:29:26 -07:00
|
|
|
|
2021-06-12 19:01:32 +02:00
|
|
|
/// Returns the unsafety of the given intrinsic.
|
2022-08-17 13:43:59 +02:00
|
|
|
pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: DefId) -> hir::Unsafety {
|
2022-09-09 16:38:33 +02:00
|
|
|
let has_safe_attr = match tcx.has_attr(intrinsic_id, sym::rustc_safe_intrinsic) {
|
2022-08-17 13:43:59 +02:00
|
|
|
true => hir::Unsafety::Normal,
|
|
|
|
false => hir::Unsafety::Unsafe,
|
2022-09-09 16:38:33 +02:00
|
|
|
};
|
|
|
|
let is_in_list = match tcx.item_name(intrinsic_id) {
|
|
|
|
// When adding a new intrinsic to this list,
|
|
|
|
// it's usually worth updating that intrinsic's documentation
|
|
|
|
// to note that it's safe to call, since
|
|
|
|
// safe extern fns are otherwise unprecedented.
|
|
|
|
sym::abort
|
|
|
|
| sym::assert_inhabited
|
|
|
|
| sym::assert_zero_valid
|
2022-12-12 15:47:32 +01:00
|
|
|
| sym::assert_mem_uninitialized_valid
|
2022-09-09 16:38:33 +02:00
|
|
|
| sym::size_of
|
|
|
|
| sym::min_align_of
|
|
|
|
| sym::needs_drop
|
|
|
|
| sym::caller_location
|
|
|
|
| sym::add_with_overflow
|
|
|
|
| sym::sub_with_overflow
|
|
|
|
| sym::mul_with_overflow
|
|
|
|
| sym::wrapping_add
|
|
|
|
| sym::wrapping_sub
|
|
|
|
| sym::wrapping_mul
|
|
|
|
| sym::saturating_add
|
|
|
|
| sym::saturating_sub
|
|
|
|
| sym::rotate_left
|
|
|
|
| sym::rotate_right
|
|
|
|
| sym::ctpop
|
|
|
|
| sym::ctlz
|
|
|
|
| sym::cttz
|
|
|
|
| sym::bswap
|
|
|
|
| sym::bitreverse
|
|
|
|
| sym::discriminant_value
|
|
|
|
| sym::type_id
|
|
|
|
| sym::likely
|
|
|
|
| sym::unlikely
|
|
|
|
| sym::ptr_guaranteed_cmp
|
|
|
|
| sym::minnumf32
|
|
|
|
| sym::minnumf64
|
|
|
|
| sym::maxnumf32
|
|
|
|
| sym::rustc_peek
|
|
|
|
| sym::maxnumf64
|
|
|
|
| sym::type_name
|
|
|
|
| sym::forget
|
|
|
|
| sym::black_box
|
|
|
|
| sym::variant_count
|
|
|
|
| sym::ptr_mask => hir::Unsafety::Normal,
|
|
|
|
_ => hir::Unsafety::Unsafe,
|
|
|
|
};
|
|
|
|
|
|
|
|
if has_safe_attr != is_in_list {
|
|
|
|
tcx.sess.struct_span_err(
|
|
|
|
tcx.def_span(intrinsic_id),
|
Use `Cow` in `{D,Subd}iagnosticMessage`.
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment:
```
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
```
This commit answers that question in the affirmative. It's not the most
compelling change ever, but it might be worth merging.
This requires changing the `impl<'a> From<&'a str>` impls to `impl
From<&'static str>`, which involves a bunch of knock-on changes that
require/result in call sites being a little more precise about exactly
what kind of string they use to create errors, and not just `&str`. This
will result in fewer unnecessary allocations, though this will not have
any notable perf effects given that these are error paths.
Note that I was lazy within Clippy, using `to_string` in a few places to
preserve the existing string imprecision. I could have used `impl
Into<{D,Subd}iagnosticMessage>` in various places as is done in the
compiler, but that would have required changes to *many* call sites
(mostly changing `&format("...")` to `format!("...")`) which didn't seem
worthwhile.
2023-05-04 10:55:21 +10:00
|
|
|
DiagnosticMessage::from(format!(
|
|
|
|
"intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `{}`",
|
|
|
|
tcx.item_name(intrinsic_id)
|
|
|
|
)
|
|
|
|
)).emit();
|
2018-12-31 04:11:17 +01:00
|
|
|
}
|
2022-09-09 16:38:33 +02:00
|
|
|
|
|
|
|
is_in_list
|
2018-12-31 04:11:17 +01:00
|
|
|
}
|
|
|
|
|
2020-09-20 12:46:06 +00:00
|
|
|
/// Remember to add all intrinsics here, in `compiler/rustc_codegen_llvm/src/intrinsic.rs`,
|
|
|
|
/// and in `library/core/src/intrinsics.rs`.
|
2019-11-28 20:18:29 +01:00
|
|
|
pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
2023-07-25 23:17:39 +02:00
|
|
|
let param = |n| Ty::new_param(tcx, n, Symbol::intern(&format!("P{n}")));
|
2022-10-27 14:02:18 +11:00
|
|
|
let intrinsic_id = it.owner_id.to_def_id();
|
2022-08-17 13:43:59 +02:00
|
|
|
let intrinsic_name = tcx.item_name(intrinsic_id);
|
2020-06-28 12:58:20 +02:00
|
|
|
let name_str = intrinsic_name.as_str();
|
2018-10-23 23:13:33 +00:00
|
|
|
|
2023-02-17 14:33:08 +11:00
|
|
|
let bound_vars = tcx.mk_bound_variable_kinds(&[
|
2023-04-06 22:07:21 -04:00
|
|
|
ty::BoundVariableKind::Region(ty::BrAnon(None)),
|
2023-02-16 16:27:05 +11:00
|
|
|
ty::BoundVariableKind::Region(ty::BrEnv),
|
|
|
|
]);
|
2019-03-25 14:28:03 -07:00
|
|
|
let mk_va_list_ty = |mutbl| {
|
2018-10-23 23:13:33 +00:00
|
|
|
tcx.lang_items().va_list().map(|did| {
|
2023-05-29 17:54:53 +00:00
|
|
|
let region = ty::Region::new_late_bound(
|
|
|
|
tcx,
|
2020-10-26 14:18:31 -04:00
|
|
|
ty::INNERMOST,
|
2023-04-06 22:07:21 -04:00
|
|
|
ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) },
|
2023-02-13 13:03:45 +11:00
|
|
|
);
|
2023-05-29 17:54:53 +00:00
|
|
|
let env_region = ty::Region::new_late_bound(
|
|
|
|
tcx,
|
2020-10-26 14:18:31 -04:00
|
|
|
ty::INNERMOST,
|
|
|
|
ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrEnv },
|
2023-02-13 13:03:45 +11:00
|
|
|
);
|
2023-07-11 22:35:29 +01:00
|
|
|
let va_list_ty = tcx.type_of(did).instantiate(tcx, &[region.into()]);
|
2023-07-05 20:13:26 +01:00
|
|
|
(Ty::new_ref(tcx, env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty)
|
2018-10-23 23:13:33 +00:00
|
|
|
})
|
|
|
|
};
|
|
|
|
|
2021-06-08 20:38:43 +02:00
|
|
|
let (n_tps, n_lts, inputs, output, unsafety) = if name_str.starts_with("atomic_") {
|
2020-06-28 12:58:20 +02:00
|
|
|
let split: Vec<&str> = name_str.split('_').collect();
|
2018-09-19 13:51:51 +02:00
|
|
|
assert!(split.len() >= 2, "Atomic intrinsic in an incorrect format");
|
2015-08-06 11:29:26 -07:00
|
|
|
|
|
|
|
//We only care about the operation here
|
|
|
|
let (n_tps, inputs, output) = match split[1] {
|
2016-10-04 02:19:40 +03:00
|
|
|
"cxchg" | "cxchgweak" => (
|
|
|
|
1,
|
2023-07-05 20:13:26 +01:00
|
|
|
vec![Ty::new_mut_ptr(tcx, param(0)), param(0), param(0)],
|
|
|
|
Ty::new_tup(tcx, &[param(0), tcx.types.bool]),
|
2019-12-22 17:42:04 -05:00
|
|
|
),
|
2023-07-05 20:13:26 +01:00
|
|
|
"load" => (1, vec![Ty::new_imm_ptr(tcx, param(0))], param(0)),
|
|
|
|
"store" => (1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx)),
|
2019-12-22 17:42:04 -05:00
|
|
|
|
2015-08-06 11:29:26 -07:00
|
|
|
"xchg" | "xadd" | "xsub" | "and" | "nand" | "or" | "xor" | "max" | "min" | "umax"
|
2023-07-05 20:13:26 +01:00
|
|
|
| "umin" => (1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], param(0)),
|
|
|
|
"fence" | "singlethreadfence" => (0, Vec::new(), Ty::new_unit(tcx)),
|
2015-08-06 11:29:26 -07:00
|
|
|
op => {
|
2020-08-27 20:09:22 +10:00
|
|
|
tcx.sess.emit_err(UnrecognizedAtomicOperation { span: it.span, op });
|
2015-08-06 11:29:26 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
2021-06-08 20:38:43 +02:00
|
|
|
(n_tps, 0, inputs, output, hir::Unsafety::Unsafe)
|
2015-08-06 11:29:26 -07:00
|
|
|
} else {
|
2022-08-17 13:43:59 +02:00
|
|
|
let unsafety = intrinsic_operation_unsafety(tcx, intrinsic_id);
|
2020-06-28 12:58:20 +02:00
|
|
|
let (n_tps, inputs, output) = match intrinsic_name {
|
|
|
|
sym::abort => (0, Vec::new(), tcx.types.never),
|
|
|
|
sym::unreachable => (0, Vec::new(), tcx.types.never),
|
2023-07-05 20:13:26 +01:00
|
|
|
sym::breakpoint => (0, Vec::new(), Ty::new_unit(tcx)),
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::size_of | sym::pref_align_of | sym::min_align_of | sym::variant_count => {
|
2020-06-23 16:46:24 +01:00
|
|
|
(1, Vec::new(), tcx.types.usize)
|
|
|
|
}
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::size_of_val | sym::min_align_of_val => {
|
2023-07-05 20:13:26 +01:00
|
|
|
(1, vec![Ty::new_imm_ptr(tcx, param(0))], tcx.types.usize)
|
2020-02-11 14:10:49 -05:00
|
|
|
}
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::rustc_peek => (1, vec![param(0)], param(0)),
|
|
|
|
sym::caller_location => (0, vec![], tcx.caller_location_ty()),
|
2022-12-12 15:47:32 +01:00
|
|
|
sym::assert_inhabited
|
|
|
|
| sym::assert_zero_valid
|
2023-07-05 20:13:26 +01:00
|
|
|
| sym::assert_mem_uninitialized_valid => (1, Vec::new(), Ty::new_unit(tcx)),
|
|
|
|
sym::forget => (1, vec![param(0)], Ty::new_unit(tcx)),
|
2023-04-22 17:14:19 -07:00
|
|
|
sym::transmute | sym::transmute_unchecked => (2, vec![param(0)], param(1)),
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::prefetch_read_data
|
|
|
|
| sym::prefetch_write_data
|
|
|
|
| sym::prefetch_read_instruction
|
|
|
|
| sym::prefetch_write_instruction => (
|
2017-04-21 09:00:34 +02:00
|
|
|
1,
|
|
|
|
vec![
|
2023-07-05 20:13:26 +01:00
|
|
|
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
2017-04-21 09:00:34 +02:00
|
|
|
tcx.types.i32,
|
|
|
|
],
|
2023-07-05 20:13:26 +01:00
|
|
|
Ty::new_unit(tcx),
|
2019-12-22 17:42:04 -05:00
|
|
|
),
|
2023-07-05 20:13:26 +01:00
|
|
|
sym::drop_in_place => (1, vec![Ty::new_mut_ptr(tcx, param(0))], Ty::new_unit(tcx)),
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::needs_drop => (1, Vec::new(), tcx.types.bool),
|
2015-08-06 11:29:26 -07:00
|
|
|
|
2023-07-05 20:13:26 +01:00
|
|
|
sym::type_name => (1, Vec::new(), Ty::new_static_str(tcx)),
|
2023-04-04 17:55:20 -07:00
|
|
|
sym::type_id => (1, Vec::new(), tcx.types.u128),
|
2023-04-25 22:41:34 -07:00
|
|
|
sym::offset => (2, vec![param(0), param(1)], param(0)),
|
|
|
|
sym::arith_offset => (
|
2015-08-06 11:29:26 -07:00
|
|
|
1,
|
2019-12-22 17:42:04 -05:00
|
|
|
vec![
|
2023-07-05 20:13:26 +01:00
|
|
|
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
2019-08-20 17:51:54 +02:00
|
|
|
tcx.types.isize,
|
2019-12-22 17:42:04 -05:00
|
|
|
],
|
2023-07-05 20:13:26 +01:00
|
|
|
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
2019-12-22 17:42:04 -05:00
|
|
|
),
|
2023-03-15 16:29:52 +01:00
|
|
|
sym::option_payload_ptr => {
|
|
|
|
let option_def_id = tcx.require_lang_item(hir::LangItem::Option, None);
|
|
|
|
let p0 = param(0);
|
|
|
|
(
|
|
|
|
1,
|
2023-07-05 20:13:26 +01:00
|
|
|
vec![Ty::new_ptr(
|
|
|
|
tcx,
|
|
|
|
ty::TypeAndMut {
|
|
|
|
ty: Ty::new_adt(
|
|
|
|
tcx,
|
|
|
|
tcx.adt_def(option_def_id),
|
2023-07-11 22:35:29 +01:00
|
|
|
tcx.mk_args_from_iter([ty::GenericArg::from(p0)].into_iter()),
|
2023-07-05 20:13:26 +01:00
|
|
|
),
|
|
|
|
mutbl: hir::Mutability::Not,
|
|
|
|
},
|
|
|
|
)],
|
|
|
|
Ty::new_ptr(tcx, ty::TypeAndMut { ty: p0, mutbl: hir::Mutability::Not }),
|
2023-03-15 16:29:52 +01:00
|
|
|
)
|
|
|
|
}
|
2022-05-11 17:52:00 +04:00
|
|
|
sym::ptr_mask => (
|
|
|
|
1,
|
|
|
|
vec![
|
2023-07-05 20:13:26 +01:00
|
|
|
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
2022-05-11 17:52:00 +04:00
|
|
|
tcx.types.usize,
|
|
|
|
],
|
2023-07-05 20:13:26 +01:00
|
|
|
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
2022-05-11 17:52:00 +04:00
|
|
|
),
|
|
|
|
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::copy | sym::copy_nonoverlapping => (
|
2019-12-22 17:42:04 -05:00
|
|
|
1,
|
2016-10-29 22:54:04 +01:00
|
|
|
vec![
|
2023-07-05 20:13:26 +01:00
|
|
|
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
|
|
|
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
|
2016-10-04 02:19:40 +03:00
|
|
|
tcx.types.usize,
|
2016-10-29 22:54:04 +01:00
|
|
|
],
|
2023-07-05 20:13:26 +01:00
|
|
|
Ty::new_unit(tcx),
|
2016-10-04 02:19:40 +03:00
|
|
|
),
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::volatile_copy_memory | sym::volatile_copy_nonoverlapping_memory => (
|
2015-08-06 11:29:26 -07:00
|
|
|
1,
|
2016-10-29 22:54:04 +01:00
|
|
|
vec![
|
2023-07-05 20:13:26 +01:00
|
|
|
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
|
|
|
|
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
2015-08-06 11:29:26 -07:00
|
|
|
tcx.types.usize,
|
2019-12-22 17:42:04 -05:00
|
|
|
],
|
2023-07-05 20:13:26 +01:00
|
|
|
Ty::new_unit(tcx),
|
2019-12-22 17:42:04 -05:00
|
|
|
),
|
2023-08-02 12:45:52 -07:00
|
|
|
sym::compare_bytes => {
|
|
|
|
let byte_ptr = Ty::new_imm_ptr(tcx, tcx.types.u8);
|
|
|
|
(0, vec![byte_ptr, byte_ptr, tcx.types.usize], tcx.types.i32)
|
|
|
|
}
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::write_bytes | sym::volatile_set_memory => (
|
2019-12-22 17:42:04 -05:00
|
|
|
1,
|
|
|
|
vec![
|
2023-07-05 20:13:26 +01:00
|
|
|
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
|
2015-08-06 11:29:26 -07:00
|
|
|
tcx.types.u8,
|
|
|
|
tcx.types.usize,
|
2019-12-22 17:42:04 -05:00
|
|
|
],
|
2023-07-05 20:13:26 +01:00
|
|
|
Ty::new_unit(tcx),
|
2019-12-22 17:42:04 -05:00
|
|
|
),
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::sqrtf32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::sqrtf64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::powif32 => (0, vec![tcx.types.f32, tcx.types.i32], tcx.types.f32),
|
|
|
|
sym::powif64 => (0, vec![tcx.types.f64, tcx.types.i32], tcx.types.f64),
|
|
|
|
sym::sinf32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::sinf64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::cosf32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::cosf64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::powf32 => (0, vec![tcx.types.f32, tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::powf64 => (0, vec![tcx.types.f64, tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::expf32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::expf64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::exp2f32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::exp2f64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::logf32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::logf64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::log10f32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::log10f64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::log2f32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::log2f64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::fmaf32 => (0, vec![tcx.types.f32, tcx.types.f32, tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::fmaf64 => (0, vec![tcx.types.f64, tcx.types.f64, tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::fabsf32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::fabsf64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::minnumf32 => (0, vec![tcx.types.f32, tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::minnumf64 => (0, vec![tcx.types.f64, tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::maxnumf32 => (0, vec![tcx.types.f32, tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::maxnumf64 => (0, vec![tcx.types.f64, tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::copysignf32 => (0, vec![tcx.types.f32, tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::copysignf64 => (0, vec![tcx.types.f64, tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::floorf32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::floorf64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::ceilf32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::ceilf64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::truncf32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::truncf64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::rintf32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::rintf64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::nearbyintf32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::nearbyintf64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
|
|
|
sym::roundf32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::roundf64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
2022-03-25 02:44:16 -04:00
|
|
|
sym::roundevenf32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
|
|
|
sym::roundevenf64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
2020-06-28 12:58:20 +02:00
|
|
|
|
|
|
|
sym::volatile_load | sym::unaligned_volatile_load => {
|
2023-07-05 20:13:26 +01:00
|
|
|
(1, vec![Ty::new_imm_ptr(tcx, param(0))], param(0))
|
2015-08-06 11:29:26 -07:00
|
|
|
}
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::volatile_store | sym::unaligned_volatile_store => {
|
2023-07-05 20:13:26 +01:00
|
|
|
(1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx))
|
2015-08-06 11:29:26 -07:00
|
|
|
}
|
2019-12-22 17:42:04 -05:00
|
|
|
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::ctpop
|
|
|
|
| sym::ctlz
|
|
|
|
| sym::ctlz_nonzero
|
|
|
|
| sym::cttz
|
|
|
|
| sym::cttz_nonzero
|
|
|
|
| sym::bswap
|
|
|
|
| sym::bitreverse => (1, vec![param(0)], param(0)),
|
2019-12-22 17:42:04 -05:00
|
|
|
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::add_with_overflow | sym::sub_with_overflow | sym::mul_with_overflow => {
|
2023-07-05 20:13:26 +01:00
|
|
|
(1, vec![param(0), param(0)], Ty::new_tup(tcx, &[param(0), tcx.types.bool]))
|
2015-08-06 11:29:26 -07:00
|
|
|
}
|
2019-12-22 17:42:04 -05:00
|
|
|
|
2023-07-05 20:13:26 +01:00
|
|
|
sym::ptr_guaranteed_cmp => (
|
|
|
|
1,
|
|
|
|
vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))],
|
|
|
|
tcx.types.u8,
|
|
|
|
),
|
2020-06-16 10:37:34 +02:00
|
|
|
|
2020-12-01 15:39:25 +05:30
|
|
|
sym::const_allocate => {
|
2023-07-05 20:13:26 +01:00
|
|
|
(0, vec![tcx.types.usize, tcx.types.usize], Ty::new_mut_ptr(tcx, tcx.types.u8))
|
2020-12-01 15:39:25 +05:30
|
|
|
}
|
2021-12-25 22:35:11 +09:00
|
|
|
sym::const_deallocate => (
|
|
|
|
0,
|
2023-07-05 20:13:26 +01:00
|
|
|
vec![Ty::new_mut_ptr(tcx, tcx.types.u8), tcx.types.usize, tcx.types.usize],
|
|
|
|
Ty::new_unit(tcx),
|
2021-12-25 22:35:11 +09:00
|
|
|
),
|
2020-12-01 15:39:25 +05:30
|
|
|
|
2023-07-05 20:13:26 +01:00
|
|
|
sym::ptr_offset_from => (
|
|
|
|
1,
|
|
|
|
vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))],
|
|
|
|
tcx.types.isize,
|
|
|
|
),
|
|
|
|
sym::ptr_offset_from_unsigned => (
|
|
|
|
1,
|
|
|
|
vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))],
|
|
|
|
tcx.types.usize,
|
|
|
|
),
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::unchecked_div | sym::unchecked_rem | sym::exact_div => {
|
2016-10-29 22:54:04 +01:00
|
|
|
(1, vec![param(0), param(0)], param(0))
|
2015-08-06 11:29:26 -07:00
|
|
|
}
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::unchecked_shl | sym::unchecked_shr | sym::rotate_left | sym::rotate_right => {
|
2016-10-29 22:54:04 +01:00
|
|
|
(1, vec![param(0), param(0)], param(0))
|
2015-08-06 11:29:26 -07:00
|
|
|
}
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::unchecked_add | sym::unchecked_sub | sym::unchecked_mul => {
|
2016-10-29 22:54:04 +01:00
|
|
|
(1, vec![param(0), param(0)], param(0))
|
2015-08-06 11:29:26 -07:00
|
|
|
}
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::wrapping_add | sym::wrapping_sub | sym::wrapping_mul => {
|
2016-10-29 22:54:04 +01:00
|
|
|
(1, vec![param(0), param(0)], param(0))
|
2015-08-06 11:29:26 -07:00
|
|
|
}
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::saturating_add | sym::saturating_sub => (1, vec![param(0), param(0)], param(0)),
|
|
|
|
sym::fadd_fast | sym::fsub_fast | sym::fmul_fast | sym::fdiv_fast | sym::frem_fast => {
|
2016-10-29 22:54:04 +01:00
|
|
|
(1, vec![param(0), param(0)], param(0))
|
2015-08-06 11:29:26 -07:00
|
|
|
}
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::float_to_int_unchecked => (2, vec![param(0)], param(1)),
|
2015-08-06 11:29:26 -07:00
|
|
|
|
2023-07-05 20:13:26 +01:00
|
|
|
sym::assume => (0, vec![tcx.types.bool], Ty::new_unit(tcx)),
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::likely => (0, vec![tcx.types.bool], tcx.types.bool),
|
|
|
|
sym::unlikely => (0, vec![tcx.types.bool], tcx.types.bool),
|
2015-08-06 11:29:26 -07:00
|
|
|
|
2023-07-05 20:13:26 +01:00
|
|
|
sym::read_via_copy => (1, vec![Ty::new_imm_ptr(tcx, param(0))], param(0)),
|
|
|
|
sym::write_via_move => {
|
|
|
|
(1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx))
|
|
|
|
}
|
2023-03-11 15:32:54 -08:00
|
|
|
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::discriminant_value => {
|
2021-11-05 18:47:52 +00:00
|
|
|
let assoc_items = tcx.associated_item_def_ids(
|
|
|
|
tcx.require_lang_item(hir::LangItem::DiscriminantKind, None),
|
|
|
|
);
|
|
|
|
let discriminant_def_id = assoc_items[0];
|
2020-04-05 19:30:03 +02:00
|
|
|
|
2023-04-06 22:07:21 -04:00
|
|
|
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) };
|
2020-04-05 19:30:03 +02:00
|
|
|
(
|
|
|
|
1,
|
2023-07-05 20:13:26 +01:00
|
|
|
vec![Ty::new_imm_ref(
|
|
|
|
tcx,
|
|
|
|
ty::Region::new_late_bound(tcx, ty::INNERMOST, br),
|
|
|
|
param(0),
|
|
|
|
)],
|
2023-07-11 22:35:29 +01:00
|
|
|
Ty::new_projection(tcx, discriminant_def_id, tcx.mk_args(&[param(0).into()])),
|
2020-04-05 19:30:03 +02:00
|
|
|
)
|
|
|
|
}
|
2015-08-06 11:29:26 -07:00
|
|
|
|
2020-06-28 12:58:20 +02:00
|
|
|
kw::Try => {
|
2023-07-05 20:13:26 +01:00
|
|
|
let mut_u8 = Ty::new_mut_ptr(tcx, tcx.types.u8);
|
2020-10-07 20:02:06 -04:00
|
|
|
let try_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
|
2023-02-16 16:05:08 +11:00
|
|
|
[mut_u8],
|
2023-07-05 20:13:26 +01:00
|
|
|
Ty::new_unit(tcx),
|
2017-02-13 10:51:06 +02:00
|
|
|
false,
|
|
|
|
hir::Unsafety::Normal,
|
|
|
|
Abi::Rust,
|
|
|
|
));
|
2020-10-07 20:02:06 -04:00
|
|
|
let catch_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
|
2023-02-16 16:05:08 +11:00
|
|
|
[mut_u8, mut_u8],
|
2023-07-05 20:13:26 +01:00
|
|
|
Ty::new_unit(tcx),
|
2020-03-02 13:59:20 +00:00
|
|
|
false,
|
|
|
|
hir::Unsafety::Normal,
|
|
|
|
Abi::Rust,
|
|
|
|
));
|
|
|
|
(
|
|
|
|
0,
|
2023-07-05 20:13:26 +01:00
|
|
|
vec![Ty::new_fn_ptr(tcx, try_fn_ty), mut_u8, Ty::new_fn_ptr(tcx, catch_fn_ty)],
|
2020-03-02 13:59:20 +00:00
|
|
|
tcx.types.i32,
|
|
|
|
)
|
2015-08-06 11:29:26 -07:00
|
|
|
}
|
|
|
|
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::va_start | sym::va_end => match mk_va_list_ty(hir::Mutability::Mut) {
|
2023-07-05 20:13:26 +01:00
|
|
|
Some((va_list_ref_ty, _)) => (0, vec![va_list_ref_ty], Ty::new_unit(tcx)),
|
2018-11-30 15:53:44 +00:00
|
|
|
None => bug!("`va_list` language item needed for C-variadic intrinsics"),
|
2018-10-23 23:13:33 +00:00
|
|
|
},
|
|
|
|
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::va_copy => match mk_va_list_ty(hir::Mutability::Not) {
|
2019-03-25 14:28:03 -07:00
|
|
|
Some((va_list_ref_ty, va_list_ty)) => {
|
2023-07-05 20:13:26 +01:00
|
|
|
let va_list_ptr_ty = Ty::new_mut_ptr(tcx, va_list_ty);
|
|
|
|
(0, vec![va_list_ptr_ty, va_list_ref_ty], Ty::new_unit(tcx))
|
2018-10-23 23:13:33 +00:00
|
|
|
}
|
2018-11-30 15:53:44 +00:00
|
|
|
None => bug!("`va_list` language item needed for C-variadic intrinsics"),
|
2018-10-23 23:13:33 +00:00
|
|
|
},
|
|
|
|
|
2020-06-28 12:58:20 +02:00
|
|
|
sym::va_arg => match mk_va_list_ty(hir::Mutability::Mut) {
|
2019-03-25 14:28:03 -07:00
|
|
|
Some((va_list_ref_ty, _)) => (1, vec![va_list_ref_ty], param(0)),
|
2018-11-30 15:53:44 +00:00
|
|
|
None => bug!("`va_list` language item needed for C-variadic intrinsics"),
|
2018-10-23 23:13:33 +00:00
|
|
|
},
|
|
|
|
|
2023-07-05 20:13:26 +01:00
|
|
|
sym::nontemporal_store => {
|
|
|
|
(1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx))
|
|
|
|
}
|
2017-10-18 10:30:29 -07:00
|
|
|
|
2021-05-30 10:25:41 -07:00
|
|
|
sym::raw_eq => {
|
2023-04-06 22:07:21 -04:00
|
|
|
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) };
|
2023-07-05 20:13:26 +01:00
|
|
|
let param_ty = Ty::new_imm_ref(
|
|
|
|
tcx,
|
|
|
|
ty::Region::new_late_bound(tcx, ty::INNERMOST, br),
|
|
|
|
param(0),
|
|
|
|
);
|
2021-05-30 11:31:56 -07:00
|
|
|
(1, vec![param_ty; 2], tcx.types.bool)
|
2021-05-30 10:25:41 -07:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:50:33 +01:00
|
|
|
sym::black_box => (1, vec![param(0)], param(0)),
|
|
|
|
|
2021-10-12 05:06:37 +00:00
|
|
|
sym::const_eval_select => (4, vec![param(0), param(1), param(2)], param(3)),
|
|
|
|
|
2022-07-18 09:48:20 -04:00
|
|
|
sym::vtable_size | sym::vtable_align => {
|
2023-07-05 20:13:26 +01:00
|
|
|
(0, vec![Ty::new_imm_ptr(tcx, Ty::new_unit(tcx))], tcx.types.usize)
|
2022-07-18 09:48:20 -04:00
|
|
|
}
|
|
|
|
|
2020-06-28 12:58:20 +02:00
|
|
|
other => {
|
2020-08-27 20:09:22 +10:00
|
|
|
tcx.sess.emit_err(UnrecognizedIntrinsicFunction { span: it.span, name: other });
|
2015-08-06 11:29:26 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
2021-07-01 13:52:44 +02:00
|
|
|
(n_tps, 0, inputs, output, unsafety)
|
2015-08-06 11:29:26 -07:00
|
|
|
};
|
2023-02-16 16:05:08 +11:00
|
|
|
let sig = tcx.mk_fn_sig(inputs, output, false, unsafety, Abi::RustIntrinsic);
|
2020-10-26 14:18:31 -04:00
|
|
|
let sig = ty::Binder::bind_with_vars(sig, bound_vars);
|
2021-06-08 20:38:43 +02:00
|
|
|
equate_intrinsic_type(tcx, it, n_tps, n_lts, sig)
|
2015-08-06 11:29:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Type-check `extern "platform-intrinsic" { ... }` functions.
|
2019-11-28 20:18:29 +01:00
|
|
|
pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
2015-08-06 11:29:26 -07:00
|
|
|
let param = |n| {
|
2023-07-25 23:17:39 +02:00
|
|
|
let name = Symbol::intern(&format!("P{n}"));
|
2023-07-05 20:13:26 +01:00
|
|
|
Ty::new_param(tcx, n, name)
|
2015-08-06 11:29:26 -07:00
|
|
|
};
|
|
|
|
|
2020-07-08 11:04:10 +10:00
|
|
|
let name = it.ident.name;
|
2015-08-06 11:29:26 -07:00
|
|
|
|
2020-07-08 11:04:10 +10:00
|
|
|
let (n_tps, inputs, output) = match name {
|
|
|
|
sym::simd_eq | sym::simd_ne | sym::simd_lt | sym::simd_le | sym::simd_gt | sym::simd_ge => {
|
2015-08-06 11:29:26 -07:00
|
|
|
(2, vec![param(0), param(0)], param(1))
|
|
|
|
}
|
2020-07-08 11:04:10 +10:00
|
|
|
sym::simd_add
|
|
|
|
| sym::simd_sub
|
|
|
|
| sym::simd_mul
|
|
|
|
| sym::simd_rem
|
|
|
|
| sym::simd_div
|
|
|
|
| sym::simd_shl
|
|
|
|
| sym::simd_shr
|
|
|
|
| sym::simd_and
|
|
|
|
| sym::simd_or
|
|
|
|
| sym::simd_xor
|
|
|
|
| sym::simd_fmin
|
|
|
|
| sym::simd_fmax
|
|
|
|
| sym::simd_fpow
|
|
|
|
| sym::simd_saturating_add
|
|
|
|
| sym::simd_saturating_sub => (1, vec![param(0), param(0)], param(0)),
|
2022-04-12 11:00:55 -04:00
|
|
|
sym::simd_arith_offset => (2, vec![param(0), param(1)], param(0)),
|
2021-04-14 15:07:36 -07:00
|
|
|
sym::simd_neg
|
2023-07-27 23:04:14 -04:00
|
|
|
| sym::simd_bswap
|
2023-07-27 23:53:45 -04:00
|
|
|
| sym::simd_bitreverse
|
|
|
|
| sym::simd_ctlz
|
|
|
|
| sym::simd_cttz
|
2021-04-14 15:07:36 -07:00
|
|
|
| sym::simd_fsqrt
|
2020-07-08 11:04:10 +10:00
|
|
|
| sym::simd_fsin
|
|
|
|
| sym::simd_fcos
|
|
|
|
| sym::simd_fexp
|
|
|
|
| sym::simd_fexp2
|
|
|
|
| sym::simd_flog2
|
|
|
|
| sym::simd_flog10
|
|
|
|
| sym::simd_flog
|
|
|
|
| sym::simd_fabs
|
2021-04-14 15:07:36 -07:00
|
|
|
| sym::simd_ceil
|
2020-07-08 11:04:10 +10:00
|
|
|
| sym::simd_floor
|
2021-04-14 15:07:36 -07:00
|
|
|
| sym::simd_round
|
|
|
|
| sym::simd_trunc => (1, vec![param(0)], param(0)),
|
2020-07-08 11:04:10 +10:00
|
|
|
sym::simd_fpowi => (1, vec![param(0), tcx.types.i32], param(0)),
|
|
|
|
sym::simd_fma => (1, vec![param(0), param(0), param(0)], param(0)),
|
|
|
|
sym::simd_gather => (3, vec![param(0), param(1), param(2)], param(0)),
|
2023-07-05 20:13:26 +01:00
|
|
|
sym::simd_scatter => (3, vec![param(0), param(1), param(2)], Ty::new_unit(tcx)),
|
2020-07-08 11:04:10 +10:00
|
|
|
sym::simd_insert => (2, vec![param(0), tcx.types.u32, param(1)], param(0)),
|
|
|
|
sym::simd_extract => (2, vec![param(0), tcx.types.u32], param(1)),
|
2022-07-22 01:48:30 +00:00
|
|
|
sym::simd_cast
|
|
|
|
| sym::simd_as
|
|
|
|
| sym::simd_cast_ptr
|
|
|
|
| sym::simd_expose_addr
|
|
|
|
| sym::simd_from_exposed_addr => (2, vec![param(0)], param(1)),
|
2020-07-08 11:04:10 +10:00
|
|
|
sym::simd_bitmask => (2, vec![param(0)], param(1)),
|
|
|
|
sym::simd_select | sym::simd_select_bitmask => {
|
|
|
|
(2, vec![param(0), param(1), param(1)], param(1))
|
2018-05-04 20:07:35 +02:00
|
|
|
}
|
2020-07-08 11:04:10 +10:00
|
|
|
sym::simd_reduce_all | sym::simd_reduce_any => (1, vec![param(0)], tcx.types.bool),
|
|
|
|
sym::simd_reduce_add_ordered | sym::simd_reduce_mul_ordered => {
|
2018-03-13 16:46:55 +01:00
|
|
|
(2, vec![param(0), param(1)], param(1))
|
2015-08-06 11:29:26 -07:00
|
|
|
}
|
2020-07-08 11:04:10 +10:00
|
|
|
sym::simd_reduce_add_unordered
|
|
|
|
| sym::simd_reduce_mul_unordered
|
|
|
|
| sym::simd_reduce_and
|
|
|
|
| sym::simd_reduce_or
|
|
|
|
| sym::simd_reduce_xor
|
|
|
|
| sym::simd_reduce_min
|
|
|
|
| sym::simd_reduce_max
|
|
|
|
| sym::simd_reduce_min_nanless
|
|
|
|
| sym::simd_reduce_max_nanless => (2, vec![param(0)], param(1)),
|
2021-09-11 14:47:28 +00:00
|
|
|
sym::simd_shuffle => (3, vec![param(0), param(0), param(1)], param(2)),
|
2015-08-06 11:29:26 -07:00
|
|
|
_ => {
|
2022-04-15 15:56:32 +09:00
|
|
|
let msg = format!("unrecognized platform-specific intrinsic function: `{name}`");
|
Restrict `From<S>` for `{D,Subd}iagnosticMessage`.
Currently a `{D,Subd}iagnosticMessage` can be created from any type that
impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static,
str>`, which are reasonable. It also includes `&String`, which is pretty
weird, and results in many places making unnecessary allocations for
patterns like this:
```
self.fatal(&format!(...))
```
This creates a string with `format!`, takes a reference, passes the
reference to `fatal`, which does an `into()`, which clones the
reference, doing a second allocation. Two allocations for a single
string, bleh.
This commit changes the `From` impls so that you can only create a
`{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static,
str>`. This requires changing all the places that currently create one
from a `&String`. Most of these are of the `&format!(...)` form
described above; each one removes an unnecessary static `&`, plus an
allocation when executed. There are also a few places where the existing
use of `&String` was more reasonable; these now just use `clone()` at
the call site.
As well as making the code nicer and more efficient, this is a step
towards possibly using `Cow<'static, str>` in
`{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing
the `From<&'a str>` impls to `From<&'static str>`, which is doable, but
I'm not yet sure if it's worthwhile.
2023-04-20 13:26:58 +10:00
|
|
|
tcx.sess.struct_span_err(it.span, msg).emit();
|
2019-01-07 08:18:32 -08:00
|
|
|
return;
|
2015-08-06 11:29:26 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-16 16:05:08 +11:00
|
|
|
let sig = tcx.mk_fn_sig(inputs, output, false, hir::Unsafety::Unsafe, Abi::PlatformIntrinsic);
|
2020-12-16 22:36:14 -05:00
|
|
|
let sig = ty::Binder::dummy(sig);
|
2021-06-08 20:38:43 +02:00
|
|
|
equate_intrinsic_type(tcx, it, n_tps, 0, sig)
|
2015-08-06 11:29:26 -07:00
|
|
|
}
|