Add a query for checking whether a function is an intrinsic.
This commit is contained in:
parent
18bd2dd5cd
commit
0a6b69106e
17 changed files with 52 additions and 45 deletions
|
@ -4,7 +4,6 @@ use rustc_hir::def_id::{DefId, LocalDefId};
|
|||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{DefIdTree, TyCtxt};
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
/// Whether the `def_id` is an unstable const fn and what feature gate is necessary to enable it
|
||||
pub fn is_unstable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Symbol> {
|
||||
|
@ -34,10 +33,7 @@ fn impl_constness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Constness {
|
|||
hir::Node::ForeignItem(hir::ForeignItem { kind: hir::ForeignItemKind::Fn(..), .. }) => {
|
||||
// Intrinsics use `rustc_const_{un,}stable` attributes to indicate constness. All other
|
||||
// foreign items cannot be evaluated at compile-time.
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
let is_const = if let Abi::RustIntrinsic | Abi::PlatformIntrinsic =
|
||||
tcx.hir().get_foreign_abi(hir_id)
|
||||
{
|
||||
let is_const = if tcx.is_intrinsic(def_id) {
|
||||
tcx.lookup_const_stability(def_id).is_some()
|
||||
} else {
|
||||
false
|
||||
|
|
|
@ -312,8 +312,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
};
|
||||
|
||||
match instance.def {
|
||||
ty::InstanceDef::Intrinsic(..) => {
|
||||
assert!(caller_abi == Abi::RustIntrinsic || caller_abi == Abi::PlatformIntrinsic);
|
||||
ty::InstanceDef::Intrinsic(def_id) => {
|
||||
assert!(self.tcx.is_intrinsic(def_id));
|
||||
// caller_fn_abi is not relevant here, we interpret the arguments directly for each intrinsic.
|
||||
M::call_intrinsic(self, instance, args, ret, unwind)
|
||||
}
|
||||
|
|
|
@ -706,8 +706,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
|||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
|
||||
use rustc_target::spec::abi::Abi::RustIntrinsic;
|
||||
|
||||
self.super_terminator(terminator, location);
|
||||
|
||||
match &terminator.kind {
|
||||
|
@ -889,7 +887,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
|||
return;
|
||||
}
|
||||
|
||||
let is_intrinsic = tcx.fn_sig(callee).abi() == RustIntrinsic;
|
||||
let is_intrinsic = tcx.is_intrinsic(callee);
|
||||
|
||||
if !tcx.is_const_fn_raw(callee) {
|
||||
if tcx.trait_of_item(callee).is_some() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue