diff --git a/build.zig b/build.zig index 313e84b..f1fb7c5 100644 --- a/build.zig +++ b/build.zig @@ -446,9 +446,11 @@ pub fn build_exe( const keybind_test_run_cmd = blk: { const tests = b.addTest(.{ - .root_source_file = b.path("src/keybind/keybind.zig"), - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("src/keybind/keybind.zig"), + .target = target, + .optimize = optimize, + }), }); tests.root_module.addImport("cbor", cbor_mod); tests.root_module.addImport("command", command_mod); @@ -567,10 +569,12 @@ pub fn build_exe( const exe = b.addExecutable(.{ .name = exe_name, - .root_source_file = b.path("src/main.zig"), - .target = target, - .optimize = optimize, - .strip = strip, + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + .strip = strip, + }), .win32_manifest = b.path("src/win32/flow.manifest"), }); @@ -619,9 +623,11 @@ pub fn build_exe( const check_exe = b.addExecutable(.{ .name = exe_name, - .root_source_file = b.path("src/main.zig"), - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }), }); check_exe.root_module.addImport("build_options", options_mod); @@ -644,12 +650,14 @@ pub fn build_exe( check_step.dependOn(&check_exe.step); const tests = b.addTest(.{ - .root_source_file = b.path("test/tests.zig"), - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("test/tests.zig"), + .target = target, + .optimize = optimize, + .strip = strip, + }), .use_llvm = use_llvm, .use_lld = use_llvm, - .strip = strip, }); tests.pie = pie; diff --git a/build.zig.version b/build.zig.version index 930e300..0417964 100644 --- a/build.zig.version +++ b/build.zig.version @@ -1 +1 @@ -0.14.1 +0.15.0-dev.1184+c41ac8f19 diff --git a/build.zig.zon b/build.zig.zon index 0a34e23..281b074 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -7,12 +7,12 @@ .dependencies = .{ .syntax = .{ .path = "src/syntax" }, .flags = .{ - .url = "https://github.com/n0s4/flags/archive/372501d1576b5723829bcba98e41361132c7b618.tar.gz", - .hash = "flags-0.8.0-AAAAAJV0AACuGBBnpUnHqZzAhoGTp4ibFROBQQQZGRqx", + .url = "git+https://github.com/neurocyte/flags?ref=main#984b27948da3e4e40a253f76c85b51ec1a9ada11", + .hash = "flags-0.10.0-a_9h3gB4AADAYn0XaZuUqH1jKRmy6dqvAIbomtTIF6V1", }, .dizzy = .{ - .url = "https://github.com/neurocyte/dizzy/archive/455d18369cbb2a0458ba70be919cd378338d695e.tar.gz", - .hash = "dizzy-1.0.0-AAAAAM1wAAAiDbx_6RwcVEOBk8p2XOu8t9WPNc3K7kBK", + .url = "https://github.com/neurocyte/dizzy/archive/c9219d23daccd9aa226cfde754fea278cb516459.tar.gz", + .hash = "dizzy-1.0.0-q40X4YCRAAAGYO9QOZiYYSOwiiFlqZlecMuQcxPiBcXM", }, .thespian = .{ .url = "git+https://github.com/neurocyte/thespian#f2980d3a747abdf0d18a01596dd8b953dd3e6243", @@ -23,22 +23,26 @@ .hash = "N-V-__8AAJiAIgDMVIi8CRb_xko9_qVQ-UiQzd5FTBBr0aPa", }, .fuzzig = .{ - .url = "https://github.com/fjebaker/fuzzig/archive/44c04733c7c0fee3db83672aaaaf4ed03e943156.tar.gz", - .hash = "fuzzig-0.1.1-AAAAALNIAQBmbHr-MPalGuR393Vem2pTQXI7_LXeNJgX", + .url = "https://github.com/fjebaker/fuzzig/archive/4251fe4230d38e721514394a485db62ee1667ff3.tar.gz", + .hash = "fuzzig-0.1.1-Ji0xivxIAQBD0g8O_NV_0foqoPf3elsg9Sc3pNfdVH4D", }, .vaxis = .{ - .url = "git+https://github.com/neurocyte/libvaxis?ref=main#846ddb8bf483e8a7eb25628d6c34ba7e781155b6", - .hash = "vaxis-0.5.1-BWNV_AsQCQDvfb-li1CZEOBG_YsteinP9qI-PpV47-jf", + .url = "git+https://github.com/neurocyte/libvaxis?ref=zig-0.15.0#04f87f558102ce8424dbcb07c62bad9370dea6ea", + .hash = "vaxis-0.5.1-BWNV_McRCQCJb40sR8iP-OcFTZ1912DBcEyMeMAkLanL", }, .zeit = .{ - .url = "https://github.com/rockorager/zeit/archive/8fd203f85f597f16e0a525c1f1ca1e0bffded809.tar.gz", - .hash = "zeit-0.0.0-AAAAACVbAgAiIzg1rccZU1qOfO_dKQKme7-37xmEQcqc", + .url = "git+https://github.com/rockorager/zeit?ref=zig-0.15#06ec40445cc477fea5a8369f1ba3881e2a3c00eb", + .hash = "zeit-0.6.0-5I6bkyJ8AgAS1_0NDvfxmFsBDTOxkZXtLUHrmPjcmt-K", }, .win32 = .{ .url = "https://github.com/marlersoft/zigwin32/archive/e8739b32a33ce48a3286aba31918b26a9dfc6ef0.tar.gz", .hash = "zigwin32-25.0.28-preview-AAAAAEEl_AMhnKSs-lgEyjmUX5JVTpNQewd8A2Bbekwc", .lazy = true, }, + .zig_tracy = .{ + .url = "git+https://github.com/neurocyte/zig-tracy?ref=master#67070c146104d93fd3bed5091738f22e33e13bce", + .hash = "zig_tracy-0.0.3-5-cp3Ht3AAAfHqShKfTK7waFK3Wjd3l2NheiqxvRRAdo", + }, }, .paths = .{ "include", diff --git a/src/buffer/Buffer.zig b/src/buffer/Buffer.zig index c094845..f1d613e 100644 --- a/src/buffer/Buffer.zig +++ b/src/buffer/Buffer.zig @@ -1244,6 +1244,7 @@ pub const LoadFromFileError = error{ LockViolation, ProcessNotFound, Canceled, + PermissionDenied, }; pub fn load_from_file( @@ -1349,6 +1350,8 @@ pub const StoreToFileError = error{ SystemResources, Unexpected, WouldBlock, + PermissionDenied, + MessageTooBig, }; pub fn store_to_existing_file_const(self: *const Self, file_path: []const u8) StoreToFileError!void { diff --git a/src/list_languages.zig b/src/list_languages.zig index 6efbd10..376424c 100644 --- a/src/list_languages.zig +++ b/src/list_languages.zig @@ -10,7 +10,7 @@ const checkmark_width = if (builtin.os.tag != .windows) 2 else 3; const success_mark = if (builtin.os.tag != .windows) "✓ " else "[y]"; const fail_mark = if (builtin.os.tag != .windows) "✘ " else "[n]"; -pub fn list(allocator: std.mem.Allocator, writer: anytype, tty_config: std.io.tty.Config) !void { +pub fn list(allocator: std.mem.Allocator, writer: *std.io.Writer, tty_config: std.io.tty.Config) !void { var max_language_len: usize = 0; var max_langserver_len: usize = 0; var max_formatter_len: usize = 0; diff --git a/src/log.zig b/src/log.zig index 71d3521..4c4e038 100644 --- a/src/log.zig +++ b/src/log.zig @@ -10,9 +10,14 @@ receiver: Receiver, subscriber: ?tp.pid, heap: [32 + 1024]u8, fba: std.heap.FixedBufferAllocator, -msg_store: MsgStoreT, +msg_store: MsgStore, + +const MsgStore = std.DoublyLinkedList; +const MsgStoreEntry = struct { + data: []u8, + node: MsgStore.Node, +}; -const MsgStoreT = std.DoublyLinkedList([]u8); const Receiver = tp.Receiver(*Self); const StartArgs = struct { @@ -38,7 +43,7 @@ fn init(args: StartArgs) !*Self { .subscriber = null, .heap = undefined, .fba = std.heap.FixedBufferAllocator.init(&p.heap), - .msg_store = MsgStoreT{}, + .msg_store = MsgStore{}, }; return p; } @@ -55,17 +60,18 @@ fn log(msg: []const u8) void { fn store(self: *Self, m: tp.message) void { const allocator: std.mem.Allocator = self.fba.allocator(); const buf: []u8 = allocator.alloc(u8, m.len()) catch return; - var node: *MsgStoreT.Node = allocator.create(MsgStoreT.Node) catch return; - node.data = buf; + var msg: *MsgStoreEntry = allocator.create(MsgStoreEntry) catch return; + msg.data = buf; @memcpy(buf, m.buf); - self.msg_store.append(node); + self.msg_store.append(&msg.node); } fn store_send(self: *Self) void { var node = self.msg_store.first; if (self.subscriber) |sub| { while (node) |node_| { - sub.send_raw(tp.message{ .buf = node_.data }) catch return; + const msg: *MsgStoreEntry = @fieldParentPtr("node", node_); + sub.send_raw(tp.message{ .buf = msg.data }) catch return; node = node_.next; } } @@ -73,7 +79,7 @@ fn store_send(self: *Self) void { } fn store_reset(self: *Self) void { - self.msg_store = MsgStoreT{}; + self.msg_store = MsgStore{}; self.fba.reset(); } diff --git a/src/main.zig b/src/main.zig index 07e1cf5..086c40b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -121,32 +121,41 @@ pub fn main() anyerror!void { scratch: bool, new_file: bool, version: bool, + + positional: struct { + trailing: []const []const u8, + }, }; - var arg_iter = try std.process.argsWithAllocator(a); - defer arg_iter.deinit(); + const args_alloc = try std.process.argsAlloc(a); + defer std.process.argsFree(a, args_alloc); var diag: flags.Diagnostics = undefined; - var positional_args = std.ArrayList([]const u8).init(a); - defer positional_args.deinit(); - const args = flags.parse(&arg_iter, "flow", Flags, .{ + const args = flags.parse(args_alloc, "flow", Flags, .{ .diagnostics = &diag, - .trailing_list = &positional_args, }) catch |err| { if (err == error.PrintedHelp) exit(0); - diag.help.generated.render(std.io.getStdOut(), flags.ColorScheme.default) catch {}; + try diag.printUsage(&flags.ColorScheme.default); exit(1); return err; }; + var stdout_buf: [4096]u8 = undefined; + var stdout_file = std.fs.File.stdout().writer(&stdout_buf); + const stdout = &stdout_file.interface; + defer stdout.flush() catch {}; + var stderr_buf: [4096]u8 = undefined; + var stderr_file = std.fs.File.stderr().writer(&stderr_buf); + const stderr = &stderr_file.interface; + defer stderr.flush() catch {}; + if (args.version) - return std.io.getStdOut().writeAll(version_info); + return std.fs.File.stdout().writeAll(version_info); if (args.list_languages) { - const stdout = std.io.getStdOut(); - const tty_config = std.io.tty.detectConfig(stdout); - return list_languages.list(a, stdout.writer(), tty_config); + const tty_config = std.io.tty.detectConfig(std.fs.File.stdout()); + return list_languages.list(a, stdout, tty_config); } if (builtin.os.tag != .windows and @hasDecl(renderer, "install_crash_handler")) { @@ -157,11 +166,12 @@ pub fn main() anyerror!void { if (args.debug_wait) { std.debug.print("press return to start", .{}); var buf: [1]u8 = undefined; - _ = try std.io.getStdIn().read(&buf); + _ = try std.fs.File.stdin().read(&buf); } if (c.setlocale(c.LC_ALL, "") == null) { - try std.io.getStdErr().writer().print("Failed to set locale. Is your locale valid?\n", .{}); + try stderr.print("Failed to set locale. Is your locale valid?\n", .{}); + stderr.flush() catch {}; exit(1); } @@ -244,7 +254,7 @@ pub fn main() anyerror!void { defer links.deinit(); var prev: ?*file_link.Dest = null; var line_next: ?usize = null; - for (positional_args.items) |arg| { + for (args.positional.trailing.items) |arg| { if (arg.len == 0) continue; if (!args.literal and arg[0] == '+') { @@ -366,17 +376,17 @@ fn count_args() usize { return count; } -fn trace(m: thespian.message.c_buffer_type) callconv(.C) void { +fn trace(m: thespian.message.c_buffer_type) callconv(.c) void { thespian.message.from(m).to_json_cb(trace_json); } -fn trace_json(json: thespian.message.json_string_view) callconv(.C) void { +fn trace_json(json: thespian.message.json_string_view) callconv(.c) void { const callstack_depth = 10; ___tracy_emit_message(json.base, json.len, callstack_depth); } extern fn ___tracy_emit_message(txt: [*]const u8, size: usize, callstack: c_int) void; -fn trace_to_file(m: thespian.message.c_buffer_type) callconv(.C) void { +fn trace_to_file(m: thespian.message.c_buffer_type) callconv(.c) void { const State = struct { file: std.fs.File, last_time: i64, diff --git a/src/renderer/vaxis/renderer.zig b/src/renderer/vaxis/renderer.zig index 3141e34..e5f91e9 100644 --- a/src/renderer/vaxis/renderer.zig +++ b/src/renderer/vaxis/renderer.zig @@ -127,7 +127,7 @@ pub fn install_crash_handler() void { } const act = std.posix.Sigaction{ .handler = .{ .sigaction = handle_crash }, - .mask = std.posix.empty_sigset, + .mask = std.posix.sigemptyset(), .flags = (std.posix.SA.SIGINFO | std.posix.SA.RESTART), }; @@ -156,7 +156,10 @@ fn handle_crash(sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque self.tty.deinit(); } if (builtin.os.tag == .linux and jit_debugger_enabled) { - handleSegfaultPosixNoAbort(sig, info, ctx_ptr); + var buf: [4096]u8 = undefined; + var stderr = std.fs.File.stderr().writer(&buf); + defer stderr.interface.flush() catch {}; + handleSegfaultPosixNoAbort(&stderr.interface, sig, info, ctx_ptr); @import("thespian").sighdl_debugger(sig, @ptrCast(@constCast(info)), ctx_ptr); std.posix.abort(); } else { @@ -165,7 +168,7 @@ fn handle_crash(sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque unreachable; } -fn handleSegfaultPosixNoAbort(sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque) void { +fn handleSegfaultPosixNoAbort(stderr: *std.io.Writer, sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque) void { const debug = @import("std/debug.zig"); debug.resetSegfaultHandler(); const addr = switch (builtin.os.tag) { @@ -177,7 +180,7 @@ fn handleSegfaultPosixNoAbort(sig: i32, info: *const std.posix.siginfo_t, ctx_pt else => unreachable, }; const code = if (builtin.os.tag == .netbsd) info.info.code else info.code; - debug.dumpSegfaultInfoPosix(sig, code, addr, ctx_ptr); + debug.dumpSegfaultInfoPosix(stderr, sig, code, addr, ctx_ptr); } pub fn run(self: *Self) Error!void { diff --git a/src/renderer/vaxis/std/debug.zig b/src/renderer/vaxis/std/debug.zig index 6c2d373..d8289d6 100644 --- a/src/renderer/vaxis/std/debug.zig +++ b/src/renderer/vaxis/std/debug.zig @@ -78,13 +78,9 @@ pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type { @branchHint(.cold); call("invalid error code", @returnAddress()); } - pub fn castTruncatedData() noreturn { + pub fn integerOutOfBounds() noreturn { @branchHint(.cold); - call("integer cast truncated bits", @returnAddress()); - } - pub fn negativeToUnsigned() noreturn { - @branchHint(.cold); - call("attempt to cast negative value to unsigned integer", @returnAddress()); + call("integer does not fit in destination type", @returnAddress()); } pub fn integerOverflow() noreturn { @branchHint(.cold); @@ -126,9 +122,9 @@ pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type { @branchHint(.cold); call("for loop over objects with non-equal lengths", @returnAddress()); } - pub fn memcpyLenMismatch() noreturn { + pub fn copyLenMismatch() noreturn { @branchHint(.cold); - call("@memcpy arguments have non-equal lengths", @returnAddress()); + call("source and destination arguments have non-equal lengths", @returnAddress()); } pub fn memcpyAlias() noreturn { @branchHint(.cold); @@ -165,9 +161,11 @@ pub const sys_can_stack_trace = switch (builtin.cpu.arch) { // `@returnAddress()` in LLVM 10 gives // "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address". + // On Emscripten, Zig only supports `@returnAddress()` in debug builds + // because Emscripten's implementation is very slow. .wasm32, .wasm64, - => native_os == .emscripten, + => native_os == .emscripten and builtin.mode == .Debug, // `@returnAddress()` is unsupported in LLVM 13. .bpfel, @@ -386,16 +384,14 @@ pub inline fn getContext(context: *ThreadContext) bool { /// Tries to print the stack trace starting from the supplied base pointer to stderr, /// unbuffered, and ignores any error returned. /// TODO multithreaded awareness -pub fn dumpStackTraceFromBase(context: *ThreadContext) void { +pub fn dumpStackTraceFromBase(stderr: *io.Writer, context: *ThreadContext) void { nosuspend { if (builtin.target.cpu.arch.isWasm()) { if (native_os == .wasi) { - const stderr = io.getStdErr().writer(); stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return; } return; } - const stderr = io.getStdErr().writer(); if (builtin.strip_debug_info) { stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return; return; @@ -404,7 +400,7 @@ pub fn dumpStackTraceFromBase(context: *ThreadContext) void { stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return; return; }; - const tty_config = io.tty.detectConfig(io.getStdErr()); + const tty_config = io.tty.detectConfig(fs.File.stderr()); if (native_os == .windows) { // On x86_64 and aarch64, the stack will be unwound using RtlVirtualUnwind using the context // provided by the exception handler. On x86, RtlVirtualUnwind doesn't exist. Instead, a new backtrace @@ -586,15 +582,20 @@ pub fn defaultPanic( // For backends that cannot handle the language features depended on by the // default panic handler, we have a simpler panic handler: - if (builtin.zig_backend == .stage2_wasm or - builtin.zig_backend == .stage2_arm or - builtin.zig_backend == .stage2_aarch64 or - builtin.zig_backend == .stage2_x86 or - (builtin.zig_backend == .stage2_x86_64 and (builtin.target.ofmt != .elf and builtin.target.ofmt != .macho)) or - builtin.zig_backend == .stage2_sparc64 or - builtin.zig_backend == .stage2_spirv64) - { - @trap(); + switch (builtin.zig_backend) { + .stage2_aarch64, + .stage2_arm, + .stage2_powerpc, + .stage2_riscv64, + .stage2_spirv, + .stage2_wasm, + .stage2_x86, + => @trap(), + .stage2_x86_64 => switch (builtin.target.ofmt) { + .elf, .macho => {}, + else => @trap(), + }, + else => {}, } switch (builtin.os.tag) { @@ -615,9 +616,9 @@ pub fn defaultPanic( // isn't visible on actual hardware if directly booted into inline for ([_]?*uefi.protocol.SimpleTextOutput{ uefi.system_table.std_err, uefi.system_table.con_out }) |o| { if (o) |out| { - _ = out.setAttribute(uefi.protocol.SimpleTextOutput.red); - _ = out.outputString(exit_msg); - _ = out.setAttribute(uefi.protocol.SimpleTextOutput.white); + out.setAttribute(.{ .foreground = .red }) catch {}; + _ = out.outputString(exit_msg) catch {}; + out.setAttribute(.{ .foreground = .white }) catch {}; } } @@ -752,7 +753,7 @@ pub const StackIterator = struct { pub fn init(first_address: ?usize, fp: ?usize) StackIterator { if (native_arch.isSPARC()) { // Flush all the register windows on stack. - asm volatile (if (std.Target.sparc.featureSetHas(builtin.cpu.features, .v9)) + asm volatile (if (builtin.cpu.has(.sparc, .v9)) "flushw" else "ta 3" // ST_FLUSH_WINDOWS @@ -905,6 +906,8 @@ pub const StackIterator = struct { } } + if (builtin.omit_frame_pointer) return null; + const fp = if (comptime native_arch.isSPARC()) // On SPARC the offset is positive. (!) math.add(usize, it.fp, fp_offset) catch return null @@ -1371,12 +1374,11 @@ pub fn attachSegfaultHandler() void { windows_segfault_handle = windows.kernel32.AddVectoredExceptionHandler(0, handleSegfaultWindows); return; } - var act = posix.Sigaction{ + const act = posix.Sigaction{ .handler = .{ .sigaction = handleSegfaultPosix }, - .mask = posix.empty_sigset, + .mask = posix.sigemptyset(), .flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND), }; - updateSegfaultHandler(&act); } @@ -1388,9 +1390,9 @@ pub fn resetSegfaultHandler() void { } return; } - var act = posix.Sigaction{ + const act = posix.Sigaction{ .handler = .{ .handler = posix.SIG.DFL }, - .mask = posix.empty_sigset, + .mask = posix.sigemptyset(), .flags = 0, }; updateSegfaultHandler(&act); @@ -1421,14 +1423,22 @@ pub fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*an lockStdErr(); defer unlockStdErr(); - dumpSegfaultInfoPosix(sig, code, addr, ctx_ptr); + var buf: [4096]u8 = undefined; + var stderr = fs.File.stderr().writer(&buf); + defer stderr.interface.flush() catch {}; + + dumpSegfaultInfoPosix(&stderr.interface, sig, code, addr, ctx_ptr); } waitForOtherThreadToFinishPanicking(); }, else => { + var buf: [4096]u8 = undefined; + var stderr = fs.File.stderr().writer(&buf); + defer stderr.interface.flush() catch {}; + // panic mutex already locked - dumpSegfaultInfoPosix(sig, code, addr, ctx_ptr); + dumpSegfaultInfoPosix(&stderr.interface, sig, code, addr, ctx_ptr); }, }; @@ -1438,8 +1448,7 @@ pub fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*an posix.abort(); } -pub fn dumpSegfaultInfoPosix(sig: i32, code: i32, addr: usize, ctx_ptr: ?*anyopaque) void { - const stderr = io.getStdErr().writer(); +pub fn dumpSegfaultInfoPosix(stderr: *io.Writer, sig: i32, code: i32, addr: usize, ctx_ptr: ?*anyopaque) void { _ = switch (sig) { posix.SIG.SEGV => if (native_arch == .x86_64 and native_os == .linux and code == 128) // SI_KERNEL // x86_64 doesn't have a full 64-bit virtual address space. @@ -1487,7 +1496,7 @@ pub fn dumpSegfaultInfoPosix(sig: i32, code: i32, addr: usize, ctx_ptr: ?*anyopa }, @ptrCast(ctx)).__mcontext_data; } relocateContext(&new_ctx); - dumpStackTraceFromBase(&new_ctx); + dumpStackTraceFromBase(stderr, &new_ctx); }, else => {}, } @@ -1504,6 +1513,12 @@ fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) callconv(.winapi) c_ } fn handleSegfaultWindowsExtra(info: *windows.EXCEPTION_POINTERS, msg: u8, label: ?[]const u8) noreturn { + // For backends that cannot handle the language features used by this segfault handler, we have a simpler one, + switch (builtin.zig_backend) { + .stage2_x86_64 => if (builtin.target.ofmt == .coff) @trap(), + else => {}, + } + comptime assert(windows.CONTEXT != void); nosuspend switch (panic_stage) { 0 => { diff --git a/src/syntax/build.zig b/src/syntax/build.zig index 2b3a149..4251ae1 100644 --- a/src/syntax/build.zig +++ b/src/syntax/build.zig @@ -14,10 +14,7 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); - const tree_sitter_host_dep = b.dependency("tree_sitter", .{ - .target = b.graph.host, - .optimize = optimize, - }); + const tree_sitter_host_dep = b.dependency("tree_sitter", .{}); const cbor_dep = b.dependency("cbor", .{ .target = target, @@ -26,8 +23,11 @@ pub fn build(b: *std.Build) void { const ts_bin_query_gen = b.addExecutable(.{ .name = "ts_bin_query_gen", - .target = b.graph.host, - .root_source_file = b.path("src/ts_bin_query_gen.zig"), + .root_module = b.createModule(.{ + .root_source_file = b.path("src/ts_bin_query_gen.zig"), + .target = b.graph.host, + .optimize = .Debug, + }), }); ts_bin_query_gen.linkLibC(); ts_bin_query_gen.root_module.addImport("cbor", cbor_dep.module("cbor")); diff --git a/src/syntax/build.zig.zon b/src/syntax/build.zig.zon index 70ca5d8..5d8194d 100644 --- a/src/syntax/build.zig.zon +++ b/src/syntax/build.zig.zon @@ -2,16 +2,16 @@ .name = .flow_syntax, .version = "0.1.0", .fingerprint = 0x3ba2584ea1cec85f, - .minimum_zig_version = "0.14.1", + .minimum_zig_version = "0.15.0-dev.1048+f43f89a70", .dependencies = .{ .tree_sitter = .{ - .url = "https://github.com/neurocyte/tree-sitter/releases/download/master-1c3ad59bd98ee430b166054030dac4c46d641e39/source.tar.gz", - .hash = "N-V-__8AANMzUiemOR2eNnrtlMmAGHFqij6VYtDUiaFfn6Dw", + .url = "https://github.com/neurocyte/tree-sitter/releases/download/master-f1f032d24f621e2ee4deab1c424d3bf9fb809f6e/source.tar.gz", + .hash = "tree_sitter-0.22.4-150-g7e3f5726-z0LhyN88UicDHlr22vQnOZ3DW9NWN1gOhDwLuCRXvrh2", }, .cbor = .{ - .url = "https://github.com/neurocyte/cbor/archive/1fccb83c70cd84e1dff57cc53f7db8fb99909a94.tar.gz", - .hash = "cbor-1.0.0-RcQE_HvqAACcrLH7t3IDZOshgY2xqJA_UX330MvwSepb", + .url = "git+https://github.com/neurocyte/cbor#6eccce0b984296e7d05c20d83933cb31530e4fac", + .hash = "cbor-1.0.0-RcQE_N3yAADXjbyvhsmTQ6lf22l1nYgePq5FT8NaC4ic", }, }, .paths = .{ diff --git a/src/syntax/src/file_type.zig b/src/syntax/src/file_type.zig index 88a1494..9faa6fa 100644 --- a/src/syntax/src/file_type.zig +++ b/src/syntax/src/file_type.zig @@ -87,7 +87,7 @@ fn ft_func_name(comptime lang: []const u8) []const u8 { return &func_name; } -pub const LangFn = *const fn () callconv(.C) ?*const treez.Language; +pub const LangFn = *const fn () callconv(.c) ?*const treez.Language; pub const FirstLineMatch = struct { prefix: ?[]const u8 = null, diff --git a/src/syntax/src/syntax.zig b/src/syntax/src/syntax.zig index 5225155..b07f6d6 100644 --- a/src/syntax/src/syntax.zig +++ b/src/syntax/src/syntax.zig @@ -48,12 +48,12 @@ pub fn create(file_type: FileType, allocator: std.mem.Allocator, query_cache: *Q return self; } -pub fn static_create_file_type(allocator: std.mem.Allocator, lang_name: []const u8, query_cache: *QueryCache) !*Self { +pub fn create_file_type_static(allocator: std.mem.Allocator, lang_name: []const u8, query_cache: *QueryCache) !*Self { const file_type = FileType.get_by_name_static(lang_name) orelse return error.NotFound; return create(file_type, allocator, query_cache); } -pub fn static_create_guess_file_type_static(allocator: std.mem.Allocator, content: []const u8, file_path: ?[]const u8, query_cache: *QueryCache) !*Self { +pub fn create_guess_file_type_static(allocator: std.mem.Allocator, content: []const u8, file_path: ?[]const u8, query_cache: *QueryCache) !*Self { const file_type = FileType.guess_static(file_path, content) orelse return error.NotFound; return create(file_type, allocator, query_cache); } @@ -102,7 +102,7 @@ pub fn refresh_from_buffer(self: *Self, buffer: anytype, metrics: anytype) !void const input: Input = .{ .payload = &state, .read = struct { - fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.C) [*:0]const u8 { + fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.c) [*:0]const u8 { const ctx: *State = @ptrCast(@alignCast(payload orelse return "")); const result = ctx.buffer.get_from_pos(.{ .row = position.row, .col = position.column }, &ctx.result_buf, ctx.metrics); bytes_read.* = @intCast(result.len); @@ -128,7 +128,7 @@ pub fn refresh_from_string(self: *Self, content: [:0]const u8) !void { const input: Input = .{ .payload = &state, .read = struct { - fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.C) [*:0]const u8 { + fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.c) [*:0]const u8 { bytes_read.* = 0; const ctx: *State = @ptrCast(@alignCast(payload orelse return "")); const pos = (find_line_begin(ctx.content, position.row) orelse return "") + position.column; diff --git a/src/syntax/src/treez_dummy.zig b/src/syntax/src/treez_dummy.zig index b73b1f4..bee4c42 100644 --- a/src/syntax/src/treez_dummy.zig +++ b/src/syntax/src/treez_dummy.zig @@ -23,12 +23,12 @@ pub const InputEncoding = enum(c_uint) { }; pub const Input = extern struct { payload: ?*anyopaque, - read: ?*const fn (payload: ?*anyopaque, byte_index: u32, position: Point, bytes_read: *u32) callconv(.C) [*:0]const u8, + read: ?*const fn (payload: ?*anyopaque, byte_index: u32, position: Point, bytes_read: *u32) callconv(.c) [*:0]const u8, encoding: InputEncoding, }; pub const Language = struct { var dummy: @This() = .{}; - pub fn LangFn() callconv(.C) ?*const Language { + pub fn LangFn() callconv(.c) ?*const Language { return &dummy; } }; diff --git a/src/syntax/src/ts_bin_query_gen.zig b/src/syntax/src/ts_bin_query_gen.zig index e32c6ef..2584921 100644 --- a/src/syntax/src/ts_bin_query_gen.zig +++ b/src/syntax/src/ts_bin_query_gen.zig @@ -91,7 +91,7 @@ const FileType = struct { highlights: [:0]const u8, injections: ?[:0]const u8, }; -const LangFn = *const fn () callconv(.C) ?*const treez.Language; +const LangFn = *const fn () callconv(.c) ?*const treez.Language; fn load_file_types(comptime Namespace: type) []const FileType { comptime switch (@typeInfo(Namespace)) {