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

Building plugin with swc_core 0.88.* leads to segfault / bus error (0.87.* working) #8540

Closed
Codex- opened this issue Jan 23, 2024 · 8 comments
Labels

Comments

@Codex-
Copy link

Codex- commented Jan 23, 2024

Describe the bug

I author swc-plugin-import-meta-env and have found when bumping the swc_core crates to 0.88.* the built wasm causes a segfault when used with @swc/jest

This issue was raised which provided this minimal reproduction: https://github.com/HermanBilous/test-swc-jest

The plugin contains this for swc_core:

[dependencies]
swc_core = { version = "0.88.*", features = [
    "ecma_plugin_transform",
    "trace_macro",
] }

When reverting swc_core to 0.87.* the plugin works as expected again.

Input code

No response

Config

No response

Playground link (or link to the minimal reproduction)

https://github.com/Codex-/swc-plugin-error

SWC Info output

No response

Expected behavior

No bus error or segfault

Actual behavior

After reverting, renovate tried to bump this again which was blocked by the integration tests I added:
https://github.com/Codex-/swc-plugin-import-meta-env/actions/runs/7619428112/job/20752472293?pr=36

With SWC_LOG=info RUST_BACKTRACE=1

➜  test-swc-jest git:(main) ✗ SWC_LOG=info RUST_BACKTRACE=1 npx jest

 RUNS  src/add.test.ts
   INFO  Done in 13.565917ms, kind: "perf"
    at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_timer-0.21.14/src/lib.rs:32
    in Compiler.parse
    in parse_js_as_input
    in process_js_with_custom_pass
    in process_js_file with fm: SourceFile(/Users/alexmiller/dev/issue/test-swc-jest/src/add.test.ts)

[1]    66485 bus error

Running multiple times gives different errors

> SWC_LOG=info RUST_BACKTRACE=1 npx jest --config ./tests/integration/jest.config.cjs --no-cache --runInBand


 RUNS  tests/integration/src/typescript.test.ts
   INFO  Done in 248.700042ms, kind: "perf"
    at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_timer-0.21.14/src/lib.rs:32
    in Compiler.parse
    in parse_js_as_input
    in process_js_with_custom_pass
    in process_js_file with fm: SourceFile(/Users/alexmiller/dev/issue/swc-plugin-error/tests/integration/src/typescript.test.ts)

sh: line 1: 74251 Segmentation fault: 11  pnpm run test:integration
memory allocation of 3117855127680 bytes failed
75266 Bus error: 10

Version

1.3.105

Additional context

No response

@Codex- Codex- added the C-bug label Jan 23, 2024
@kwonoj
Copy link
Member

kwonoj commented Jan 23, 2024

I think this is dupe of #7479

@kdy1
Copy link
Member

kdy1 commented Jan 23, 2024

The serialized form/memory layout of AST of 0.88.x is different from the old versions.
Please see https://swc.rs/docs/plugin/selecting-swc-core

This is duplicate of #5060

@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2024
@Codex-
Copy link
Author

Codex- commented Jan 23, 2024

Excellent, thanks @kdy1

@kireevmp
Copy link

While it's understandable the breaking changes in AST will appear, is there an existing/planned way for swc or plugin authors to notify users that the AST version does not match and the plugin will fail?

A SEGFAULT and BUS ERROR isn't the best error message we can provide to the user

@kwonoj
Copy link
Member

kwonoj commented Jan 26, 2024

Refer pinned issue.

@Codex-
Copy link
Author

Codex- commented Jan 27, 2024

@kireevmp to be fair, plugins are still experimental

@kireevmp
Copy link

kireevmp commented Jan 27, 2024

True, @Codex-, and I appreciate all the team's work to get even to this point. Making plugins backward-compatible would be a great feat, but that's not what I'm talking about here

Is allowing the plugin to fail gracefully when the AST version mismatches possible? It would go a long way if we could show a meaningful message, like

plugin-name@old-version is incompatible with your @swc/core, please install plugin-name@new-version

Even if the compatibility information is provided by the plugin developer, and not the SWC team, I feel this would be a significant boost to the end-user experience

@swc-bot
Copy link
Collaborator

swc-bot commented Feb 27, 2024

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Feb 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

5 participants