-
Notifications
You must be signed in to change notification settings - Fork 469
Ignore inferred arity in case of %raw
.
#7542
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
Conversation
avoids a type error with rescript v12 cf rescript-lang/rescript#7542
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cristianoc this means inferred arity will be ignored even when there's no type signature, right? It's dangerous anyway since it doesn't reflect it in the types.
I guess you can still use %ffi if you want to type your js code. We should likely document %ffi by the way.
The inferred arity of raw JS code is actively used with `%ffi`, but it can produce unexpected results with `%raw`: ``` let foo: int => int = %raw(`function add(x, y=5){ return x + y }`) Console.log(foo(2)) ```
b21c81d
to
327280d
Compare
%raw
.%raw
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR disables the inferred arity for raw JavaScript code passed to %raw
, ensuring that the provided type annotations (e.g. int => int) are respected rather than inferring parameters from the raw JS function.
- Updated tests to validate the behavior with raw JS code.
- Removed logic handling arity inference for
%raw
code in the compiler passes. - Updated the CHANGELOG to document this bug fix.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
tests/tests/src/raw_arity.res | Adds a test using %raw to confirm that arity inference is disabled. |
tests/tests/src/raw_arity.mjs | Mirrors the Rescript test for raw JS code in JavaScript. |
compiler/core/lam_pass_collect.ml | Removes the arity inference logic for %raw JS code in the lam pass collection. |
compiler/core/lam_arity_analysis.ml | Removes the arity inference handling for %raw JS functions in arity analysis. |
CHANGELOG.md | Documents the bug fix regarding raw JS arity inference. |
Comments suppressed due to low confidence (2)
compiler/core/lam_pass_collect.ml:64
- Ensure that the removal of arity inference is paired with proper fallback handling for
%raw
usage, and consider adding a clarifying comment to explain why this case is now ignored.
| Lprim {primitive = Psome | Psome_not_nest; args = [v]} ->
compiler/core/lam_arity_analysis.ml:69
- Confirm that dropping this case does not affect other related arity analyses, and add inline documentation linking this change to the PR rationale for future maintainability.
with
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/win32-x64
commit: |
The inferred arity of raw JS code is actively used with
%ffi
, but it can produce unexpected results with%raw
:This PR tests turning off the use of inferred arity so that
int => int
above is just taken at face value.