You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AGENTS.md
+170-1Lines changed: 170 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -254,4 +254,173 @@ The compiler is designed for fast feedback loops and scales to large codebases:
254
254
- Remember Lambda IR is the core optimization layer
255
255
- All `lam_*.ml` files process this representation
256
256
- Use `lam_print.ml` for debugging lambda expressions
257
-
- Test both with and without optimization passes
257
+
- Test both with and without optimization passes
258
+
259
+
## Working on the Build System
260
+
261
+
### Rewatch Architecture
262
+
263
+
Rewatch is the modern build system written in Rust that replaces the legacy bsb (BuckleScript) build system. It provides faster incremental builds, better error messages, and improved developer experience.
264
+
265
+
#### Key Components
266
+
267
+
```
268
+
rewatch/src/
269
+
├── build/ # Core build system logic
270
+
│ ├── build_types.rs # Core data structures (BuildState, Module, etc.)
271
+
│ ├── compile.rs # Compilation logic and bsc argument generation
272
+
│ ├── parse.rs # AST generation and parser argument handling
273
+
│ ├── packages.rs # Package discovery and dependency resolution
274
+
│ ├── deps.rs # Dependency analysis and module graph
**Note**: The rewatch project is located in the `rewatch/` directory with its own `Cargo.toml` file. All cargo commands should be run from the project root using the `--manifest-path rewatch/Cargo.toml` flag, as shown in the CI workflow.
356
+
357
+
**Integration Tests**: The `make test-rewatch` command runs bash-based integration tests located in `rewatch/tests/suite-ci.sh`. These tests use the `rewatch/testrepo/` directory as a test workspace with various package configurations to verify rewatch's behavior across different scenarios.
358
+
359
+
#### Debugging
360
+
361
+
-**Build State**: Use `log::debug!` to inspect `BuildState` contents
362
+
-**Compiler Args**: Check generated `bsc` arguments in `compile.rs`
363
+
-**Dependencies**: Inspect module dependency graph in `deps.rs`
364
+
-**File Watching**: Monitor file change events in `watcher.rs`
365
+
366
+
#### Performance Considerations
367
+
368
+
-**Incremental Builds**: Only recompile dirty modules
369
+
-**Parallel Compilation**: Use `rayon` for parallel processing
370
+
-**Memory Usage**: Be mindful of `BuildState` size in large projects
371
+
-**File I/O**: Minimize file system operations
372
+
373
+
#### Performance vs Code Quality Trade-offs
374
+
375
+
When clippy suggests refactoring that could impact performance, consider the trade-offs:
376
+
377
+
-**Parameter Structs vs Many Arguments**: While clippy prefers parameter structs for functions with many arguments, sometimes the added complexity isn't worth it. Use `#[allow(clippy::too_many_arguments)]` for functions that legitimately need many parameters and where a struct would add unnecessary complexity.
378
+
379
+
-**Cloning vs Borrowing**: Sometimes cloning is necessary due to Rust's borrow checker rules. If the clone is:
380
+
- Small and one-time (e.g., `Vec<String>` with few elements)
381
+
- Necessary for correct ownership semantics
382
+
- Not in a hot path
383
+
384
+
Then accept the clone rather than over-engineering the solution.
385
+
386
+
-**When to Optimize**: Profile before optimizing. Most "performance concerns" in build systems are negligible compared to actual compilation time.
387
+
388
+
-**Avoid Unnecessary Type Conversions**: When threading parameters through multiple function calls, use consistent types (e.g., `String` throughout) rather than converting between `String` and `&str` at each boundary. This eliminates unnecessary allocations and conversions.
389
+
390
+
#### Compatibility with Legacy bsb
391
+
392
+
-**Command-line Flags**: Maintain compatibility with bsb flags where possible
393
+
-**Configuration**: Support both old (`bs-*`) and new field names
0 commit comments