Skip to content
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

fix(es/minifier): Remove pure function used by variable initialization #9107

Closed
wants to merge 1 commit into from

Conversation

CPunisher
Copy link
Contributor

Description:

https://play.swc.rs/?version=1.6.5&code=H4sIAAAAAAAAA9PXVygvyixJVcgvUihILAYykvNTUhUyUotSubjKEosUwlNTs10SKxVsFfS1lOPjA0KDXOPjtfQVNNJK85JLMvPzFDSgSow0Faq5FGAajPQSgXqUgkvzUhIrlayBEkWpJaVFeXB5rlpNmE6FmhqF6lpNay4ADxpWp44AAAA%3D&config=H4sIAAAAAAAAA4WVO47jMAxA%2B5wiUD3FIsUWc4Dt5gyCYlGOsvoYIpWJMcjdl7aTiSdr2q4M8okUv%2Fra7ffqjI1633%2Fx7%2FSpzhSE8kPGUuwTmStLFTTRYFN8R%2BptTpxxUDsTEL7FtyehQs4ID2Imjz5517%2F6a3LsCiC%2ByFljSlsjJML%2Fbd31JX8OSir1VXfMOYBJG1ptUPtE0EKRnDQ5BNMh6IspgrUhAlM8ZsndAFQCq7uSO5FJ1pPPie%2BwTFgwVjfZgqD2BRryF5COs28%2BnpBDF2IdEQvH2rZjXyxYgYsJ1ZBwB7iOpeQoBA%2Bn7JG0q0lK9wSs5GkC7sVYsuCdLkC1pOXz5%2BzTSi3%2FAnCWgkFMJoLkY6Qc9%2BeaFbdpwSfHI0G9wPAcSVlI0HIRtPdOqMSQQSjkpW4oYGsDQyUa6Yp3ZCXV6C1ocI77TnCDn56ak3QJ6jvITlByjxgndeqk1N8bYIUZhm8D%2BcNZILlp71Q0dFonsI%2FHHDacRaBTthsQl4%2FyOlJ4a127daYmC9xiYEWs4qhcXkg8aJR1AJJ6jEeRres25ONzbc2g2%2FyEiia1z92z%2BHQQz9ToTgEefh0O%2FPDsZszzCZlFozx%2BZFvDz0lQ8SF7vCpju02mf6vJ6u72Dzzk3g4aBwAA

The above code will not be optimized in SWC but will be optimized in Terser. Terser analyzes variable usage step-by-step, so it first determines whether WeekDay is used at the top level. It does not consider the parameter in the call expression within the variable declaration as a reference to this variable. Additionally, Terser does not inline pure functions because inlining them would directly result in the variable being referenced at the top level.

See: https://github.com/terser/terser/blob/master/lib/compress/inline.js#L347

Perhaps this variable should be optimized during the DCE (Dead Code Elimination) phase? However, the DCE phase cannot determine the pure mark.

Maybe a more fundamental reason is that all side effect determinations should directly consider the pure mark, like: https://github.com/terser/terser/blob/9083832e6818eeda9b892c4140716a3d3a2632b7/lib/compress/inference.js#L884

I am not sure if the code I modified is correct, and I am somewhat confused about the determination of side effects and pure marks in the project...

BREAKING CHANGE:

Related issue (if exists):

@CPunisher CPunisher requested a review from a team as a code owner June 26, 2024 07:55
@CLAassistant
Copy link

CLAassistant commented Jun 26, 2024

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@kdy1
Copy link
Member

kdy1 commented Jun 29, 2024

Can you run UPDATE=1 cargo test -p swc -p swc_ecma_minifier --features concurrent and commit/push the changes?

@CPunisher CPunisher closed this Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants