feat(minifier): implement known methods Math.clz32 and Math.imul#12405
feat(minifier): implement known methods Math.clz32 and Math.imul#12405sapphi-red merged 2 commits intooxc-project:mainfrom
Math.clz32 and Math.imul#12405Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
CodSpeed Instrumentation Performance ReportMerging #12405 will not alter performanceComparing Summary
|
8c5413f to
b62804c
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR implements two new known methods for Math in the minifier: Math.clz32 and Math.imul. The PR also introduces a new ToUint32 trait and refactors existing code to use it for proper unsigned 32-bit integer conversions in shift operations.
- Adds
ToUint32trait that builds onToInt32for unsigned 32-bit integer conversions - Implements constant folding for
Math.clz32(count leading zeros) andMath.imul(32-bit integer multiplication) - Refactors shift operations to use proper unsigned conversion instead of casting
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
crates/oxc_ecmascript/src/to_int_32.rs |
Adds ToUint32 trait and comprehensive tests |
crates/oxc_ecmascript/src/lib.rs |
Exports the new ToUint32 trait |
crates/oxc_ecmascript/src/constant_evaluation/call_expr.rs |
Implements Math.clz32 and Math.imul constant folding |
crates/oxc_ecmascript/src/constant_evaluation/mod.rs |
Updates shift operations to use ToUint32 |
crates/oxc_transformer/src/typescript/enum.rs |
Updates enum evaluation to use ToUint32 for shift operations |
crates/oxc_isolated_declarations/src/enum.rs |
Updates isolated declarations to use ToUint32 for shift operations |
crates/oxc_minifier/src/peephole/replace_known_methods.rs |
Adds comprehensive tests for the new Math methods |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
Based on the request, I took over this one. I rebased on top of #13272 and refactored a bit. |
0f4ad8b to
66a5673
Compare
b62804c to
ff623b6
Compare
The known methods module of
NumberandMathonly leftMath.powunimplemented!