| ... | ... | @@ -719,10 +719,11 @@ fn zirStructDecl( |
| 719 | 719 | const struct_obj = try new_decl_arena.allocator.create(Module.Struct); |
| 720 | 720 | const struct_ty = try Type.Tag.@"struct".create(&new_decl_arena.allocator, struct_obj); |
| 721 | 721 | const struct_val = try Value.Tag.ty.create(&new_decl_arena.allocator, struct_ty); |
| 722 | | const new_decl = try sema.mod.createAnonymousDecl(&block.base, .{ |
| 722 | const type_name = try sema.createTypeName(block, small.name_strategy); |
| 723 | const new_decl = try sema.mod.createAnonymousDeclNamed(&block.base, .{ |
| 723 | 724 | .ty = Type.initTag(.type), |
| 724 | 725 | .val = struct_val, |
| 725 | | }); |
| 726 | }, type_name); |
| 726 | 727 | struct_obj.* = .{ |
| 727 | 728 | .owner_decl = new_decl, |
| 728 | 729 | .fields = .{}, |
| ... | ... | @@ -744,6 +745,32 @@ fn zirStructDecl( |
| 744 | 745 | return sema.analyzeDeclVal(block, src, new_decl); |
| 745 | 746 | } |
| 746 | 747 | |
| 748 | fn createTypeName(sema: *Sema, block: *Scope.Block, name_strategy: Zir.Inst.NameStrategy) ![:0]u8 { |
| 749 | switch (name_strategy) { |
| 750 | .anon => { |
| 751 | // It would be neat to have "struct:line:column" but this name has |
| 752 | // to survive incremental updates, where it may have been shifted down |
| 753 | // or up to a different line, but unchanged, and thus not unnecessarily |
| 754 | // semantically analyzed. |
| 755 | const name_index = sema.mod.getNextAnonNameIndex(); |
| 756 | return std.fmt.allocPrintZ(sema.gpa, "{s}__anon_{d}", .{ |
| 757 | sema.owner_decl.name, name_index, |
| 758 | }); |
| 759 | }, |
| 760 | .parent => return sema.gpa.dupeZ(u8, mem.spanZ(sema.owner_decl.name)), |
| 761 | .func => { |
| 762 | const name_index = sema.mod.getNextAnonNameIndex(); |
| 763 | const name = try std.fmt.allocPrintZ(sema.gpa, "{s}__anon_{d}", .{ |
| 764 | sema.owner_decl.name, name_index, |
| 765 | }); |
| 766 | log.warn("TODO: handle NameStrategy.func correctly instead of using anon name '{s}'", .{ |
| 767 | name, |
| 768 | }); |
| 769 | return name; |
| 770 | }, |
| 771 | } |
| 772 | } |
| 773 | |
| 747 | 774 | fn zirEnumDecl( |
| 748 | 775 | sema: *Sema, |
| 749 | 776 | block: *Scope.Block, |
| ... | ... | @@ -807,10 +834,11 @@ fn zirEnumDecl( |
| 807 | 834 | }; |
| 808 | 835 | const enum_ty = Type.initPayload(&enum_ty_payload.base); |
| 809 | 836 | const enum_val = try Value.Tag.ty.create(&new_decl_arena.allocator, enum_ty); |
| 810 | | const new_decl = try sema.mod.createAnonymousDecl(&block.base, .{ |
| 837 | const type_name = try sema.createTypeName(block, small.name_strategy); |
| 838 | const new_decl = try sema.mod.createAnonymousDeclNamed(&block.base, .{ |
| 811 | 839 | .ty = Type.initTag(.type), |
| 812 | 840 | .val = enum_val, |
| 813 | | }); |
| 841 | }, type_name); |
| 814 | 842 | enum_obj.* = .{ |
| 815 | 843 | .owner_decl = new_decl, |
| 816 | 844 | .tag_ty = tag_ty, |
| ... | ... | @@ -957,10 +985,11 @@ fn zirUnionDecl( |
| 957 | 985 | const union_obj = try new_decl_arena.allocator.create(Module.Union); |
| 958 | 986 | const union_ty = try Type.Tag.@"union".create(&new_decl_arena.allocator, union_obj); |
| 959 | 987 | const union_val = try Value.Tag.ty.create(&new_decl_arena.allocator, union_ty); |
| 960 | | const new_decl = try sema.mod.createAnonymousDecl(&block.base, .{ |
| 988 | const type_name = try sema.createTypeName(block, small.name_strategy); |
| 989 | const new_decl = try sema.mod.createAnonymousDeclNamed(&block.base, .{ |
| 961 | 990 | .ty = Type.initTag(.type), |
| 962 | 991 | .val = union_val, |
| 963 | | }); |
| 992 | }, type_name); |
| 964 | 993 | union_obj.* = .{ |
| 965 | 994 | .owner_decl = new_decl, |
| 966 | 995 | .tag_ty = Type.initTag(.@"null"), |
| ... | ... | @@ -1021,10 +1050,11 @@ fn zirErrorSetDecl( |
| 1021 | 1050 | const error_set = try new_decl_arena.allocator.create(Module.ErrorSet); |
| 1022 | 1051 | const error_set_ty = try Type.Tag.error_set.create(&new_decl_arena.allocator, error_set); |
| 1023 | 1052 | const error_set_val = try Value.Tag.ty.create(&new_decl_arena.allocator, error_set_ty); |
| 1024 | | const new_decl = try sema.mod.createAnonymousDecl(&block.base, .{ |
| 1053 | const type_name = try sema.createTypeName(block, name_strategy); |
| 1054 | const new_decl = try sema.mod.createAnonymousDeclNamed(&block.base, .{ |
| 1025 | 1055 | .ty = Type.initTag(.type), |
| 1026 | 1056 | .val = error_set_val, |
| 1027 | | }); |
| 1057 | }, type_name); |
| 1028 | 1058 | const names = try new_decl_arena.allocator.alloc([]const u8, fields.len); |
| 1029 | 1059 | for (fields) |str_index, i| { |
| 1030 | 1060 | names[i] = try new_decl_arena.allocator.dupe(u8, sema.code.nullTerminatedString(str_index)); |