Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

HerrCai0907
Copy link
Member

@HerrCai0907 HerrCai0907 commented Aug 26, 2025

Module.getExpressionId will be used for nullptr ExpressionRef. It works because deref nullptr in binaryen's wasm is valid.
check BinaryenExprRef non-null before.

Module.getExpressionId will be used for nullptr ExpressionRef. It works because deref nullptr in binaryen's wasm is valid.
Adding guard can enhance robustness
@HerrCai0907
Copy link
Member Author

If we replace guard with assert, the compiler will crash during testing.

▌ Whoops, the AssemblyScript compiler has crashed during compile :-(

▌ Here is the stack trace hinting at the problem, perhaps it's useful?

▌ AssertionError: assertion failed
▌ at Z.assert (/Users/caicongcong/dev/assemblyscript/std/portable/index.js:216:11)
▌ at getExpressionId (/Users/caicongcong/dev/assemblyscript/src/module.ts:3022:3)
▌ at isConstZero (/Users/caicongcong/dev/assemblyscript/src/module.ts:3063:7)
▌ at t.operandsTostack (/Users/caicongcong/dev/assemblyscript/src/compiler.ts:6767:14)
▌ at t.makeCallDirect (/Users/caicongcong/dev/assemblyscript/src/compiler.ts:6910:24)
▌ at t.ensureConstructor (/Users/caicongcong/dev/assemblyscript/src/compiler.ts:8865:18)
▌ at t.compileNewExpression (/Users/caicongcong/dev/assemblyscript/src/compiler.ts:8758:21)
▌ at t.compileExpression (/Users/caicongcong/dev/assemblyscript/src/compiler.ts:3432:21)
▌ at t.compileVariableStatement (/Users/caicongcong/dev/assemblyscript/src/compiler.ts:3011:27)
▌ at t.compileStatement (/Users/caicongcong/dev/assemblyscript/src/compiler.ts:2241:21)
▌ at t.compileStatements (/Users/caicongcong/dev/assemblyscript/src/compiler.ts:2284:23)
▌ at t.compileFunctionBody (/Users/caicongcong/dev/assemblyscript/src/compiler.ts:1733:20)
▌ at t.compileFunction (/Users/caicongcong/dev/assemblyscript/src/compiler.ts:1612:17)
▌ at t.makeCallDirect (/Users/caicongcong/dev/assemblyscript/src/compiler.ts:6841:15)
▌ at t.compileCallDirect (/Users/caicongcong/dev/assemblyscript/src/compiler.ts:6364:17)

▌ If you see where the error is, feel free to send us a pull request. If not,
▌ please let us know: https://github.com/AssemblyScript/assemblyscript/issues

@HerrCai0907
Copy link
Member Author

HerrCai0907 commented Aug 26, 2025

some background: I am trying to revert the relationship between AS and binaryen. it will create a new c++ program integrated binaryen in native as static lib and WASM runtime. Then it will load AS bootstrapped WASM to compile source code.
The benefit is we can reuse the lots of WASM infra in binaryen to improve the performance and code size.
But it is harmful to browser compatibility...

@CountBleck
Copy link
Member

Regarding that compiler crash, maybe we should find out where a null pointer is being passed, and see if that's intended? If it is intended, this change makes more sense.

Regarding your testing with the AS compiler embedded within a C++ executable...I don't think you can upstream that, but it might be interesting to open-source if possible. It would definitely be cool to see how necessary the JS glue in binaryen.js is to AssemblyScript.

@HerrCai0907
Copy link
Member Author

it might be interesting to open-source if possible

open source is in progress. it should be finished in this year

Regarding that compiler crash, maybe we should find out where a null pointer is being passed, and see if that's intended? If it is intended, this change makes more sense.

It generated by module.runExpression. I would fix it in caller side.

@HerrCai0907 HerrCai0907 requested a review from CountBleck August 29, 2025 03:05
Copy link
Member

@CountBleck CountBleck left a comment

Choose a reason for hiding this comment

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

LGTM. Looks like everyone else in compiler.ts/flow.ts does the same thing too!

@CountBleck CountBleck merged commit 7e2a62d into AssemblyScript:main Aug 29, 2025
15 checks passed
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.

2 participants