From 006bc80f12360ed5438c2a42712ebcf9d7e8850c Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Mon, 30 Sep 2024 22:15:40 +0200 Subject: [PATCH] fixing duplicate structs --- hblang/src/codegen.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hblang/src/codegen.rs b/hblang/src/codegen.rs index 4931320..4e0365d 100644 --- a/hblang/src/codegen.rs +++ b/hblang/src/codegen.rs @@ -735,6 +735,7 @@ impl Codegen { fn build_struct( &mut self, + file: FileId, explicit_alignment: Option, fields: &[CommentOr], ) -> ty::Struct { @@ -746,6 +747,7 @@ impl Codegen { self.tys.structs.push(Struct { field_start: self.tys.fields.len() as _, explicit_alignment, + file, ..Default::default() }); self.tys.fields.extend(self.tys.fields_tmp.drain(prev_tmp..)); @@ -757,11 +759,9 @@ impl Codegen { use {Expr as E, TokenKind as T}; let value = match *expr { E::Mod { id, .. } => Some(Value::ty(ty::Kind::Module(id).compress())), - E::Struct { fields, captured, packed, .. } => { + E::Struct { captured, .. } => { if captured.is_empty() { - Some(Value::ty( - ty::Kind::Struct(self.build_struct(packed.then_some(1), fields)).compress(), - )) + Some(Value::ty(self.ty(expr))) } else { let values = captured .iter() @@ -2380,7 +2380,8 @@ impl Codegen { } let stru = - ty::Kind::Struct(self.build_struct(packed.then_some(1), fields)).compress(); + ty::Kind::Struct(self.build_struct(self.ci.file, packed.then_some(1), fields)) + .compress(); self.ci.vars.truncate(prev_len); self.ct.vm.write_reg(1, stru.repr() as u64); debug_assert_ne!(stru.expand().inner(), 1); @@ -2473,8 +2474,8 @@ impl Codegen { Expr::BinOp { left: &Expr::Ident { .. }, op: TokenKind::Decl, - right: Expr::Struct { fields, packed, .. }, - } => ty::Kind::Struct(self.build_struct(packed.then_some(1), fields)), + right: stru @ Expr::Struct { .. }, + } => self.ty(stru).expand(), Expr::BinOp { left, op: TokenKind::Decl, right } => { let gid = self.tys.globals.len() as ty::Global; self.tys.globals.push(Global { file, name: ident, ..Default::default() });