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

@swc/wasm-typescript exits on Windows arm64 when fed with certain syntax #9520

Open
wojtekmaj opened this issue Aug 31, 2024 · 13 comments
Open
Assignees
Labels
Milestone

Comments

@wojtekmaj
Copy link

wojtekmaj commented Aug 31, 2024

Describe the bug

After investigation in nodejs/node#54645 I finally came to conclusion that on Windows arm64 (this particular configuration, not Windows other than arm64, not arm64 other than Windows), swc fails to transform certain syntax and just silently exits instead.

Input code

export function foo() {
	if (false) {
	}
	return 'foo';
};

Config

n/a

Playground link (or link to the minimal reproduction)

https://gist.github.com/wojtekmaj/c37e1eb07676cde83e5201ade8b7f02f

SWC Info output

Operating System:
    Platform: win32
    Arch: arm64
    Machine Type: unknown
    Version: Windows 11 Home
    CPU: (12 cores)
        Models: Snapdragon(R) X 12-core X1E80100 @ 3.40 GHz

Binaries:
    Node: 22.7.0
    npm: N/A
    Yarn: N/A
    pnpm: N/A

Relevant Packages:
    @swc/core: N/A
    @swc/helpers: N/A
    @swc/types: N/A


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

Next.js info:
    output: N/A

Expected behavior

Code should be transformed, types should be stripped, swc should not silently exit.

Actual behavior

swc silently exists, and neither the output, nor "End 2" console.log (see playground link) never appears on the screen.

Version

1.7.22

Additional context

No response

@kdy1 kdy1 added this to the Planned milestone Sep 1, 2024
@wojtekmaj wojtekmaj changed the title @swc/wasm-typescript exists on Windows arm64 when fed with certain syntax @swc/wasm-typescript exits on Windows arm64 when fed with certain syntax Sep 1, 2024
@kdy1 kdy1 self-assigned this Sep 3, 2024
@magic-akari
Copy link
Member

Is this issue only related to the strip-only?
You can check it by adding the option mode: "transform" as shown below:

import { transformSync } from "@swc/wasm-typescript";

const options = {
	mode: "transform",
	transform: {
		verbatimModuleSyntax: true,
		nativeClassProperties: true,
		noEmptyExport: true,
		importNotUsedAsValues: "preserve",
	}
}

console.log("Begin 1");
console.log(
	transformSync(`
export function foo() {
	return 'foo';
};
`, options).code,
);
console.log("End 1");

console.log("Begin 2");
console.log(
	transformSync(`
export function foo() {
	if (false) {
	}
	return 'foo';
};
`, options).code,
);
console.log("End 2");

@wojtekmaj
Copy link
Author

@magic-akari No luck:

PS C:\test> node swc.js 
Begin 1
export function foo() {
    return 'foo';
}

End 1
Begin 2

@magic-akari
Copy link
Member

It's suspected that the issue arises at an earlier stage, possibly in the parser.

@wojtekmaj
Copy link
Author

wojtekmaj commented Sep 6, 2024

It's my first encounter with swc, so apologies if my diagnosis so far aren't the best, but I'll do my best to help out. The hardware is yours to experiment on :D

@magic-akari
Copy link
Member

let's do more experiments to pinpoint this issue.

  1. Test the strip-only mode in your browser by clicking this link:
    https://play.swc.rs/?version=1.7.23&code=H4sIAAAAAAAAA0utKMgvKlFIK81LLsnMz1NIy8%2FX0FSo5uLMTFPQSEvMKU4F82q5OItSS0qL8hTUgSrUrblqrQGZRHv4OgAAAA%3D%3D&config=H4sIAAAAAAAAA6vmUlBQyipOVrJSqAYygZyCxKLi1CI4HyhSXJlXklgBFFFKTc5NLE4uyiwoUQJL1nKBcC0ABwZxP0UAAAA%3D&strip-types=

  2. Check the parser's functionality in your browser using this link:
    https://swc-ast.vercel.app/#code/KYDwDg9gTgLgBAMwK4DsDGMCWEWIhACgEo4BvAKAEhME4CEBDAGwGdgSLKBfKqYGJFFwByBPmEBuclwlA

  3. Run this command to verify the parser's functionality in Node:

npx swc_ast_viewer path/to/your_file.js

@wojtekmaj
Copy link
Author

wojtekmaj commented Sep 11, 2024

@magic-akari

Ad 1 - This worked perfectly fine, on latest Microsoft Edge, arm64 build. input === output.
Ad 2 - This resulted in the following output (no crash):

Output Module( Module { span: 1..59, body: [ ModuleDecl( ExportDecl( ExportDecl { span: 1..58, decl: Fn( FnDecl { ident: Ident { span: 17..20, ctxt: #2, sym: "foo", optional: false, }, declare: false, function: Function { params: [], decorators: [], span: 8..58, ctxt: #3, body: Some( BlockStmt { span: 23..58, ctxt: #3, stmts: [ If( IfStmt { span: 26..41, test: Lit( Bool( Bool { span: 30..35, value: false, }, ), ), cons: Block( BlockStmt { span: 37..41, ctxt: #4, stmts: [], }, ), alt: None, }, ), Return( ReturnStmt { span: 43..56, arg: Some( Lit( Str( Str { span: 50..55, value: "foo", raw: Some( "'foo'", ), }, ), ), ), }, ), ], }, ), is_generator: false, is_async: false, type_params: None, return_type: None, }, }, ), }, ), ), Stmt( Empty( EmptyStmt { span: 58..59, }, ), ), ], shebang: None, }, )
Ad 3 - This just prints the version number, regardless of the file I'm feeding it (!):
PS C:\test> npx swc_ast_viewer ./simple-file.ts
[email protected]

@magic-akari
Copy link
Member

It seems that our WASM version parser isn't working on Windows ARM64 with Node.js.
The lack of error messages from WASM, which just exits quietly, complicates debugging.

Moreover, there are no methods in WASM that trigger process.exit, and I think that exiting silently is an unexpected behavior in Node.js.

What are your thoughts? @kdy1

@marco-ippolito
Copy link
Contributor

My feeling is that there is no crash/error, it simply exits the transpilation early with an empty output.
Github recently released arm64 windows runner, we could use that to reproduce.

@kdy1
Copy link
Member

kdy1 commented Sep 11, 2024

@magic-akari I think we can use the CI of SWC. You can add some node.js tests and run the publish action with only nightly enabled.
I'll do it soon.

@kdy1
Copy link
Member

kdy1 commented Sep 11, 2024

Let's try with @swc/core first.
I made #9547 and triggered https://github.com/swc-project/swc/actions/runs/10810667484

@marco-ippolito
Copy link
Contributor

Let's try with @swc/core first.
I made #9547 and triggered https://github.com/swc-project/swc/actions/runs/10810667484

I see the CI is green, might be related to WASM?

@kdy1
Copy link
Member

kdy1 commented Sep 16, 2024

I got an arm64 windows device. My mother had one 👍
I'll fix this issue after Chuseok holiday(through Wednesday)

@kdy1
Copy link
Member

kdy1 commented Sep 20, 2024

I managed to install VS and rust on it. I'll try later today.

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

4 participants