authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-04-13 17:38:24+02:00
committergravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-04-13 17:38:24+02:00
log5c9906c231f65be759435fe0dc59acd8d9bc4d9c
tree2c834273a17a3d40538dac45ce17726e637a3bd9
parent31738de2817f7932fa9237492f20fb736bc07dd3

autodoc: make DeclStatus references long-lived


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

src/Autodoc.zig+10-4
...@@ -350,7 +350,7 @@ const Scope = struct {...@@ -350,7 +350,7 @@ const Scope = struct {
350 parent: ?*Scope,350 parent: ?*Scope,
351 map: std.AutoHashMapUnmanaged(351 map: std.AutoHashMapUnmanaged(
352 u32, // index into the current file's string table (decl name)352 u32, // index into the current file's string table (decl name)
353 DeclStatus,353 *DeclStatus,
354 ) = .{},354 ) = .{},
355355
356 enclosing_type: usize, // index into `types`356 enclosing_type: usize, // index into `types`
...@@ -359,15 +359,17 @@ const Scope = struct {...@@ -359,15 +359,17 @@ const Scope = struct {
359 Analyzed: usize, // index into `decls`359 Analyzed: usize, // index into `decls`
360 Pending,360 Pending,
361 NotRequested: u32, // instr_index361 NotRequested: u32, // instr_index
362
363 };362 };
364363
365 /// Returns a pointer so that the caller has a chance to modify the value364 /// Returns a pointer so that the caller has a chance to modify the value
366 /// in case they decide to start analyzing a previously not requested decl.365 /// in case they decide to start analyzing a previously not requested decl.
366 /// Another reason is that in some places we use the pointer to uniquely
367 /// refer to a decl, as we wait for it to be analyzed. This means that
368 /// those pointers must stay stable.
367 pub fn resolveDeclName(self: Scope, string_table_idx: u32, file: *File, inst_index: usize) *DeclStatus {369 pub fn resolveDeclName(self: Scope, string_table_idx: u32, file: *File, inst_index: usize) *DeclStatus {
368 var cur: ?*const Scope = &self;370 var cur: ?*const Scope = &self;
369 return while (cur) |s| : (cur = s.parent) {371 return while (cur) |s| : (cur = s.parent) {
370 break s.map.getPtr(string_table_idx) orelse continue;372 break s.map.get(string_table_idx) orelse continue;
371 } else {373 } else {
372 printWithContext(374 printWithContext(
373 file,375 file,
...@@ -385,7 +387,11 @@ const Scope = struct {...@@ -385,7 +387,11 @@ const Scope = struct {
385 decl_name_index: u32, // index into the current file's string table387 decl_name_index: u32, // index into the current file's string table
386 decl_status: DeclStatus,388 decl_status: DeclStatus,
387 ) !void {389 ) !void {
388 try self.map.put(arena, decl_name_index, decl_status);390 const decl_status_ptr = try arena.create(DeclStatus);
391 errdefer arena.destroy(decl_status_ptr);
392
393 decl_status_ptr.* = decl_status;
394 try self.map.put(arena, decl_name_index, decl_status_ptr);
389 }395 }
390};396};
391397