Skip to content

Commit c2b82bf

Browse files
authored
Disable wasm import/export minification in wasm2js (emscripten-core#9880)
As it may legalize, and not see the proper getTempRet0 etc. import names as the minification happens earlier, and then it will not import things properly as the JS side has minified names. emscripten-core#9879 documents this issue which hopefully we can fix later. For now, just disable this specific optimization.
1 parent dd1fd6a commit c2b82bf

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

tools/shared.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,12 +2534,17 @@ def minify_wasm_js(js_file, wasm_file, expensive_optimizations, minify_whitespac
25342534
logger.debug('running post-meta-DCE cleanup on shell code: ' + ' '.join(passes))
25352535
js_file = Building.acorn_optimizer(js_file, passes)
25362536
# Also minify the names used between js and wasm, if we are emitting an optimized JS+wasm combo (then the JS knows how to load the minified names).
2537-
# If we are building with DECLARE_ASM_MODULE_EXPORTS=0, we must *not* minify the exports from the wasm module, since in DECLARE_ASM_MODULE_EXPORTS=0 mode, the code that
2538-
# reads out the exports is compacted by design that it does not have a chance to unminify the functions. If we are building with DECLARE_ASM_MODULE_EXPORTS=1, we might
2539-
# as well minify wasm exports to regain some of the code size loss that setting DECLARE_ASM_MODULE_EXPORTS=1 caused.
2540-
# ASYNCIFY_LAZY_LOAD_CODE disables minification because it runs after the wasm is completely finalized, and we need to be able to still
2541-
# identify import names at that time. To avoid that, we would need to keep a mapping of the names and send that to binaryen.
2542-
if not Settings.STANDALONE_WASM and not Settings.AUTODEBUG and not Settings.ASSERTIONS and not Settings.SIDE_MODULE and emitting_js and not Settings.ASYNCIFY_LAZY_LOAD_CODE:
2537+
# Things that process the JS after this operation would be done must disable this.
2538+
# For example, ASYNCIFY_LAZY_LOAD_CODE needs to identify import names, and wasm2js
2539+
# needs to use the getTempRet0 imports (otherwise, it may create new ones to replace
2540+
# the old, which would break).
2541+
if not Settings.STANDALONE_WASM and \
2542+
not Settings.AUTODEBUG and \
2543+
not Settings.ASSERTIONS and \
2544+
not Settings.SIDE_MODULE and \
2545+
emitting_js and \
2546+
not Settings.ASYNCIFY_LAZY_LOAD_CODE and \
2547+
not Settings.WASM2JS:
25432548
js_file = Building.minify_wasm_imports_and_exports(js_file, wasm_file, minify_whitespace=minify_whitespace, minify_exports=Settings.DECLARE_ASM_MODULE_EXPORTS, debug_info=debug_info)
25442549
return js_file
25452550

0 commit comments

Comments
 (0)