Skip to content

Commit a5842a8

Browse files
committed
Make Builder generic
1 parent 158d454 commit a5842a8

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

Diff for: compiler/rustc_codegen_llvm/src/builder.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,18 @@ use crate::type_::Type;
3737
use crate::type_of::LayoutLlvmExt;
3838
use crate::value::Value;
3939

40-
// All Builders must have an llfn associated with them
41-
#[must_use]
42-
pub(crate) struct SBuilder<'a, 'll> {
43-
pub llbuilder: &'ll mut llvm::Builder<'ll>,
44-
pub cx: &'a SimpleCx<'ll>,
45-
}
4640

47-
impl Drop for SBuilder<'_, '_> {
48-
fn drop(&mut self) {
49-
unsafe {
50-
llvm::LLVMDisposeBuilder(&mut *(self.llbuilder as *mut _));
51-
}
52-
}
53-
}
41+
pub(crate) type SBuilder<'a, 'll> = GenericBuilder<'a, 'll, SimpleCx<'ll>>;
5442

55-
// All Builders must have an llfn associated with them
5643
#[must_use]
57-
pub(crate) struct Builder<'a, 'll, 'tcx> {
44+
pub(crate) struct GenericBuilder<'a, 'll, CX> {
5845
pub llbuilder: &'ll mut llvm::Builder<'ll>,
59-
pub cx: &'a CodegenCx<'ll, 'tcx>,
46+
pub cx: &'a CX,
6047
}
6148

62-
impl Drop for Builder<'_, '_, '_> {
49+
pub(crate) type Builder<'a, 'll, 'tcx> = GenericBuilder<'a, 'll, CodegenCx<'ll, 'tcx>>;
50+
51+
impl<'a, 'll, CX> Drop for GenericBuilder<'a, 'll, CX> {
6352
fn drop(&mut self) {
6453
unsafe {
6554
llvm::LLVMDisposeBuilder(&mut *(self.llbuilder as *mut _));

Diff for: compiler/rustc_codegen_llvm/src/intrinsic.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1081,11 +1081,11 @@ fn codegen_emcc_try<'ll>(
10811081

10821082
// Helper function to give a Block to a closure to codegen a shim function.
10831083
// This is currently primarily used for the `try` intrinsic functions above.
1084-
fn gen_fn<'ll, 'tcx>(
1085-
cx: &CodegenCx<'ll, 'tcx>,
1084+
fn gen_fn<'a, 'll, 'tcx>(
1085+
cx: &'a CodegenCx<'ll, 'tcx>,
10861086
name: &str,
10871087
rust_fn_sig: ty::PolyFnSig<'tcx>,
1088-
codegen: &mut dyn FnMut(Builder<'_, 'll, 'tcx>),
1088+
codegen: &mut dyn FnMut(Builder<'a, 'll, 'tcx>),
10891089
) -> (&'ll Type, &'ll Value) {
10901090
let fn_abi = cx.fn_abi_of_fn_ptr(rust_fn_sig, ty::List::empty());
10911091
let llty = fn_abi.llvm_type(cx);
@@ -1104,9 +1104,9 @@ fn gen_fn<'ll, 'tcx>(
11041104
// catch exceptions.
11051105
//
11061106
// This function is only generated once and is then cached.
1107-
fn get_rust_try_fn<'ll, 'tcx>(
1108-
cx: &CodegenCx<'ll, 'tcx>,
1109-
codegen: &mut dyn FnMut(Builder<'_, 'll, 'tcx>),
1107+
fn get_rust_try_fn<'a, 'll, 'tcx>(
1108+
cx: &'a CodegenCx<'ll, 'tcx>,
1109+
codegen: &mut dyn FnMut(Builder<'a, 'll, 'tcx>),
11101110
) -> (&'ll Type, &'ll Value) {
11111111
if let Some(llfn) = cx.rust_try_fn.get() {
11121112
return llfn;

0 commit comments

Comments
 (0)