Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2d3b1e0

Browse files
authoredMay 29, 2024
Rollup merge of #124251 - scottmcm:unop-ptr-metadata, r=oli-obk
Add an intrinsic for `ptr::metadata` The follow-up to #123840, so we can remove `PtrComponents` and `PtrRepr` from libcore entirely (well, after a bootstrap update). As discussed in <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/.60ptr_metadata.60.20in.20MIR/near/435637808>, this introduces `UnOp::PtrMetadata` taking a raw pointer and returning the associated metadata value. By no longer going through a `union`, this should also help future PRs better optimize pointer operations. r? ``@oli-obk``
2 parents da159eb + 57948c8 commit 2d3b1e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+600
-53
lines changed
 

‎compiler/rustc_mir_transform/src/validate.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,16 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
11091109
ty::Int(..) | ty::Uint(..) | ty::Bool
11101110
);
11111111
}
1112+
UnOp::PtrMetadata => {
1113+
if !matches!(self.mir_phase, MirPhase::Runtime(_)) {
1114+
// It would probably be fine to support this in earlier phases,
1115+
// but at the time of writing it's only ever introduced from intrinsic lowering,
1116+
// so earlier things can just `bug!` on it.
1117+
self.fail(location, "PtrMetadata should be in runtime MIR only");
1118+
}
1119+
1120+
check_kinds!(a, "Cannot PtrMetadata non-pointer type {:?}", ty::RawPtr(..));
1121+
}
11121122
}
11131123
}
11141124
Rvalue::ShallowInitBox(operand, _) => {

‎compiler/rustc_smir/src/rustc_internal/internal.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_span::Symbol;
1010
use stable_mir::abi::Layout;
1111
use stable_mir::mir::alloc::AllocId;
1212
use stable_mir::mir::mono::{Instance, MonoItem, StaticDef};
13-
use stable_mir::mir::{BinOp, Mutability, Place, ProjectionElem, Safety};
13+
use stable_mir::mir::{BinOp, Mutability, Place, ProjectionElem, Safety, UnOp};
1414
use stable_mir::ty::{
1515
Abi, AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind, Const,
1616
DynKind, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FloatTy, FnSig,
@@ -582,6 +582,18 @@ impl RustcInternal for BinOp {
582582
}
583583
}
584584

585+
impl RustcInternal for UnOp {
586+
type T<'tcx> = rustc_middle::mir::UnOp;
587+
588+
fn internal<'tcx>(&self, _tables: &mut Tables<'_>, _tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
589+
match self {
590+
UnOp::Not => rustc_middle::mir::UnOp::Not,
591+
UnOp::Neg => rustc_middle::mir::UnOp::Neg,
592+
UnOp::PtrMetadata => rustc_middle::mir::UnOp::PtrMetadata,
593+
}
594+
}
595+
}
596+
585597
impl<T> RustcInternal for &T
586598
where
587599
T: RustcInternal,
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.