Skip to content

Commit 9928b44

Browse files
fix(core): async return instruction usage
This commit fixes two issues in the async return machinery: 1. `Instruction::Return` calculation of `amt` for async functions 2. Missing use of `Instruction::AsyncTaskReturn` Both issues were in the function with no result case: For (1), the code did not take into account that the async functions *always* return at least the async state (a single i64). For (2), the code did not use an `Instruction::AsyncTaskReturn`, rather than a regular `Instruction::Return`
1 parent dce66c9 commit 9928b44

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

crates/core/src/abi.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ impl<'a, B: Bindgen> Generator<'a, B> {
12711271
self.emit(&Instruction::AsyncTaskReturn { name, params });
12721272
}
12731273

1274-
// All async/non-async cases with results that need to be returned are present here
1274+
// All async/non-async cases with results that need to be returned
12751275
//
12761276
// In practice, async imports should not end up here, as the returned result of an
12771277
// async import is *not* a pointer but instead a status code.
@@ -1281,14 +1281,17 @@ impl<'a, B: Bindgen> Generator<'a, B> {
12811281
self.emit(&Instruction::AsyncTaskReturn { name, params });
12821282
}
12831283

1284-
// All async/non-async cases with no results simply return
1285-
//
1286-
// In practice, an async import will never get here (it always has a result, the error code)
1284+
// All async/non-async cases with no results
12871285
(_, None) => {
1288-
self.emit(&Instruction::Return {
1289-
func,
1290-
amt: sig.results.len(),
1291-
});
1286+
if async_ {
1287+
let name = &format!("[task-return]{}", func.name);
1288+
self.emit(&Instruction::AsyncTaskReturn {
1289+
name: name,
1290+
params: &[WasmType::Pointer],
1291+
});
1292+
} else {
1293+
self.emit(&Instruction::Return { func, amt: 0 });
1294+
}
12921295
}
12931296
}
12941297

0 commit comments

Comments
 (0)