Skip to content

Commit 7c1c07d

Browse files
authored
Merge pull request #293 from Pivot-Studio/Chronostasys/issue292
refactor: better impl
2 parents 7669f2a + 27baa21 commit 7c1c07d

Some content is hidden

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

54 files changed

+1172
-579
lines changed

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.65.0
1+
1.69.0

src/ast/builder/llvmbuilder.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ use inkwell::{
3232
use llvm_sys::{core::LLVMStructSetBody, prelude::LLVMTypeRef};
3333
use rustc_hash::FxHashMap;
3434

35-
use crate::ast::{diag::PLDiag, pass::run_immix_pass, pltype::ClosureType};
35+
use crate::ast::{
36+
diag::PLDiag,
37+
pass::run_immix_pass,
38+
pltype::{ClosureType, TraitImplAble},
39+
};
3640

3741
use super::{
3842
super::{
@@ -445,7 +449,9 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
445449
if let Some(f) = self.module.get_function(fname) {
446450
return f;
447451
}
448-
let f = self.module.add_function(fname, ftp, None);
452+
let f = self
453+
.module
454+
.add_function(fname, ftp, Some(Linkage::LinkOnceAny));
449455
// the array is a struct, the first field is the visit function, the second field is the real array
450456
// array struct it self is the first parameter
451457
// the other three parameters are the visit function for different type
@@ -585,7 +591,7 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
585591
st: &STType,
586592
) -> FunctionValue<'ctx> {
587593
let ptrtp = p.get_type();
588-
let llvmname = st.get_st_full_name() + "@";
594+
let llvmname = st.get_full_name() + "@";
589595
if let Some(v) = self.module.get_function(&llvmname) {
590596
return v;
591597
}
@@ -879,17 +885,17 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
879885
PLType::Struct(x) | PLType::Trait(x) => {
880886
let sttp = self.struct_type(x, ctx);
881887
// 若已经生成过,直接查表返回
882-
if RefCell::borrow(&self.ditypes).contains_key(&x.get_st_full_name()) {
888+
if RefCell::borrow(&self.ditypes).contains_key(&x.get_full_name()) {
883889
return Some(
884890
*RefCell::borrow(&self.ditypes)
885-
.get(&x.get_st_full_name())
891+
.get(&x.get_full_name())
886892
.unwrap(),
887893
);
888894
}
889895
// 生成占位符,为循环引用做准备
890896
self.ditypes_placeholder
891897
.borrow_mut()
892-
.insert(x.get_st_full_name(), RefCell::new(vec![]));
898+
.insert(x.get_full_name(), RefCell::new(vec![]));
893899
let mut m = vec![];
894900
ctx.run_in_type_mod(x, |ctx, x| {
895901
m = x
@@ -922,7 +928,7 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
922928
let members = self
923929
.ditypes_placeholder
924930
.borrow_mut()
925-
.remove(&x.get_st_full_name())
931+
.remove(&x.get_full_name())
926932
.unwrap();
927933
// 替换循环引用生成的占位符
928934
for m in members.borrow().iter() {
@@ -935,7 +941,7 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
935941
);
936942
unsafe { self.dibuilder.replace_placeholder_derived_type(*m, realtp) };
937943
}
938-
self.ditypes.borrow_mut().insert(x.get_st_full_name(), st);
944+
self.ditypes.borrow_mut().insert(x.get_full_name(), st);
939945
Some(st)
940946
}
941947
PLType::Primitive(pt) => {
@@ -1141,7 +1147,7 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
11411147
}
11421148

11431149
fn struct_type(&self, pltp: &STType, ctx: &mut Ctx<'a>) -> StructType<'ctx> {
1144-
let st = self.module.get_struct_type(&pltp.get_st_full_name());
1150+
let st = self.module.get_struct_type(&pltp.get_full_name());
11451151
if let Some(st) = st {
11461152
return st;
11471153
}
@@ -1150,7 +1156,7 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
11501156
let fields = &self.get_fields(pltp, ctx);
11511157
return self.context.struct_type(fields, false);
11521158
}
1153-
let st = self.context.opaque_struct_type(&pltp.get_st_full_name());
1159+
let st = self.context.opaque_struct_type(&pltp.get_full_name());
11541160
st.set_body(&self.get_fields(pltp, ctx), false);
11551161
st
11561162
}
@@ -2006,9 +2012,9 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for LLVMBuilder<'a, 'ctx> {
20062012
let ptrtp = self.struct_type(v, ctx).ptr_type(AddressSpace::default());
20072013
let ty = ptrtp.get_element_type().into_struct_type();
20082014
let ftp = self.mark_fn_tp(ptrtp);
2009-
let f = self
2010-
.module
2011-
.add_function(&(v.get_st_full_name() + "@"), ftp, None);
2015+
let f =
2016+
self.module
2017+
.add_function(&(v.get_full_name() + "@"), ftp, Some(Linkage::LinkOnceAny));
20122018
let bb = self.context.append_basic_block(f, "entry");
20132019
self.builder.position_at_end(bb);
20142020
let fieldn = ty.count_fields();

0 commit comments

Comments
 (0)