From 9d6bef49a5fc2a5387734fa8d8cc698f0da8d5fa Mon Sep 17 00:00:00 2001 From: Jimmi Holst Christensen Date: Fri, 7 Jan 2022 18:58:40 +0100 Subject: Add two more resolution status' to Struct and Union resolveTypeForCodegen is called when we needed to resolve a type fully, even through pointer. This commit fully implements this, even through pointer fields on structs and unions. The function has now also been renamed to resolveTypeFully --- src/Module.zig | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index 0cbf75c735..8c14f080d2 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -831,6 +831,10 @@ pub const Struct = struct { have_field_types, layout_wip, have_layout, + fully_resolved_wip, + // The types and all its fields have had their layout resolved. Even through pointer, + // which `have_layout` does not ensure. + fully_resolved, }, /// If true, definitely nonzero size at runtime. If false, resolving the fields /// is necessary to determine whether it has bits at runtime. @@ -889,6 +893,22 @@ pub const Struct = struct { .have_field_types, .layout_wip, .have_layout, + .fully_resolved_wip, + .fully_resolved, + => true, + }; + } + + pub fn haveLayout(s: Struct) bool { + return switch (s.status) { + .none, + .field_types_wip, + .have_field_types, + .layout_wip, + => false, + .have_layout, + .fully_resolved_wip, + .fully_resolved, => true, }; } @@ -1003,6 +1023,10 @@ pub const Union = struct { have_field_types, layout_wip, have_layout, + fully_resolved_wip, + // The types and all its fields have had their layout resolved. Even through pointer, + // which `have_layout` does not ensure. + fully_resolved, }, pub const Field = struct { @@ -1033,6 +1057,8 @@ pub const Union = struct { .have_field_types, .layout_wip, .have_layout, + .fully_resolved_wip, + .fully_resolved, => true, }; } @@ -1102,8 +1128,22 @@ pub const Union = struct { tag_size: u64, }; + pub fn haveLayout(u: Union) bool { + return switch (u.status) { + .none, + .field_types_wip, + .have_field_types, + .layout_wip, + => false, + .have_layout, + .fully_resolved_wip, + .fully_resolved, + => true, + }; + } + pub fn getLayout(u: Union, target: Target, have_tag: bool) Layout { - assert(u.status == .have_layout); + assert(u.haveLayout()); var most_aligned_field: u32 = undefined; var most_aligned_field_size: u64 = undefined; var biggest_field: u32 = undefined; -- cgit v1.2.3 From f78d3b27ca1bea33c92e2f8eae84589db28c06cb Mon Sep 17 00:00:00 2001 From: Jimmi Holst Christensen Date: Fri, 7 Jan 2022 19:00:51 +0100 Subject: Increment `runtime_param_index` for zero sized parameters `runtime_param_index` is used to get the parameter type from `fn_type`, but this variable was not incremented for zero sized parameters, causing two zero sized parameters of different type to cause miss complication. --- src/Module.zig | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index 8c14f080d2..643e793206 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -4437,6 +4437,7 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn, arena: Allocator) Sem const arg = try sema.addConstant(param_type, opv); sema.inst_map.putAssumeCapacityNoClobber(inst, arg); total_param_index += 1; + runtime_param_index += 1; continue; } const ty_ref = try sema.addType(param_type); -- cgit v1.2.3