diff --git a/.gitignore b/.gitignore index 29751ba..5211f11 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ /.zig-cache/ -/zig-pkg/ diff --git a/build.zig b/build.zig index 8b5ad53..a069e72 100644 --- a/build.zig +++ b/build.zig @@ -34,7 +34,7 @@ pub fn build(b: *std.Build) void { ts_bin_query_gen.use_llvm = value; ts_bin_query_gen.use_lld = value; } - ts_bin_query_gen.root_module.link_libc = true; + ts_bin_query_gen.linkLibC(); ts_bin_query_gen.root_module.addImport("cbor", cbor_dep.module("cbor")); ts_bin_query_gen.root_module.addImport("treez", tree_sitter_host_dep.module("treez")); ts_bin_query_gen.root_module.addImport("build_options", options_mod); diff --git a/build.zig.zon b/build.zig.zon index 5de39dc..3166aa2 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -2,16 +2,16 @@ .name = .flow_syntax, .version = "0.7.2", .fingerprint = 0x3ba2584ea1cec85f, - .minimum_zig_version = "0.16.0-dev.3133+5ec8e45f3", + .minimum_zig_version = "0.15.2", .dependencies = .{ .tree_sitter = .{ - .url = "https://github.com/neurocyte/tree-sitter/releases/download/master-70dbb6fa9d998bcf599c3aaeecac7479e9ee3f0c/source.tar.gz", - .hash = "tree_sitter-0.26.7-z0LhyGSQZzENNbCzqsMPu63xwpZI1WTHcf62imt-H6YL", + .url = "https://github.com/neurocyte/tree-sitter/releases/download/master-9327512f8d36343bb3adfa6fb982b0b467ddce91/source.tar.gz", + .hash = "tree_sitter-0.26.7-z0LhyJOPZzF4S6ZW6MrFTfJgiM9Fp81hqKrXUKSBaUAc", }, .cbor = .{ - .url = "git+https://github.com/neurocyte/cbor?ref=master#66c28df31b8e4448dac7edf063417f2234d6f3c9", - .hash = "cbor-1.1.0-RcQE_DZMAQBg77bTLWHEMF7QSF2lWUudUbarD9xC5yVJ", + .url = "git+https://github.com/neurocyte/cbor?ref=master#7d2eeb68c8a2fb3f4d6baad6cc04c521b92974c0", + .hash = "cbor-1.0.0-RcQE_AswAQAPlqBCZXYQf9DZXn-0Ubt8Mk03ZcJWcsAG", }, }, .paths = .{ diff --git a/src/QueryCache.zig b/src/QueryCache.zig index 6cb03a3..024f50b 100644 --- a/src/QueryCache.zig +++ b/src/QueryCache.zig @@ -12,16 +12,15 @@ pub const tss = @import("ts_serializer.zig"); pub const FileType = @import("file_type.zig"); const Query = treez.Query; -io: std.Io, allocator: std.mem.Allocator, -mutex: ?std.Io.Mutex, +mutex: ?std.Thread.Mutex, highlights: std.StringHashMapUnmanaged(*CacheEntry) = .{}, injections: std.StringHashMapUnmanaged(*CacheEntry) = .{}, errors: std.StringHashMapUnmanaged(*CacheEntry) = .{}, ref_count: usize = 1, const CacheEntry = struct { - mutex: ?std.Io.Mutex, + mutex: ?std.Thread.Mutex, query: ?*Query, query_arena: ?*std.heap.ArenaAllocator, query_type: QueryType, @@ -61,13 +60,12 @@ const CacheError = error{ pub const Error = CacheError || QueryParseError || QuerySerializeError; -pub fn create(io: std.Io, allocator: std.mem.Allocator, opts: struct { lock: bool = false }) !*Self { +pub fn create(allocator: std.mem.Allocator, opts: struct { lock: bool = false }) !*Self { const self = try allocator.create(Self); errdefer allocator.destroy(self); self.* = .{ - .io = io, .allocator = allocator, - .mutex = if (opts.lock) .init else null, + .mutex = if (opts.lock) .{} else null, }; return self; } @@ -83,8 +81,8 @@ fn add_ref_locked(self: *Self) void { fn release_ref_unlocked_and_maybe_destroy(self: *Self) void { { - if (self.mutex) |*mtx| mtx.lockUncancelable(self.io); - defer if (self.mutex) |*mtx| mtx.unlock(self.io); + if (self.mutex) |*mtx| mtx.lock(); + defer if (self.mutex) |*mtx| mtx.unlock(); self.ref_count -= 1; if (self.ref_count > 0) return; } @@ -106,8 +104,8 @@ fn release_cache_entry_hash_map(allocator: std.mem.Allocator, hash_map: *std.Str } fn get_cache_entry(self: *Self, file_type: FileType, comptime query_type: QueryType) CacheError!*CacheEntry { - if (self.mutex) |*mtx| mtx.lockUncancelable(self.io); - defer if (self.mutex) |*mtx| mtx.unlock(self.io); + if (self.mutex) |*mtx| mtx.lock(); + defer if (self.mutex) |*mtx| mtx.unlock(); const hash = switch (query_type) { .highlights => &self.highlights, @@ -122,7 +120,7 @@ fn get_cache_entry(self: *Self, file_type: FileType, comptime query_type: QueryT q.* = .{ .query = null, .query_arena = null, - .mutex = if (self.mutex) |_| .init else null, + .mutex = if (self.mutex) |_| .{} else null, .lang_fn = file_type.lang_fn, .file_type_name = file_type.name, .query_type = query_type, @@ -134,8 +132,8 @@ fn get_cache_entry(self: *Self, file_type: FileType, comptime query_type: QueryT } fn get_cached_query(self: *Self, entry: *CacheEntry) Error!?*Query { - if (entry.mutex) |*mtx| mtx.lockUncancelable(self.io); - defer if (entry.mutex) |*mtx| mtx.unlock(self.io); + if (entry.mutex) |*mtx| mtx.lock(); + defer if (entry.mutex) |*mtx| mtx.unlock(); return if (entry.query) |query| query else blk: { const lang = entry.lang_fn() orelse std.debug.panic("tree-sitter parser function failed for language: {s}", .{entry.file_type_name}); @@ -175,7 +173,7 @@ pub fn get(self: *Self, file_type: FileType, comptime query_type: QueryType) Err const query = try self.get_cached_query(try self.get_cache_entry(file_type, query_type)); if (query != null) self.add_ref_locked(); return switch (@typeInfo(ReturnType(query_type))) { - .optional => query, + .optional => |_| query, else => query.?, }; } diff --git a/src/syntax.zig b/src/syntax.zig index 8ae49c5..e461603 100644 --- a/src/syntax.zig +++ b/src/syntax.zig @@ -27,7 +27,7 @@ query: *Query, errors_query: *Query, injections: ?*Query, tree: ?*treez.Tree = null, -injection_list: std.ArrayList(Injection) = .empty, +injection_list: std.ArrayListUnmanaged(Injection) = .{}, content: ?[]u8 = null, pub const Injection = struct { @@ -484,16 +484,15 @@ pub fn count_error_nodes(self: *const Self) usize { } test "simple build and link test" { - const io = std.testing.io; const gpa = std.testing.allocator; const zig_file_type = @import("file_type.zig").get_by_name_static("zig") orelse return error.TestFailed; - const query_cache = try QueryCache.create(io, gpa, .{}); + const query_cache = try QueryCache.create(gpa, .{}); defer query_cache.deinit(); const syntax = try create(zig_file_type, gpa, query_cache); defer syntax.destroy(); - const content = try std.Io.Dir.readFileAlloc(.cwd(), io, "src/syntax.zig", gpa, .unlimited); + const content = try std.fs.cwd().readFileAlloc(gpa, "src/syntax.zig", std.math.maxInt(usize)); defer gpa.free(content); try syntax.refresh_full(content); diff --git a/src/ts_bin_query_gen.zig b/src/ts_bin_query_gen.zig index 0190b59..a265abe 100644 --- a/src/ts_bin_query_gen.zig +++ b/src/ts_bin_query_gen.zig @@ -6,25 +6,24 @@ pub const tss = @import("ts_serializer.zig"); const verbose = false; -pub fn main(init: std.process.Init) anyerror!void { - const io = init.io; +pub fn main() anyerror!void { const allocator = std.heap.c_allocator; + const args = try std.process.argsAlloc(allocator); var opt_output_file_path: ?[]const u8 = null; - var args = try init.minimal.args.iterateAllocator(allocator); - defer args.deinit(); - _ = args.next(); - while (args.next()) |arg| { + var i: usize = 1; + while (i < args.len) : (i += 1) { + const arg = args[i]; if (opt_output_file_path != null) fatal("duplicated {s} argument", .{arg}); - opt_output_file_path = arg; + opt_output_file_path = args[i]; } const output_file_path = opt_output_file_path orelse fatal("missing output file", .{}); - var output_file = std.Io.Dir.cwd().createFile(io, output_file_path, .{}) catch |err| { + var output_file = std.fs.cwd().createFile(output_file_path, .{}) catch |err| { fatal("unable to open '{s}': {s}", .{ output_file_path, @errorName(err) }); }; - defer output_file.close(io); + defer output_file.close(); var output = std.Io.Writer.Allocating.init(allocator); const writer = &output.writer; @@ -94,7 +93,7 @@ pub fn main(init: std.process.Init) anyerror!void { } } - try output_file.writeStreamingAll(io, output.written()); + try output_file.writeAll(output.written()); if (verbose) std.log.info("file_types total {d} bytes", .{output.written().len}); }