Skip to content

Commit 4a7ca3d

Browse files
Aiden Fox Iveyk0kubun
authored andcommitted
ZJIT: Reformat and add highlighting to ZJIT documentation
* Add bash above code blocks that can use highlighting * Move Useful dev commands below documentation, testing, and building * Rewrite testing documentation to better explain what each form of test does
1 parent a3d1752 commit 4a7ca3d

1 file changed

Lines changed: 51 additions & 57 deletions

File tree

doc/zjit.md

Lines changed: 51 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## Build Instructions
44

55
To build ZJIT on macOS:
6-
```
6+
7+
```bash
78
./autogen.sh
89

910
./configure \
@@ -15,113 +16,89 @@ To build ZJIT on macOS:
1516
make -j miniruby
1617
```
1718

18-
## Useful dev commands
19-
20-
To view YARV output for code snippets:
21-
```
22-
./miniruby --dump=insns -e0
23-
```
24-
25-
To run code snippets with ZJIT:
26-
```
27-
./miniruby --zjit -e0
28-
```
29-
30-
You can also try https://www.rubyexplorer.xyz/ to view Ruby YARV disasm output with syntax highlighting
31-
in a way that can be easily shared with other team members.
32-
3319
## Documentation
3420

3521
You can generate and open the source level documentation in your browser using:
36-
```
22+
23+
```bash
3724
cargo doc --document-private-items -p zjit --open
3825
```
3926

4027
## Testing
4128

42-
Make sure you have a `--enable-zjit=dev` build, and install the following tools:
43-
```
44-
cargo install cargo-nextest
45-
cargo install cargo-insta
46-
```
47-
`cargo-nextest` is required for running tests, whereas `cargo-insta` is used for updating snapshots.
29+
Note that tests link against CRuby, so directly calling `cargo test`, or `cargo nextest` should not build. All tests are instead accessed through `make`.
4830

49-
### make zjit-check
31+
### Setup
5032

51-
This command runs all ZJIT tests: `make zjit-test` and `test/ruby/test_zjit.rb`.
33+
First, ensure you have `cargo` installed. If you do not already have it, you can use [rustup.rs](https://rustup.rs/).
5234

53-
```
54-
make zjit-check
35+
Make sure to add `--enable-zjit=dev` when you run `configure`, then install the following tools:
36+
37+
```bash
38+
cargo install cargo-nextest
39+
cargo install cargo-insta
5540
```
5641

57-
### make zjit-test
42+
`cargo-insta` is used for updating snapshots. `cargo-nextest` runs each test in its own process, which is valuable since CRuby only supports booting once per process, and most APIs are not thread safe.
5843

59-
This command runs Rust unit tests using `insta` for snapshot testing.
44+
### Running unit tests
6045

61-
```
46+
For testing functionality within ZJIT, use:
47+
48+
```bash
6249
make zjit-test
6350
```
6451

6552
You can also run a single test case by specifying the function name:
6653

67-
```
54+
```bash
6855
make zjit-test ZJIT_TESTS=test_putobject
6956
```
7057

7158
#### Snapshot Testing
7259

73-
ZJIT uses [insta](https://insta.rs/) for snapshot testing. When tests fail due to snapshot mismatches, pending snapshots are created. The test command will notify you if there are pending snapshots:
60+
ZJIT uses [insta](https://insta.rs/) for snapshot testing within unit tests. When tests fail due to snapshot mismatches, pending snapshots are created. The test command will notify you if there are pending snapshots:
7461

7562
```
7663
Pending snapshots found. Accept with: make zjit-test-update
7764
```
7865

7966
To update/accept all the snapshot changes:
8067

81-
```
68+
```bash
8269
make zjit-test-update
8370
```
8471

8572
You can also review snapshot changes interactively one by one:
8673

87-
```
74+
```bash
8875
cd zjit && cargo insta review
8976
```
9077

9178
Test changes will be reviewed alongside code changes.
9279

93-
<details>
94-
95-
<summary>Setting up zjit-test</summary>
96-
97-
ZJIT uses `cargo-nextest` for Rust unit tests instead of `cargo test`.
98-
`cargo-nextest` runs each test in its own process, which is valuable since
99-
CRuby only supports booting once per process, and most APIs are not thread
100-
safe. Use `brew install cargo-nextest` to install it on macOS, otherwise, refer
101-
to <https://nexte.st/docs/installation/pre-built-binaries/> for installation
102-
instructions.
103-
104-
Since it uses Cargo, you'll also need a `configure --enable-zjit=dev ...` build
105-
for `make zjit-test`. Since the tests need to link against CRuby, directly
106-
calling `cargo test`, or `cargo nextest` likely won't build. Make sure to
107-
use `make`.
108-
109-
</details>
110-
111-
### test/ruby/test\_zjit.rb
80+
### Running integration tests
11281

11382
This command runs Ruby execution tests.
11483

115-
```
84+
```bash
11685
make test-all TESTS="test/ruby/test_zjit.rb"
11786
```
11887

11988
You can also run a single test case by matching the method name:
12089

121-
```
90+
```bash
12291
make test-all TESTS="test/ruby/test_zjit.rb -n TestZJIT#test_putobject"
12392
```
12493

94+
### Running all tests
95+
96+
Runs both `make zjit-test` and `test/ruby/test_zjit.rb`:
97+
98+
```bash
99+
make zjit-check
100+
```
101+
125102
## Statistics Collection
126103

127104
ZJIT provides detailed statistics about JIT compilation and execution behavior.
@@ -173,12 +150,29 @@ Through [Stackprof](https://github.com/tmm1/stackprof), detailed information abo
173150
./miniruby --zjit-trace-exits script.rb
174151
```
175152

176-
A file called `zjit_exit_locations.dump` will be created in the same directory as `script.rb`. Viewing the side exited methods can be done with Stackprof:
153+
A file called `zjit_exit_locations{timestamp}.dump` will be created in the same directory as `script.rb`. Viewing the side exited methods can be done with Stackprof:
154+
155+
```bash
156+
stackprof path/to/zjit_exit_locations{timestamp}.dump
157+
```
158+
159+
## Useful dev commands
160+
161+
To view YARV output for code snippets:
162+
163+
```bash
164+
./miniruby --dump=insns -e0
165+
```
166+
167+
To run code snippets with ZJIT:
177168

178169
```bash
179-
stackprof path/to/zjit_exit_locations.dump
170+
./miniruby --zjit -e0
180171
```
181172

173+
You can also try https://www.rubyexplorer.xyz/ to view Ruby YARV disasm output with syntax highlighting
174+
in a way that can be easily shared with other team members.
175+
182176
## ZJIT Glossary
183177

184178
This glossary contains terms that are helpful for understanding ZJIT.

0 commit comments

Comments
 (0)