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