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 {
350350 parent: ?*Scope,
351351 map: std.AutoHashMapUnmanaged(
352352 u32, // index into the current file's string table (decl name)
353 DeclStatus,
353 *DeclStatus,
354354 ) = .{},
355355
356356 enclosing_type: usize, // index into `types`
......@@ -359,15 +359,17 @@ const Scope = struct {
359359 Analyzed: usize, // index into `decls`
360360 Pending,
361361 NotRequested: u32, // instr_index
362
363362 };
364363
365364 /// Returns a pointer so that the caller has a chance to modify the value
366365 /// 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.
367369 pub fn resolveDeclName(self: Scope, string_table_idx: u32, file: *File, inst_index: usize) *DeclStatus {
368370 var cur: ?*const Scope = &self;
369371 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;
371373 } else {
372374 printWithContext(
373375 file,
......@@ -385,7 +387,11 @@ const Scope = struct {
385387 decl_name_index: u32, // index into the current file's string table
386388 decl_status: DeclStatus,
387389 ) !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);
389395 }
390396};
391397