Skip to content

Crash with files that have too deeply nested ASTs #1627

@mischnic

Description

@mischnic

Describe the bug

Especially debug swc builds easily crash with a stack overflow for not-so-large input files, for example

Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Codes: KERN_PROTECTION_FAILURE at 0x000070000aea96e0 Exception Note: EXC_CORPSE_NOTIFY 0 swc.darwin-x64.node	0x000000010aa014a9 _$LT$swc_ecma_transforms_compat..es2015..template_literal..TemplateLiteral$u20$as$u20$swc_ecma_visit..Fold$GT$::fold_expr::hd97ea0c1d90812be + 41 (template_literal.rs:27) 1 swc.darwin-x64.node	0x000000010abb7a7d swc_ecma_visit::fold_bin_expr::hb48857750e72e52d + 333 (lib.rs:414) 2 swc.darwin-x64.node	0x000000010aacf3eb swc_ecma_visit::Fold::fold_bin_expr::hb192c8b94e28d940 + 59 3 swc.darwin-x64.node	0x000000010b128203 swc_ecma_visit::fold_expr::ha5de18fc24f14652 + 1603 (lib.rs:414) 4 swc.darwin-x64.node	0x000000010a832203 _$LT$swc_ecma_ast..expr..Expr$u20$as$u20$swc_ecma_visit..FoldWith$LT$V$GT$$GT$::fold_children_with::h3e0bab8c2d6f35d8 + 99 5 swc.darwin-x64.node	0x000000010aa015cf _$LT$swc_ecma_transforms_compat..es2015..template_literal..TemplateLiteral$u20$as$u20$swc_ecma_visit..Fold$GT$::fold_expr::hd97ea0c1d90812be + 335 (template_literal.rs:28) 6 swc.darwin-x64.node	0x000000010abb7a7d swc_ecma_visit::fold_bin_expr::hb48857750e72e52d + 333 (lib.rs:414) 7 swc.darwin-x64.node	0x000000010aacf3eb swc_ecma_visit::Fold::fold_bin_expr::hb192c8b94e28d940 + 59 8 swc.darwin-x64.node	0x000000010b128203 swc_ecma_visit::fold_expr::ha5de18fc24f14652 + 1603 (lib.rs:414) 9 swc.darwin-x64.node	0x000000010a832203 _$LT$swc_ecma_ast..expr..Expr$u20$as$u20$swc_ecma_visit..FoldWith$LT$V$GT$$GT$::fold_children_with::h3e0bab8c2d6f35d8 + 99 10 swc.darwin-x64.node	0x000000010aa015cf _$LT$swc_ecma_transforms_compat..es2015..template_literal..TemplateLiteral$u20$as$u20$swc_ecma_visit..Fold$GT$::fold_expr::hd97ea0c1d90812be + 335 (template_literal.rs:28) 11 swc.darwin-x64.node	0x000000010abb7a7d swc_ecma_visit::fold_bin_expr::hb48857750e72e52d + 333 (lib.rs:414) 12 swc.darwin-x64.node	0x000000010aacf3eb swc_ecma_visit::Fold::fold_bin_expr::hb192c8b94e28d940 + 59 13 swc.darwin-x64.node	0x000000010b128203 swc_ecma_visit::fold_expr::ha5de18fc24f14652 + 1603 (lib.rs:414) 14 swc.darwin-x64.node	0x000000010a832203 _$LT$swc_ecma_ast..expr..Expr$u20$as$u20$swc_ecma_visit..FoldWith$LT$V$GT$$GT$::fold_children_with::h3e0bab8c2d6f35d8 + 99 15 swc.darwin-x64.node	0x000000010aa015cf _$LT$swc_ecma_transforms_compat..es2015..template_literal..TemplateLiteral$u20$as$u20$swc_ecma_visit..Fold$GT$::fold_expr::hd97ea0c1d90812be + 335 (template_literal.rs:28) 

Input code

console.log( 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1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 );

Config

const swc = require("."); const INPUT = `<the input code>`; swc .transform(INPUT, { // Some options cannot be specified in .swcrc filename: "input.js", // All options below can be configured via .swcrc jsc: { parser: { syntax: "ecmascript", }, transform: {}, }, }) .then((output) => { console.log(output.code); });

Expected behavior
Doesn't crash

Version
d1415f9

(Run yarn build:dev in the cloned repo and execute the file above)

Additional context
The actual file that caused this for crash: https://github.com/parcel-bundler/parcel/blob/1f04a4a/packages/core/integration-tests/test/integration/scope-hoisting/es6/shared-bundle-reexport/shared/a.js

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions