Skip to content

Commit

Permalink
emscripten.py: optimize check_all_implemented. (emscripten-core#8453)
Browse files Browse the repository at this point in the history
make it more efficient and skip it entirely when possible
  • Loading branch information
waterlike86 authored and belraquib committed Dec 23, 2020
1 parent a872923 commit 0c38074
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,24 +852,26 @@ def get_all_implemented(forwarded_json, metadata):


def check_all_implemented(all_implemented, pre):
for requested in shared.Settings.ORIGINAL_EXPORTED_FUNCTIONS:
if not is_already_implemented(requested, pre, all_implemented):
# we are not checking anyway, so just skip this
if not shared.Settings.ERROR_ON_UNDEFINED_SYMBOLS and not shared.Settings.WARN_ON_UNDEFINED_SYMBOLS:
return
# the initial list of missing functions are those we expected to export, but were not implemented in compiled code
missing = list(set(shared.Settings.ORIGINAL_EXPORTED_FUNCTIONS) - set(all_implemented))
# special-case malloc, EXPORTED by default for internal use, but we bake in a
# trivial allocator and warn at runtime if used in ASSERTIONS
if '_malloc' in missing:
missing.remove('_malloc')

for requested in missing:
in_pre = ('function ' + asstr(requested)) in pre
if not in_pre:
# could be a js library func
if shared.Settings.ERROR_ON_UNDEFINED_SYMBOLS:
exit_with_error('undefined exported function: "%s"', requested)
elif shared.Settings.WARN_ON_UNDEFINED_SYMBOLS:
logger.warning('undefined exported function: "%s"', requested)


def is_already_implemented(requested, pre, all_implemented):
is_implemented = requested in all_implemented
# special-case malloc, EXPORTED by default for internal use, but we bake in a
# trivial allocator and warn at runtime if used in ASSERTIONS
is_exception = requested == '_malloc'
in_pre = ('function ' + asstr(requested)) in pre
return is_implemented or is_exception or in_pre


def get_exported_implemented_functions(all_exported_functions, all_implemented, metadata):
funcs = set(metadata['exports'])
export_bindings = shared.Settings.EXPORT_BINDINGS
Expand Down

0 comments on commit 0c38074

Please sign in to comment.