From 383b60b79146937e12c82abaaca2ce213d210b7f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 16 Nov 2026 22:43:18 -0300 Subject: syntax: the highlight queries are filtered by the build, not in every compile: colorQuery kept each grammar's patterns whose captures pardes colours by scanning the 29 highlights.scm byte by byte at comptime, a quarter of a full recompile of the core (and again in each of the ~15 artifacts that import it); build.zig's treeSitter now runs the same filter once over the query it reads (grammar_manifest.colorQuery, a plain function, with Syn and synFor's capture-to-class table beside it, the one copy both the build and syntax.zig read), so ts_queries' _highlights is the filtered query and Spec.query_src a field read; typst's supplement is the manifest's highlights_extra, appended before the filter as before; _highlights_unfiltered is the whole query, for the test that the filter keeps every colour; a package that depends on pardes gets the same through library's treeSitter, for its own grammar set; proven byte-identical before the comptime path went (29 grammars, 28,398 filtered bytes of 79,678); core-test's forced full recompile 12.7-12.9 s wall / 17.5 s CPU to 9.7-10.1 s / 14.6 s; syntax snapshots unchanged; the changelog says so --- build.zig | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'build.zig') diff --git a/build.zig b/build.zig index 0e67b61e..c7604c62 100644 --- a/build.zig +++ b/build.zig @@ -2101,8 +2101,12 @@ fn treeSitter(b: *std.Build, io: std.Io, target: std.Build.ResolvedTarget, c_opt (tree_sitter_grammars == .zig and g.tier == .zig)) grammar: { const dep = b.lazyDependency(g.dep, .{}) orelse break :grammar; - const query = configureRead(b, io, dep.builder.root, g.query, 0x100000) catch @panic("read " ++ g.name ++ " highlights"); - ts_queries.addOption([]const u8, g.name ++ "_highlights", query); + const upstream = configureRead(b, io, dep.builder.root, g.query, 0x100000) catch @panic("read " ++ g.name ++ " highlights"); + // the patterns that colour, filtered here once and not in + // every compile, and the whole query, the filter's test's + const query = std.mem.concat(b.allocator, u8, &.{ upstream, g.highlights_extra }) catch @panic("OOM"); + ts_queries.addOption([]const u8, g.name ++ "_highlights_unfiltered", query); + ts_queries.addOption([]const u8, g.name ++ "_highlights", grammar_manifest.colorQuery(query, b.allocator.alloc(u8, query.len) catch @panic("OOM"))); // helix's textobject queries, vendored (vendor/queries); a // grammar without one gets none const objects = configureRead(b, io, b.root, "vendor/queries/" ++ g.name ++ "/textobjects.scm", 0x100000) catch ""; -- cgit v1.3 From e6e81a6bc544c5ab5a47c21d85e6868020031abb Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 01:18:56 -0300 Subject: regexp: a class's range may end at \xff: mvzr counted `c1..c2 + 1` in a u8, which overflowed at 0xff (a panic in a safe build, a loop past its bounds in a fast one), so `[\x80-\xff]` in any search, an address, s or S, a plumbing rule, took the editor down; build.zig's patch of mvzr widens the count to usize, beside its other patches (one occurrence, checked); found writing the plumber's rules, whose classes for UTF-8 names the design record wrote as \x80-\xff; test: a class of a-z and the high bytes finds café, [\xff-\xff] compiles; the changelog says so MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- build.zig | 4 ++++ src/CHANGELOG.md | 4 ++++ src/regexp.zig | 8 ++++++++ 3 files changed, 16 insertions(+) (limited to 'build.zig') diff --git a/build.zig b/build.zig index d99f3985..acd402b6 100644 --- a/build.zig +++ b/build.zig @@ -400,7 +400,11 @@ pub fn build(b: *std.Build) void { if (std.mem.count(u8, backed, end_anchor) != 1) @panic("mvzr's parser changed: redo its `$` before `|` in build.zig"); var patched = std.mem.replaceOwned(u8, b.allocator, backed, end_anchor, end_before_alt) catch @panic("OOM"); // Zig 0.17 removed `**`; mvzr still has it (its PR #16 replaces it upstream). + // A class's range ending at `\xff` counted to 256 in a u8, an + // overflow (a panic in a safe build, a runaway loop in a fast one): + // `[\x80-\xff]` in any search took the editor down. for ([_][3][]const u8{ + .{ "for (c1..c2 + 1) |c_range|", "for (c1..@as(usize, c2) + 1) |c_range|", "1" }, .{ "[1]RegOp{.{ .unused = {} }} ** ops", "@splat(.{ .unused = {} })", "1" }, .{ "[1]CharSet{.{ .low = 0, .hi = 0 }} ** char_sets", "@splat(.{ .low = 0, .hi = 0 })", "1" }, .{ "\"a\" ** 2048", "&@as([2048]u8, @splat('a'))", "2" }, diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index d4d237f0..ed8993c9 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +- A search with a class whose range ends at `\xff` (`[\x80-\xff]`, in an + address, `s`, a plumbing rule) no longer takes the editor down: mvzr + counted the range past a byte's end. + - The plumber, Plan 9's, is in the session: `plumb/rules` holds its rules in plumb(6)'s language (rule sets of `object verb arg` lines, variables, `include`, `matches` over the whole text or around a click, diff --git a/src/regexp.zig b/src/regexp.zig index 7bcbceff..87fc51d6 100644 --- a/src/regexp.zig +++ b/src/regexp.zig @@ -595,6 +595,14 @@ test "a \\x without two hex digits is refused, not handed to mvzr to panic on" { try std.testing.expectEqual(@as(usize, 1), (try rx.find("xA", 0, 1, 2)).?.start); } +test "a class's range may end at \\xff: UTF-8's high bytes as one class" { + var rx = try Regex.compile("[a-z\\x80-\\xff]+"); + const text = "-- café --"; + const m = (try rx.find(text, 0, text.len, text.len)).?; + try std.testing.expectEqualStrings("café", text[m.start..m.end]); + _ = try Regex.compile("[\\xff-\\xff]"); +} + test "a repeat inside a group gives back to what follows the group" { const Case = struct { pat: []const u8, text: []const u8, start: usize, end: usize }; for ([_]Case{ -- cgit v1.3