Skip to content

Commit 91e0cf4

Browse files
committed
generic first attempt, erroring intrinsic.rs
1 parent 158d454 commit 91e0cf4

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::borrow::Cow;
1+
use std::borrow::{Borrow, Cow};
22
use std::ops::Deref;
33
use std::{iter, ptr};
44

@@ -38,28 +38,37 @@ use crate::type_of::LayoutLlvmExt;
3838
use crate::value::Value;
3939

4040
// 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-
}
46-
47-
impl Drop for SBuilder<'_, '_> {
48-
fn drop(&mut self) {
49-
unsafe {
50-
llvm::LLVMDisposeBuilder(&mut *(self.llbuilder as *mut _));
51-
}
52-
}
53-
}
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+
//}
46+
47+
pub(crate) type SBuilder<'a, 'll> = GenericBuilder<'a, 'll, SimpleCx<'ll>>;
48+
49+
//impl Drop for SBuilder<'_, '_> {
50+
// fn drop(&mut self) {
51+
// unsafe {
52+
// llvm::LLVMDisposeBuilder(&mut *(self.llbuilder as *mut _));
53+
// }
54+
// }
55+
//}
5456

5557
// All Builders must have an llfn associated with them
5658
#[must_use]
57-
pub(crate) struct Builder<'a, 'll, 'tcx> {
59+
//pub(crate) struct Builder<'a, 'll, 'tcx> {
60+
// pub llbuilder: &'ll mut llvm::Builder<'ll>,
61+
// pub cx: &'a CodegenCx<'ll, 'tcx>,
62+
//}
63+
//
64+
pub(crate) struct GenericBuilder<'a, 'll, CX: Borrow<SimpleCx<'ll>>> {
5865
pub llbuilder: &'ll mut llvm::Builder<'ll>,
59-
pub cx: &'a CodegenCx<'ll, 'tcx>,
66+
pub cx: &'a CX,
6067
}
6168

62-
impl Drop for Builder<'_, '_, '_> {
69+
pub(crate) type Builder<'a, 'll, 'tcx> = GenericBuilder<'a, 'll, CodegenCx<'ll, 'tcx>>;
70+
71+
impl<'a, 'll, CX: Borrow<SimpleCx<'ll>>> Drop for GenericBuilder<'a, 'll, CX> {
6372
fn drop(&mut self) {
6473
unsafe {
6574
llvm::LLVMDisposeBuilder(&mut *(self.llbuilder as *mut _));
@@ -269,7 +278,8 @@ macro_rules! set_math_builder_methods {
269278
}
270279
}
271280

272-
impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
281+
//impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
282+
impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for GenericBuilder<'a, 'll, CodegenCx<'ll, 'tcx>> {
273283
type CodegenCx = CodegenCx<'ll, 'tcx>;
274284

275285
fn build(cx: &'a CodegenCx<'ll, 'tcx>, llbb: &'ll BasicBlock) -> Self {

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ impl<'ll, 'tcx> Deref for CodegenCx<'ll, 'tcx> {
5757
}
5858
}
5959

60+
impl<'ll> Borrow<SimpleCx<'ll>> for CodegenCx<'ll, '_> {
61+
fn borrow(&self) -> &SimpleCx<'ll> {
62+
&self.scx
63+
}
64+
}
65+
6066
/// There is one `CodegenCx` per codegen unit. Each one has its own LLVM
6167
/// `llvm::Context` so that several codegen units may be processed in parallel.
6268
/// All other LLVM data structures in the `CodegenCx` are tied to that `llvm::Context`.

0 commit comments

Comments
 (0)