Skip to content

Commit 774fdbb

Browse files
authored
Bysyncify => Asyncify (#2226)
After some discussion this seems like a less confusing name: what the pass does is "asyncify" code, after all. The one downside is the name overlaps with the old emscripten "Asyncify" utility, which we'll need to clarify in the docs there. This keeps the old --bysyncify flag around for now, which is helpful for avoiding temporary breakage on CI as we move the emscripten side as well.
1 parent cdab4ef commit 774fdbb

25 files changed

+1242
-1240
lines changed

build-js.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ mkdir -p ${OUT}
9393
$BINARYEN_SRC/ir/ReFinalize.cpp \
9494
$BINARYEN_SRC/passes/pass.cpp \
9595
$BINARYEN_SRC/passes/AlignmentLowering.cpp \
96+
$BINARYEN_SRC/passes/Asyncify.cpp \
9697
$BINARYEN_SRC/passes/AvoidReinterprets.cpp \
97-
$BINARYEN_SRC/passes/Bysyncify.cpp \
9898
$BINARYEN_SRC/passes/CoalesceLocals.cpp \
9999
$BINARYEN_SRC/passes/DeadArgumentElimination.cpp \
100100
$BINARYEN_SRC/passes/CodeFolding.cpp \

scripts/fuzz_opt.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def run(self, wasm):
245245
return out
246246

247247

248-
class Bysyncify(TestCaseHandler):
248+
class Asyncify(TestCaseHandler):
249249
def handle_pair(self, before_wasm, after_wasm, opts):
250250
# we must legalize in order to run in JS
251251
run([in_bin('wasm-opt'), before_wasm, '--legalize-js-interface', '-o', before_wasm] + FEATURE_OPTS)
@@ -255,36 +255,36 @@ def handle_pair(self, before_wasm, after_wasm, opts):
255255

256256
# TODO: also something that actually does async sleeps in the code, say
257257
# on the logging commands?
258-
# --remove-unused-module-elements removes the bysyncify intrinsics, which are not valid to call
258+
# --remove-unused-module-elements removes the asyncify intrinsics, which are not valid to call
259259

260-
def do_bysyncify(wasm):
261-
cmd = [in_bin('wasm-opt'), wasm, '--bysyncify', '-o', 't.wasm']
260+
def do_asyncify(wasm):
261+
cmd = [in_bin('wasm-opt'), wasm, '--asyncify', '-o', 't.wasm']
262262
if random.random() < 0.5:
263263
cmd += ['--optimize-level=%d' % random.randint(1, 3)]
264264
if random.random() < 0.5:
265265
cmd += ['--shrink-level=%d' % random.randint(1, 2)]
266266
cmd += FEATURE_OPTS
267267
run(cmd)
268268
out = run_d8('t.wasm')
269-
# emit some status logging from bysyncify
269+
# emit some status logging from asyncify
270270
print(out.splitlines()[-1])
271-
# ignore the output from the new bysyncify API calls - the ones with asserts will trap, too
272-
for ignore in ['[fuzz-exec] calling $bysyncify_start_unwind\nexception!\n',
273-
'[fuzz-exec] calling $bysyncify_start_unwind\n',
274-
'[fuzz-exec] calling $bysyncify_start_rewind\nexception!\n',
275-
'[fuzz-exec] calling $bysyncify_start_rewind\n',
276-
'[fuzz-exec] calling $bysyncify_stop_rewind\n',
277-
'[fuzz-exec] calling $bysyncify_stop_unwind\n']:
271+
# ignore the output from the new asyncify API calls - the ones with asserts will trap, too
272+
for ignore in ['[fuzz-exec] calling $asyncify_start_unwind\nexception!\n',
273+
'[fuzz-exec] calling $asyncify_start_unwind\n',
274+
'[fuzz-exec] calling $asyncify_start_rewind\nexception!\n',
275+
'[fuzz-exec] calling $asyncify_start_rewind\n',
276+
'[fuzz-exec] calling $asyncify_stop_rewind\n',
277+
'[fuzz-exec] calling $asyncify_stop_unwind\n']:
278278
out = out.replace(ignore, '')
279-
out = '\n'.join([l for l in out.splitlines() if 'bysyncify: ' not in l])
279+
out = '\n'.join([l for l in out.splitlines() if 'asyncify: ' not in l])
280280
return fix_output(out)
281281

282-
before_bysyncify = do_bysyncify(before_wasm)
283-
after_bysyncify = do_bysyncify(after_wasm)
282+
before_asyncify = do_asyncify(before_wasm)
283+
after_asyncify = do_asyncify(after_wasm)
284284

285-
compare(before, after, 'Bysyncify (before/after)')
286-
compare(before, before_bysyncify, 'Bysyncify (before/before_bysyncify)')
287-
compare(before, after_bysyncify, 'Bysyncify (before/after_bysyncify)')
285+
compare(before, after, 'Asyncify (before/after)')
286+
compare(before, before_asyncify, 'Asyncify (before/before_asyncify)')
287+
compare(before, after_asyncify, 'Asyncify (before/after_asyncify)')
288288

289289

290290
# The global list of all test case handlers
@@ -293,7 +293,7 @@ def do_bysyncify(wasm):
293293
FuzzExec(),
294294
CheckDeterminism(),
295295
Wasm2JS(),
296-
Bysyncify(),
296+
Asyncify(),
297297
]
298298

299299

scripts/fuzz_shell.js

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ var detrand = (function() {
3838
};
3939
})();
4040

41-
// Bysyncify integration.
42-
var Bysyncify = {
41+
// Asyncify integration.
42+
var Asyncify = {
4343
sleeping: false,
4444
sleepingFunction: null,
4545
sleeps: 0,
@@ -55,43 +55,43 @@ var Bysyncify = {
5555
if (typeof imports[module][i] === 'function') {
5656
(function(module, i) {
5757
ret[module][i] = function() {
58-
if (!Bysyncify.sleeping) {
59-
// Sleep if bysyncify support is present, and at a certain
58+
if (!Asyncify.sleeping) {
59+
// Sleep if asyncify support is present, and at a certain
6060
// probability.
61-
if (exports.bysyncify_start_unwind &&
61+
if (exports.asyncify_start_unwind &&
6262
detrand() < 0.5) {
6363
// We are called in order to start a sleep/unwind.
64-
console.log('bysyncify: sleep in ' + i + '...');
65-
Bysyncify.sleepingFunction = i;
66-
Bysyncify.sleeps++;
64+
console.log('asyncify: sleep in ' + i + '...');
65+
Asyncify.sleepingFunction = i;
66+
Asyncify.sleeps++;
6767
var depth = new Error().stack.split('\n').length - 6;
68-
Bysyncify.maxDepth = Math.max(Bysyncify.maxDepth, depth);
68+
Asyncify.maxDepth = Math.max(Asyncify.maxDepth, depth);
6969
// Save the memory we use for data, so after we restore it later, the
7070
// sleep/resume appears to have had no change to memory.
71-
Bysyncify.savedMemory = new Int32Array(view.subarray(Bysyncify.DATA_ADDR >> 2, Bysyncify.DATA_MAX >> 2));
71+
Asyncify.savedMemory = new Int32Array(view.subarray(Asyncify.DATA_ADDR >> 2, Asyncify.DATA_MAX >> 2));
7272
// Unwinding.
7373
// Fill in the data structure. The first value has the stack location,
7474
// which for simplicity we can start right after the data structure itself.
75-
view[Bysyncify.DATA_ADDR >> 2] = Bysyncify.DATA_ADDR + 8;
75+
view[Asyncify.DATA_ADDR >> 2] = Asyncify.DATA_ADDR + 8;
7676
// The end of the stack will not be reached here anyhow.
77-
view[Bysyncify.DATA_ADDR + 4 >> 2] = Bysyncify.DATA_MAX;
78-
exports.bysyncify_start_unwind(Bysyncify.DATA_ADDR);
79-
Bysyncify.sleeping = true;
77+
view[Asyncify.DATA_ADDR + 4 >> 2] = Asyncify.DATA_MAX;
78+
exports.asyncify_start_unwind(Asyncify.DATA_ADDR);
79+
Asyncify.sleeping = true;
8080
} else {
8181
// Don't sleep, normal execution.
8282
return imports[module][i].apply(null, arguments);
8383
}
8484
} else {
8585
// We are called as part of a resume/rewind. Stop sleeping.
86-
console.log('bysyncify: resume in ' + i + '...');
87-
assert(Bysyncify.sleepingFunction === i);
88-
exports.bysyncify_stop_rewind();
86+
console.log('asyncify: resume in ' + i + '...');
87+
assert(Asyncify.sleepingFunction === i);
88+
exports.asyncify_stop_rewind();
8989
// The stack should have been all used up, and so returned to the original state.
90-
assert(view[Bysyncify.DATA_ADDR >> 2] == Bysyncify.DATA_ADDR + 8);
91-
assert(view[Bysyncify.DATA_ADDR + 4 >> 2] == Bysyncify.DATA_MAX);
92-
Bysyncify.sleeping = false;
90+
assert(view[Asyncify.DATA_ADDR >> 2] == Asyncify.DATA_ADDR + 8);
91+
assert(view[Asyncify.DATA_ADDR + 4 >> 2] == Asyncify.DATA_MAX);
92+
Asyncify.sleeping = false;
9393
// Restore the memory to the state from before we slept.
94-
view.set(Bysyncify.savedMemory, Bysyncify.DATA_ADDR >> 2);
94+
view.set(Asyncify.savedMemory, Asyncify.DATA_ADDR >> 2);
9595
return imports[module][i].apply(null, arguments);
9696
}
9797
};
@@ -101,27 +101,27 @@ var Bysyncify = {
101101
}
102102
}
103103
}
104-
// Add ignored.print, which is ignored by bysyncify, and allows debugging of bysyncified code.
104+
// Add ignored.print, which is ignored by asyncify, and allows debugging of asyncified code.
105105
ret['ignored'] = { 'print': function(x, y) { console.log(x, y) } };
106106
return ret;
107107
},
108108
instrumentExports: function(exports) {
109109
var ret = {};
110110
for (var e in exports) {
111111
if (typeof exports[e] === 'function' &&
112-
!e.startsWith('bysyncify_')) {
112+
!e.startsWith('asyncify_')) {
113113
(function(e) {
114114
ret[e] = function() {
115115
while (1) {
116116
var ret = exports[e].apply(null, arguments);
117117
// If we are sleeping, then the stack was unwound; rewind it.
118-
if (Bysyncify.sleeping) {
119-
console.log('bysyncify: stop unwind; rewind');
118+
if (Asyncify.sleeping) {
119+
console.log('asyncify: stop unwind; rewind');
120120
assert(!ret, 'results during sleep are meaningless, just 0');
121-
//console.log('bysyncify: after unwind', view[Bysyncify.DATA_ADDR >> 2], view[Bysyncify.DATA_ADDR + 4 >> 2]);
121+
//console.log('asyncify: after unwind', view[Asyncify.DATA_ADDR >> 2], view[Asyncify.DATA_ADDR + 4 >> 2]);
122122
try {
123-
exports.bysyncify_stop_unwind();
124-
exports.bysyncify_start_rewind(Bysyncify.DATA_ADDR);
123+
exports.asyncify_stop_unwind();
124+
exports.asyncify_start_rewind(Asyncify.DATA_ADDR);
125125
} catch (e) {
126126
console.log('error in unwind/rewind switch', e);
127127
}
@@ -138,11 +138,11 @@ var Bysyncify = {
138138
return ret;
139139
},
140140
check: function() {
141-
assert(!Bysyncify.sleeping);
141+
assert(!Asyncify.sleeping);
142142
},
143143
finish: function() {
144-
if (Bysyncify.sleeps > 0) {
145-
print('bysyncify:', 'sleeps:', Bysyncify.sleeps, 'max depth:', Bysyncify.maxDepth);
144+
if (Asyncify.sleeps > 0) {
145+
print('asyncify:', 'sleeps:', Asyncify.sleeps, 'max depth:', Asyncify.maxDepth);
146146
}
147147
},
148148
};
@@ -170,14 +170,14 @@ var imports = {
170170
},
171171
};
172172

173-
imports = Bysyncify.instrumentImports(imports);
173+
imports = Asyncify.instrumentImports(imports);
174174

175175
// Create the wasm.
176176
var instance = new WebAssembly.Instance(new WebAssembly.Module(binary), imports);
177177

178178
// Handle the exports.
179179
var exports = instance.exports;
180-
exports = Bysyncify.instrumentExports(exports);
180+
exports = Asyncify.instrumentExports(exports);
181181
if (exports.memory) {
182182
var view = new Int32Array(exports.memory.buffer);
183183
}
@@ -190,10 +190,10 @@ for (var e in exports) {
190190
sortedExports.sort();
191191
sortedExports = sortedExports.filter(function(e) {
192192
// Filter special intrinsic functions.
193-
return !e.startsWith('bysyncify_');
193+
return !e.startsWith('asyncify_');
194194
});
195195
sortedExports.forEach(function(e) {
196-
Bysyncify.check();
196+
Asyncify.check();
197197
if (typeof exports[e] !== 'function') return;
198198
try {
199199
console.log('[fuzz-exec] calling $' + e);
@@ -207,5 +207,5 @@ sortedExports.forEach(function(e) {
207207
});
208208

209209
// Finish up
210-
Bysyncify.finish();
210+
Asyncify.finish();
211211

0 commit comments

Comments
 (0)