| ... | ... | @@ -822,7 +822,7 @@ pub const Scope = struct { |
| 822 | 822 | pub fn namespace(scope: *Scope) *Namespace { |
| 823 | 823 | switch (scope.tag) { |
| 824 | 824 | .block => return scope.cast(Block).?.sema.owner_decl.namespace, |
| 825 | | .file => return scope.cast(File).?.namespace.?, |
| 825 | .file => return scope.cast(File).?.root_decl.?.namespace, |
| 826 | 826 | .namespace => return scope.cast(Namespace).?, |
| 827 | 827 | .decl_ref => return scope.cast(DeclRef).?.decl.namespace, |
| 828 | 828 | } |
| ... | ... | @@ -998,10 +998,8 @@ pub const Scope = struct { |
| 998 | 998 | zir: Zir, |
| 999 | 999 | /// Package that this file is a part of, managed externally. |
| 1000 | 1000 | pkg: *Package, |
| 1001 | | /// The namespace of the struct that represents this file. |
| 1002 | | /// Populated only when `have_decl` is true. |
| 1003 | | /// Owned by its owner Decl Value. |
| 1004 | | namespace: ?*Namespace, |
| 1001 | /// The Decl of the struct that represents this File. |
| 1002 | root_decl: ?*Decl, |
| 1005 | 1003 | |
| 1006 | 1004 | /// Used by change detection algorithm, after astgen, contains the |
| 1007 | 1005 | /// set of decls that existed in the previous ZIR but not in the new one. |
| ... | ... | @@ -1049,8 +1047,8 @@ pub const Scope = struct { |
| 1049 | 1047 | log.debug("deinit File {s}", .{file.sub_file_path}); |
| 1050 | 1048 | file.deleted_decls.deinit(gpa); |
| 1051 | 1049 | file.outdated_decls.deinit(gpa); |
| 1052 | | if (file.namespace) |ns| { |
| 1053 | | ns.getDecl().destroy(mod); |
| 1050 | if (file.root_decl) |root_decl| { |
| 1051 | root_decl.destroy(mod); |
| 1054 | 1052 | } |
| 1055 | 1053 | gpa.free(file.sub_file_path); |
| 1056 | 1054 | file.unload(gpa); |
| ... | ... | @@ -2576,11 +2574,11 @@ pub fn astGenFile(mod: *Module, file: *Scope.File, prog_node: *std.Progress.Node |
| 2576 | 2574 | gpa.destroy(file_prev_zir); |
| 2577 | 2575 | file.prev_zir = null; |
| 2578 | 2576 | try updateZirRefs(gpa, file, prev_zir); |
| 2579 | | } else if (file.namespace) |ns| { |
| 2577 | } else if (file.root_decl) |root_decl| { |
| 2580 | 2578 | // First time the File has succeeded ZIR. We must mark it outdated since |
| 2581 | 2579 | // we have already tried to semantically analyze it. |
| 2582 | 2580 | try file.outdated_decls.resize(gpa, 1); |
| 2583 | | file.outdated_decls.items[0] = ns.getDecl(); |
| 2581 | file.outdated_decls.items[0] = root_decl; |
| 2584 | 2582 | } |
| 2585 | 2583 | } else { |
| 2586 | 2584 | try updateZirRefs(gpa, file, prev_zir); |
| ... | ... | @@ -2626,7 +2624,7 @@ fn updateZirRefs(gpa: *Allocator, file: *Scope.File, old_zir: Zir) !void { |
| 2626 | 2624 | var decl_stack: std.ArrayListUnmanaged(*Decl) = .{}; |
| 2627 | 2625 | defer decl_stack.deinit(gpa); |
| 2628 | 2626 | |
| 2629 | | const root_decl = file.namespace.?.getDecl(); |
| 2627 | const root_decl = file.root_decl.?; |
| 2630 | 2628 | try decl_stack.append(gpa, root_decl); |
| 2631 | 2629 | |
| 2632 | 2630 | file.deleted_decls.clearRetainingCapacity(); |
| ... | ... | @@ -2848,7 +2846,7 @@ pub fn semaFile(mod: *Module, file: *Scope.File) InnerError!void { |
| 2848 | 2846 | const tracy = trace(@src()); |
| 2849 | 2847 | defer tracy.end(); |
| 2850 | 2848 | |
| 2851 | | if (file.namespace != null) return; |
| 2849 | if (file.root_decl != null) return; |
| 2852 | 2850 | |
| 2853 | 2851 | const gpa = mod.gpa; |
| 2854 | 2852 | var new_decl_arena = std.heap.ArenaAllocator.init(gpa); |
| ... | ... | @@ -2870,8 +2868,8 @@ pub fn semaFile(mod: *Module, file: *Scope.File) InnerError!void { |
| 2870 | 2868 | .file_scope = file, |
| 2871 | 2869 | }, |
| 2872 | 2870 | }; |
| 2873 | | file.namespace = &struct_obj.namespace; |
| 2874 | 2871 | const new_decl = try mod.allocateNewDecl(&struct_obj.namespace, 0); |
| 2872 | file.root_decl = new_decl; |
| 2875 | 2873 | struct_obj.owner_decl = new_decl; |
| 2876 | 2874 | new_decl.src_line = 0; |
| 2877 | 2875 | new_decl.name = try file.fullyQualifiedNameZ(gpa); |
| ... | ... | @@ -2917,9 +2915,12 @@ pub fn semaFile(mod: *Module, file: *Scope.File) InnerError!void { |
| 2917 | 2915 | }; |
| 2918 | 2916 | defer block_scope.instructions.deinit(gpa); |
| 2919 | 2917 | |
| 2920 | | try sema.analyzeStructDecl(new_decl, main_struct_inst, struct_obj); |
| 2921 | | |
| 2922 | | new_decl.analysis = .complete; |
| 2918 | if (sema.analyzeStructDecl(new_decl, main_struct_inst, struct_obj)) |_| { |
| 2919 | new_decl.analysis = .complete; |
| 2920 | } else |err| switch (err) { |
| 2921 | error.OutOfMemory => return error.OutOfMemory, |
| 2922 | error.AnalysisFail => {}, |
| 2923 | } |
| 2923 | 2924 | } else { |
| 2924 | 2925 | new_decl.analysis = .file_failure; |
| 2925 | 2926 | } |
| ... | ... | @@ -2964,6 +2965,9 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool { |
| 2964 | 2965 | log.debug("semaDecl root {*} ({s})", .{ decl, decl.name }); |
| 2965 | 2966 | const main_struct_inst = zir.getMainStruct(); |
| 2966 | 2967 | const struct_obj = decl.getStruct().?; |
| 2968 | // This might not have gotten set in `semaFile` if the first time had |
| 2969 | // a ZIR failure, so we set it here in case. |
| 2970 | struct_obj.zir_index = main_struct_inst; |
| 2967 | 2971 | try sema.analyzeStructDecl(decl, main_struct_inst, struct_obj); |
| 2968 | 2972 | decl.analysis = .complete; |
| 2969 | 2973 | decl.generation = mod.generation; |
| ... | ... | @@ -3165,7 +3169,7 @@ pub fn importPkg(mod: *Module, cur_pkg: *Package, pkg: *Package) !ImportFileResu |
| 3165 | 3169 | .zir = undefined, |
| 3166 | 3170 | .status = .never_loaded, |
| 3167 | 3171 | .pkg = pkg, |
| 3168 | | .namespace = null, |
| 3172 | .root_decl = null, |
| 3169 | 3173 | }; |
| 3170 | 3174 | return ImportFileResult{ |
| 3171 | 3175 | .file = new_file, |
| ... | ... | @@ -3231,7 +3235,7 @@ pub fn importFile( |
| 3231 | 3235 | .zir = undefined, |
| 3232 | 3236 | .status = .never_loaded, |
| 3233 | 3237 | .pkg = cur_file.pkg, |
| 3234 | | .namespace = null, |
| 3238 | .root_decl = null, |
| 3235 | 3239 | }; |
| 3236 | 3240 | return ImportFileResult{ |
| 3237 | 3241 | .file = new_file, |