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

Bump swc #9574

Open
wants to merge 13 commits into
base: v2
Choose a base branch
from
Open

Bump swc #9574

wants to merge 13 commits into from

Conversation

mischnic
Copy link
Member

@mischnic mischnic commented Mar 11, 2024

Closes #9632
Closes #9607

There's a major breaking change, the LHS of assignments is now a special enum.

There's one place which I haven't been able to fix yet. Putting this up in case someone else wants to bump swc sooner rather than later for some reason

@mischnic
Copy link
Member Author

Even in release builds, there is a segfault now in the EnvReplacer, the stack trace does many fold_expr -> fold_bin_expr -> fold_expr -> .... Happens on this file, which has a string concatenation expression containing 750 +: https://github.com/highlightjs/highlight.js/blob/105a11a13eedbf830c0e80cc052028ceb593837f/src/languages/isbl.js

Usually, this is only a problem (and has happened for a long time) in non-release builds.

But only on Linux and Windows, macOS works fine.

@mischnic mischnic marked this pull request as ready for review March 16, 2024 13:02
@mischnic mischnic force-pushed the bump-swc branch 2 times, most recently from 9109912 to dd8513d Compare March 19, 2024 19:56
@mischnic
Copy link
Member Author

The same asset also works fine in a standalone Rust projects (with the exact code as the JSTransformer, just without the Node process).
So I guess the stack occupied by Node plus the recursion in swc triggers the crash, and with just Rust the stack space is enough. And macOS probably also has more stack

@marcins
Copy link
Contributor

marcins commented Mar 25, 2024

The same asset also works fine in a standalone Rust projects (with the exact code as the JSTransformer, just without the Node process). So I guess the stack occupied by Node plus the recursion in swc triggers the crash, and with just Rust the stack space is enough. And macOS probably also has more stack

Not really an area I have any experience in, but a quick search shows that is possible to increase the stack size with some linker flags: https://www.reddit.com/r/rust/comments/872fc4/how_to_increase_the_stack_size/

Is that worth experimenting with?

EDIT: read something else that mentioned threads on linux specifically have a smaller stack, maybe we need to increase the Rayon thread stack size (that's where this code is running, right?): https://docs.rs/rayon/latest/rayon/struct.ThreadPoolBuilder.html#method.stack_size

@mischnic
Copy link
Member Author

I want to try bisecting which swc version introduced this, because not much changed regarding the AST depth

So increasing the stack size would maybe just be a workaround until some future version.

@mischnic
Copy link
Member Author

As it turns out, this also occurs in Deno and Turbopack: swc-project/swc#8840

@mischnic mischnic marked this pull request as draft April 11, 2024 15:20
@mischnic mischnic force-pushed the bump-swc branch 2 times, most recently from 9022329 to 214a0b2 Compare April 12, 2024 08:05
@jondlm
Copy link
Contributor

jondlm commented May 7, 2024

Weirdly I couldn't reproduce even with PARCEL_WORKERS=0 on my machine. After a bunch of fiddling it looks like CI passes with a "red zone" of 32KiB in the main fold in the EnvReplacer. Hopefully that number holds 🙏

And yeah it looks like you're right about stack overflows not reporting a back trace. I should have known better than to trust gpt lol.

Copy link
Contributor

@jondlm jondlm left a comment

Choose a reason for hiding this comment

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

Not sure if my review is enough here but this LGTM.

@mischnic mischnic requested review from devongovett and a team May 8, 2024 18:48
@mischnic
Copy link
Member Author

mischnic commented May 8, 2024

No, Github doesn't see it as a approving review...

@jondlm
Copy link
Contributor

jondlm commented May 10, 2024

@devongovett when you have a moment could you review this PR? Normally I wouldn't bother with a ping but it's currently a blocker for us at Stripe. I think it's good to go it just needs an approving review.

Copy link
Contributor

@marcins marcins left a comment

Choose a reason for hiding this comment

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

Found a new bug that affects non-scope hoisted builds, needs to be fixed before merging.

@@ -594,7 +595,7 @@ impl Fold for ESMFold {
if self.in_export_decl {
self.create_export(
node.key.sym.clone(),
Expr::Ident(node.key.clone()),
Expr::Ident(node.key.id.clone()),
Copy link
Contributor

@marcins marcins May 13, 2024

Choose a reason for hiding this comment

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

Just sharing what I shared in Discord here, it seems that the change arround AssignPatProp means that after visiting here it will visit into fold_binding_intent, this results in a duplicate export being added for exports of the form export const { Foo } = bar; in non-scope hoisting mode - this breaks at runtime.

This change fixed the issue for me, but not sure if there's some edge case that it might not be correct for. It would be good to start with a failing integration test.

diff --git a/packages/transformers/js/core/src/modules.rs b/packages/transformers/js/core/src/modules.rs
index 65235f3c3..bd13d10b6 100644
--- a/packages/transformers/js/core/src/modules.rs
+++ b/packages/transformers/js/core/src/modules.rs
@@ -598,9 +598,11 @@ impl Fold for ESMFold {
         Expr::Ident(node.key.id.clone()),
         DUMMY_SP,
       );
+      node
+    } else {
+      node.fold_children_with(self)
     }
 
-    node.fold_children_with(self)
   }
 
   modules_visit_fn!(fold_function, Function);

@mischnic
Copy link
Member Author

mischnic commented May 14, 2024

@marcins @jondlm I fixed that problem, there's a new dev release published at parcel@2.0.0-dev.1606 if you want to test it again.

https://github.com/parcel-bundler/parcel/actions/runs/9077140040/job/24942042946

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants