Skip to content

Commit e5ea16c

Browse files
committed
Merge branch 'master' into result-get-or-throw-message
2 parents 368e400 + caf4154 commit e5ea16c

35 files changed

+594
-349
lines changed

AGENTS.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is the ReScript compiler repository - a robustly typed language that compiles to efficient and human-readable JavaScript. ReScript is built using OCaml and includes a complete toolchain with compiler, build system, syntax parser, and standard library.
8+
9+
## Build Commands
10+
11+
### Basic Development
12+
```bash
13+
# Build compiler and copy executables
14+
make
15+
16+
# Build in watch mode
17+
make watch
18+
19+
# Build everything including standard library
20+
make lib
21+
22+
# Build artifacts and update artifact list
23+
make artifacts
24+
```
25+
26+
### Testing
27+
```bash
28+
# Run all tests
29+
make test
30+
31+
# Run specific test types
32+
make test-syntax # Syntax parser tests
33+
make test-syntax-roundtrip # Roundtrip syntax tests
34+
make test-gentype # GenType tests
35+
make test-analysis # Analysis tests
36+
make test-tools # Tools tests
37+
make test-rewatch # Rewatch tests
38+
39+
# Run single file test
40+
./cli/bsc.js myTestFile.res
41+
42+
# View parse/typed trees for debugging
43+
./cli/bsc.js -dparsetree myTestFile.res
44+
./cli/bsc.js -dtypedtree myTestFile.res
45+
```
46+
47+
### Code Quality
48+
```bash
49+
# Format code
50+
make format
51+
52+
# Check formatting
53+
make checkformat
54+
55+
# Lint with Biome
56+
npm run check
57+
npm run check:all
58+
59+
# TypeScript type checking
60+
npm run typecheck
61+
```
62+
63+
### Clean Operations
64+
```bash
65+
make clean # Clean OCaml build artifacts
66+
make clean-all # Clean everything including Rust/gentype
67+
```
68+
69+
## Compiler Architecture
70+
71+
The ReScript compiler follows this high-level pipeline:
72+
73+
```
74+
ReScript Source (.res)
75+
↓ (ReScript Parser - compiler/syntax/)
76+
Surface Syntax Tree
77+
↓ (Frontend transformations - compiler/frontend/)
78+
Surface Syntax Tree
79+
↓ (OCaml Type Checker - compiler/ml/)
80+
Typedtree
81+
↓ (Lambda compilation - compiler/core/lam_*)
82+
Lambda IR
83+
↓ (JS compilation - compiler/core/js_*)
84+
JS IR
85+
↓ (JS output - compiler/core/js_dump*)
86+
JavaScript Code
87+
```
88+
89+
### Key Directories
90+
91+
- **`compiler/syntax/`** - ReScript syntax parser (MIT licensed, separate from main LGPL)
92+
- **`compiler/frontend/`** - AST transformations, external FFI processing, built-in attributes
93+
- **`compiler/ml/`** - OCaml compiler infrastructure (type checker, typedtree, etc.)
94+
- **`compiler/core/`** - Core compilation:
95+
- `lam_*` files: Lambda IR compilation and optimization passes
96+
- `js_*` files: JavaScript IR and code generation
97+
- **`compiler/ext/`** - Extended utilities and data structures
98+
- **`compiler/bsb/`** - Build system implementation
99+
- **`compiler/gentype/`** - TypeScript generation
100+
- **`runtime/`** - ReScript standard library (written in ReScript)
101+
- **`lib/`** - Compiled JavaScript output of standard library
102+
- **`analysis/`** - Language server and tooling support
103+
104+
### Build System Components
105+
106+
- **`compiler/bsb_exe/`** - Main ReScript build tool entry point
107+
- **`compiler/bsc/`** - Compiler binary entry point
108+
- **`rewatch/`** - File watcher (written in Rust)
109+
- **`ninja/`** - Vendored Ninja build system
110+
111+
## Development Setup Notes
112+
113+
- Uses OCaml 5.3.0+ with opam for compiler development
114+
- Uses dune as build system with specific profiles (dev, release, browser)
115+
- Node.js 20+ required for JavaScript tooling
116+
- Rust toolchain needed for rewatch file watcher
117+
- Python ≤3.11 required for building ninja
118+
119+
## Coding Conventions
120+
121+
- **OCaml code**: snake_case (e.g., `to_string`)
122+
- **ReScript code**: camelCase (e.g., `toString`)
123+
- Use DCO sign-off for all commits: `Signed-Off-By: Your Name <email>`
124+
125+
## Testing Strategy
126+
127+
- **Mocha tests** (`tests/tests/`) - Runtime library unit tests
128+
- **Build system tests** (`tests/build_tests/`) - Integration tests
129+
- **OUnit tests** (`tests/ounit_tests/`) - Compiler unit tests
130+
- **Expectation tests** - Plain `.res` files that check compilation output
131+
- Always include appropriate tests with new features/changes
132+
133+
## Performance Notes
134+
135+
The compiler is designed for fast feedback loops and scales to large codebases. When making changes:
136+
- Avoid introducing meaningless symbols
137+
- Maintain readable JavaScript output
138+
- Consider compilation speed impact
139+
- Use appropriate optimization passes in the Lambda and JS IRs

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#### :boom: Breaking Change
1616

1717
- `Result.getOrThrow` now throws a JS error instead of a `Not_found` ReScript exception. https://github.com/rescript-lang/rescript/pull/7630
18+
- Rust implementation of the `rescript format` command. Command line options changed from `-all`, `-check` and `-stdin` to `--all`, `--check` and `--stdin` compared to the legacy implementation. https://github.com/rescript-lang/rescript/pull/7603
1819

1920
#### :nail_care: Polish
2021

@@ -29,6 +30,7 @@
2930
- Clean up `config.ml`. https://github.com/rescript-lang/rescript/pull/7636
3031
- Rewatch: simplify getting bsc path. https://github.com/rescript-lang/rescript/pull/7634
3132
- Rewatch: only get `"type": "dev"` source files for local packages. https://github.com/rescript-lang/rescript/pull/7646
33+
- Rewatch: add support for `rescript -w` for compatibility. https://github.com/rescript-lang/rescript/pull/7649
3234

3335
#### :rocket: New Feature
3436

@@ -40,6 +42,8 @@
4042
- Fix `typeof` parens on functions. https://github.com/rescript-lang/rescript/pull/7643
4143
- Rewatch: Add --dev flag to clean command. https://github.com/rescript-lang/rescript/pull/7622
4244
- Rewatch: Use root package suffix in clean log messages. https://github.com/rescript-lang/rescript/pull/7648
45+
- Fix inside comment printing for empty dict. https://github.com/rescript-lang/rescript/pull/7654
46+
- Fix I/O error message when trying to extract extra info from non-existing file. https://github.com/rescript-lang/rescript/pull/7656
4347

4448
# 12.0.0-beta.1
4549

CLAUDE.md

Lines changed: 0 additions & 139 deletions
This file was deleted.

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AGENTS.md

GEMINI.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AGENTS.md

compiler/frontend/ast_comb.ml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,6 @@ open Ast_helper
3333
[Exp.constraint_ ~loc e
3434
(Ast_literal.type_unit ~loc ())] *)
3535

36-
let tuple_type_pair ?loc kind arity =
37-
let prefix = "a" in
38-
if arity = 0 then
39-
let ty = Typ.var ?loc (prefix ^ "0") in
40-
match kind with
41-
| `Run -> (ty, [], ty)
42-
| `Make ->
43-
( Ast_compatible.arrow ?loc ~arity:None (Ast_literal.type_unit ?loc ()) ty,
44-
[],
45-
ty )
46-
else
47-
let number = arity + 1 in
48-
let tys =
49-
Ext_list.init number (fun i ->
50-
Typ.var ?loc (prefix ^ string_of_int (number - i - 1)))
51-
in
52-
match tys with
53-
| result :: rest ->
54-
( Ext_list.reduce_from_left tys (fun r arg ->
55-
Ast_compatible.arrow ?loc ~arity:None arg r),
56-
List.rev rest,
57-
result )
58-
| [] -> assert false
59-
6036
let regexp_id = Ast_literal.Lid.regexp_id
6137

6238
let to_regexp_type loc = Typ.constr ~loc {txt = regexp_id; loc} []

compiler/frontend/ast_comb.mli

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@
3131
(* val discard_exp_as_unit :
3232
Location.t -> Parsetree.expression -> Parsetree.expression *)
3333

34-
val tuple_type_pair :
35-
?loc:Ast_helper.loc ->
36-
[< `Make | `Run] ->
37-
int ->
38-
Parsetree.core_type * Parsetree.core_type list * Parsetree.core_type
39-
4034
val to_undefined_type : Location.t -> Parsetree.core_type -> Parsetree.core_type
4135

4236
val to_regexp_type : Location.t -> Parsetree.core_type

0 commit comments

Comments
 (0)