Skip to content

Don't rewrite it in Rust. Rewrite the 5% that's slow: profile your app, port the hot functions with your coding agent, prove they behave the same. Python, JS/TS, Ruby, Java, Kotlin, Go, PHP, C/C++, C#, R.

feat(verify,report): add Arabic/RTL edge-case synthesis and SVG unicode-bidi isolation

Dr. Mohammed Lubbad1fb79c6fdc5f
diff --git a/skills/fast-anything/SKILL.md b/skills/fast-anything/SKILL.md
index 7162f52..8600770 100644
--- a/skills/fast-anything/SKILL.md
+++ b/skills/fast-anything/SKILL.md
@@ -16,7 +16,7 @@ The `fast-anything` CLI measures, records, builds, checks and swaps. You write t
2. **Port**: `fast-anything port <id>`. It re-runs the app, records up to 500 real calls, and creates
`.fast/ports/<id>/` with a stub `src/lib.rs` and a `TASK.md`. Read TASK.md fully.
3. **Write the Rust** in `src/lib.rs` (Ruby, Java, Go, PHP, C, C++, C#: `src/port.rs`; `src/lib.rs` there is generated glue):
- - Same semantics: Unicode code points (`.chars()`; JavaScript compares UTF-16 units), integer ranges, float operation order, error cases.
+ - Same semantics: Unicode code points (`.chars()`; JavaScript compares UTF-16 units; Arabic harakat `U+064B..U+065F`, Tatweel `U+0640`, Eastern digits `٠-٩`, and BiDi marks `U+200C..U+200F` are distinct scalar values), integer ranges, float operation order, error cases.
- Fast: borrow, no needless allocation, ASCII fast paths, `with_capacity`.
- Keep the function and module names. Run `cargo check` in the crate.
4. **Verify**: `fast-anything verify <id>` builds in release mode and replays every recorded call.
diff --git a/src/cfamily/rec.hpp b/src/cfamily/rec.hpp
index a809d95..c872486 100644
--- a/src/cfamily/rec.hpp
+++ b/src/cfamily/rec.hpp
@@ -99,9 +99,10 @@ inline std::vector<std::string> edges(const std::string &v) {
c++;
}
}
- // an accent, CJK, an emoji with a modifier, a combining mark (UTF-8 bytes)
- const std::string a = "\xC3\xA9", cjk = "\xE6\x97\xA5\xE6\x9C\xAC", emoji = "\xF0\x9F\x91\x8D\xF0\x9F\x8F\xBD", comb = "e\xCC\x81";
- return {v.substr(0, mid) + a + v.substr(mid), v + cjk, emoji + v, v + comb, ""};
+ // an accent, CJK, an emoji with a modifier, a combining mark, Arabic/RTL with harakat/Tatweel/digits (UTF-8 bytes)
+ const std::string a = "\xC3\xA9", cjk = "\xE6\x97\xA5\xE6\x9C\xAC", emoji = "\xF0\x9F\x91\x8D\xF0\x9F\x8F\xBD", comb = "e\xCC\x81",
+ ar = "\xD9\x85\xD9\x8F\xD8\xAD\xD9\x8E\xD9\x85\xD9\x8E\xD9\x91\xD8\xAF\xD9\x80\xD9\xA1\xD9\xA2\xD8\x9F\xE2\x80\x8F";
+ return {v.substr(0, mid) + a + v.substr(mid), v + cjk, emoji + v, v + comb, v + ar, ""};
}
template <class T, class Al> std::vector<std::vector<T, Al>> edges(const std::vector<T, Al> &v) {
std::vector<std::vector<T, Al>> out;
diff --git a/src/csharp/Rec.cs b/src/csharp/Rec.cs
index 8a65c56..545f45e 100644
--- a/src/csharp/Rec.cs
+++ b/src/csharp/Rec.cs
@@ -25,7 +25,7 @@ static class FastAnythingRec
static bool Mutates;
static Func<object?[], object?>? Fn;
static Type[] Types = Array.Empty<Type>();
- static readonly string[] Texts = { "", "ÀÉÎõü ñ", "日本語のテキスト", "emoji 👍🏽🎉", "é́", "İ ß Dž ΣΑΣ" };
+ static readonly string[] Texts = { "", "ÀÉÎõü ñ", "日本語のテキスト", "emoji 👍🏽🎉", "é́", "İ ß Dž ΣΑΣ", "مُحَمَّدـ١٢؟\u200F" };
static readonly int[] Slices = { 0, 1, 2, 3, 5, 8, 13, 21, 34, 55 };
static FastAnythingRec()
diff --git a/src/golang/rec.go b/src/golang/rec.go
index 358be5b..883679b 100644
--- a/src/golang/rec.go
+++ b/src/golang/rec.go
@@ -229,8 +229,8 @@ func fastAnythingRecVariants(v any) []any {
return out
}
-// Non-ASCII text that ports often get wrong: an accent, CJK, an emoji with a modifier, a combining mark.
-var fastAnythingRecNonASCII = []string{"é", "日本", "👍🏽", "é"}
+// Non-ASCII text that ports often get wrong: an accent, CJK, an emoji with a modifier, a combining mark, Arabic/RTL with harakat/Tatweel/Eastern digits.
+var fastAnythingRecNonASCII = []string{"é", "日本", "👍🏽", "é", "مُحَمَّدـ١٢؟\u200f"}
// Inputs where ports and originals tend to part ways, of the same type as the recorded value.
func fastAnythingRecEdges(v any) []any {
@@ -263,7 +263,7 @@ func fastAnythingRecEdges(v any) []any {
s := []rune(rv.String())
mid := len(s) / 2
na := fastAnythingRecNonASCII
- for _, x := range []string{string(s[:mid]) + na[0] + string(s[mid:]), string(s) + na[1], na[2] + string(s), string(s) + na[3], ""} {
+ for _, x := range []string{string(s[:mid]) + na[0] + string(s[mid:]), string(s) + na[1], na[2] + string(s), string(s) + na[3], string(s) + na[4], ""} {
put(func(n reflect.Value) { n.SetString(x) })
}
case reflect.Slice:
diff --git a/src/native.rs b/src/native.rs
index 459eb89..cc2597d 100644
--- a/src/native.rs
+++ b/src/native.rs
@@ -188,7 +188,7 @@ Only edit files in this folder. Don't touch the {label} project.\n\n\
## Real calls\n\n\
fast-anything recorded {recorded} real calls (out of {seen} while the app ran). Arguments arrive as JSON. A few:\n\n{fence}\n{samples}\n{fence}\n\n\
## Rules\n\n\
-- Same result for every input, edge cases included: empty input, zero, negatives, non-ASCII text, very long input. verify tests these too.\n\
+- Same result for every input, edge cases included: empty input, zero, negatives, non-ASCII and Arabic/RTL text (harakat U+064B..U+065F, Tatweel U+0640, Eastern digits ٠-٩, BiDi marks), very long input. verify tests these too.\n\
{rules}\
- Return `Err(message)` where the original would fail.\n\
- Make it fast: no needless allocation, borrow, `with_capacity`, fast paths for common cases. Threads are fine if the result is the same.\n\
diff --git a/src/node.rs b/src/node.rs
index 609cc32..e7ec42d 100644
--- a/src/node.rs
+++ b/src/node.rs
@@ -444,7 +444,7 @@ Only edit files in this folder. Don't touch the JavaScript project.\n\n\
{helpers}## Real calls\n\n\
fast-anything recorded {recorded} real calls (out of {seen} while the app ran). A few:\n\n{fence}\n{samples}\n{fence}\n\n\
## Rules\n\n\
-- Same result for every input, edge cases included: empty input, zero, negatives, NaN and infinity, non-ASCII text, very long input. verify tests these too.\n\
+- Same result for every input, edge cases included: empty input, zero, negatives, NaN and infinity, non-ASCII and Arabic/RTL text (harakat U+064B..U+065F, Tatweel U+0640, Eastern digits ٠-٩, BiDi marks), very long input. verify tests these too.\n\
- JavaScript strings are UTF-16: `.length`, indexing and `charCodeAt` count UTF-16 code units. \
Use `s.encode_utf16()` for anything index- or length-based (bytes are fine after checking `is_ascii()`).\n\
- JavaScript numbers are f64. Integer math is exact only up to 2^53; use `f64` unless the values are clearly small integers.\n\
diff --git a/src/node/runner.mjs b/src/node/runner.mjs
index 435472f..a7065b7 100644
--- a/src/node/runner.mjs
+++ b/src/node/runner.mjs
@@ -359,7 +359,7 @@ function variants(value, rand) {
);
}
-const NON_ASCII = ["\u{e9}", "\u{65e5}\u{672c}", "\u{1f44d}\u{1f3fd}", "e\u{301}"];
+const NON_ASCII = ["\u{e9}", "\u{65e5}\u{672c}", "\u{1f44d}\u{1f3fd}", "e\u{301}", "\u{645}\u{64f}\u{62d}\u{64e}\u{645}\u{64e}\u{651}\u{62f}\u{640}\u{661}\u{662}\u{61f}\u{200f}"];
const BIG = 4096; // the longest "huge" input, in items or characters
const EDGE_SAMPLE = 20;
const EDGE_LIMIT = 100;
@@ -374,7 +374,7 @@ function edges(v) {
if (typeof v === "string") {
const cs = [...v];
const mid = cs.length >> 1;
- return [cs.slice(0, mid).join("") + NON_ASCII[0] + cs.slice(mid).join(""), v + NON_ASCII[1], NON_ASCII[2] + v, v + NON_ASCII[3], ""];
+ return [cs.slice(0, mid).join("") + NON_ASCII[0] + cs.slice(mid).join(""), v + NON_ASCII[1], NON_ASCII[2] + v, v + NON_ASCII[3], v + NON_ASCII[4], ""];
}
if (Array.isArray(v) && v.length) return [[], ...edges(v[0]).slice(0, 4).map((e) => [e, ...v.slice(1)])];
if (ArrayBuffer.isView(v) && !(v instanceof DataView) && v.length) {
diff --git a/src/python.rs b/src/python.rs
index 775bf0d..c7ff691 100644
--- a/src/python.rs
+++ b/src/python.rs
@@ -687,8 +687,8 @@ Only edit files in this folder. Don't touch the Python project.\n\n\
{helpers}## Real calls\n\n\
fast-anything recorded {recorded} real calls (out of {seen} while the app ran). A few:\n\n{fence}\n{samples}\n{fence}\n\n\
## Rules\n\n\
-- Same result for every input, edge cases included: empty input, zero, negatives, NaN and infinity, non-ASCII text, very long input. verify tests these too.\n\
-- Python `str` indexes by Unicode code point: use `.chars()` (or bytes only after checking `is_ascii()`).\n\
+- Same result for every input, edge cases included: empty input, zero, negatives, NaN and infinity, non-ASCII and Arabic/RTL text (harakat U+064B..U+065F, Tatweel U+0640, Eastern digits ٠-٩, BiDi marks U+200C..U+200F), very long input. verify tests these too.\n\
+- Python `str` indexes by Unicode code point: use `.chars()` (or bytes only after checking `is_ascii()`). Note that Arabic harakat are distinct code points in `.chars()`.\n\
- Python ints don't overflow. `i64` is fine unless the recorded values are bigger.\n\
- Float results are compared with a relative tolerance of 1e-9. Keep the same order of operations.\n\
- Where Python raises, raise too (`PyValueError::new_err(...)`, `PyKeyError`, ...).\n\
diff --git a/src/python/runner.py b/src/python/runner.py
index daa4ac3..af1551a 100644
--- a/src/python/runner.py
+++ b/src/python/runner.py
@@ -749,7 +749,7 @@ def variants(value, rng):
return out
-NON_ASCII = ("\u00e9", "\u65e5\u672c", "\U0001f44d\U0001f3fd", "e\u0301")
+NON_ASCII = ("\u00e9", "\u65e5\u672c", "\U0001f44d\U0001f3fd", "e\u0301", "\u0645\u064f\u062d\u064e\u0645\u064e\u0651\u062f\u0640\u0661\u0662\u061f\u200f")
BIG = 4096 # the longest "huge" input, in items or characters
EDGE_SAMPLE, EDGE_LIMIT = 20, 100
GROW = (4, 16, 64, 256, 512) # how much bigger, step by step, than the short version of an input
@@ -766,7 +766,7 @@ def edges(value):
if isinstance(value, str):
mid = len(value) // 2
return [value[:mid] + NON_ASCII[0] + value[mid:], value + NON_ASCII[1], NON_ASCII[2] + value,
- value + NON_ASCII[3], ""]
+ value + NON_ASCII[3], value + NON_ASCII[4], ""]
if isinstance(value, bytes):
return [b"", value + b"\x00", b"\xff" + value]
if is_array(value):
diff --git a/src/r/runner.R b/src/r/runner.R
index cfafc5a..3a92be0 100644
--- a/src/r/runner.R
+++ b/src/r/runner.R
@@ -142,7 +142,7 @@ random <- function(n) { # 0..n-1, our own generator
floor(seed / 4294967296 * n)
}
-NON_ASCII <- c("\u00e9", "\u65e5\u672c", "\U0001f44d\U0001f3fd", "e\u0301")
+NON_ASCII <- c("\u00e9", "\u65e5\u672c", "\U0001f44d\U0001f3fd", "e\u0301", "\u0645\u064f\u062d\u064e\u0645\u064e\u0651\u062f\u0640\u0661\u0662\u061f\u200f")
# inputs where ports and originals tend to part ways, of the same type as the recorded value
edges <- function(v) {
@@ -153,7 +153,7 @@ edges <- function(v) {
integer = Filter(function(x) !identical(x, v), list(0L, 1L, -1L, NA_integer_)),
logical = list(NA),
character = list(paste0(substr(v, 1, nchar(v) %/% 2), NON_ASCII[1], substring(v, nchar(v) %/% 2 + 1)),
- paste0(v, NON_ASCII[2]), paste0(NON_ASCII[3], v), paste0(v, NON_ASCII[4]), "", NA_character_),
+ paste0(v, NON_ASCII[2]), paste0(NON_ASCII[3], v), paste0(v, NON_ASCII[4]), paste0(v, NON_ASCII[5]), "", NA_character_),
list()))
}
out <- list(v[0])
diff --git a/src/report.rs b/src/report.rs
index 4b5b30d..3b6a812 100644
--- a/src/report.rs
+++ b/src/report.rs
@@ -38,7 +38,7 @@ pub fn svg(project: &str, b: &BenchResult, ports: &[&Port]) -> String {
<rect width="760" height="220" rx="16" fill="#0d1117"/>
<rect x="0.5" y="0.5" width="759" height="219" rx="15.5" fill="none" stroke="#30363d"/>
<text x="32" y="44" font-family="{mono}" font-size="14" fill="#f74c00">⚡ fast-anything</text>
- <text x="32" y="78" font-family="{sans}" font-size="20" fill="#e6edf3">{project}</text>
+ <text x="32" y="78" font-family="{sans}" font-size="20" fill="#e6edf3" direction="auto" unicode-bidi="plaintext">{project}</text>
<text x="32" y="148" font-family="{sans}" font-size="64" font-weight="800" fill="#f74c00">{headline}<tspan dx="12" font-size="28" font-weight="600" fill="#e6edf3">faster</tspan></text>
<text x="420" y="92" font-family="{sans}" font-size="13" fill="#8b949e">{original}</text>
<text x="720" y="92" font-family="{mono}" font-size="13" fill="#e6edf3" text-anchor="end">{before}</text>
@@ -46,7 +46,7 @@ pub fn svg(project: &str, b: &BenchResult, ports: &[&Port]) -> String {
<text x="420" y="146" font-family="{sans}" font-size="13" fill="#8b949e">Rust</text>
<text x="720" y="146" font-family="{mono}" font-size="13" fill="#e6edf3" text-anchor="end">{after}</text>
<rect x="420" y="154" width="{after_w:.1}" height="16" rx="4" fill="#f74c00"/>
- <text x="32" y="196" font-family="{sans}" font-size="13" fill="#8b949e">{detail}</text>
+ <text x="32" y="196" font-family="{sans}" font-size="13" fill="#8b949e" direction="auto" unicode-bidi="plaintext">{detail}</text>
</svg>
"##,
project = xml(project),
@@ -106,5 +106,6 @@ mod tests {
assert!(card.contains("a&lt;b&gt;&amp;c"));
assert!(card.contains("8.0×"));
assert!(card.contains(r#"width="37.5""#));
+ assert!(card.contains(r#"unicode-bidi="plaintext""#));
}
}
diff --git a/src/ruby/runner.rb b/src/ruby/runner.rb
index cdc326b..83b84c5 100644
--- a/src/ruby/runner.rb
+++ b/src/ruby/runner.rb
@@ -230,7 +230,7 @@ def variants(value, rng)
end
end
-NON_ASCII = ["\u{e9}", "\u{65e5}\u{672c}", "\u{1f44d}\u{1f3fd}", "e\u{301}"].freeze
+NON_ASCII = ["\u{e9}", "\u{65e5}\u{672c}", "\u{1f44d}\u{1f3fd}", "e\u{301}", "\u{645}\u{64f}\u{62d}\u{64e}\u{645}\u{64e}\u{651}\u{62f}\u{640}\u{661}\u{662}\u{61f}\u{200f}"].freeze
BIG = 4096 # the longest "huge" input, in items or characters
EDGE_SAMPLE = 20
EDGE_LIMIT = 100
@@ -243,7 +243,7 @@ def edges(value)
when Float then [Float::NAN, Float::INFINITY, -Float::INFINITY, -0.0, 0.0, 1e308, 5e-324]
when String
mid = value.length / 2
- [value[0, mid] + NON_ASCII[0] + value[mid..], value + NON_ASCII[1], NON_ASCII[2] + value, value + NON_ASCII[3], ""]
+ [value[0, mid] + NON_ASCII[0] + value[mid..], value + NON_ASCII[1], NON_ASCII[2] + value, value + NON_ASCII[3], value + NON_ASCII[4], ""]
when Array
return [] if value.empty?