Skip to content

Commit 7740c59

Browse files
committed
Merge branch 'master' into docstrings-before-type-expansions
2 parents 6ae295a + 4276895 commit 7740c59

File tree

391 files changed

+6294
-3005
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

391 files changed

+6294
-3005
lines changed

.devcontainer/.dockerignore

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
*~
2+
_build
3+
*.obj
4+
*.out
5+
*.compile
6+
*.native
7+
*.byte
8+
*.cmo
9+
*.annot
10+
*.cmi
11+
*.cmx
12+
*.cmt
13+
*.cmti
14+
*.cma
15+
*.a
16+
*.cmxa
17+
*.obj
18+
*~
19+
*.annot
20+
*.mj
21+
*.bak
22+
*.swp
23+
*.swo
24+
*.flambda
25+
*.jsx
26+
*.lambda
27+
*.rawlambda
28+
*.s
29+
*.o
30+
*.lam
31+
*.0.js
32+
*#
33+
*.log
34+
.#*
35+
*.cmj
36+
*.rawlambda
37+
*.lambda
38+
*.zip
39+
*.mlast
40+
*.mliast
41+
42+
.idea
43+
.DS_Store
44+
45+
node_modules
46+
*.dump
47+
coverage
48+
49+
.ninja_log
50+
.bsdeps
51+
.bsbuild
52+
lib/ocaml
53+
tests/build_tests/*/lib/
54+
#ignore temporary directory
55+
*.goog.js
56+
*.jsoo.js
57+
*.so
58+
tmp/
59+
tracing*.json
60+
61+
_opam
62+
63+
.env
64+
playground/packages/
65+
playground/stdlib/
66+
playground/*.cmj
67+
playground/*.cmi
68+
playground/.netrc
69+
playground/compiler.*js
70+
71+
rewatch/target/
72+
rewatch/rewatch
73+
74+
tests/tools_tests/**/*.res.js
75+
tests/tools_tests/lib
76+
tests/analysis_tests*/lib
77+
tests/analysis_tests/**/*.bs.js
78+
79+
/linux/*.exe
80+
/linuxarm64/*.exe
81+
/darwin/*.exe
82+
/darwinarm64/*.exe
83+
/win32/*.exe
84+
85+
.yarn/*
86+
!.yarn/patches
87+
!.yarn/plugins
88+
!.yarn/releases
89+
!.yarn/sdks
90+
!.yarn/versions
91+
92+
*.tsbuildinfo
93+
94+
# package tarballs
95+
package.tgz
96+
*.exe
97+
98+
/ninja/ninja
99+
/ninja/build.ninja

.devcontainer/Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ FROM mcr.microsoft.com/devcontainers/rust:1-1-bookworm
22
LABEL org.opencontainers.image.authors="Christoph Knittel <[email protected]>"
33
LABEL org.opencontainers.image.description="Docker image for ReScript development."
44

5-
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
5+
RUN sudo apt-get update && export DEBIAN_FRONTEND=noninteractive \
66
&& apt-get -y install --no-install-recommends \
7-
yarn \
8-
opam \
7+
cmake \
8+
ninja-build \
99
musl-tools \
1010
python-is-python3 \
1111
&& rm -rf /var/lib/apt/lists/*
12+
13+
# Install OPAM
14+
ARG OPAM_VERSION=2.4.1
15+
RUN printf '\n\n' | bash -c "sh <(curl -fsSL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh) --version $OPAM_VERSION"

.devcontainer/devcontainer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
"name": "ReScript Compiler",
33
"build": {
44
"context": ".",
5-
"dockerfile": "Dockerfile"
5+
"dockerfile": "Dockerfile",
6+
"args": {
7+
"USER_UID": "${localEnv:UID}",
8+
"USER_GID": "${localEnv:GID}"
9+
}
610
},
711
"features": {
812
"ghcr.io/devcontainers/features/github-cli:1": {
@@ -23,5 +27,7 @@
2327
]
2428
}
2529
},
26-
"postCreateCommand": ".devcontainer/postCreate.sh"
30+
"postCreateCommand": ".devcontainer/postCreate.sh",
31+
"remoteUser": "vscode",
32+
"containerUser": "vscode"
2733
}

.devcontainer/postCreate.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
# Install dev dependencies from OPAM
44
opam init -y --bare --disable-sandboxing
5-
opam switch create 5.3.0 --packages ocaml-option-static
6-
opam install . --deps-only -y
7-
8-
# For IDE support, install the OCaml language server
9-
opam install ocaml-lsp-server -y
5+
opam switch create 5.3.0
6+
opam install . --deps-only --with-test --with-dev-setup -y
107

118
# Add OPAM environment setup to shell startup script
129
echo 'eval $(opam env)' >> ~/.zshrc
1310
echo 'eval $(opam env)' >> ~/.bashrc
1411

15-
npm install --ignore-scripts
12+
nvm install
13+
14+
corepack enable
15+
printf "\n" | yarn

.github/workflows/ci.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ jobs:
8080
OPAM_VERSION: 2.3.0
8181
DUNE_PROFILE: release
8282
RUST_BACKTRACE: "1"
83+
RUSTFLAGS: "-Dwarnings"
8384

8485
steps:
8586
- name: "Windows: Set git config"
@@ -131,16 +132,21 @@ jobs:
131132
run: |
132133
cargo build --manifest-path rewatch/Cargo.toml --target ${{ matrix.rust-target }} --release
133134
135+
- name: Lint rewatch
136+
if: steps.rewatch-build-cache.outputs.cache-hit != 'true'
137+
run: |
138+
cargo clippy --manifest-path rewatch/Cargo.toml --all-targets --all-features
139+
134140
- name: Run rewatch unit tests
135141
if: steps.rewatch-build-cache.outputs.cache-hit != 'true'
136142
run: |
137-
cargo test --manifest-path rewatch/Cargo.toml
143+
cargo test --manifest-path rewatch/Cargo.toml --release
138144
139145
- name: Copy rewatch binary
140146
run: |
141-
cp rewatch/target/${{ matrix.rust-target }}/release/rewatch${{ runner.os == 'Windows' && '.exe' || '' }} rewatch
147+
cp rewatch/target/${{ matrix.rust-target }}/release/rescript${{ runner.os == 'Windows' && '.exe' || '' }} rescript
142148
mkdir -p rewatch/target/release
143-
cp rewatch/target/${{ matrix.rust-target }}/release/rewatch${{ runner.os == 'Windows' && '.exe' || '' }} rewatch/target/release
149+
cp rewatch/target/${{ matrix.rust-target }}/release/rescript${{ runner.os == 'Windows' && '.exe' || '' }} rewatch/target/release
144150
./scripts/copyExes.js --rewatch
145151
shell: bash
146152

@@ -360,6 +366,14 @@ jobs:
360366
if: runner.os != 'Windows'
361367
run: make -C tests/gentype_tests/typescript-react-example clean test
362368

369+
# On Windows, after running setup-ocaml (if it wasn't cached yet or the cache couldn't be restored),
370+
# Cygwin bash is used instead of Git Bash for Windows, breaking the rewatch tests.
371+
# So we need to adjust the path to bring back Git Bash for Windows.
372+
- name: Rewatch tests need Git Bash for Windows
373+
if: ${{ runner.os == 'Windows' }}
374+
run: echo "C:\Program Files\Git\bin" >> $GITHUB_PATH
375+
shell: bash
376+
363377
- name: Run rewatch tests
364378
run: ./rewatch/tests/suite-ci.sh
365379
shell: bash

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,6 @@ tests/analysis_tests/**/*.bs.js
9999
# package tarballs
100100
package.tgz
101101
*.exe
102+
103+
# AI Agents
104+
.claude/settings.local.json

.mcp.json

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

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

0 commit comments

Comments
 (0)