Skip to content
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

Add %ffi as variation of %raw with arity checking. #6251

Merged
merged 8 commits into from
May 23, 2023
Merged

Conversation

cristianoc
Copy link
Collaborator

@cristianoc cristianoc commented May 13, 2023

Add %ffi extension which is a variation of %raw taking arity into account.
The argument string is parsed as JS function, the arity extracted, and used to wrap the expression in a type constraint.
For example, arity 2 constrains to type (_, _) => _ so just the shape of a function with 2 arguments.

See #6213

% cat tst.res           
let canUseCanvas: unit => bool = %ffi(`
  function canUseCanvas() {
    return !!document.createElement('canvas').getContext;
  }
`)

@cristianoc cristianoc requested a review from zth May 13, 2023 02:37
@cristianoc cristianoc changed the title Begin exposing %raw arity Add %ffi as variation of %raw with arity checking. May 14, 2023
@cristianoc cristianoc requested a review from zth May 15, 2023 00:55
Copy link
Collaborator

@zth zth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Great stuff.

Only print to stderr for now?

See #6213
Move to using `%ffi` extension to avoid breaking changes, and begin checking arity zero.

For a JS function of arity 0, check that the ReScript type is `unit => _`.
Extend arity check to all arities.

Iterate on the error message so gpt3.5 can figure out a correct fix when given the error message with no context.
@cristianoc cristianoc merged commit c72928e into master May 23, 2023
2 checks passed
@cristianoc cristianoc deleted the raw_arity branch May 23, 2023 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants