authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-09-30 18:02:00+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-09-30 18:03:10+03:00
log6d3858dc8a5e5d510a6c9cc972357dda551628b3
treeba3a2c2147601a7fa39eb4b71897bd33a7b1a5d1
parentd819da4350cc4325a7281ebeaf6057586b8eb0d7
signature Commit is signed but in an unrecognized format.

stage2: use directory handles for imports


3 files changed, 33 insertions(+), 10 deletions(-)

src/Compilation.zig+17-1
......@@ -8,6 +8,7 @@ const log = std.log.scoped(.compilation);
88const Target = std.Target;
99
1010const Value = @import("value.zig").Value;
11const Type = @import("type.zig").Type;
1112const target_util = @import("target.zig");
1213const Package = @import("Package.zig");
1314const link = @import("link.zig");
......@@ -638,15 +639,19 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
638639
639640 const root_scope = rs: {
640641 if (mem.endsWith(u8, root_pkg.root_src_path, ".zig")) {
642 const struct_payload = try gpa.create(Type.Payload.EmptyStruct);
641643 const root_scope = try gpa.create(Module.Scope.File);
644 struct_payload.* = .{ .scope = &root_scope.root_container };
642645 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),
644648 .source = .{ .unloaded = {} },
645649 .contents = .{ .not_available = {} },
646650 .status = .never_loaded,
647651 .root_container = .{
648652 .file_scope = root_scope,
649653 .decls = .{},
654 .ty = Type.initPayload(&struct_payload.base),
650655 },
651656 };
652657 break :rs &root_scope.base;
......@@ -1022,6 +1027,17 @@ pub fn update(self: *Compilation) !void {
10221027 else => |e| return e,
10231028 };
10241029 }
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 }
10251041 }
10261042 }
10271043
src/Module.zig+11-9
......@@ -70,14 +70,14 @@ deletion_set: ArrayListUnmanaged(*Decl) = .{},
7070/// Error tags and their values, tag names are duped with mod.gpa.
7171global_error_set: std.StringHashMapUnmanaged(u16) = .{},
7272
73/// Keys are fully qualified paths
74import_table: std.StringArrayHashMapUnmanaged(*Scope.File) = .{},
75
7376/// Incrementing integer used to compare against the corresponding Decl
7477/// field to determine whether a Decl's status applies to an ongoing update, or a
7578/// previous analysis.
7679generation: u32 = 0,
7780
78/// Keys are fully qualified paths
79import_table: std.StringArrayHashMapUnmanaged(*Scope.File) = .{},
80
8181stage1_flags: packed struct {
8282 have_winmain: bool = false,
8383 have_wwinmain: bool = false,
......@@ -2392,10 +2392,7 @@ pub fn analyzeSlice(self: *Module, scope: *Scope, src: usize, array_ptr: *Inst,
23922392
23932393pub fn analyzeImport(self: *Module, scope: *Scope, src: usize, target_string: []const u8) !*Scope.File {
23942394 // TODO if (package_table.get(target_string)) |pkg|
2395
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| {
2395 if (self.import_table.get(target_string)) |some| {
23992396 return some;
24002397 }
24012398
......@@ -2404,10 +2401,15 @@ pub fn analyzeImport(self: *Module, scope: *Scope, src: usize, target_string: []
24042401
24052402 // TODO Scope.Container arena for ty and sub_file_path
24062403 const struct_payload = try self.gpa.create(Type.Payload.EmptyStruct);
2404 errdefer self.gpa.destroy(struct_payload);
24072405 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
24082410 struct_payload.* = .{ .scope = &file_scope.root_container };
24092411 file_scope.* = .{
2410 .sub_file_path = try self.gpa.dupe(u8, file_path),
2412 .sub_file_path = file_path,
24112413 .source = .{ .unloaded = {} },
24122414 .contents = .{ .not_available = {} },
24132415 .status = .never_loaded,
......@@ -2419,7 +2421,7 @@ pub fn analyzeImport(self: *Module, scope: *Scope, src: usize, target_string: []
24192421 };
24202422 self.analyzeContainer(&file_scope.root_container) catch |err| switch (err) {
24212423 error.AnalysisFail => {
2422 assert(self.totalErrorCount() != 0);
2424 assert(self.comp.totalErrorCount() != 0);
24232425 },
24242426 else => |e| return e,
24252427 };
src/main.zig+5
......@@ -1446,6 +1446,11 @@ fn buildOutputType(
14461446 cleanup_root_dir = dir;
14471447 root_pkg_memory.root_src_directory = .{ .path = p, .handle = dir };
14481448 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);
14491454 } else {
14501455 root_pkg_memory.root_src_directory = .{ .path = null, .handle = fs.cwd() };
14511456 root_pkg_memory.root_src_path = src_path;