Skip to content

Commit c9c966e

Browse files
committedOct 20, 2020
allow intrinsics
1 parent 714c06d commit c9c966e

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed
 

‎compiler/rustc_mir/src/transform/inline.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -849,19 +849,30 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
849849
}
850850
}
851851

852-
struct FunctionCallFinder {
852+
struct FunctionCallFinder<'tcx> {
853+
tcx: TyCtxt<'tcx>,
853854
found: bool,
854855
}
855856

856-
impl FunctionCallFinder {
857-
fn new() -> Self {
858-
FunctionCallFinder { found: false }
857+
impl<'tcx> FunctionCallFinder<'tcx> {
858+
fn new(tcx: TyCtxt<'tcx>) -> Self {
859+
FunctionCallFinder { tcx, found: false }
859860
}
860861
}
861862

862-
impl<'tcx> Visitor<'tcx> for FunctionCallFinder {
863+
impl<'tcx> Visitor<'tcx> for FunctionCallFinder<'tcx> {
863864
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, _location: Location) {
864-
if let TerminatorKind::Call { .. } = terminator.kind {
865+
if let TerminatorKind::Call { func: Operand::Constant(ref f), .. } = terminator.kind {
866+
if let ty::FnDef(def_id, _) = *f.literal.ty.kind() {
867+
// Don't forbid intrinsics.
868+
let f = self.tcx.fn_sig(def_id);
869+
if f.abi() == Abi::RustIntrinsic || f.abi() == Abi::PlatformIntrinsic {
870+
return;
871+
}
872+
873+
// FIXME: We may also want to check for `tcx.is_mir_available(def_id)`.
874+
}
875+
865876
self.found = true;
866877
}
867878
}
@@ -884,7 +895,7 @@ pub fn is_trivial_mir(tcx: TyCtxt<'tcx>, did: DefId) -> bool {
884895
let body = tcx
885896
.mir_drops_elaborated_and_const_checked(ty::WithOptConstParam::unknown(did))
886897
.borrow();
887-
let mut finder = FunctionCallFinder::new();
898+
let mut finder = FunctionCallFinder::new(tcx);
888899
finder.visit_body(&body);
889900
debug!("is_trivial_mir = {}", !finder.found);
890901
!finder.found

0 commit comments

Comments
 (0)