From 74d7ea2d10bf2c06437ffeb5a9014da71c3b2afe Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Mon, 22 Sep 2025 11:46:49 -0700 Subject: [PATCH] Remove more dead python code found using `deadcode` module. NFC The remaining dead code being reported is false positives I believe. --- emcc.py | 11 ------ emrun.py | 4 +- pyproject.toml | 2 +- test/common.py | 62 ------------------------------ test/runner.py | 4 +- test/test_core.py | 5 --- test/test_other.py | 5 --- tools/cmdline.py | 2 - tools/diagnostics.py | 11 ------ tools/feature_matrix.py | 1 - tools/js_optimizer.py | 1 - tools/maint/create_dom_pk_codes.py | 11 ++---- 12 files changed, 9 insertions(+), 110 deletions(-) diff --git a/emcc.py b/emcc.py index 35b32d76e79c2..775d2eed85363 100644 --- a/emcc.py +++ b/emcc.py @@ -165,17 +165,6 @@ def make_relative(filename): reproduce_file.add(rsp_name, os.path.join(root, 'response.txt')) -def get_library_basename(filename): - """Similar to get_file_suffix this strips off all numeric suffixes and then - then final non-numeric one. For example for 'libz.so.1.2.8' returns 'libz'""" - filename = os.path.basename(filename) - while filename: - filename, suffix = os.path.splitext(filename) - # Keep stipping suffixes until we strip a non-numeric one. - if not suffix[1:].isdigit(): - return filename - - # # Main run() function # diff --git a/emrun.py b/emrun.py index 53344441a1291..43e49ebfbae1e 100644 --- a/emrun.py +++ b/emrun.py @@ -577,8 +577,9 @@ def shutdown(self): # Processes HTTP request back to the browser. class HTTPHandler(SimpleHTTPRequestHandler): + protocol_version = 'HTTP/1.1' + def send_head(self): - self.protocol_version = 'HTTP/1.1' global page_last_served_time path = self.translate_path(self.path) f = None @@ -669,7 +670,6 @@ def log_message(self, format, *args): sys.stderr.write(msg) def do_POST(self): - self.protocol_version = 'HTTP/1.1' global page_exit_code, have_received_messages (_, _, path, query, _) = urlsplit(self.path) diff --git a/pyproject.toml b/pyproject.toml index f2fdc36b8fa89..50e2a6f73fe99 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -110,4 +110,4 @@ module = ["psutil", "win32con", "win32gui", "win32process"] ignore_missing_imports = true [tool.deadcode] -exclude = ["out", "third_party", "test/third_party"] +exclude = ["out", "third_party", "test/third_party", "node_modules", "site/source/_themes", "site/source/conf.py"] diff --git a/test/common.py b/test/common.py index 18408a220cacd..a594fb04df503 100644 --- a/test/common.py +++ b/test/common.py @@ -414,17 +414,6 @@ def decorated(self, *args, **kwargs): return decorated -def requires_wasm_legacy_eh(func): - assert callable(func) - - @wraps(func) - def decorated(self, *args, **kwargs): - self.require_wasm_legacy_eh() - return func(self, *args, **kwargs) - - return decorated - - def requires_wasm_eh(func): assert callable(func) @@ -632,31 +621,6 @@ def metafunc(self, rawfs, *args, **kwargs): return metafunc -# Decorator version of env_modify -def also_with_env_modify(name_updates_mapping): - - def decorated(f): - @wraps(f) - def metafunc(self, updates, *args, **kwargs): - if DEBUG: - print('parameterize:env_modify=%s' % (updates)) - if updates: - with env_modify(updates): - return f(self, *args, **kwargs) - else: - return f(self, *args, **kwargs) - - params = {'': (None,)} - for name, updates in name_updates_mapping.items(): - params[name] = (updates,) - - parameterize(metafunc, params) - - return metafunc - - return decorated - - def also_with_minimal_runtime(f): assert callable(f) @@ -1638,32 +1602,6 @@ def get_func(self, src, name): t += 1 assert t < len(src) - def count_funcs(self, javascript_file): - num_funcs = 0 - start_tok = "// EMSCRIPTEN_START_FUNCS" - end_tok = "// EMSCRIPTEN_END_FUNCS" - start_off = 0 - end_off = 0 - - js = read_file(javascript_file) - blob = "".join(js.splitlines()) - - start_off = blob.find(start_tok) + len(start_tok) - end_off = blob.find(end_tok) - asm_chunk = blob[start_off:end_off] - num_funcs = asm_chunk.count('function ') - return num_funcs - - def count_wasm_contents(self, wasm_binary, what): - out = self.run_process([os.path.join(building.get_binaryen_bin(), 'wasm-opt'), wasm_binary, '--metrics'], stdout=PIPE).stdout - # output is something like - # [?] : 125 - for line in out.splitlines(): - if '[' + what + ']' in line: - ret = line.split(':')[1].strip() - return int(ret) - self.fail('Failed to find [%s] in wasm-opt output' % what) - def get_wasm_text(self, wasm_binary): return self.run_process([WASM_DIS, wasm_binary], stdout=PIPE).stdout diff --git a/test/runner.py b/test/runner.py index 9ac5dad4f7c70..ce76aba756863 100755 --- a/test/runner.py +++ b/test/runner.py @@ -119,8 +119,8 @@ def check_js_engines(): def get_and_import_modules(): modules = [] for filename in glob.glob(os.path.join(common.TEST_ROOT, 'test*.py')): - module_dir, module_file = os.path.split(filename) - module_name, module_ext = os.path.splitext(module_file) + module_file = os.path.basename(filename) + module_name = os.path.splitext(module_file)[0] __import__(module_name) modules.append(sys.modules[module_name]) return modules diff --git a/test/test_core.py b/test/test_core.py index 145f9d9de4414..13c95cbe0d961 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -3775,11 +3775,6 @@ def zzztest_dlfcn_exceptions(self): @no_js_math('JS_MATH is not compatible with MAIN_MODULE') def test_dlfcn_handle_alloc(self): # verify that dlopen does not allocate already used handles - dirname = self.get_dir() - - def indir(name): - return os.path.join(dirname, name) - create_file('a.cpp', r''' #include diff --git a/test/test_other.py b/test/test_other.py index 280a908b887a4..4c57cf1a70509 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -51,14 +51,12 @@ from tools.settings import settings from tools.system_libs import DETERMINISTIC_PREFIX -scons_path = shutil.which('scons') emmake = shared.bat_suffix(path_from_root('emmake')) emconfig = shared.bat_suffix(path_from_root('em-config')) emsize = shared.bat_suffix(path_from_root('emsize')) emprofile = shared.bat_suffix(path_from_root('emprofile')) emstrip = shared.bat_suffix(path_from_root('emstrip')) emsymbolizer = shared.bat_suffix(path_from_root('emsymbolizer')) -wasm_opt = Path(building.get_binaryen_bin(), 'wasm-opt') def is_bitcode(filename): @@ -3055,9 +3053,6 @@ def verify_dwarf(self, wasm_file, verify_func): def verify_dwarf_exists(self, wasm_file): self.verify_dwarf(wasm_file, self.assertIn) - def verify_dwarf_does_not_exist(self, wasm_file): - self.verify_dwarf(wasm_file, self.assertNotIn) - # Verify if the given file name contains a source map def verify_source_map_exists(self, map_file): self.assertExists(map_file) diff --git a/tools/cmdline.py b/tools/cmdline.py index a8e1df4ec8171..cd316d8c8963d 100644 --- a/tools/cmdline.py +++ b/tools/cmdline.py @@ -61,7 +61,6 @@ def __init__(self): self.post_link = False self.save_temps = False self.executable = False - self.compiler_wrapper = None self.oformat = None self.requested_debug = None self.emit_symbol_map = False @@ -78,7 +77,6 @@ def __init__(self): self.shell_path = None self.source_map_base = '' self.emit_tsd = '' - self.embind_emit_tsd = '' self.emrun = False self.cpu_profiler = False self.memory_profiler = False diff --git a/tools/diagnostics.py b/tools/diagnostics.py index 362b4060e8b3a..b75f206bc6349 100644 --- a/tools/diagnostics.py +++ b/tools/diagnostics.py @@ -22,7 +22,6 @@ # diagnostic levels WARN = 1 ERROR = 2 -FATAL = 3 # available colors RED = 1 @@ -249,16 +248,6 @@ def add_warning(name, enabled=True, part_of_all=True, shared=False, error=False) manager.add_warning(name, enabled, part_of_all, shared, error) -def enable_warning(name, as_error=False): - manager.warnings[name]['enabled'] = True - if as_error: - manager.warnings[name]['error'] = True - - -def disable_warning(name): - manager.warnings[name]['enabled'] = False - - def is_enabled(name): return manager.warnings[name]['enabled'] diff --git a/tools/feature_matrix.py b/tools/feature_matrix.py index 509f1a666edcc..ac711f5f1765b 100644 --- a/tools/feature_matrix.py +++ b/tools/feature_matrix.py @@ -42,7 +42,6 @@ class Feature(IntEnum): MEMORY64 = auto() -default_features = {Feature.SIGN_EXT, Feature.MUTABLE_GLOBALS} disable_override_features = set() enable_override_features = set() diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py index 02beac71b45ea..a2278da8b775e 100755 --- a/tools/js_optimizer.py +++ b/tools/js_optimizer.py @@ -34,7 +34,6 @@ func_sig = re.compile(r'function ([_\w$]+)\(') func_sig_json = re.compile(r'\["defun", ?"([_\w$]+)",') -import_sig = re.compile(r'(var|const) ([_\w$]+ *=[^;]+);') def get_acorn_cmd(): diff --git a/tools/maint/create_dom_pk_codes.py b/tools/maint/create_dom_pk_codes.py index e9d8ac2b7c781..d7e25c36699bb 100755 --- a/tools/maint/create_dom_pk_codes.py +++ b/tools/maint/create_dom_pk_codes.py @@ -237,29 +237,26 @@ def hash_all(k1, k2): else: hashes[h] = s[1] str_to_hash[s[1]] = h - return (hashes, str_to_hash) + return str_to_hash # Find an appropriate hash function that is collision free within the set of all input strings # Try hash function format h_i = ((h_(i-1) ^ k_1) << k_2) ^ s_i, where h_i is the hash function # value at step i, k_1 and k_2 are the constants we are searching, and s_i is the i'th input # character -perfect_hash_table = None # Last used perfect hash constants. Stored here so that this script will # produce the same output it did when the current output was generated. k1 = 0x7E057D79 k2 = 3 -perfect_hash_table = hash_all(k1, k2) +str_to_hash = hash_all(k1, k2) -while not perfect_hash_table: +while not str_to_hash: # The search space is super-narrow, but since there are so few items to hash, practically # almost any choice gives a collision free hash. k1 = int(random.randint(0, 0x7FFFFFFF)) k2 = int(random.uniform(1, 8)) - perfect_hash_table = hash_all(k1, k2) - -hash_to_str, str_to_hash = perfect_hash_table + str_to_hash = hash_all(k1, k2) print('Found collision-free hash function!', file=sys.stderr) print('h_i = ((h_(i-1) ^ %s) << %s) ^ s_i' % (hex(k1), hex(k2)), file=sys.stderr)