| ... | ... | @@ -576,7 +576,6 @@ pub const Decl = struct { |
| 576 | 576 | } |
| 577 | 577 | mod.destroyFunc(func); |
| 578 | 578 | } |
| 579 | | _ = mod.memoized_decls.remove(decl.val.ip_index); |
| 580 | 579 | } |
| 581 | 580 | |
| 582 | 581 | /// This name is relative to the containing namespace of the decl. |
| ... | ... | @@ -690,10 +689,30 @@ pub const Decl = struct { |
| 690 | 689 | } |
| 691 | 690 | |
| 692 | 691 | pub fn getFullyQualifiedName(decl: Decl, mod: *Module) !InternPool.NullTerminatedString { |
| 693 | | const gpa = mod.gpa; |
| 692 | if (decl.name_fully_qualified) return decl.name; |
| 693 | |
| 694 | 694 | const ip = &mod.intern_pool; |
| 695 | const count = count: { |
| 696 | var count: usize = ip.stringToSlice(decl.name).len + 1; |
| 697 | var ns: Namespace.Index = decl.src_namespace; |
| 698 | while (true) { |
| 699 | const namespace = mod.namespacePtr(ns); |
| 700 | const ns_decl_index = namespace.getDeclIndex(mod); |
| 701 | const ns_decl = mod.declPtr(ns_decl_index); |
| 702 | count += ip.stringToSlice(ns_decl.name).len + 1; |
| 703 | ns = namespace.parent.unwrap() orelse { |
| 704 | count += namespace.file_scope.sub_file_path.len; |
| 705 | break :count count; |
| 706 | }; |
| 707 | } |
| 708 | }; |
| 709 | |
| 710 | const gpa = mod.gpa; |
| 695 | 711 | const start = ip.string_bytes.items.len; |
| 696 | | try decl.renderFullyQualifiedName(mod, ip.string_bytes.writer(gpa)); |
| 712 | // Protects reads of interned strings from being reallocated during the call to |
| 713 | // renderFullyQualifiedName. |
| 714 | try ip.string_bytes.ensureUnusedCapacity(gpa, count); |
| 715 | decl.renderFullyQualifiedName(mod, ip.string_bytes.writer(gpa)) catch unreachable; |
| 697 | 716 | |
| 698 | 717 | // Sanitize the name for nvptx which is more restrictive. |
| 699 | 718 | // TODO This should be handled by the backend, not the frontend. Have a |
| ... | ... | @@ -4018,7 +4037,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void { |
| 4018 | 4037 | .unreferenced => false, |
| 4019 | 4038 | }; |
| 4020 | 4039 | |
| 4021 | | var decl_prog_node = mod.sema_prog_node.start(mod.intern_pool.stringToSlice(decl.name), 0); |
| 4040 | var decl_prog_node = mod.sema_prog_node.start("", 0); |
| 4022 | 4041 | decl_prog_node.activate(); |
| 4023 | 4042 | defer decl_prog_node.end(); |
| 4024 | 4043 | |
| ... | ... | @@ -5774,9 +5793,11 @@ pub fn createAnonymousDeclFromDecl( |
| 5774 | 5793 | const new_decl_index = try mod.allocateNewDecl(namespace, src_decl.src_node, src_scope); |
| 5775 | 5794 | errdefer mod.destroyDecl(new_decl_index); |
| 5776 | 5795 | const ip = &mod.intern_pool; |
| 5777 | | const name = try ip.getOrPutStringFmt(mod.gpa, "{s}__anon_{d}", .{ |
| 5796 | // This protects the getOrPutStringFmt from reallocating src decl name while reading it. |
| 5797 | try ip.string_bytes.ensureUnusedCapacity(mod.gpa, ip.stringToSlice(src_decl.name).len + 20); |
| 5798 | const name = ip.getOrPutStringFmt(mod.gpa, "{s}__anon_{d}", .{ |
| 5778 | 5799 | ip.stringToSlice(src_decl.name), @enumToInt(new_decl_index), |
| 5779 | | }); |
| 5800 | }) catch unreachable; |
| 5780 | 5801 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, tv, name); |
| 5781 | 5802 | return new_decl_index; |
| 5782 | 5803 | } |