| author | |
| committer | |
| log | 6d3858dc8a5e5d510a6c9cc972357dda551628b3 |
| tree | ba3a2c2147601a7fa39eb4b71897bd33a7b1a5d1 |
| parent | d819da4350cc4325a7281ebeaf6057586b8eb0d7 |
| signature | Commit is signed but in an unrecognized format. |
3 files changed, 33 insertions(+), 10 deletions(-)
src/Compilation.zig+17-1| ... | @@ -8,6 +8,7 @@ const log = std.log.scoped(.compilation); | ... | @@ -8,6 +8,7 @@ const log = std.log.scoped(.compilation); |
| 8 | const Target = std.Target; | 8 | const Target = std.Target; |
| 9 | 9 | ||
| 10 | const Value = @import("value.zig").Value; | 10 | const Value = @import("value.zig").Value; |
| 11 | const Type = @import("type.zig").Type; | ||
| 11 | const target_util = @import("target.zig"); | 12 | const target_util = @import("target.zig"); |
| 12 | const Package = @import("Package.zig"); | 13 | const Package = @import("Package.zig"); |
| 13 | const link = @import("link.zig"); | 14 | const link = @import("link.zig"); |
| ... | @@ -638,15 +639,19 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -638,15 +639,19 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 638 | 639 | ||
| 639 | const root_scope = rs: { | 640 | const root_scope = rs: { |
| 640 | if (mem.endsWith(u8, root_pkg.root_src_path, ".zig")) { | 641 | if (mem.endsWith(u8, root_pkg.root_src_path, ".zig")) { |
| 642 | const struct_payload = try gpa.create(Type.Payload.EmptyStruct); | ||
| 641 | const root_scope = try gpa.create(Module.Scope.File); | 643 | const root_scope = try gpa.create(Module.Scope.File); |
| 644 | struct_payload.* = .{ .scope = &root_scope.root_container }; | ||
| 642 | root_scope.* = .{ | 645 | root_scope.* = .{ |
| 643 | .sub_file_path = root_pkg.root_src_path, | 646 | // TODO this is duped so it can be freed in Container.deinit |
| 647 | .sub_file_path = try gpa.dupe(u8, root_pkg.root_src_path), | ||
| 644 | .source = .{ .unloaded = {} }, | 648 | .source = .{ .unloaded = {} }, |
| 645 | .contents = .{ .not_available = {} }, | 649 | .contents = .{ .not_available = {} }, |
| 646 | .status = .never_loaded, | 650 | .status = .never_loaded, |
| 647 | .root_container = .{ | 651 | .root_container = .{ |
| 648 | .file_scope = root_scope, | 652 | .file_scope = root_scope, |
| 649 | .decls = .{}, | 653 | .decls = .{}, |
| 654 | .ty = Type.initPayload(&struct_payload.base), | ||
| 650 | }, | 655 | }, |
| 651 | }; | 656 | }; |
| 652 | break :rs &root_scope.base; | 657 | break :rs &root_scope.base; |
| ... | @@ -1022,6 +1027,17 @@ pub fn update(self: *Compilation) !void { | ... | @@ -1022,6 +1027,17 @@ pub fn update(self: *Compilation) !void { |
| 1022 | else => |e| return e, | 1027 | else => |e| return e, |
| 1023 | }; | 1028 | }; |
| 1024 | } | 1029 | } |
| 1030 | |||
| 1031 | // TODO only analyze imports if they are still referenced | ||
| 1032 | for (module.import_table.items()) |entry| { | ||
| 1033 | entry.value.unload(module.gpa); | ||
| 1034 | module.analyzeContainer(&entry.value.root_container) catch |err| switch (err) { | ||
| 1035 | error.AnalysisFail => { | ||
| 1036 | assert(self.totalErrorCount() != 0); | ||
| 1037 | }, | ||
| 1038 | else => |e| return e, | ||
| 1039 | }; | ||
| 1040 | } | ||
| 1025 | } | 1041 | } |
| 1026 | } | 1042 | } |
| 1027 | 1043 |
src/Module.zig+11-9| ... | @@ -70,14 +70,14 @@ deletion_set: ArrayListUnmanaged(*Decl) = .{}, | ... | @@ -70,14 +70,14 @@ deletion_set: ArrayListUnmanaged(*Decl) = .{}, |
| 70 | /// Error tags and their values, tag names are duped with mod.gpa. | 70 | /// Error tags and their values, tag names are duped with mod.gpa. |
| 71 | global_error_set: std.StringHashMapUnmanaged(u16) = .{}, | 71 | global_error_set: std.StringHashMapUnmanaged(u16) = .{}, |
| 72 | 72 | ||
| 73 | /// Keys are fully qualified paths | ||
| 74 | import_table: std.StringArrayHashMapUnmanaged(*Scope.File) = .{}, | ||
| 75 | |||
| 73 | /// Incrementing integer used to compare against the corresponding Decl | 76 | /// Incrementing integer used to compare against the corresponding Decl |
| 74 | /// field to determine whether a Decl's status applies to an ongoing update, or a | 77 | /// field to determine whether a Decl's status applies to an ongoing update, or a |
| 75 | /// previous analysis. | 78 | /// previous analysis. |
| 76 | generation: u32 = 0, | 79 | generation: u32 = 0, |
| 77 | 80 | ||
| 78 | /// Keys are fully qualified paths | ||
| 79 | import_table: std.StringArrayHashMapUnmanaged(*Scope.File) = .{}, | ||
| 80 | |||
| 81 | stage1_flags: packed struct { | 81 | stage1_flags: packed struct { |
| 82 | have_winmain: bool = false, | 82 | have_winmain: bool = false, |
| 83 | have_wwinmain: bool = false, | 83 | have_wwinmain: bool = false, |
| ... | @@ -2392,10 +2392,7 @@ pub fn analyzeSlice(self: *Module, scope: *Scope, src: usize, array_ptr: *Inst, | ... | @@ -2392,10 +2392,7 @@ pub fn analyzeSlice(self: *Module, scope: *Scope, src: usize, array_ptr: *Inst, |
| 2392 | 2392 | ||
| 2393 | pub fn analyzeImport(self: *Module, scope: *Scope, src: usize, target_string: []const u8) !*Scope.File { | 2393 | pub fn analyzeImport(self: *Module, scope: *Scope, src: usize, target_string: []const u8) !*Scope.File { |
| 2394 | // TODO if (package_table.get(target_string)) |pkg| | 2394 | // TODO if (package_table.get(target_string)) |pkg| |
| 2395 | 2395 | if (self.import_table.get(target_string)) |some| { | |
| 2396 | const file_path = try std.fs.path.join(scope.arena(), &[_][]const u8{ self.root_pkg.root_src_dir_path, target_string }); | ||
| 2397 | |||
| 2398 | if (self.import_table.get(file_path)) |some| { | ||
| 2399 | return some; | 2396 | return some; |
| 2400 | } | 2397 | } |
| 2401 | 2398 | ||
| ... | @@ -2404,10 +2401,15 @@ pub fn analyzeImport(self: *Module, scope: *Scope, src: usize, target_string: [] | ... | @@ -2404,10 +2401,15 @@ pub fn analyzeImport(self: *Module, scope: *Scope, src: usize, target_string: [] |
| 2404 | 2401 | ||
| 2405 | // TODO Scope.Container arena for ty and sub_file_path | 2402 | // TODO Scope.Container arena for ty and sub_file_path |
| 2406 | const struct_payload = try self.gpa.create(Type.Payload.EmptyStruct); | 2403 | const struct_payload = try self.gpa.create(Type.Payload.EmptyStruct); |
| 2404 | errdefer self.gpa.destroy(struct_payload); | ||
| 2407 | const file_scope = try self.gpa.create(Scope.File); | 2405 | const file_scope = try self.gpa.create(Scope.File); |
| 2406 | errdefer self.gpa.destroy(file_scope); | ||
| 2407 | const file_path = try self.gpa.dupe(u8, target_string); | ||
| 2408 | errdefer self.gpa.free(file_path); | ||
| 2409 | |||
| 2408 | struct_payload.* = .{ .scope = &file_scope.root_container }; | 2410 | struct_payload.* = .{ .scope = &file_scope.root_container }; |
| 2409 | file_scope.* = .{ | 2411 | file_scope.* = .{ |
| 2410 | .sub_file_path = try self.gpa.dupe(u8, file_path), | 2412 | .sub_file_path = file_path, |
| 2411 | .source = .{ .unloaded = {} }, | 2413 | .source = .{ .unloaded = {} }, |
| 2412 | .contents = .{ .not_available = {} }, | 2414 | .contents = .{ .not_available = {} }, |
| 2413 | .status = .never_loaded, | 2415 | .status = .never_loaded, |
| ... | @@ -2419,7 +2421,7 @@ pub fn analyzeImport(self: *Module, scope: *Scope, src: usize, target_string: [] | ... | @@ -2419,7 +2421,7 @@ pub fn analyzeImport(self: *Module, scope: *Scope, src: usize, target_string: [] |
| 2419 | }; | 2421 | }; |
| 2420 | self.analyzeContainer(&file_scope.root_container) catch |err| switch (err) { | 2422 | self.analyzeContainer(&file_scope.root_container) catch |err| switch (err) { |
| 2421 | error.AnalysisFail => { | 2423 | error.AnalysisFail => { |
| 2422 | assert(self.totalErrorCount() != 0); | 2424 | assert(self.comp.totalErrorCount() != 0); |
| 2423 | }, | 2425 | }, |
| 2424 | else => |e| return e, | 2426 | else => |e| return e, |
| 2425 | }; | 2427 | }; |
src/main.zig+5| ... | @@ -1446,6 +1446,11 @@ fn buildOutputType( | ... | @@ -1446,6 +1446,11 @@ fn buildOutputType( |
| 1446 | cleanup_root_dir = dir; | 1446 | cleanup_root_dir = dir; |
| 1447 | root_pkg_memory.root_src_directory = .{ .path = p, .handle = dir }; | 1447 | root_pkg_memory.root_src_directory = .{ .path = p, .handle = dir }; |
| 1448 | root_pkg_memory.root_src_path = try fs.path.relative(arena, p, src_path); | 1448 | root_pkg_memory.root_src_path = try fs.path.relative(arena, p, src_path); |
| 1449 | } else if (fs.path.dirname(src_path)) |p| { | ||
| 1450 | const dir = try fs.cwd().openDir(p, .{}); | ||
| 1451 | cleanup_root_dir = dir; | ||
| 1452 | root_pkg_memory.root_src_directory = .{ .path = p, .handle = dir }; | ||
| 1453 | root_pkg_memory.root_src_path = fs.path.basename(src_path); | ||
| 1449 | } else { | 1454 | } else { |
| 1450 | root_pkg_memory.root_src_directory = .{ .path = null, .handle = fs.cwd() }; | 1455 | root_pkg_memory.root_src_directory = .{ .path = null, .handle = fs.cwd() }; |
| 1451 | root_pkg_memory.root_src_path = src_path; | 1456 | root_pkg_memory.root_src_path = src_path; |