Skip to content

RFC: Compiler API #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions text/0003-compiler-apis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
Feature Name: compiler-apis
Start Date: 2025-04-30
RFC PR: https://github.com/rescript-lang/rfcs/pull/3
ReScript Issue: (leave this empty)
---

## Summary

Define and standardize a programmatic API surface for the ReScript compiler to enable consistent and reliable integration across tools and environments.

## Motivation

Currently, ReScript lacks a stable, documented programmatic interface.

As a result, most tooling around ReScript—such as editors, external build systems, and web-based tools—depend on reverse-engineered knowledge or tight coupling to the compiler's internal implementation details. This approach is fragile, difficult to maintain, and prone to breakage with compiler updates.

For instance:

- Some projects vendor large parts of the compiler source to extract basic capabilities like parsing or type-checking.
- Some projects implement custom CLI wrappers to invoke the compiler in subprocesses and then parse its output—an error-prone strategy that limits interactivity and flexibility.
- Building browser-based tools like the ReScript Playground is particularly challenging, since the compiler is not designed for use in non-Node.js environments. This forces projects to either patch or rebuild the compiler entirely.

A stable, documented, and minimal programmatic API would simplify these use cases, encourage ecosystem innovation, and reduce duplication of effort across the community.

## Detailed design

### Metadata

`rescript` entry provides locations of executable binaries.

```resi
let version: string
```

### Compiler entry

`rescript/compiler` entry provides interfaces for the standalone compiler instance.

### Parser entry

`rescript/parser` entry provides interfaces for the standalone parser instance.

### The LSP entry

`rescript/lsp` entry provides interfaces for the standalone parser instance.