Skip to content

Comments

feat(minifier): implement known methods Math.clz32 and Math.imul#12405

Merged
sapphi-red merged 2 commits intooxc-project:mainfrom
7086cmd:feat/minifier-math-clz32-imul
Aug 24, 2025
Merged

feat(minifier): implement known methods Math.clz32 and Math.imul#12405
sapphi-red merged 2 commits intooxc-project:mainfrom
7086cmd:feat/minifier-math-clz32-imul

Conversation

@7086cmd
Copy link
Contributor

@7086cmd 7086cmd commented Jul 20, 2025

The known methods module of Number and Math only left Math.pow unimplemented!

@graphite-app
Copy link
Contributor

graphite-app bot commented Jul 20, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@github-actions github-actions bot added A-minifier Area - Minifier C-enhancement Category - New feature or request labels Jul 20, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Jul 20, 2025

CodSpeed Instrumentation Performance Report

Merging #12405 will not alter performance

Comparing 7086cmd:feat/minifier-math-clz32-imul (ff623b6) with main (2a21d1b)

Summary

✅ 34 untouched benchmarks

@sapphi-red sapphi-red self-assigned this Aug 9, 2025
Copilot AI review requested due to automatic review settings August 23, 2025 16:19
@sapphi-red sapphi-red force-pushed the feat/minifier-math-clz32-imul branch from 8c5413f to b62804c Compare August 23, 2025 16:19
@github-actions github-actions bot added A-transformer Area - Transformer / Transpiler A-isolated-declarations Isolated Declarations labels Aug 23, 2025
@sapphi-red sapphi-red changed the base branch from main to 08-24-refactor_ecmascript_add_touint32_trait August 23, 2025 16:20
Copy link
Contributor

Copilot AI left a 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 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 ToUint32 trait that builds on ToInt32 for unsigned 32-bit integer conversions
  • Implements constant folding for Math.clz32 (count leading zeros) and Math.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.

@sapphi-red sapphi-red marked this pull request as draft August 23, 2025 16:20
@sapphi-red
Copy link
Member

Based on the request, I took over this one. I rebased on top of #13272 and refactored a bit.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@graphite-app graphite-app bot force-pushed the 08-24-refactor_ecmascript_add_touint32_trait branch from 0f4ad8b to 66a5673 Compare August 24, 2025 01:08
@graphite-app graphite-app bot deleted the branch oxc-project:main August 24, 2025 01:14
@graphite-app graphite-app bot closed this Aug 24, 2025
@sapphi-red sapphi-red reopened this Aug 24, 2025
@sapphi-red sapphi-red changed the base branch from 08-24-refactor_ecmascript_add_touint32_trait to main August 24, 2025 04:23
@sapphi-red sapphi-red force-pushed the feat/minifier-math-clz32-imul branch from b62804c to ff623b6 Compare August 24, 2025 04:23
@sapphi-red sapphi-red marked this pull request as ready for review August 24, 2025 04:25
@sapphi-red sapphi-red merged commit a1b6ad4 into oxc-project:main Aug 24, 2025
24 checks passed
@sapphi-red sapphi-red removed A-transformer Area - Transformer / Transpiler A-isolated-declarations Isolated Declarations labels Aug 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants