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 building parcel with a debug build of itself #9829

Merged
merged 6 commits into from
Jul 2, 2024
Merged

Conversation

yamadapc
Copy link
Contributor

@yamadapc yamadapc commented Jul 1, 2024

This commit fixes a segmentation fault in parcel when building itself using a debug build of its native extensions.

This would previously crash due to usage of Fold and its recursive nature.

All expressions will recurse in the typeof replacer code, so SWC will crash if a module has large enough expressions, which is a case that does happen within parcel own dependencies.

This should improve performance and is the recommended usage by SWC

/discussions/9828

This commit fixes a segmentation fault in parcel when building itself
using a debug build of its native extensions.

This would previously crash due to usage of `Fold` and its recursive
nature.

All expressions will recurse in the typeof replacer code, so SWC will
crash if a module has large enough expressions, which is a case that
does happen within parcel own dependencies.

This should improve performance and is the recommended usage by SWC
* #9828
We should replace all SWC transformations from `Fold` to `VisitMut`.

/discussions/9828
@@ -388,7 +384,12 @@ pub fn transform(
),
);

module.fold_with(&mut passes)
let mut module = module.fold_with(&mut passes);
if config.source_type != SourceType::Script {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be done before passes so that the other optimisations (e.g. dead branch, paren remover, etc) are guaranteed to execute?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I think you're right; I've put it back in the same place surrounded with an as_folder which will wrap the visit-mut with a top-level Fold instance that just implements fold_module by calling into the visitor

Copy link
Contributor

@MonicaOlejniczak MonicaOlejniczak left a comment

Choose a reason for hiding this comment

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

👏 for figuring this out! It looks like this broke a couple of tests legitimately, it's probably something subtle that needs to be fixed prior to merging.

@yamadapc yamadapc merged commit 7ae35de into v2 Jul 2, 2024
17 checks passed
@MonicaOlejniczak MonicaOlejniczak deleted the no-swc-fold-on-typeof branch July 2, 2024 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants