- Notifications
You must be signed in to change notification settings - Fork471
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| functionconstant(){ | ||
| 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:
functionconstant(){letopt=42;if(opt!==undefined){console.log(opt);return;}}
pkg-pr-newbot commentedSep 20, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
rescript@rescript/darwin-arm64@rescript/darwin-x64@rescript/linux-arm64@rescript/linux-x64@rescript/runtime@rescript/win32-x64commit: |
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 letfoo:option<int>=Obj.magic(Some(Obj.magic(None:option<int>)))letres=switchfoo { |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. |
645e1a9 intomasterUh oh!
There was an error while loading.Please reload this page.
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.