rescript-lang / rescript-compiler

The compiler for ReScript.
https://rescript-lang.org
Other
6.7k stars 447 forks source link

Gate future features behind an @@experimental directive. #6262

Closed cristianoc closed 1 month ago

cristianoc commented 1 year ago

Sometimes features in the compiler are ready ahead of time, but for some reason they belong to the next version of the compiler. Instead of letting them leave in some branch, that needs rebasing and maintenance, they can be gated under an @@future directive. The idea is that

@@future

...

will enable all the future features.

And one can select individual one using @@future(feat1, feat2)

cristianoc commented 1 year ago

Here's a test of how easily one can pick up the meaning of this as well as the %ffi directive with no previous context.

Interactive session with gpt3.5.

What does this ReScript code do?

@@future(uncurriedByDefault, ffiArityCheck)

let sum : (int, int) => int = %ffi(function(x,y) { return x+y; })

This ReScript code defines a function called sum that takes two integers as arguments and returns an integer. The function is implemented using a foreign function interface (FFI) to call a JavaScript function that performs the addition.

Here's a breakdown of the code:

In summary, this code defines a ReScript function sum that uses an FFI to call a JavaScript function responsible for adding two numbers.

Explain the future directive to me.

The @@future directive in ReScript is used to enable and configure the usage of experimental language features. It allows you to opt into features that are still under development or may not be fully supported or stable yet.

The @@future directive takes one or more arguments that specify the options for the enabled features. These options are comma-separated and enclosed in parentheses.

Here are a couple of options commonly used with @@future:

It's important to note that features enabled using @@future are experimental and subject to change. They may not be fully supported or behave as expected. Therefore, it's recommended to use them with caution and be aware of the potential risks and limitations.

The @@future directive allows developers to experiment with upcoming language features and provide feedback to the ReScript development team, contributing to the evolution of the language.

zth commented 1 year ago

Should this be accompanied by an option in the config as well? So things can be turned on project wide.

cristianoc commented 1 year ago

Should this be accompanied by an option in the config as well? So things can be turned on project wide.

Yes

ryyppy commented 1 year ago

probably something for the upcoming rescript.json file @cometkim

cristianoc commented 1 year ago

probably something for the upcoming rescript.json file @cometkim

Actually we could merge the rescript.json PR pretty soon if we could gate it, no need to wait for v11. Goes both ways.

The other natural one is this https://github.com/rescript-lang/rescript-compiler/pull/6102 as it's ready to do but we don't want to cause too many output changes for people who try out v11.

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.