Skip to content

Commit 2564354

Browse files
authored
Move warnOnce to JS library (#17423)
Once we disable LEGACY_RUNTIME by default we will see that code size wins.
1 parent f08ae1c commit 2564354

10 files changed

+24
-28
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ See docs/process.md for more on how version tagging works.
4949
- writeAsciiToMemory
5050
- intArrayFromString
5151
- intArrayToString
52+
- warnOnce
5253
However, they all still available by default due to a new setting called
5354
`LEGACY_RUNTIME` which is enabled by default. When `LEGACY_RUNTIME` is
5455
disabled (which it may be in the future) these symbols would only be included

emcc.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,16 +1848,21 @@ def phase_linker_setup(options, state, newargs, user_settings):
18481848
if settings.CLOSURE_WARNINGS not in ['quiet', 'warn', 'error']:
18491849
exit_with_error('Invalid option -sCLOSURE_WARNINGS=%s specified! Allowed values are "quiet", "warn" or "error".' % settings.CLOSURE_WARNINGS)
18501850

1851-
# Include dynCall() function by default in DYNCALLS builds in classic runtime; in MINIMAL_RUNTIME, must add this explicitly.
1852-
if settings.DYNCALLS and not settings.MINIMAL_RUNTIME:
1853-
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$dynCall']
1854-
18551851
if not settings.BOOTSTRAPPING_STRUCT_INFO:
1856-
if settings.SAFE_HEAP:
1857-
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$getValue_safe', '$setValue_safe']
18581852
if not settings.MINIMAL_RUNTIME:
1853+
if settings.DYNCALLS:
1854+
# Include dynCall() function by default in DYNCALLS builds in classic runtime; in MINIMAL_RUNTIME, must add this explicitly.
1855+
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$dynCall']
1856+
1857+
if settings.ASSERTIONS and not settings.EXIT_RUNTIME:
1858+
# "checkUnflushedContent()" depends on warnOnce
1859+
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$warnOnce']
1860+
18591861
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$getValue', '$setValue']
18601862

1863+
if settings.SAFE_HEAP:
1864+
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$getValue_safe', '$setValue_safe']
1865+
18611866
if settings.MAIN_MODULE:
18621867
assert not settings.SIDE_MODULE
18631868
if settings.MAIN_MODULE == 1:

src/library.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,15 +2360,13 @@ mergeInto(LibraryManager.library, {
23602360
return nowIsMonotonic;
23612361
},
23622362

2363-
#if MINIMAL_RUNTIME
23642363
$warnOnce: function(text) {
23652364
if (!warnOnce.shown) warnOnce.shown = {};
23662365
if (!warnOnce.shown[text]) {
23672366
warnOnce.shown[text] = 1;
23682367
err(text);
23692368
}
23702369
},
2371-
#endif
23722370

23732371
// Returns [parentFuncArguments, functionName, paramListName]
23742372
$traverseStack: function(args) {
@@ -2400,11 +2398,7 @@ mergeInto(LibraryManager.library, {
24002398
return [args, funcname, str];
24012399
},
24022400

2403-
emscripten_get_callstack_js__deps: ['$traverseStack', '$jsStackTrace',
2404-
#if MINIMAL_RUNTIME
2405-
, '$warnOnce'
2406-
#endif
2407-
],
2401+
emscripten_get_callstack_js__deps: ['$traverseStack', '$jsStackTrace', '$warnOnce'],
24082402
emscripten_get_callstack_js__docs: '/** @param {number=} flags */',
24092403
emscripten_get_callstack_js: function(flags) {
24102404
var callstack = jsStackTrace();
@@ -3299,9 +3293,14 @@ mergeInto(LibraryManager.library, {
32993293
throw 'unwind';
33003294
},
33013295

3296+
emscripten_force_exit__deps: [
3297+
#if !EXIT_RUNTIME && ASSERTIONS
3298+
'$warnOnce',
3299+
#endif
33023300
#if MINIMAL_RUNTIME
3303-
emscripten_force_exit__deps: ['exit'],
3301+
'exit',
33043302
#endif
3303+
],
33053304
emscripten_force_exit__proxy: 'sync',
33063305
emscripten_force_exit__sig: 'vi',
33073306
emscripten_force_exit: function(status) {
@@ -3651,5 +3650,6 @@ DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push(
36513650
'$writeAsciiToMemory',
36523651
'$intArrayFromString',
36533652
'$intArrayToString',
3653+
'$warnOnce',
36543654
);
36553655
#endif

src/library_browser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var LibraryBrowser = {
1010
'$setMainLoop',
1111
'$callUserCallback',
1212
'$safeSetTimeout',
13+
'$warnOnce',
1314
'emscripten_set_main_loop_timing',
1415
],
1516
$Browser__postset: 'Module["requestFullscreen"] = function Module_requestFullscreen(lockPointer, resizeCanvas) { Browser.requestFullscreen(lockPointer, resizeCanvas) };\n' + // exports

src/library_pthread.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,7 @@ var LibraryPThread = {
776776
return spawnThread(threadParams);
777777
},
778778

779-
#if MINIMAL_RUNTIME
780779
emscripten_check_blocking_allowed__deps: ['$warnOnce'],
781-
#endif
782780
emscripten_check_blocking_allowed: function() {
783781
#if ASSERTIONS || IN_TEST_HARNESS || !MINIMAL_RUNTIME || !ALLOW_BLOCKING_ON_MAIN_THREAD
784782
#if ENVIRONMENT_MAY_BE_NODE

src/modules.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ function exportRuntime() {
411411
// MINIMAL_RUNTIME has moved these functions to library_strings.js
412412
runtimeElements = runtimeElements.concat([
413413
'run',
414-
'warnOnce',
415414
'ExitStatus',
416415
]);
417416
}

src/support.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ var POINTER_SIZE = {{{ MEMORY64 ? 8 : 4 }}};
99

1010
{{{ getNativeTypeSize }}}
1111

12-
function warnOnce(text) {
13-
if (!warnOnce.shown) warnOnce.shown = {};
14-
if (!warnOnce.shown[text]) {
15-
warnOnce.shown[text] = 1;
16-
err(text);
17-
}
18-
}
19-
2012
#include "runtime_debug.js"
2113

2214
var tempRet0 = 0;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
26717
1+
26713
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
94927
1+
94954
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
56491
1+
56517

0 commit comments

Comments
 (0)