Skip to content

Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.

website: name the languages shadow and profile refuse (#1277)

jakalijey8771c5324384
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 11ce9759..9d5f5046 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -103,6 +103,9 @@
included (`:save!` names `save!`, not `save`; `:+` and `:[]=` stay listed); before,
`:soundex_str` also matched `soundex` as a substring, so the export was listed twice (found
porting the `text` gem's `soundex.rb`, by @cfreyes7).
+- The website's Shadow page names Kotlin with Java and says what PHP, C#, PowerShell and Swift do
+ instead of a shadow module, and the Analyze page says which languages `profile` runs and the
+ profiler to use for the others. `tests/skill.rs` checks both pages (#1267 by @jakalijey).
- Every `app` subcommand, `spec`, `map` and the `obligations` commands say `no folder <path>` for a
folder that does not exist, with no operating system error after it, as `analyze` does. They
check through `walk::resolve_root`, so a folder that exists but cannot be read is no longer
diff --git a/tests/skill.rs b/tests/skill.rs
index b08c22f1..688fa3ac 100644
--- a/tests/skill.rs
+++ b/tests/skill.rs
@@ -334,6 +334,10 @@ fn the_languages_shadow_refuses_are_named_where_the_docs_tell_you_to_run_it() {
.lines()
.find(|l| l.starts_with("| 4. Shadow |"))
.expect("how-it-works.md has a Shadow row");
+ let page = std::fs::read_to_string(
+ PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("website/pages/en/docs/concepts/shadow.md"),
+ )
+ .unwrap();
for (language, name) in [
("php", "PHP"),
("csharp", "C#"),
@@ -361,6 +365,10 @@ fn the_languages_shadow_refuses_are_named_where_the_docs_tell_you_to_run_it() {
row.contains(name),
"the Shadow row does not name {name}: {row}"
);
+ assert!(
+ page.contains(name),
+ "website/pages/en/docs/concepts/shadow.md does not name {name}"
+ );
}
let _ = std::fs::remove_dir_all(&dir);
}
@@ -380,6 +388,19 @@ fn the_skill_names_every_language_profile_refuses() {
.split_whitespace()
.map(|w| w.trim_matches(|c| ",.;:()`".contains(c)))
.collect();
+ let page = std::fs::read_to_string(
+ PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("website/pages/en/docs/concepts/analyze.md"),
+ )
+ .unwrap();
+ let section = page
+ .split("`profile` runs a real workload")
+ .nth(1)
+ .and_then(|rest| rest.split("\n\n").next())
+ .expect("analyze.md describes what profile runs");
+ let page_words: Vec<&str> = section
+ .split_whitespace()
+ .map(|w| w.trim_matches(|c| ",.;:()`".contains(c)))
+ .collect();
for lang in [
Lang::C,
Lang::Kotlin,
@@ -402,6 +423,11 @@ fn the_skill_names_every_language_profile_refuses() {
"the skill's profile paragraph does not name {}: {paragraph}",
lang.name()
);
+ assert!(
+ page_words.contains(&lang.name()),
+ "the profile paragraph of website/pages/en/docs/concepts/analyze.md does not name {}: {section}",
+ lang.name()
+ );
}
let _ = std::fs::remove_dir_all(&dir);
}
diff --git a/website/pages/en/docs/concepts/analyze.md b/website/pages/en/docs/concepts/analyze.md
index 29f08046..51f8812f 100644
--- a/website/pages/en/docs/concepts/analyze.md
+++ b/website/pages/en/docs/concepts/analyze.md
@@ -14,7 +14,7 @@ rust-anything profile <repo> -- node bench.mjs # or: python3 bench.py, ruby
# java -cp out Main, go test -run X -bench . ./pkg
```
-`profile` runs a real workload under the language's profiler (node, cProfile, `go test` pprof, JFR, a Ruby tracer) and lists hot functions by inclusive time, their callers, and which loops to batch. Go profiles only through `go test`; C is not supported.
+`profile` runs a real workload under the language's profiler (node, cProfile, `go test` pprof, JFR, a Ruby tracer) and lists hot functions by inclusive time, their callers, and which loops to batch. It runs TS/JS, Python, Go, Java and Ruby workloads; Go profiles only through `go test`. For the others it stops and names the profiler to use instead: `perf record -g` for C, JFR (`jfr print --stack-depth 256`) for Kotlin, SPX or Xdebug's profiler for PHP, `dotnet-trace` for C#, `Measure-Command` for PowerShell (time one `pwsh` start first: when a tool starts a shell per command, start-up is the slow part), and Instruments' Time Profiler (or `perf record -g` on Linux) for Swift.
- A small function called once per item is **not** worth porting alone: one call into Rust costs more than its work, and JITs (V8, the JVM, Go) run it in nanoseconds. Port it together with its callers, or [batch it](/docs/concepts/batches). The advice line says which, with the exact command.
- Code that is already compiled (numba `@njit`, Cython, `@jax.jit`) runs as machine code: a Rust port gains little speed. `profile` lists it under "Already compiled".
diff --git a/website/pages/en/docs/concepts/shadow.md b/website/pages/en/docs/concepts/shadow.md
index 3107a89c..15aeca05 100644
--- a/website/pages/en/docs/concepts/shadow.md
+++ b/website/pages/en/docs/concepts/shadow.md
@@ -9,7 +9,16 @@ description: shadow generates a drop-in module that runs the original and the Ru
rust-anything shadow <crate>
```
-`shadow` generates a drop-in with the original's API: a TS or Python module, a Go package, a Ruby file, Java classes or a C file. Load it where the app loaded the original. It runs both, returns the original's result, and reports Rust mismatches while you build confidence in production.
+`shadow` generates a drop-in with the original's API: a TS or Python module, a Go package, a Ruby file, Java classes (for Java and Kotlin) or a C file. Load it where the app loaded the original. It runs both, returns the original's result, and reports Rust mismatches while you build confidence in production.
+
+Four languages have no shadow module yet, and `shadow` stops with what to do instead once `diff` passes:
+
+| Language | Instead |
+| --- | --- |
+| PHP | PHP cannot redefine a function once the original is loaded: require the generated PHP wrapper in place of the original files |
+| C# | C# binds calls when it compiles: compile the generated wrapper into the project and call the `<namespace>.Rust` classes (or alias them with `using`), with the built library next to the app |
+| PowerShell | `rust-anything enable <crate>` dot-sources the generated wrapper at the end of the original file |
+| Swift | Swift binds calls when it compiles: compile the generated wrapper into the target in place of the original file |
| `RUST_ANYTHING_MODE` | Behavior |
| --- | --- |