Skip to content

Commit

Permalink
Make Builder generic
Browse files Browse the repository at this point in the history
Co-authored-by: Oli Scherer <[email protected]>
  • Loading branch information
ZuseZ4 and oli-obk committed Jan 24, 2025
1 parent 158d454 commit ae2b41a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
23 changes: 6 additions & 17 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,18 @@ use crate::type_::Type;
use crate::type_of::LayoutLlvmExt;
use crate::value::Value;

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

impl Drop for SBuilder<'_, '_> {
fn drop(&mut self) {
unsafe {
llvm::LLVMDisposeBuilder(&mut *(self.llbuilder as *mut _));
}
}
}
pub(crate) type SBuilder<'a, 'll> = GenericBuilder<'a, 'll, SimpleCx<'ll>>;

// All Builders must have an llfn associated with them
#[must_use]
pub(crate) struct Builder<'a, 'll, 'tcx> {
pub(crate) struct GenericBuilder<'a, 'll, CX> {
pub llbuilder: &'ll mut llvm::Builder<'ll>,
pub cx: &'a CodegenCx<'ll, 'tcx>,
pub cx: &'a CX,
}

impl Drop for Builder<'_, '_, '_> {
pub(crate) type Builder<'a, 'll, 'tcx> = GenericBuilder<'a, 'll, CodegenCx<'ll, 'tcx>>;

impl<'a, 'll, CX> Drop for GenericBuilder<'a, 'll, CX> {
fn drop(&mut self) {
unsafe {
llvm::LLVMDisposeBuilder(&mut *(self.llbuilder as *mut _));
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,11 +1081,11 @@ fn codegen_emcc_try<'ll>(

// Helper function to give a Block to a closure to codegen a shim function.
// This is currently primarily used for the `try` intrinsic functions above.
fn gen_fn<'ll, 'tcx>(
cx: &CodegenCx<'ll, 'tcx>,
fn gen_fn<'a, 'll, 'tcx>(
cx: &'a CodegenCx<'ll, 'tcx>,
name: &str,
rust_fn_sig: ty::PolyFnSig<'tcx>,
codegen: &mut dyn FnMut(Builder<'_, 'll, 'tcx>),
codegen: &mut dyn FnMut(Builder<'a, 'll, 'tcx>),
) -> (&'ll Type, &'ll Value) {
let fn_abi = cx.fn_abi_of_fn_ptr(rust_fn_sig, ty::List::empty());
let llty = fn_abi.llvm_type(cx);
Expand All @@ -1104,9 +1104,9 @@ fn gen_fn<'ll, 'tcx>(
// catch exceptions.
//
// This function is only generated once and is then cached.
fn get_rust_try_fn<'ll, 'tcx>(
cx: &CodegenCx<'ll, 'tcx>,
codegen: &mut dyn FnMut(Builder<'_, 'll, 'tcx>),
fn get_rust_try_fn<'a, 'll, 'tcx>(
cx: &'a CodegenCx<'ll, 'tcx>,
codegen: &mut dyn FnMut(Builder<'a, 'll, 'tcx>),
) -> (&'ll Type, &'ll Value) {
if let Some(llfn) = cx.rust_try_fn.get() {
return llfn;
Expand Down

0 comments on commit ae2b41a

Please sign in to comment.