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

Panic from symbol rename failure #9523

Closed
airhorns opened this issue Sep 2, 2024 · 5 comments
Closed

Panic from symbol rename failure #9523

airhorns opened this issue Sep 2, 2024 · 5 comments
Labels
Milestone

Comments

@airhorns
Copy link

airhorns commented Sep 2, 2024

Describe the bug

When upgrading to @swc/core v1.7.19 or newer, I get a new panic when compiling and minifying:

thread '<unnamed>' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_transforms_base-0.145.0/src/rename/mod.rs:204:25:
internal error: entered unreachable code: ARDUINO_KW_type is already renamed to e, but it's renamed as n
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[webpack-cli] HookWebpackError: failed to handle: internal error: entered unreachable code: ARDUINO_KW_type is already renamed to e, but it's renamed as n

Stack backtrace:
   0: _napi_register_module_v1
   1: _wasmer_vm_imported_memory32_atomic_notify
   2: <unknown>
   3: <unknown>
   4: <unknown>
    at makeWebpackError (/Users/airhorns/Code/gadget/node_modules/.pnpm/webpack@5.88.2_@swc+core@1.7.19_webpack-cli@5.1.4/node_modules/webpack/lib/HookWebpackError.js:48:9)
    at /Users/airhorns/Code/gadget/node_modules/.pnpm/webpack@5.88.2_@swc+core@1.7.19_webpack-cli@5.1.4/node_modules/webpack/lib/Compilation.js:3068:12
    at eval (eval at create (/Users/airhorns/Code/gadget/node_modules/.pnpm/tapable@2.2.0/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:68:1)
-- inner error --
Error: failed to handle: internal error: entered unreachable code: ARDUINO_KW_type is already renamed to e, but it's renamed as n

Stack backtrace:
   0: _napi_register_module_v1
   1: _wasmer_vm_imported_memory32_atomic_notify
   2: <unknown>
   3: <unknown>
   4: <unknown>
caused by plugins in Compilation.hooks.processAssets
Error: failed to handle: internal error: entered unreachable code: ARDUINO_KW_type is already renamed to e, but it's renamed as n

Stack backtrace:
   0: _napi_register_module_v1
   1: _wasmer_vm_imported_memory32_atomic_notify
   2: <unknown>
   3: <unknown>
   4: <unknown>

@swc/core v1.7.18 works just fine. I bisected to find that v1.7.19 is the first version that fails like this for me, and it fails on v1.7.22 as well.

I am struggling to figure out what file or what element is even causing this error -- it's happening when building a very large TypeScript monorepo using SWC for TypeScript transpilation and minification via webpack and swc-loader. I tried:

  • running webpack with DEBUG="*" but didn't see anything useful there
  • searching for that ARDUINO_KW_type symbol in my codebase (not there) and in node_modules (also not there, searched with rg --hidden --no-ignore -g 'node_modules/**' 'ARDUINO_KW_type')
  • searching the internet for that symbol, couldn't find it anywhere!

I am not sure where it's coming from but if there are any other logs I can gather and share to help hunt this down please let me know. Please make some suggestions, I am happy to hunt just not quite sure how!

Input code

<unknown>

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "decorators": true,
      "dynamicImport": true
    },
    "target": "esnext",
    "externalHelpers": true,
    "experimental": {
      "plugins": [
        ["@swc/plugin-loadable-components", {}],
        [
          "@swc/plugin-transform-imports",
          {
            "lodash": {
              "transform": "lodash/{{member}}"
            }
          }
        ]
      ]
    }
  },
  "module": {
    "type": "es6"
  }
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.19&code=H4sIAAAAAAAAA0vLzwcAIWVzjAMAAAA%3D&config=H4sIAAAAAAAAA1WPSw7DIAwF9zkF8rrbdtE79BAWdSIifrKJVBTl7iUE0maH3xsz8jooBbNoeKq1PMsQkYX4nEsi2Sf8lARIOxTNJia49XaWvRrRCtVoOxpIyBOluiX3hoMNQajjLXPGmzH%2FC3VwkUnkCu4o%2BsnSVTc0JbjwXmrZDkk50qF%2FwA%2FqsvNjMPLqm4kXGrYvhlQioBQBAAA%3D

SWC Info output

Operating System:
    Platform: darwin
    Arch: arm64
    Machine Type: arm64
    Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:04 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6020
    CPU: (12 cores)
        Models: Apple M2 Max

Binaries:
    Node: 22.2.0
    npm: 10.7.0
    Yarn: 1.22.22
    pnpm: 8.12.0

Relevant Packages:
    @swc/core: 1.7.19
    @swc/helpers: 0.5.12
    @swc/types: 0.1.12
    typescript: 5.6.0-beta

SWC Config:
    output: N/A
    .swcrc path: N/A

Next.js info:
    output: N/A

Expected behavior

No panic thrown, code is assembled as normal

Actual behavior

Panic is thrown

Version

1.7.19

Additional context

No response

@airhorns airhorns added the C-bug label Sep 2, 2024
@kdy1
Copy link
Member

kdy1 commented Sep 2, 2024

How did you invoke SWC? Minifier mangle cache is not enabled by default at now.

@kdy1
Copy link
Member

kdy1 commented Sep 2, 2024

Relevant code:

if let Some(total_map) = &mut self.total_map {
total_map.reserve(map.len());
for (k, v) in &map {
match total_map.entry(k.clone()) {
Entry::Occupied(old) => {
unreachable!(
"{} is already renamed to {}, but it's renamed as {}",
k.0,
old.get(),
v
);
}
Entry::Vacant(e) => {
e.insert(v.clone());
}
}
}
}

total_map is Some iff get_cached returns Some

fn load_cache(&mut self) {
if let Some(cache) = self.renamer.get_cached() {
self.previous_cache = cache.into_owned();
self.total_map = Some(Default::default());
}
}
.

@kdy1 kdy1 added this to the Planned milestone Sep 2, 2024
@kdy1
Copy link
Member

kdy1 commented Sep 2, 2024

Fixed by #9524

@kdy1 kdy1 closed this as completed Sep 2, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.7.23 Sep 2, 2024
@tonyabracadabra
Copy link

I've posted an issue for Next.js here. I hope you're able to replicate the issue, and that it can be resolved in an upcoming canary release. Thanks for your attention to this!

@airhorns
Copy link
Author

airhorns commented Sep 3, 2024

@tonyabracadabra the issue has already been fixed in swc core and is in PR for next here: vercel/next.js#69605

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants