From 6fdd8ce3a967b6400a9dac0e03ffbb01f85d7b41 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Mon, 30 Dec 2024 11:36:59 -0800 Subject: [PATCH] Remove `POLYFILL_OLD_MATH_FUNCTIONS` setting These polyfills are only needed on ancient browser versions that there should be no need to support. This change bumps out minimum required chrome version from 33 to 38. --- ChangeLog.md | 3 ++ src/preamble.js | 2 - src/preamble_minimal.js | 1 - src/runtime_math.js | 53 ------------------- .../codesize/test_codesize_hello_O0.gzsize | 2 +- .../codesize/test_codesize_hello_O0.jssize | 2 +- .../codesize/test_codesize_minimal_O0.gzsize | 2 +- .../codesize/test_codesize_minimal_O0.jssize | 2 +- test/other/test_unoptimized_code_size.js.size | 2 +- ...t_unoptimized_code_size_no_asserts.js.size | 2 +- .../test_unoptimized_code_size_strict.js.size | 2 +- test/test_other.py | 14 ----- tools/link.py | 7 --- 13 files changed, 10 insertions(+), 84 deletions(-) delete mode 100644 src/runtime_math.js diff --git a/ChangeLog.md b/ChangeLog.md index 785f80d53087d..687277411713a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -48,6 +48,9 @@ See docs/process.md for more on how version tagging works. `--post-js` files will now be delayed until after module creation and after `main` runs. This matches the existing behaviour when using sync instantation (`-sWASM_ASYNC_COMPILATION=0`) but is an observable difference. (#23157) +- The `POLYFILL_OLD_MATH_FUNCTIONS` setting was removed. The browser versions + that require these polyfills are no longer supported by emscripten so the + polyfills should never be needed. (#23262) 3.1.74 - 12/14/24 ----------------- diff --git a/src/preamble.js b/src/preamble.js index eaec26460ab79..e0bb2f3c57470 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -328,8 +328,6 @@ function addOnPostRun(cb) { __ATPOSTRUN__.unshift(cb); } -#include "runtime_math.js" - // A counter of dependencies for calling run(). If we need to // do asynchronous work before running, increment this and // decrement it. Incrementing must happen in a place like diff --git a/src/preamble_minimal.js b/src/preamble_minimal.js index 322adb69982e4..5f0a7594bda22 100644 --- a/src/preamble_minimal.js +++ b/src/preamble_minimal.js @@ -89,7 +89,6 @@ var runtimeExited = false; var runtimeInitialized = false; #endif -#include "runtime_math.js" #include "memoryprofiler.js" #include "runtime_exceptions.js" #include "runtime_debug.js" diff --git a/src/runtime_math.js b/src/runtime_math.js deleted file mode 100644 index 999255167fae6..0000000000000 --- a/src/runtime_math.js +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @license - * Copyright 2019 The Emscripten Authors - * SPDX-License-Identifier: MIT - */ - -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul -#if POLYFILL_OLD_MATH_FUNCTIONS || MIN_CHROME_VERSION < 28 || MIN_FIREFOX_VERSION < 20 || MIN_SAFARI_VERSION < 90000 // || MIN_NODE_VERSION < 0.12 -// || MIN_NODE_VERSION < 0.12 -// check for imul support, and also for correctness ( https://bugs.webkit.org/show_bug.cgi?id=126345 ) -if (!Math.imul || Math.imul(0xffffffff, 5) !== -5) Math.imul = (a, b) => { - var ah = a >>> 16; - var al = a & 0xffff; - var bh = b >>> 16; - var bl = b & 0xffff; - return (al*bl + ((ah*bl + al*bh) << 16))|0; -}; -#endif - -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround -#if POLYFILL_OLD_MATH_FUNCTIONS || MIN_CHROME_VERSION < 38 || MIN_FIREFOX_VERSION < 26 || MIN_SAFARI_VERSION < 80000 // || MIN_NODE_VERSION < 0.12 -if (!Math.fround) { - var froundBuffer = new Float32Array(1); - Math.fround = (x) => { froundBuffer[0] = x; return froundBuffer[0] }; -} -#endif - -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32 -#if POLYFILL_OLD_MATH_FUNCTIONS || MIN_CHROME_VERSION < 38 || MIN_FIREFOX_VERSION < 31 // || MIN_NODE_VERSION < 0.12 -Math.clz32 ||= (x) => { - var n = 32; - var y = x >> 16; if (y) { n -= 16; x = y; } - y = x >> 8; if (y) { n -= 8; x = y; } - y = x >> 4; if (y) { n -= 4; x = y; } - y = x >> 2; if (y) { n -= 2; x = y; } - y = x >> 1; if (y) return n - 2; - return n - x; -}; -#endif - -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc -#if POLYFILL_OLD_MATH_FUNCTIONS || MIN_CHROME_VERSION < 38 || MIN_FIREFOX_VERSION < 25 || MIN_SAFARI_VERSION < 80000 // || MIN_NODE_VERSION < 0.12 -Math.trunc ||= (x) => { - return x < 0 ? Math.ceil(x) : Math.floor(x); -}; -#endif - -#if ASSERTIONS -assert(Math.imul, 'This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'); -assert(Math.fround, 'This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'); -assert(Math.clz32, 'This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'); -assert(Math.trunc, 'This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'); -#endif diff --git a/test/other/codesize/test_codesize_hello_O0.gzsize b/test/other/codesize/test_codesize_hello_O0.gzsize index f36af27d0621f..631cfb1647488 100644 --- a/test/other/codesize/test_codesize_hello_O0.gzsize +++ b/test/other/codesize/test_codesize_hello_O0.gzsize @@ -1 +1 @@ -8012 +7891 diff --git a/test/other/codesize/test_codesize_hello_O0.jssize b/test/other/codesize/test_codesize_hello_O0.jssize index 0c10608bd8f7e..70f81fd011114 100644 --- a/test/other/codesize/test_codesize_hello_O0.jssize +++ b/test/other/codesize/test_codesize_hello_O0.jssize @@ -1 +1 @@ -21588 +21016 diff --git a/test/other/codesize/test_codesize_minimal_O0.gzsize b/test/other/codesize/test_codesize_minimal_O0.gzsize index 8793d3d379858..186aada4a792c 100644 --- a/test/other/codesize/test_codesize_minimal_O0.gzsize +++ b/test/other/codesize/test_codesize_minimal_O0.gzsize @@ -1 +1 @@ -6554 +6435 diff --git a/test/other/codesize/test_codesize_minimal_O0.jssize b/test/other/codesize/test_codesize_minimal_O0.jssize index 406ffb9d96d4c..53b0d1202080f 100644 --- a/test/other/codesize/test_codesize_minimal_O0.jssize +++ b/test/other/codesize/test_codesize_minimal_O0.jssize @@ -1 +1 @@ -17637 +17061 diff --git a/test/other/test_unoptimized_code_size.js.size b/test/other/test_unoptimized_code_size.js.size index 5b5e77051524d..14144ec1c08be 100644 --- a/test/other/test_unoptimized_code_size.js.size +++ b/test/other/test_unoptimized_code_size.js.size @@ -1 +1 @@ -53887 +52851 diff --git a/test/other/test_unoptimized_code_size_no_asserts.js.size b/test/other/test_unoptimized_code_size_no_asserts.js.size index 85517970c8c6c..620d8a7590703 100644 --- a/test/other/test_unoptimized_code_size_no_asserts.js.size +++ b/test/other/test_unoptimized_code_size_no_asserts.js.size @@ -1 +1 @@ -29086 +28642 diff --git a/test/other/test_unoptimized_code_size_strict.js.size b/test/other/test_unoptimized_code_size_strict.js.size index be31bd8016b9c..e8a794252c731 100644 --- a/test/other/test_unoptimized_code_size_strict.js.size +++ b/test/other/test_unoptimized_code_size_strict.js.size @@ -1 +1 @@ -52670 +51634 diff --git a/test/test_other.py b/test/test_other.py index 9d8728646a57f..05350ec01aa20 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -4908,20 +4908,6 @@ def test_precompiled_headers(self, suffix): output = self.run_js('a.out.js') self.assertContained('|5|', output) - def test_LEGACY_VM_SUPPORT(self): - # when modern features are lacking, we can polyfill them or at least warn - create_file('pre.js', 'Math.imul = undefined;') - - def test(expected, opts): - print(opts) - self.run_process([EMCC, test_file('hello_world.c'), '--pre-js', 'pre.js'] + opts) - self.assertContained(expected, self.run_js('a.out.js', assert_returncode=0 if opts else NON_ZERO)) - - # when legacy is needed, we show an error indicating so - test('build with LEGACY_VM_SUPPORT', []) - # legacy + disabling wasm works - test('hello, world!', ['-sLEGACY_VM_SUPPORT', '-sWASM=0']) - @crossplatform def test_on_abort(self): expected_output = 'Module.onAbort was called' diff --git a/tools/link.py b/tools/link.py index 6c3ca352ff6d7..0f7888ee30a61 100644 --- a/tools/link.py +++ b/tools/link.py @@ -1157,9 +1157,6 @@ def phase_linker_setup(options, state, newargs): # noqa: C901, PLR0912, PLR0915 if settings.MINIMAL_RUNTIME and options.oformat == OFormat.HTML and not settings.PTHREADS: settings.USE_READY_PROMISE = 0 - if settings.WASM2JS and settings.LEGACY_VM_SUPPORT: - settings.POLYFILL_OLD_MATH_FUNCTIONS = 1 - check_browser_versions() if settings.MIN_NODE_VERSION >= 150000: @@ -1202,10 +1199,6 @@ def phase_linker_setup(options, state, newargs): # noqa: C901, PLR0912, PLR0915 diagnostics.warning('transpile', '-sEXCEPTION_STACK_TRACES requires an engine that support ES6 classes.') settings.EXCEPTION_STACK_TRACES = 0 - # Silently drop any individual backwards compatibility emulation flags that are known never to occur on browsers that support WebAssembly. - if not settings.WASM2JS: - settings.POLYFILL_OLD_MATH_FUNCTIONS = 0 - if settings.STB_IMAGE: state.append_link_flag('-lstb_image') settings.EXPORTED_FUNCTIONS += ['_stbi_load', '_stbi_load_from_memory', '_stbi_image_free']