Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2ab9cee
Branch for release 10.0
cristianoc Jul 18, 2022
64756da
changelog: string constants don't need escaping
cristianoc Jul 21, 2022
7fa2f3a
Merge all alpha/beta changes into one, and cleanup.
cristianoc Jul 21, 2022
1afc323
Update CHANGELOG.md
cristianoc Jul 21, 2022
fa94627
Update CHANGELOG.md
cristianoc Jul 21, 2022
e35190a
Update CHANGELOG.md
cristianoc Jul 21, 2022
d559f5f
Fix issue with bytes_to_string in library.
cristianoc Jul 22, 2022
cf7792b
Remove bytes_of_string.
cristianoc Jul 22, 2022
daed394
snapshot after cherrypick
cristianoc Jul 22, 2022
dc71e98
Update CHANGELOG.md
cristianoc Jul 22, 2022
ac3744a
Version 10.0.0-rc.1 (#5584)
cknitt Jul 23, 2022
8e3ccc6
New README (#5586)
cknitt Jul 23, 2022
26eb4ab
Further fix for %bytes_to_string
TheSpyder Jul 24, 2022
5bc6519
snapshot after cherrypick
cristianoc Jul 24, 2022
00d896b
Bump version to rc.2
cristianoc Jul 24, 2022
31a3645
chore: remove mention of @optional from changelog
Aug 21, 2022
23d5167
Consolidate changelog into a single 10.0.
cristianoc Aug 22, 2022
35365bc
Streamline building all build artifacts / cmij files required by the …
ryyppy Aug 22, 2022
be8d771
format
cristianoc Aug 23, 2022
2730b62
Version 10.0.0
cknitt Aug 23, 2022
e7cbf55
add changelog note for unicode support
zth Aug 23, 2022
3d37316
Update CHANGELOG.md
cristianoc Aug 24, 2022
e92d1fc
Update CHANGELOG.md
cristianoc Aug 24, 2022
8aa9ec8
Add playground upload script for KEYCDN publishing
ryyppy Aug 26, 2022
0bce868
Add more comments to the upload script
ryyppy Aug 26, 2022
dd35d0a
Close the lock file after opening
hellos3b Aug 30, 2022
d158010
Add changelog for 10.0.1.
cristianoc Aug 30, 2022
aa2e009
Close the lock file after opening
hellos3b Aug 30, 2022
fe2c822
Add changelog for 10.0.1.
cristianoc Aug 30, 2022
d025441
Merge branch '10.0_release' of https://github.com/rescript-lang/rescr…
cristianoc Aug 30, 2022
8149ea2
Version 10.0.1 (#5624)
cknitt Aug 31, 2022
db60e49
Update CONTRIBUTING with correct playground cmi / cmj information
ryyppy Sep 5, 2022
d25fb0e
Merge pull request #5618 from rescript-lang/ryyppy/playground-upload-…
ryyppy Sep 5, 2022
e777d3e
Sync CONTRIBUTING.ml with master.
cristianoc Sep 5, 2022
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [master]
branches: [master, 10.0_release]
pull_request:
branches: [master]
branches: [master, 10.0_release]

jobs:
build:
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,11 @@ jscomp/ml/lexer.ml

# opam local switch is stored in `_opam` folder
_opam

.env
playground/packages/
playground/stdlib/
playground/*.cmj
playground/*.cmi
playground/.netrc
playground/compiler.js
76 changes: 28 additions & 48 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,84 +10,59 @@
> - :house: [Internal]
> - :nail_care: [Polish]

# master

#### :boom: Breaking Change

- Vendor genType, which does not need to be installed separately anymore. **Only TypeScript back-end** supported.

#### :nail_care: Polish

- Print patterns in warnings using rescript printer https://github.com/rescript-lang/rescript-compiler/pull/5492

# 10.0 first full release

- No change yet w.r.t. beta.3

# 10.0.0-beta.3
# 10.0.1

#### :bug: Bug Fix

- Fix issue with compiler log not terminated that causes problems with editor extension not clearing issues when fixed [#5545](https://github.com/rescript-lang/rescript-compiler/issues/5545)

# 10.0.0-beta.2

##### :nail_care: Polish
- Fix issue where watch mode would give an error on Windows https://github.com/rescript-lang/rescript-compiler/pull/5621

- Changed Linux build to depend on GLIBC 2.28 again for compatibility with Debian 10.
# 10.0.0

# 10.0.0-beta.1
**Compiler**

#### :boom: Breaking Change

- `bsconfig.json` does not support `// line` comments anymore.
- Example: `"suffix": ".bs.js" // determine the suffix`
- Fix: remove the comment and use standard json.
- Externals without `@val` annotations do not work anymore, and externals with `= ""` give an error.
- Example: `external setTimeout: (unit => unit, int) => float = "setTimeout"` is not supported anymore.
- Fix: use `[@val] external setTimeout: (unit => unit, int) => float = "setTimeout"` instead.
- Example2: `[@val] external setTimeout: (unit => unit, int) => float = ""` is not supported anymore.
- Fix2: use `[@val] external setTimeout: (unit => unit, int) => float = "setTimeout"` instead.
- Regular expressions don't need escaping.
- Example: `let blockCommentsRe = %re("/\\/\\*([^*]|[\\r\\n]|(\\*+([^*/]|[\\r\\n])))*\\*+\\//g")`.
- Fix: use `let blockCommentsRe = %re("/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g")` instead.

#### :bug: Bug Fix

- Fixed crash in `rescript build` on Windows [#5516](https://github.com/rescript-lang/rescript-compiler/pull/5516)
- Fixed `rescript init` command not working [#5526](https://github.com/rescript-lang/rescript-compiler/pull/5526)

# 10.0.0-alpha.1

**Compiler**

#### :boom: Breaking Change

- `@bs.send.pipe` is now removed. Earlier it was deprecated.
- Missing labels in function application is now an error (https://forum.rescript-lang.org/t/ann-more-strict-checks-in-missed-labels/2117).
- Example: `let f = (x, ~z) => x + z; f(1, 2)`
- Fix: do `let f = (x, ~z) => x + z; f(1, ~z=2)` instead
- Changed return type of `Js.String.match_` as it was wrong. [#5070](https://github.com/rescript-lang/rescript-compiler/pull/5070)
- Example: any use of `Js.String.match_` and `Js.String2.match_`
- Fix: follow the type errors

#### :rocket: New Feature

- New records with optional fields e.g. `type opt = {x: int, y?: string}` were added as an experimental feature [#5423](https://github.com/rescript-lang/rescript-compiler/pull/5423) [#5452](https://github.com/rescript-lang/rescript-compiler/issues/5452) [New Syntax](https://github.com/rescript-lang/syntax/pull/589/files)
- Add support for `@new @variadic` (see https://github.com/rescript-lang/rescript-compiler/pull/5364)
- New records with `@optional` fields [#5423](https://github.com/rescript-lang/rescript-compiler/pull/5423) [#5452](https://github.com/rescript-lang/rescript-compiler/issues/5452)

#### :bug: Bug Fix

- Classify bigint correctly [#5351](https://github.com/rescript-lang/rescript-compiler/pull/5351)
- Fixed crash in `rescript build` on Windows [#5516](https://github.com/rescript-lang/rescript-compiler/pull/5516)
- Fixed `rescript init` command not working [#5526](https://github.com/rescript-lang/rescript-compiler/pull/5526)
- Fix issue with compiler log not terminated that causes problems with editor extension not clearing issues when fixed [#5545](https://github.com/rescript-lang/rescript-compiler/issues/5545)

#### :house: [Internal]
##### :nail_care: Polish

- Changed Linux build to depend on GLIBC 2.28 again for compatibility with Debian 10.

- Proper M1 support (CI now supports M1 native builds)

**Syntax**

#### :boom: Breaking Change

- `@bs.send.pipe` is now removed. Earlier it was deprecated.
- Missing labels in function application is now an error (https://forum.rescript-lang.org/t/ann-more-strict-checks-in-missed-labels/2117).
- Example: `let f = (x, ~z) => x + z; f(1, 2)`
- Fix: do `let f = (x, ~z) => x + z; f(1, ~z=2)` instead
- Externals without `@val` annotations do not work anymore, and externals with `= ""` give an error.
- Example: `external setTimeout: (unit => unit, int) => float = "setTimeout"` is not supported anymore.
- Fix: use `@val external setTimeout: (unit => unit, int) => float = "setTimeout"` instead.
- Example2: `@val external setTimeout: (unit => unit, int) => float = ""` is not supported anymore.
- Fix2: use `@val external setTimeout: (unit => unit, int) => float = "setTimeout"` instead.
- Strings processed at compile-time don't need escaping anymore.
- Example: `let blockCommentsRe = %re("/\\/\\*([^*]|[\\r\\n]|(\\*+([^*/]|[\\r\\n])))*\\*+\\//g")`.
- Fix: use `let blockCommentsRe = %re("/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g")` instead.
- Remove parsing of "import" and "export" which was never officially supported https://github.com/rescript-lang/syntax/pull/597 https://github.com/rescript-lang/syntax/pull/599
- Example: `export type t = int`
- Fix: `@genType type t = int`
Expand All @@ -96,6 +71,7 @@

#### :rocket: New Feature

- Unicode is now supported in regular strings and chars (when the symbol fits). This is now going to work: `let str = "Σ"`. And, you'll be able to pattern match on unicode chars: `switch c { | 'Σ' => "what a fine unicode char" | _ => "unicode is fun" }`
- Doc comments `/** ... */` are now supported. Inernally, they are attributes, so are only valid at positions where `@foo` is allowed, or a syntax error is given. Similarly for module-level `/*** comments */` that can go where `@@attributes` go.

#### :bug: Bug Fix
Expand All @@ -116,6 +92,10 @@
- Fix: use `rescript-relay@beta` or the new version when released.
- Removed printing modules (Printf, Format etc) and related functions. Details of files added/removed: https://github.com/rescript-lang/rescript-compiler/commit/0fd8bb0e77c4b0e96a9647ac8af614305057003f.

#### :bug: Bug Fix

- Fix library issue with missing `bytes_to_string` https://github.com/rescript-lang/rescript-compiler/issues/5573 https://github.com/rescript-lang/rescript-compiler/pull/5589

#### :nail_care: Polish

- Several Belt / Js libraries are now converted to ReScript syntax, with corresponding comments in Markdown format suitable for hovering. See [#5361](https://github.com/rescript-lang/rescript-compiler/pull/5361).
Expand Down
113 changes: 64 additions & 49 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,93 +99,81 @@ dune build -w

> Please note that `dune` will not build the final `rescript` binaries. Use the aforementioned `ninja` workflow if you want to build, test and distribute the final product.

## Adding new Files
## Adding new Files to the Npm Package

To make sure that no files are added to or removed from the npm package inadvertently, an artifact list is kept at `packages/artifacts.txt`. During CI build, it is verified that only the files that are listed there are actually included in the npm package.

When adding a new file to the repository that should go into the npm package - e.g., a new stdlib module -, first compile and test everything locally. Next, run `./scripts/makeArtifactList.js` to update the artifact list and include the updated artifact list in your commit.
When adding a new file to the repository that should go into the npm package - e.g., a new stdlib module -, first compile and test everything locally. Then

## Running tests for independent ReScript files
- `node scripts/install -force-lib-rebuild` to copy library files into `lib/ocaml`
- `./scripts/makeArtifactList.js` to update the artifact list and include the updated artifact list in your commit.

The simplest way for running tests is to run your locally built compiler on separate ReScript files:
## Test the compiler

```sh
# Make sure to rebuild the compiler before running any tests (./scripts/ninja.js config / build etc)
./darwinarm64/bsc.exe myTestFile.res
```

**Different architectures:**

- `darwinarm64/bsc.exe`: M1 Macs
- `darwin/bsc.exe`: Intel Macs
- `linux/bsc.exe`: Linux computers
Make sure to build the compiler first following the instructions above.

### Testing the whole ReScript Package

If you'd like to bundle up and use your modified ReScript like an end-user, try:
### Single file

```sh
node scripts/install -force-lib-rebuild # make sure lib/ocaml is populated

npm uninstall -g rescript # a cache-busting uninstall is needed, but only for npm >=7

# This will globally install your local build via npm
RESCRIPT_FORCE_REBUILD=1 npm install -g .
./bsc myTestFile.res
```

Then you may initialize and build your ReScript project as usual:
### Project

```sh
rescript init my-project
cd my-project
npm run build
node scripts/install -force-lib-rebuild ## populate lib/ocaml
cd myProject
npm install __path_to_this_repository__
```

### Running Automatic Tests

We provide different test suites for different levels of the compiler and build system infrastructure. Always make sure to locally build your compiler before running any tests.

**Run Mocha tests for our runtime code:**
To run all tests:

```sh
npm test
```

**Run Mocha tests only (for our runtime code):**

This will run our `mocha` unit test suite defined in `jscomp/test`.

```
npx node scripts/ciTest.js -mocha
node scripts/ciTest.js -mocha
```

**Run build system test (integration tests):**

This will run the whole build system test suite defined in `jscomp/build_tests`.

```
# Make sure to globally install rescript via npm first
npm install -g .

npx node scripts/ciTest.js -bsb
node scripts/ciTest.js -bsb
```

**Run ounit tests:**

This will run unit tests for compiler related modules. The tests can be found in `jscomp/ounit_tests`.

```
npx node scripts/ciTest.js -ounit
node scripts/ciTest.js -ounit
```

## Contributing to the ReScript Runtime
## Contributing to the Runtime

Our runtime implementation is written in pure OCaml with some raw JS code embedded (`jscomp/runtime` directory).
The runtime implementation is written in OCaml with some raw JS code embedded (`jscomp/runtime` directory).

The goal is to implement the runtime **purely in OCaml**. This includes removing all existing occurrences of embedded raw JS code as well, and you can help!
The goal is to implement the runtime **purely in OCaml**. This includes removing all existing occurrences of embedded raw JS code as well whenever possible, and you can help!

Each new PR should include appropriate testing.

Currently all tests are located in the `jscomp/test` directory and you should either add / update test files according to your changes to the compiler.

There are currently two formats for test files:

1. Proper mocha test files with executed javascript test code
2. Plain `.ml` files which are only supposed to be compiled to JS (without any logic validation)
1. Mocha test files that run javascript test code
2. Plain `.ml` files to check the result of compilation to JS (expectation tests)

Below we will discuss on how to write, build and run these test files.

Expand Down Expand Up @@ -241,35 +229,50 @@ mkdir playground && mkdir playground/stdlib
# We build the ReScript source code and also the bytecode for the JSOO entrypoint
node scripts/ninja.js config && node scripts/ninja.js build

# Now we run the repl.js script pointing to our playground directory (note how it needs to be relative to the repl.js file)
PLAYGROUND=../playground node scripts/repl.js
# Now we run the repl.js script which will create all the required artifacts in the `./playground` directory
node scripts/repl.js
```

In case you want to build the project with our default third party packages (like `@rescript/react`), prepare the `playground-bundling` project and then run `repl.js` with `BUILD_THIRD_PARTY` enabled:

```
# Prepare the `playground-bundling` project to allow building of the third party cmij packages
npm link
cd packages/playground-bundling
npm install
npm link rescript

BUILD_THIRD_PARTY=true node scripts/repl.js
```

_Troubleshooting: if ninja build step failed with `Error: cannot find file '+runtime.js'`, make sure `ocamlfind` is installed with `opam install ocamlfind`._

After a successful compilation, you will find following files in your project:

- `playground/exports.js` -> This is the ReScript compiler, which binds the ReScript API to the `window` object.
- `playground/compiler.js` -> This is the ReScript compiler, which binds the ReScript API to the `window` object.
- `playground/stdlib/*.js` -> All the ReScript runtime files.
- `playground/packages` -> Contains third party deps with cmij.js files (as defined in `packages/playground-bundling/bsconfig.json`)

You can now use the `exports.js` file either directly by using a `<script src="/path/to/exports.js"/>` inside a html file, use a browser bundler infrastructure to optimize it, or you can even use it with `nodejs`:
You can now use the `compiler.js` file either directly by using a `<script src="/path/to/compiler.js"/>` inside a html file, use a browser bundler infrastructure to optimize it, or you can even use it with `nodejs`:

```
$ node
> require("./exports.js");
> require("./compiler.js");
> let compiler = rescript_compiler.make()
> let result = compiler.rescript.compile(`Js.log(Sys.ocaml_version)`);
> eval(result.js_code);
4.06.2+BS
```

You can also run `node playground/playground_test.js` for a quick sanity check to see if all the build artifacts are working together correctly.

### Playground JS bundle API

As soon as the bundle is loaded, you will get access to the functions exposed in [`jsoo_playground_main.ml`](jscomp/main/jsoo_playground_main.ml). Best way to check out the API is by inspecting a compiler instance it either in node, or in the browser:

```
$ node
require('./exports.js')
require('./compiler.js')

> let compiler = rescript_compiler.make()
> console.log(compiler)
Expand All @@ -281,7 +284,7 @@ Whenever you are modifying any files in the ReScript compiler, or in the `jsoo_p

```sh
node scripts/ninja.js config && node scripts/ninja.js build
PLAYGROUND=../playground node scripts/repl.js
node scripts/repl.js
```

**.cmj files in the Web**
Expand All @@ -292,11 +295,23 @@ A `.cmi` file is an [OCaml originated file extension](https://waleedkhan.name/bl

In this repo, these files usually sit right next to each compiled `.ml` / `.res` file. The structure of a `.cmj` file is defined in [js_cmj_format.ml](jscomp/core/js_cmj_format.ml). You can run a tool called `./jscomp/bin/cmjdump.exe [some-file.cmj]` to inspect the contents of given `.cmj` file.

`.cmj` files are required for making ReScript compile modules (this includes modules like ReasonReact). ReScript includes a subset of modules by default, which can be found in `jscomp/stdlib-406` and `jscomp/others`. You can also find those modules listed in the `jsoo` call in `scripts/repl.js`. As you probably noticed, the generated `playground` files are all plain `.js`, so how are the `cmj` / `cmi` files embedded?
`.cmj` files are required to compile modules (this includes modules like RescriptReact). ReScript includes a subset of modules by default, which can be found in `jscomp/stdlib-406` and `jscomp/others`. You can also find those modules listed in the JSOO call in `scripts/repl.js`. As you probably noticed, the generated `playground` files are all plain `.js`, so how are the `cmj` / `cmi` files embedded?

JSOO offers an `build-fs` subcommand that takes a list of `.cmi` and `.cmj` files and creates a `cmij.js` file that can be loaded by the JS runtime **after** the `compiler.js` bundle has been loaded (either via a `require()` call in Node, or via `<link/>` directive in an HTML file). Since we are shipping our playground with third party modules like `RescriptReact`, we created a utility directory `packages/playground-bundling` that comes with a utility script to do the `cmij.js` file creation for us. Check out `packages/playground-bundling/scripts/generate_cmijs.js` for details.

`repl.js` calls an executable called `cmjbrowser.exe` on every build, which is a compile artifact from `jscomp/main/jscmj_main.ml`. It is used to serialize `cmj` / `cmi` artifacts into two files called `jscomp/core/js_cmj_datasets.ml`. These files are only linked for the browser target, where ReScript doesn't have access to the filesystem. When working on BS, you'll see diffs on those files whenever there are changes on core modules, e.g. stdlib modules or when the ocaml version was changed. We usually check in these files to keep it in sync with the most recent compiler implementation. JSOO will pick up those files to encode them into the `exports.js` bundle.
### Publishing the Playground Bundle on our KeyCDN

> Note: If you want to publish from your local machine, make sure to set the `KEYCDN_USER` and `KEYCDN_PASSWORD` environment variables accordingly (credentials currently managed by @ryyppy). Our CI servers / GH Action servers are already pre-configured with the right env variable values.

Our `compiler.js` and third-party packages bundles are hosted on [KeyCDN](https://www.keycdn.com) and uploaded via FTPS.

After a successful bundle build, run our upload script to publish the build artifacts to our server:

```
playground/upload_bundle.sh
```

For any other dependency needed in the playground, such as `ReasonReact`, you will be required to serialize your `.cmi` / `.cmt` files accordingly from binary to hex encoded strings so that BS Playground's `ocaml.load` function can load the data. Right now we don't provide any instructions inside here yet, but [here's how the official ReasonML playground did it](https://github.com/reasonml/reasonml.github.io/blob/source/website/setupSomeArtifacts.js#L65).
The script will automatically detect the ReScript version from the `compiler.js` bundle and automatically create the correct directory structure on our CDN ftp server.

## Contribute to the API Reference

Expand Down
Loading