Skip to content

Commit d15678b

Browse files
authored
Move add/removeRunDependency to library code. NFC (#24952)
This change just moves the code in the JS library. For now we still included these symbol unconditionally. I follow up by trying to limit the inclusion to when its actually needed.
1 parent 4e416b4 commit d15678b

File tree

50 files changed

+298
-277
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+298
-277
lines changed

src/lib/libcore.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,6 +2274,110 @@ addToLibrary({
22742274
$noExitRuntime__postset: () => addAtModule(makeModuleReceive('noExitRuntime')),
22752275
$noExitRuntime: {{{ !EXIT_RUNTIME }}},
22762276

2277+
// A counter of dependencies for calling run(). If we need to
2278+
// do asynchronous work before running, increment this and
2279+
// decrement it. Incrementing must happen in a place like
2280+
// Module.preRun (used by emcc to add file preloading).
2281+
// Note that you can add dependencies in preRun, even though
2282+
// it happens right before run - run will be postponed until
2283+
// the dependencies are met.
2284+
$runDependencies__internal: true,
2285+
$runDependencies: 0,
2286+
// overridden to take different actions when all run dependencies are fulfilled
2287+
$dependenciesFulfilled__internal: true,
2288+
$dependenciesFulfilled: null,
2289+
#if ASSERTIONS
2290+
$runDependencyTracking__internal: true,
2291+
$runDependencyTracking: {},
2292+
$runDependencyWatcher__internal: true,
2293+
$runDependencyWatcher: null,
2294+
#endif
2295+
2296+
$addRunDependency__deps: ['$runDependencies',
2297+
#if ASSERTIONS
2298+
'$runDependencyTracking',
2299+
'$runDependencyWatcher',
2300+
#endif
2301+
],
2302+
$addRunDependency: (id) => {
2303+
runDependencies++;
2304+
2305+
#if expectToReceiveOnModule('monitorRunDependencies')
2306+
Module['monitorRunDependencies']?.(runDependencies);
2307+
#endif
2308+
2309+
#if ASSERTIONS
2310+
#if RUNTIME_DEBUG
2311+
dbg('addRunDependency', id);
2312+
#endif
2313+
assert(id, 'addRunDependency requires an ID')
2314+
assert(!runDependencyTracking[id]);
2315+
runDependencyTracking[id] = 1;
2316+
if (runDependencyWatcher === null && typeof setInterval != 'undefined') {
2317+
// Check for missing dependencies every few seconds
2318+
runDependencyWatcher = setInterval(() => {
2319+
if (ABORT) {
2320+
clearInterval(runDependencyWatcher);
2321+
runDependencyWatcher = null;
2322+
return;
2323+
}
2324+
var shown = false;
2325+
for (var dep in runDependencyTracking) {
2326+
if (!shown) {
2327+
shown = true;
2328+
err('still waiting on run dependencies:');
2329+
}
2330+
err(`dependency: ${dep}`);
2331+
}
2332+
if (shown) {
2333+
err('(end of list)');
2334+
}
2335+
}, 10000);
2336+
#if ENVIRONMENT_MAY_BE_NODE
2337+
// Prevent this timer from keeping the runtime alive if nothing
2338+
// else is.
2339+
runDependencyWatcher.unref?.()
2340+
#endif
2341+
}
2342+
#endif
2343+
},
2344+
2345+
$removeRunDependency__deps: ['$runDependencies', '$dependenciesFulfilled',
2346+
#if ASSERTIONS
2347+
'$runDependencyTracking',
2348+
'$runDependencyWatcher',
2349+
#endif
2350+
],
2351+
$removeRunDependency: (id) => {
2352+
runDependencies--;
2353+
2354+
#if expectToReceiveOnModule('monitorRunDependencies')
2355+
Module['monitorRunDependencies']?.(runDependencies);
2356+
#endif
2357+
2358+
#if ASSERTIONS
2359+
#if RUNTIME_DEBUG
2360+
dbg('removeRunDependency', id);
2361+
#endif
2362+
assert(id, 'removeRunDependency requires an ID');
2363+
assert(runDependencyTracking[id]);
2364+
delete runDependencyTracking[id];
2365+
#endif
2366+
if (runDependencies == 0) {
2367+
#if ASSERTIONS
2368+
if (runDependencyWatcher !== null) {
2369+
clearInterval(runDependencyWatcher);
2370+
runDependencyWatcher = null;
2371+
}
2372+
#endif
2373+
if (dependenciesFulfilled) {
2374+
var callback = dependenciesFulfilled;
2375+
dependenciesFulfilled = null;
2376+
callback(); // can add another dependenciesFulfilled
2377+
}
2378+
}
2379+
},
2380+
22772381
// The following addOn<X> functions are for adding runtime callbacks at
22782382
// various executions points. Each addOn<X> function has a corresponding
22792383
// compiled time version named addAt<X> that will instead inline during

src/modules.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,6 @@ function exportRuntimeSymbols() {
430430
// All possible runtime elements that can be exported
431431
let runtimeElements = [
432432
'run',
433-
'addRunDependency',
434-
'removeRunDependency',
435433
'out',
436434
'err',
437435
'callMain',

src/postamble.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,15 @@ function run(args = arguments_) {
161161
function run() {
162162
#endif
163163

164+
#if !BOOTSTRAPPING_STRUCT_INFO
164165
if (runDependencies > 0) {
165166
#if RUNTIME_DEBUG
166167
dbg('run() called, but dependencies remain, so not running');
167168
#endif
168169
dependenciesFulfilled = run;
169170
return;
170171
}
172+
#endif
171173

172174
#if PTHREADS || WASM_WORKERS
173175
if ({{{ ENVIRONMENT_IS_WORKER_THREAD() }}}) {
@@ -185,6 +187,7 @@ function run() {
185187

186188
preRun();
187189

190+
#if !BOOTSTRAPPING_STRUCT_INFO
188191
// a preRun added a dependency, run will be called later
189192
if (runDependencies > 0) {
190193
#if RUNTIME_DEBUG
@@ -193,6 +196,7 @@ function run() {
193196
dependenciesFulfilled = run;
194197
return;
195198
}
199+
#endif
196200

197201
{{{ asyncIf(ASYNCIFY == 2) }}}function doRun() {
198202
// run may have just been called through dependencies being fulfilled just in this very frame,

src/preamble.js

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -229,93 +229,6 @@ function postRun() {
229229
<<< ATPOSTRUNS >>>
230230
}
231231

232-
// A counter of dependencies for calling run(). If we need to
233-
// do asynchronous work before running, increment this and
234-
// decrement it. Incrementing must happen in a place like
235-
// Module.preRun (used by emcc to add file preloading).
236-
// Note that you can add dependencies in preRun, even though
237-
// it happens right before run - run will be postponed until
238-
// the dependencies are met.
239-
var runDependencies = 0;
240-
var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
241-
#if ASSERTIONS
242-
var runDependencyTracking = {};
243-
var runDependencyWatcher = null;
244-
#endif
245-
246-
function addRunDependency(id) {
247-
runDependencies++;
248-
249-
#if expectToReceiveOnModule('monitorRunDependencies')
250-
Module['monitorRunDependencies']?.(runDependencies);
251-
#endif
252-
253-
#if ASSERTIONS
254-
#if RUNTIME_DEBUG
255-
dbg('addRunDependency', id);
256-
#endif
257-
assert(id, 'addRunDependency requires an ID')
258-
assert(!runDependencyTracking[id]);
259-
runDependencyTracking[id] = 1;
260-
if (runDependencyWatcher === null && typeof setInterval != 'undefined') {
261-
// Check for missing dependencies every few seconds
262-
runDependencyWatcher = setInterval(() => {
263-
if (ABORT) {
264-
clearInterval(runDependencyWatcher);
265-
runDependencyWatcher = null;
266-
return;
267-
}
268-
var shown = false;
269-
for (var dep in runDependencyTracking) {
270-
if (!shown) {
271-
shown = true;
272-
err('still waiting on run dependencies:');
273-
}
274-
err(`dependency: ${dep}`);
275-
}
276-
if (shown) {
277-
err('(end of list)');
278-
}
279-
}, 10000);
280-
#if ENVIRONMENT_MAY_BE_NODE
281-
// Prevent this timer from keeping the runtime alive if nothing
282-
// else is.
283-
runDependencyWatcher.unref?.()
284-
#endif
285-
}
286-
#endif
287-
}
288-
289-
function removeRunDependency(id) {
290-
runDependencies--;
291-
292-
#if expectToReceiveOnModule('monitorRunDependencies')
293-
Module['monitorRunDependencies']?.(runDependencies);
294-
#endif
295-
296-
#if ASSERTIONS
297-
#if RUNTIME_DEBUG
298-
dbg('removeRunDependency', id);
299-
#endif
300-
assert(id, 'removeRunDependency requires an ID');
301-
assert(runDependencyTracking[id]);
302-
delete runDependencyTracking[id];
303-
#endif
304-
if (runDependencies == 0) {
305-
#if ASSERTIONS
306-
if (runDependencyWatcher !== null) {
307-
clearInterval(runDependencyWatcher);
308-
runDependencyWatcher = null;
309-
}
310-
#endif
311-
if (dependenciesFulfilled) {
312-
var callback = dependenciesFulfilled;
313-
dependenciesFulfilled = null;
314-
callback(); // can add another dependenciesFulfilled
315-
}
316-
}
317-
}
318-
319232
/** @param {string|number=} what */
320233
function abort(what) {
321234
#if expectToReceiveOnModule('onAbort')

test/code_size/test_codesize_cxx_ctors1.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 19749,
3-
"a.out.js.gz": 8155,
3+
"a.out.js.gz": 8156,
44
"a.out.nodebug.wasm": 129507,
55
"a.out.nodebug.wasm.gz": 49234,
66
"total": 149256,
7-
"total_gz": 57389,
7+
"total_gz": 57390,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

test/code_size/test_codesize_cxx_ctors2.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 19727,
3-
"a.out.js.gz": 8145,
3+
"a.out.js.gz": 8144,
44
"a.out.nodebug.wasm": 128935,
55
"a.out.nodebug.wasm.gz": 48881,
66
"total": 148662,
7-
"total_gz": 57026,
7+
"total_gz": 57025,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

test/code_size/test_codesize_cxx_lto.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 19077,
3-
"a.out.js.gz": 7835,
3+
"a.out.js.gz": 7834,
44
"a.out.nodebug.wasm": 106468,
55
"a.out.nodebug.wasm.gz": 42616,
66
"total": 125545,
7-
"total_gz": 50451,
7+
"total_gz": 50450,
88
"sent": [
99
"a (emscripten_resize_heap)",
1010
"b (_setitimer_js)",

test/code_size/test_codesize_cxx_mangle.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 23464,
3-
"a.out.js.gz": 9162,
3+
"a.out.js.gz": 9161,
44
"a.out.nodebug.wasm": 235325,
55
"a.out.nodebug.wasm.gz": 78943,
66
"total": 258789,
7-
"total_gz": 88105,
7+
"total_gz": 88104,
88
"sent": [
99
"__cxa_begin_catch",
1010
"__cxa_end_catch",

test/code_size/test_codesize_cxx_noexcept.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 19749,
3-
"a.out.js.gz": 8155,
3+
"a.out.js.gz": 8156,
44
"a.out.nodebug.wasm": 131925,
55
"a.out.nodebug.wasm.gz": 50235,
66
"total": 151674,
7-
"total_gz": 58390,
7+
"total_gz": 58391,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

test/code_size/test_codesize_cxx_wasmfs.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"a.out.js": 7138,
2+
"a.out.js": 7139,
33
"a.out.js.gz": 3337,
44
"a.out.nodebug.wasm": 169796,
55
"a.out.nodebug.wasm.gz": 63083,
6-
"total": 176934,
6+
"total": 176935,
77
"total_gz": 66420,
88
"sent": [
99
"__cxa_throw",

0 commit comments

Comments
 (0)