Rollup merge of #109179 - llogiq:intrinsically-option-as-slice, r=eholk
move Option::as_slice to intrinsic ````@scottmcm```` suggested on #109095 I use a direct approach of unpacking the operation in MIR lowering, so here's the implementation. cc ````@nikic```` as this should hopefully unblock #107224 (though perhaps other changes to the prior implementation, which I left for bootstrapping, are needed).
This commit is contained in:
commit
14d06467f0
8 changed files with 152 additions and 72 deletions
|
@ -301,6 +301,7 @@ language_item_table! {
|
|||
Context, sym::Context, context, Target::Struct, GenericRequirement::None;
|
||||
FuturePoll, sym::poll, future_poll_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
|
||||
|
||||
Option, sym::Option, option_type, Target::Enum, GenericRequirement::None;
|
||||
OptionSome, sym::Some, option_some_variant, Target::Variant, GenericRequirement::None;
|
||||
OptionNone, sym::None, option_none_variant, Target::Variant, GenericRequirement::None;
|
||||
|
||||
|
|
|
@ -223,6 +223,21 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
],
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
),
|
||||
sym::option_payload_ptr => {
|
||||
let option_def_id = tcx.require_lang_item(hir::LangItem::Option, None);
|
||||
let p0 = param(0);
|
||||
(
|
||||
1,
|
||||
vec![tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: tcx.mk_adt(
|
||||
tcx.adt_def(option_def_id),
|
||||
tcx.mk_substs_from_iter([ty::GenericArg::from(p0)].into_iter()),
|
||||
),
|
||||
mutbl: hir::Mutability::Not,
|
||||
})],
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: p0, mutbl: hir::Mutability::Not }),
|
||||
)
|
||||
}
|
||||
sym::ptr_mask => (
|
||||
1,
|
||||
vec![
|
||||
|
|
|
@ -6,6 +6,7 @@ use rustc_middle::ty::subst::SubstsRef;
|
|||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::VariantIdx;
|
||||
|
||||
pub struct LowerIntrinsics;
|
||||
|
||||
|
@ -191,6 +192,35 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
|
|||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
}
|
||||
sym::option_payload_ptr => {
|
||||
if let (Some(target), Some(arg)) = (*target, args[0].place()) {
|
||||
let ty::RawPtr(ty::TypeAndMut { ty: dest_ty, .. }) =
|
||||
destination.ty(local_decls, tcx).ty.kind()
|
||||
else { bug!(); };
|
||||
|
||||
block.statements.push(Statement {
|
||||
source_info: terminator.source_info,
|
||||
kind: StatementKind::Assign(Box::new((
|
||||
*destination,
|
||||
Rvalue::AddressOf(
|
||||
Mutability::Not,
|
||||
arg.project_deeper(
|
||||
&[
|
||||
PlaceElem::Deref,
|
||||
PlaceElem::Downcast(
|
||||
Some(sym::Some),
|
||||
VariantIdx::from_u32(1),
|
||||
),
|
||||
PlaceElem::Field(Field::from_u32(0), *dest_ty),
|
||||
],
|
||||
tcx,
|
||||
),
|
||||
),
|
||||
))),
|
||||
});
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
}
|
||||
_ if intrinsic_name.as_str().starts_with("simd_shuffle") => {
|
||||
validate_simd_shuffle(tcx, args, terminator.source_info.span);
|
||||
}
|
||||
|
|
|
@ -1044,6 +1044,7 @@ symbols! {
|
|||
optin_builtin_traits,
|
||||
option,
|
||||
option_env,
|
||||
option_payload_ptr,
|
||||
options,
|
||||
or,
|
||||
or_patterns,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue