| ... | @@ -40,6 +40,8 @@ pub const EventLoopLocal = struct { | ... | @@ -40,6 +40,8 @@ pub const EventLoopLocal = struct { |
| 40 | | 40 | |
| 41 | native_libc: event.Future(LibCInstallation), | 41 | native_libc: event.Future(LibCInstallation), |
| 42 | | 42 | |
| | 43 | cwd: []const u8, |
| | 44 | |
| 43 | var lazy_init_targets = std.lazyInit(void); | 45 | var lazy_init_targets = std.lazyInit(void); |
| 44 | | 46 | |
| 45 | fn init(loop: *event.Loop) !EventLoopLocal { | 47 | fn init(loop: *event.Loop) !EventLoopLocal { |
| ... | @@ -51,16 +53,22 @@ pub const EventLoopLocal = struct { | ... | @@ -51,16 +53,22 @@ pub const EventLoopLocal = struct { |
| 51 | var seed_bytes: [@sizeOf(u64)]u8 = undefined; | 53 | var seed_bytes: [@sizeOf(u64)]u8 = undefined; |
| 52 | try std.os.getRandomBytes(seed_bytes[0..]); | 54 | try std.os.getRandomBytes(seed_bytes[0..]); |
| 53 | const seed = std.mem.readInt(seed_bytes, u64, builtin.Endian.Big); | 55 | const seed = std.mem.readInt(seed_bytes, u64, builtin.Endian.Big); |
| | 56 | |
| | 57 | const cwd = try os.getCwd(loop.allocator); |
| | 58 | errdefer loop.allocator.free(cwd); |
| | 59 | |
| 54 | return EventLoopLocal{ | 60 | return EventLoopLocal{ |
| 55 | .loop = loop, | 61 | .loop = loop, |
| 56 | .llvm_handle_pool = std.atomic.Stack(llvm.ContextRef).init(), | 62 | .llvm_handle_pool = std.atomic.Stack(llvm.ContextRef).init(), |
| 57 | .prng = event.Locked(std.rand.DefaultPrng).init(loop, std.rand.DefaultPrng.init(seed)), | 63 | .prng = event.Locked(std.rand.DefaultPrng).init(loop, std.rand.DefaultPrng.init(seed)), |
| 58 | .native_libc = event.Future(LibCInstallation).init(loop), | 64 | .native_libc = event.Future(LibCInstallation).init(loop), |
| | 65 | .cwd = cwd, |
| 59 | }; | 66 | }; |
| 60 | } | 67 | } |
| 61 | | 68 | |
| 62 | /// Must be called only after EventLoop.run completes. | 69 | /// Must be called only after EventLoop.run completes. |
| 63 | fn deinit(self: *EventLoopLocal) void { | 70 | fn deinit(self: *EventLoopLocal) void { |
| | 71 | self.loop.allocator.free(self.cwd); |
| 64 | while (self.llvm_handle_pool.pop()) |node| { | 72 | while (self.llvm_handle_pool.pop()) |node| { |
| 65 | c.LLVMContextDispose(node.data); | 73 | c.LLVMContextDispose(node.data); |
| 66 | self.loop.allocator.destroy(node); | 74 | self.loop.allocator.destroy(node); |
| ... | @@ -867,13 +875,16 @@ pub const Compilation = struct { | ... | @@ -867,13 +875,16 @@ pub const Compilation = struct { |
| 867 | span: Span, | 875 | span: Span, |
| 868 | text: []u8, | 876 | text: []u8, |
| 869 | ) !void { | 877 | ) !void { |
| 870 | const msg = try self.loop.allocator.create(errmsg.Msg{ | 878 | const relpath = try os.path.relative(self.gpa(), self.event_loop_local.cwd, root.realpath); |
| 871 | .path = root.realpath, | 879 | errdefer self.gpa().free(relpath); |
| | 880 | |
| | 881 | const msg = try self.gpa().create(errmsg.Msg{ |
| | 882 | .path = if (relpath.len < root.realpath.len) relpath else root.realpath, |
| 872 | .text = text, | 883 | .text = text, |
| 873 | .span = span, | 884 | .span = span, |
| 874 | .tree = &root.tree, | 885 | .tree = &root.tree, |
| 875 | }); | 886 | }); |
| 876 | errdefer self.loop.allocator.destroy(msg); | 887 | errdefer self.gpa().destroy(msg); |
| 877 | | 888 | |
| 878 | const compile_errors = await (async self.compile_errors.acquire() catch unreachable); | 889 | const compile_errors = await (async self.compile_errors.acquire() catch unreachable); |
| 879 | defer compile_errors.release(); | 890 | defer compile_errors.release(); |