Skip to content

Commit dbdbde2

Browse files
committed
Rename OperandBundleOwned to OperandBundleBox
As with `DIBuilderBox`, the "Box" suffix does a better job of communicating that this is an owning pointer to some borrowable resource. This also renames the `raw` method to `as_ref`, which is what it would have been named originally if the `Deref` problem had been known at the time.
1 parent 9a7e19f commit dbdbde2

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
361361

362362
// Emit KCFI operand bundle
363363
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn);
364-
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.raw()) {
364+
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.as_ref()) {
365365
bundles.push(kcfi_bundle);
366366
}
367367

@@ -1416,7 +1416,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14161416

14171417
// Emit KCFI operand bundle
14181418
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn);
1419-
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.raw()) {
1419+
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.as_ref()) {
14201420
bundles.push(kcfi_bundle);
14211421
}
14221422

@@ -1749,7 +1749,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
17491749

17501750
// Emit KCFI operand bundle
17511751
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn);
1752-
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.raw()) {
1752+
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.as_ref()) {
17531753
bundles.push(kcfi_bundle);
17541754
}
17551755

@@ -1836,7 +1836,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
18361836
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
18371837
instance: Option<Instance<'tcx>>,
18381838
llfn: &'ll Value,
1839-
) -> Option<llvm::OperandBundleOwned<'ll>> {
1839+
) -> Option<llvm::OperandBundleBox<'ll>> {
18401840
let is_indirect_call = unsafe { llvm::LLVMRustIsNonGVFunctionPointerTy(llfn) };
18411841
let kcfi_bundle = if self.tcx.sess.is_sanitizer_kcfi_enabled()
18421842
&& let Some(fn_abi) = fn_abi
@@ -1862,7 +1862,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
18621862
kcfi::typeid_for_fnabi(self.tcx, fn_abi, options)
18631863
};
18641864

1865-
Some(llvm::OperandBundleOwned::new("kcfi", &[self.const_u32(kcfi_typeid)]))
1865+
Some(llvm::OperandBundleBox::new("kcfi", &[self.const_u32(kcfi_typeid)]))
18661866
} else {
18671867
None
18681868
};

compiler/rustc_codegen_llvm/src/common.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,20 @@ use crate::value::Value;
6767
/// the `OperandBundleDef` value created for MSVC landing pads.
6868
pub(crate) struct Funclet<'ll> {
6969
cleanuppad: &'ll Value,
70-
operand: llvm::OperandBundleOwned<'ll>,
70+
operand: llvm::OperandBundleBox<'ll>,
7171
}
7272

7373
impl<'ll> Funclet<'ll> {
7474
pub(crate) fn new(cleanuppad: &'ll Value) -> Self {
75-
Funclet { cleanuppad, operand: llvm::OperandBundleOwned::new("funclet", &[cleanuppad]) }
75+
Funclet { cleanuppad, operand: llvm::OperandBundleBox::new("funclet", &[cleanuppad]) }
7676
}
7777

7878
pub(crate) fn cleanuppad(&self) -> &'ll Value {
7979
self.cleanuppad
8080
}
8181

8282
pub(crate) fn bundle(&self) -> &llvm::OperandBundle<'ll> {
83-
self.operand.raw()
83+
self.operand.as_ref()
8484
}
8585
}
8686

compiler/rustc_codegen_llvm/src/llvm/mod.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,13 @@ pub(crate) fn last_error() -> Option<String> {
363363
}
364364
}
365365

366-
/// Owns an [`OperandBundle`], and will dispose of it when dropped.
367-
pub(crate) struct OperandBundleOwned<'a> {
366+
/// Owning pointer to an [`OperandBundle`] that will dispose of the bundle
367+
/// when dropped.
368+
pub(crate) struct OperandBundleBox<'a> {
368369
raw: ptr::NonNull<OperandBundle<'a>>,
369370
}
370371

371-
impl<'a> OperandBundleOwned<'a> {
372+
impl<'a> OperandBundleBox<'a> {
372373
pub(crate) fn new(name: &str, vals: &[&'a Value]) -> Self {
373374
let raw = unsafe {
374375
LLVMCreateOperandBundle(
@@ -378,21 +379,21 @@ impl<'a> OperandBundleOwned<'a> {
378379
vals.len() as c_uint,
379380
)
380381
};
381-
OperandBundleOwned { raw: ptr::NonNull::new(raw).unwrap() }
382+
Self { raw: ptr::NonNull::new(raw).unwrap() }
382383
}
383384

384-
/// Returns inner `OperandBundle` type.
385+
/// Dereferences to the underlying `&OperandBundle`.
385386
///
386-
/// This could be a `Deref` implementation, but `OperandBundle` contains an extern type and
387-
/// `Deref::Target: ?Sized`.
388-
pub(crate) fn raw(&self) -> &OperandBundle<'a> {
387+
/// This can't be a `Deref` implementation because `OperandBundle` transitively
388+
/// contains an extern type, which is incompatible with `Deref::Target: ?Sized`.
389+
pub(crate) fn as_ref(&self) -> &OperandBundle<'a> {
389390
// SAFETY: The returned reference is opaque and can only used for FFI.
390391
// It is valid for as long as `&self` is.
391392
unsafe { self.raw.as_ref() }
392393
}
393394
}
394395

395-
impl Drop for OperandBundleOwned<'_> {
396+
impl Drop for OperandBundleBox<'_> {
396397
fn drop(&mut self) {
397398
unsafe {
398399
LLVMDisposeOperandBundle(self.raw);

0 commit comments

Comments
 (0)