-
Notifications
You must be signed in to change notification settings - Fork 471
Improve option optimization for constants #7913
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
|
||
function constant() { | ||
console.log(42); | ||
} |
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.
Before this change:
function constant() {
let opt = 42;
if (opt !== undefined) {
console.log(opt);
return;
}
}
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
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.
This looks great.
I have a process going trying to find adversarial attacks, as an experiment.
This change looks so simple and clearly right, I don't expect surprises.
CODEX review: The new clause in You can see the behavioural change with a tiny repro that smuggles an let foo: option<int> = Obj.magic(Some(Obj.magic(None: option<int>)))
let res =
switch foo {
| Some(_) => "some"
| None => "none"
}
Js.log(res)
I verified this by locally reverting the new Could we gate the optimisation on |
CODEX follow-up: You’re absolutely right—the simplified JS ( |
However, the report is legit in a wider sense. |
I think with incorrect externals, all bets are off. |
Optimizes the option alias pass so we skip the redundant is-not-none guard whenever the compiler already knows the value is
Some
, which trims the JS we emit for simple constant cases.