| ... | @@ -173,6 +173,8 @@ pub const Decl = struct { | ... | @@ -173,6 +173,8 @@ pub const Decl = struct { |
| 173 | value_arena: ?*std.heap.ArenaAllocator.State = null, | 173 | value_arena: ?*std.heap.ArenaAllocator.State = null, |
| 174 | /// The direct parent namespace of the Decl. | 174 | /// The direct parent namespace of the Decl. |
| 175 | /// Reference to externally owned memory. | 175 | /// Reference to externally owned memory. |
| | 176 | /// In the case of the Decl corresponding to a file, this is |
| | 177 | /// the namespace of the struct, since there is no parent. |
| 176 | namespace: *Scope.Namespace, | 178 | namespace: *Scope.Namespace, |
| 177 | | 179 | |
| 178 | /// An integer that can be checked against the corresponding incrementing | 180 | /// An integer that can be checked against the corresponding incrementing |
| ... | @@ -279,7 +281,7 @@ pub const Decl = struct { | ... | @@ -279,7 +281,7 @@ pub const Decl = struct { |
| 279 | | 281 | |
| 280 | pub fn destroy(decl: *Decl, module: *Module) void { | 282 | pub fn destroy(decl: *Decl, module: *Module) void { |
| 281 | const gpa = module.gpa; | 283 | const gpa = module.gpa; |
| 282 | log.debug("destroy Decl {s}", .{decl.name}); | 284 | log.debug("destroy Decl {*} ({s})", .{ decl, decl.name }); |
| 283 | decl.clearName(gpa); | 285 | decl.clearName(gpa); |
| 284 | if (decl.has_tv) { | 286 | if (decl.has_tv) { |
| 285 | if (decl.val.castTag(.function)) |payload| { | 287 | if (decl.val.castTag(.function)) |payload| { |
| ... | @@ -469,6 +471,7 @@ pub const EmitH = struct { | ... | @@ -469,6 +471,7 @@ pub const EmitH = struct { |
| 469 | | 471 | |
| 470 | /// Represents the data that an explicit error set syntax provides. | 472 | /// Represents the data that an explicit error set syntax provides. |
| 471 | pub const ErrorSet = struct { | 473 | pub const ErrorSet = struct { |
| | 474 | /// The Decl that corresponds to the error set itself. |
| 472 | owner_decl: *Decl, | 475 | owner_decl: *Decl, |
| 473 | /// Offset from Decl node index, points to the error set AST node. | 476 | /// Offset from Decl node index, points to the error set AST node. |
| 474 | node_offset: i32, | 477 | node_offset: i32, |
| ... | @@ -488,6 +491,7 @@ pub const ErrorSet = struct { | ... | @@ -488,6 +491,7 @@ pub const ErrorSet = struct { |
| 488 | | 491 | |
| 489 | /// Represents the data that a struct declaration provides. | 492 | /// Represents the data that a struct declaration provides. |
| 490 | pub const Struct = struct { | 493 | pub const Struct = struct { |
| | 494 | /// The Decl that corresponds to the struct itself. |
| 491 | owner_decl: *Decl, | 495 | owner_decl: *Decl, |
| 492 | /// Set of field names in declaration order. | 496 | /// Set of field names in declaration order. |
| 493 | fields: std.StringArrayHashMapUnmanaged(Field), | 497 | fields: std.StringArrayHashMapUnmanaged(Field), |
| ... | @@ -537,6 +541,7 @@ pub const Struct = struct { | ... | @@ -537,6 +541,7 @@ pub const Struct = struct { |
| 537 | /// is inferred to be the smallest power of two unsigned int that fits | 541 | /// is inferred to be the smallest power of two unsigned int that fits |
| 538 | /// the number of fields. | 542 | /// the number of fields. |
| 539 | pub const EnumSimple = struct { | 543 | pub const EnumSimple = struct { |
| | 544 | /// The Decl that corresponds to the enum itself. |
| 540 | owner_decl: *Decl, | 545 | owner_decl: *Decl, |
| 541 | /// Set of field names in declaration order. | 546 | /// Set of field names in declaration order. |
| 542 | fields: std.StringArrayHashMapUnmanaged(void), | 547 | fields: std.StringArrayHashMapUnmanaged(void), |
| ... | @@ -555,6 +560,7 @@ pub const EnumSimple = struct { | ... | @@ -555,6 +560,7 @@ pub const EnumSimple = struct { |
| 555 | /// Represents the data that an enum declaration provides, when there is | 560 | /// Represents the data that an enum declaration provides, when there is |
| 556 | /// at least one tag value explicitly specified, or at least one declaration. | 561 | /// at least one tag value explicitly specified, or at least one declaration. |
| 557 | pub const EnumFull = struct { | 562 | pub const EnumFull = struct { |
| | 563 | /// The Decl that corresponds to the enum itself. |
| 558 | owner_decl: *Decl, | 564 | owner_decl: *Decl, |
| 559 | /// An integer type which is used for the numerical value of the enum. | 565 | /// An integer type which is used for the numerical value of the enum. |
| 560 | /// Whether zig chooses this type or the user specifies it, it is stored here. | 566 | /// Whether zig chooses this type or the user specifies it, it is stored here. |
| ... | @@ -585,6 +591,7 @@ pub const EnumFull = struct { | ... | @@ -585,6 +591,7 @@ pub const EnumFull = struct { |
| 585 | /// Extern functions do not have this data structure; they are represented by | 591 | /// Extern functions do not have this data structure; they are represented by |
| 586 | /// the `Decl` only, with a `Value` tag of `extern_fn`. | 592 | /// the `Decl` only, with a `Value` tag of `extern_fn`. |
| 587 | pub const Fn = struct { | 593 | pub const Fn = struct { |
| | 594 | /// The Decl that corresponds to the function itself. |
| 588 | owner_decl: *Decl, | 595 | owner_decl: *Decl, |
| 589 | /// undefined unless analysis state is `success`. | 596 | /// undefined unless analysis state is `success`. |
| 590 | body: ir.Body, | 597 | body: ir.Body, |
| ... | @@ -736,6 +743,8 @@ pub const Scope = struct { | ... | @@ -736,6 +743,8 @@ pub const Scope = struct { |
| 736 | pub fn clearDecls(ns: *Namespace, mod: *Module) void { | 743 | pub fn clearDecls(ns: *Namespace, mod: *Module) void { |
| 737 | const gpa = mod.gpa; | 744 | const gpa = mod.gpa; |
| 738 | | 745 | |
| | 746 | log.debug("clearDecls {*}", .{ns}); |
| | 747 | |
| 739 | var decls = ns.decls; | 748 | var decls = ns.decls; |
| 740 | ns.decls = .{}; | 749 | ns.decls = .{}; |
| 741 | | 750 | |
| ... | @@ -2919,12 +2928,12 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) InnerError!vo | ... | @@ -2919,12 +2928,12 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) InnerError!vo |
| 2919 | const test_name = zir.nullTerminatedString(decl_name_index + 1); | 2928 | const test_name = zir.nullTerminatedString(decl_name_index + 1); |
| 2920 | break :name try std.fmt.allocPrintZ(gpa, "test.{s}", .{test_name}); | 2929 | break :name try std.fmt.allocPrintZ(gpa, "test.{s}", .{test_name}); |
| 2921 | }; | 2930 | }; |
| 2922 | log.debug("scan decl {s} is_pub={}", .{ decl_name, is_pub }); | | |
| 2923 | | 2931 | |
| 2924 | // We create a Decl for it regardless of analysis status. | 2932 | // We create a Decl for it regardless of analysis status. |
| 2925 | const gop = try namespace.decls.getOrPut(gpa, decl_name); | 2933 | const gop = try namespace.decls.getOrPut(gpa, decl_name); |
| 2926 | if (!gop.found_existing) { | 2934 | if (!gop.found_existing) { |
| 2927 | const new_decl = try mod.allocateNewDecl(namespace, decl_node); | 2935 | const new_decl = try mod.allocateNewDecl(namespace, decl_node); |
| | 2936 | log.debug("scan new decl {*} ({s}) into {*}", .{ new_decl, decl_name, namespace }); |
| 2928 | new_decl.src_line = line; | 2937 | new_decl.src_line = line; |
| 2929 | new_decl.name = decl_name; | 2938 | new_decl.name = decl_name; |
| 2930 | gop.entry.value = new_decl; | 2939 | gop.entry.value = new_decl; |
| ... | @@ -2947,6 +2956,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) InnerError!vo | ... | @@ -2947,6 +2956,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) InnerError!vo |
| 2947 | return; | 2956 | return; |
| 2948 | } | 2957 | } |
| 2949 | const decl = gop.entry.value; | 2958 | const decl = gop.entry.value; |
| | 2959 | log.debug("scan existing decl {*} ({s}) of {*}", .{ decl, decl_name, namespace }); |
| 2950 | // Update the AST node of the decl; even if its contents are unchanged, it may | 2960 | // Update the AST node of the decl; even if its contents are unchanged, it may |
| 2951 | // have been re-ordered. | 2961 | // have been re-ordered. |
| 2952 | const prev_src_node = decl.src_node; | 2962 | const prev_src_node = decl.src_node; |