Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pl_linker = { path = "./pl_linker", optional = true }
immix = { path = "./immix", optional = true, features = ["llvm_gc_plugin", "llvm_stackmap"] }
vm = { path = "./vm", optional = true, features = ["jit"] }
indexmap = "1.9"
linked-hash-map = "0.5.6"
lazy_static = "1.4"
paste = "1.0"
internal_macro = { path = "./internal_macro", default-features = false }
Expand Down
12 changes: 6 additions & 6 deletions src/ast/builder/llvmbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
let mut m = vec![];
ctx.run_in_type_mod(x, |ctx, x| {
m = x
.ordered_fields
.get_all_field()
.iter()
.map(|v| {
let offset = td.offset_of_element(&sttp, v.index).unwrap() * 8;
Expand Down Expand Up @@ -957,9 +957,8 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
ctx.run_in_type_mod(pltp, |ctx, pltp| {
st.set_body(
&pltp
.ordered_fields
.clone()
.into_iter()
.get_all_field()
.iter()
.map(|order_field| {
self.get_basic_type_op(
&order_field
Expand Down Expand Up @@ -1195,10 +1194,11 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for LLVMBuilder<'a, 'ctx> {
self.context.opaque_struct_type(name);
}

fn add_body_to_struct_type(&self, name: &str, order_fields: &[Field], ctx: &mut Ctx<'a>) {
fn add_body_to_struct_type(&self, name: &str, sttype: &STType, ctx: &mut Ctx<'a>) {
let st = self.module.get_struct_type(name).unwrap();
st.set_body(
&order_fields
&sttype
.get_all_field()
.iter()
.map(|order_field| {
self.get_basic_type_op(
Expand Down
4 changes: 2 additions & 2 deletions src/ast/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::{
ctx::Ctx,
diag::PLDiag,
node::{types::TypedIdentifierNode, TypeNodeEnum},
pltype::{FNValue, Field, PLType, PriType, STType},
pltype::{FNValue, PLType, PriType, STType},
range::{Pos, Range},
};

Expand Down Expand Up @@ -119,7 +119,7 @@ pub trait IRBuilder<'a, 'ctx> {
) -> ValueHandle;
fn build_unconditional_branch(&self, bb: BlockHandle);
fn position_at_end_block(&self, block: BlockHandle);
fn add_body_to_struct_type(&self, name: &str, order_fields: &[Field], ctx: &mut Ctx<'a>);
fn add_body_to_struct_type(&self, name: &str, sttype: &STType, ctx: &mut Ctx<'a>);
fn get_or_insert_fn_handle(&self, pltp: &FNValue, ctx: &mut Ctx<'a>) -> ValueHandle;
fn get_or_add_global(
&self,
Expand Down
2 changes: 1 addition & 1 deletion src/ast/builder/no_op_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for NoOpBuilder<'a, 'ctx> {
fn add_body_to_struct_type(
&self,
_name: &str,
_order_fields: &[crate::ast::pltype::Field],
_sttype: &STType,
_ctx: &mut crate::ast::ctx::Ctx<'a>,
) {
}
Expand Down
24 changes: 14 additions & 10 deletions src/ast/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ impl<'a, 'ctx> Ctx<'a> {
));
}
let trait_handle = builder.alloc("tmp_traitv", &trait_pltype.borrow(), self, None);
for (name, f) in &t.fields {
let mthd = st.find_method(self, name).unwrap();
for f in t.list_trait_fields().iter() {
let mthd = st.find_method(self, &f.name).unwrap();
let fnhandle = builder.get_or_insert_fn_handle(&mthd, self);
let targetftp = f.typenode.get_type(self, builder).unwrap();
let casted = builder.bitcast(self, fnhandle, &targetftp.borrow(), "fncast_tmp");
Expand Down Expand Up @@ -1012,9 +1012,12 @@ impl<'a, 'ctx> Ctx<'a> {
need_up_cast: false,
};
}
} else if !self
.eq(lg.trait_impl.as_ref().unwrap().clone(), r.clone())
.eq
} else if lg
.trait_impl
.as_ref()
.unwrap()
.iter()
.any(|lt| !self.eq(lt.clone(), r.clone()).eq)
{
return EqRes {
eq: false,
Expand All @@ -1031,6 +1034,12 @@ impl<'a, 'ctx> Ctx<'a> {
unreachable!()
}
if l != r {
if matches!(&*l.borrow(), PLType::Union(_)) {
return EqRes {
eq: true,
need_up_cast: true,
};
}
let trait_pltype = l;
let st_pltype = self.auto_deref_tp(r);
if let (PLType::Trait(t), PLType::Struct(st)) =
Expand All @@ -1040,11 +1049,6 @@ impl<'a, 'ctx> Ctx<'a> {
eq: st.implements_trait(t, &self.plmod),
need_up_cast: true,
};
} else if let PLType::Union(_) = &*trait_pltype.borrow() {
return EqRes {
eq: true,
need_up_cast: true,
};
}
return EqRes {
eq: false,
Expand Down
3 changes: 2 additions & 1 deletion src/ast/diag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ define_error!(
UNION_DOES_NOT_CONTAIN_TYPE = "union does not contain type",
INVALID_IS_EXPR = "invalid `is` expression",
INVALID_CAST = "invalid cast",
METHOD_NOT_FOUND = "method not found"
METHOD_NOT_FOUND = "method not found",
DERIVE_TRAIT_NOT_IMPL = "derive trait not impl"
);
macro_rules! define_warn {
($(
Expand Down
13 changes: 10 additions & 3 deletions src/ast/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ impl FmtBuilder {
self.token("trait");
self.space();
self.token(node.id.name.as_str());
node.derives.format(self);
self.space();
self.l_brace();
self.enter();
Expand Down Expand Up @@ -687,13 +688,19 @@ impl FmtBuilder {
pub fn parse_trait_bound_node(&mut self, node: &TraitBoundNode) {
node.generic.format(self);
if let Some(impl_trait) = &node.impl_trait {
self.token(":");
self.space();
impl_trait.format(self);
}
}
pub fn parse_multi_trait_node(&mut self, node: &MultiTraitNode) {
node.traits.format(self)
if !node.traits.is_empty() {
self.colon();
self.space();
node.traits[0..node.traits.len() - 1].iter().for_each(|d| {
d.format(self);
self.token("+");
});
node.traits.last().unwrap().format(self);
}
}
pub fn parse_union_def_node(&mut self, node: &UnionDefNode) {
self.prefix();
Expand Down
Loading