Skip to content

Commit a20771e

Browse files
authored
Add instructions to run Rewatch directly. (#8204)
1 parent c0e72ff commit a20771e

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

AGENTS.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ tests/
106106
- **JS layer** (`compiler/core/js_*`): JavaScript generation
107107

108108
2. **Always run appropriate tests:**
109+
109110
```bash
110111
# For compiler or stdlib changes
111112
make test
@@ -128,6 +129,7 @@ tests/
128129
### Debugging Techniques
129130

130131
#### View Intermediate Representations
132+
131133
```bash
132134
# Source code (for debugging preprocessing)
133135
./cli/bsc.js -dsource myfile.res
@@ -145,6 +147,7 @@ tests/
145147
```
146148

147149
#### Common Debug Scenarios
150+
148151
- **JavaScript formatting issues**: Check `compiler/ml/pprintast.ml`
149152
- **Type checking issues**: Look in `compiler/ml/` type checker modules
150153
- **Optimization bugs**: Check `compiler/core/lam_*.ml` analysis passes
@@ -153,12 +156,14 @@ tests/
153156
### Testing Requirements
154157

155158
#### When to Add Tests
159+
156160
- **Always** for new language features
157161
- **Always** for bug fixes
158162
- **When modifying** analysis passes
159163
- **When changing** JavaScript generation
160164

161165
#### Test Types to Include
166+
162167
1. **Syntax tests** (`tests/syntax_tests/`) - Parser validation
163168
2. **Integration tests** (`tests/tests/`) - End-to-end behavior
164169
3. **Unit tests** (`tests/ounit_tests/`) - Compiler functions
@@ -168,6 +173,7 @@ tests/
168173
## Build Commands & Development
169174

170175
### Essential Commands
176+
171177
```bash
172178
# Build compiler
173179
make
@@ -189,6 +195,7 @@ make clean
189195
```
190196

191197
### Testing Commands
198+
192199
```bash
193200
# Specific test types
194201
make test-syntax # Syntax parser tests
@@ -203,6 +210,7 @@ make test-rewatch # Rewatch tests
203210
```
204211

205212
### Code Quality
213+
206214
```bash
207215
# Format code
208216
make format
@@ -218,7 +226,6 @@ npm run check:all
218226
npm run typecheck
219227
```
220228

221-
222229
## Performance Considerations
223230

224231
The compiler is designed for fast feedback loops and scales to large codebases:
@@ -232,15 +239,18 @@ The compiler is designed for fast feedback loops and scales to large codebases:
232239
## Coding Conventions
233240

234241
### Naming
242+
235243
- **OCaml code**: snake_case (e.g., `to_string`)
236244
- **ReScript code**: camelCase (e.g., `toString`)
237245

238246
### Commit Standards
247+
239248
- Use DCO sign-off: `Signed-Off-By: Your Name <email>`
240249
- Include appropriate tests with all changes
241250
- Build must pass before committing
242251

243252
### Code Quality
253+
244254
- Follow existing patterns in the codebase
245255
- Prefer existing utility functions over reinventing
246256
- Comment complex algorithms and non-obvious logic
@@ -256,6 +266,7 @@ The compiler is designed for fast feedback loops and scales to large codebases:
256266
## Common Tasks
257267

258268
### Adding New Language Features
269+
259270
1. Update parser in `compiler/syntax/`
260271
2. Update AST definitions in `compiler/ml/`
261272
3. Implement type checking in `compiler/ml/`
@@ -264,13 +275,15 @@ The compiler is designed for fast feedback loops and scales to large codebases:
264275
6. Add comprehensive tests
265276

266277
### Debugging Compilation Issues
278+
267279
1. Identify which compilation phase has the issue
268280
2. Use appropriate debugging flags (`-dparsetree`, `-dtypedtree`)
269281
3. Check intermediate representations
270282
4. Add debug output in relevant compiler modules
271283
5. Verify with minimal test cases
272284

273285
### Working with Lambda IR
286+
274287
- Remember Lambda IR is the core optimization layer
275288
- All `lam_*.ml` files process this representation
276289
- Use `lam_print.ml` for debugging lambda expressions
@@ -383,6 +396,23 @@ make test-rewatch # Run integration tests
383396
- **Dependencies**: Inspect module dependency graph in `deps.rs`
384397
- **File Watching**: Monitor file change events in `watcher.rs`
385398

399+
#### Running Rewatch Directly
400+
401+
When running the rewatch binary directly (via `cargo run` or the compiled binary) during development, you need to set environment variables to point to the local compiler and runtime. Otherwise, rewatch will try to use the installed versions:
402+
403+
```bash
404+
# Set the compiler executable path
405+
export RESCRIPT_BSC_EXE=$(realpath _build/default/compiler/bsc/rescript_compiler_main.exe)
406+
407+
# Set the runtime path
408+
export RESCRIPT_RUNTIME=$(realpath packages/@rescript/runtime)
409+
410+
# Now you can run rewatch directly
411+
cargo run --manifest-path rewatch/Cargo.toml -- build
412+
```
413+
414+
This is useful when testing rewatch changes against local compiler modifications without running a full `make` build cycle.
415+
386416
#### Performance Considerations
387417

388418
- **Incremental Builds**: Only recompile dirty modules
@@ -400,7 +430,7 @@ When clippy suggests refactoring that could impact performance, consider the tra
400430
- Small and one-time (e.g., `Vec<String>` with few elements)
401431
- Necessary for correct ownership semantics
402432
- Not in a hot path
403-
433+
404434
Then accept the clone rather than over-engineering the solution.
405435

406436
- **When to Optimize**: Profile before optimizing. Most "performance concerns" in build systems are negligible compared to actual compilation time.

0 commit comments

Comments
 (0)