Skip to content

Remove some unnecessary complexity in create_receiving. NFC #21131

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

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 24 additions & 28 deletions tools/emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,9 @@ def create_sending(metadata, library_symbols):
return '{\n ' + ',\n '.join(f'{prefix}{k}: {v}' for k, v in sorted_items) + '\n}'


def make_export_wrappers(function_exports, delay_assignment):
def make_export_wrappers(function_exports):
assert not settings.MINIMAL_RUNTIME

wrappers = []

# The emscripten stack functions are called very early (by writeStackCookie) before
Expand Down Expand Up @@ -794,8 +796,8 @@ def install_wrapper(sym):
# With assertions enabled we create a wrapper that are calls get routed through, for
# the lifetime of the program.
wrapper += "createExportWrapper('%s');" % name
elif delay_assignment:
# With assertions disabled the wrapper will replace the global var and Module var on
elif settings.WASM_ASYNC_COMPILATION:
# With WASM_ASYNC_COMPILATION wrapper will replace the global var and Module var on
# first use.
args = [f'a{i}' for i in range(nargs)]
args = ', '.join(args)
Expand All @@ -815,32 +817,26 @@ def create_receiving(function_exports):

receiving = []

# with WASM_ASYNC_COMPILATION that asm object may not exist at this point in time
# so we need to support delayed assignment.
delay_assignment = settings.WASM_ASYNC_COMPILATION and not settings.MINIMAL_RUNTIME
if not delay_assignment:
if settings.MINIMAL_RUNTIME:
# In Wasm exports are assigned inside a function to variables
# existing in top level JS scope, i.e.
# var _main;
# WebAssembly.instantiate(Module['wasm'], imports).then((output) => {
# var wasmExports = output.instance.exports;
# _main = wasmExports["_main"];
generate_dyncall_assignment = settings.DYNCALLS and '$dynCall' in settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE
exports_that_are_not_initializers = [x for x in function_exports if x != building.WASM_CALL_CTORS]

for s in exports_that_are_not_initializers:
mangled = asmjs_mangle(s)
dynCallAssignment = ('dynCalls["' + s.replace('dynCall_', '') + '"] = ') if generate_dyncall_assignment and mangled.startswith('dynCall_') else ''
should_export = settings.EXPORT_ALL or (settings.EXPORT_KEEPALIVE and mangled in settings.EXPORTED_FUNCTIONS)
export_assignment = ''
if settings.MODULARIZE and should_export:
export_assignment = f"Module['{mangled}'] = "
receiving += [f'{export_assignment}{dynCallAssignment}{mangled} = wasmExports["{s}"]']
else:
receiving += make_export_wrappers(function_exports, delay_assignment)
if settings.MINIMAL_RUNTIME:
# In Wasm exports are assigned inside a function to variables
# existing in top level JS scope, i.e.
# var _main;
# WebAssembly.instantiate(Module['wasm'], imports).then((output) => {
# var wasmExports = output.instance.exports;
# _main = wasmExports["_main"];
generate_dyncall_assignment = settings.DYNCALLS and '$dynCall' in settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE
exports_that_are_not_initializers = [x for x in function_exports if x != building.WASM_CALL_CTORS]

for s in exports_that_are_not_initializers:
mangled = asmjs_mangle(s)
dynCallAssignment = ('dynCalls["' + s.replace('dynCall_', '') + '"] = ') if generate_dyncall_assignment and mangled.startswith('dynCall_') else ''
should_export = settings.EXPORT_ALL or (settings.EXPORT_KEEPALIVE and mangled in settings.EXPORTED_FUNCTIONS)
export_assignment = ''
if settings.MODULARIZE and should_export:
export_assignment = f"Module['{mangled}'] = "
receiving += [f'{export_assignment}{dynCallAssignment}{mangled} = wasmExports["{s}"]']
else:
receiving += make_export_wrappers(function_exports, delay_assignment)
receiving += make_export_wrappers(function_exports)

if settings.MINIMAL_RUNTIME:
return '\n '.join(receiving) + '\n'
Expand Down