authorgravatar for cody+topolarity@tapscott.meCody Tapscott <cody+topolarity@tapscott.me> 2022-01-24 12:47:03-07:00
committergravatar for cody+topolarity@tapscott.meCody Tapscott <cody+topolarity@tapscott.me> 2022-01-24 12:49:14-07:00
log60e6bf112cf00e96818209cafd36b98546cc4d8b
tree68f7d007711c77e29cd6bfd748afcfd1e48630de
parentcb24799368c3b944f18aae3c030a070038f3de9b

Cleanup unnecessary switches in union logic


1 files changed, 4 insertions(+), 10 deletions(-)

src/codegen/c.zig+4-10
......@@ -591,6 +591,7 @@ pub const DeclGen = struct {
591591 },
592592 .Union => {
593593 const union_obj = val.castTag(.@"union").?.data;
594 const union_ty = ty.cast(Type.Payload.Union).?.data;
594595 const target = dg.module.getTarget();
595596 const layout = ty.unionGetLayout(target);
596597
......@@ -607,11 +608,7 @@ pub const DeclGen = struct {
607608 try writer.writeAll(".payload = {");
608609 }
609610
610 const index = switch (ty.tag()) {
611 .union_tagged => ty.castTag(.union_tagged).?.data.tag_ty.enumTagFieldIndex(union_obj.tag).?,
612 .@"union" => ty.castTag(.@"union").?.data.tag_ty.enumTagFieldIndex(union_obj.tag).?,
613 else => unreachable,
614 };
611 const index = union_ty.tag_ty.enumTagFieldIndex(union_obj.tag).?;
615612 const field_ty = ty.unionFields().values()[index].ty;
616613 const field_name = ty.unionFields().keys()[index];
617614 if (field_ty.hasCodeGenBits()) {
......@@ -815,11 +812,8 @@ pub const DeclGen = struct {
815812 }
816813
817814 fn renderUnionTypedef(dg: *DeclGen, t: Type) error{ OutOfMemory, AnalysisFail }![]const u8 {
818 const fqn = switch (t.tag()) {
819 .@"union" => try t.castTag(.@"union").?.data.getFullyQualifiedName(dg.typedefs.allocator),
820 .union_tagged => try t.castTag(.union_tagged).?.data.getFullyQualifiedName(dg.typedefs.allocator),
821 else => unreachable,
822 };
815 const union_ty = t.cast(Type.Payload.Union).?.data;
816 const fqn = try union_ty.getFullyQualifiedName(dg.typedefs.allocator);
823817 defer dg.typedefs.allocator.free(fqn);
824818
825819 const target = dg.module.getTarget();