-
Notifications
You must be signed in to change notification settings - Fork 1
Description
This issue is intended to document, discuss and track some difficulties that occur when performing host calls in the presence of stack switching that in turn re-enter wasm.
For example, consider the following logical call stack (here, "logical" means that this is not a single, contingent stack):
$f -resume-> $g -call-> host_function -call-> $h
where $f, $g, and $h are wasm functions. Here, $g is not executing on the main stack, but inside a continuation, when performing the host call. The latter then re-enters wasm by calling $h.
There are multiple issues that would need to be resolved in order for this to work correctly:
-
Most likely, we want to consider host calls to act as barriers for the purposes of stack switching, meaning that a
suspendin$hcannot get handled in$for$g. This means that if any of these functions run in instances of the sameStore, we need to set aside the continuation chain when enteringhand restore it once it returns. -
The first point illustrates that when starting execution of
$h, we would want to indicate that it is not subject to any handlers. Currently, this would be achieved by setting itsStore's stack chain toMainStack(independently from whether it actually shares aStorewith the other involved wasm functions or not).
However,$his not actually running on the main stack, since it is running on sameFiberStackas$g. For the purposes of correctly handling stack limits, we would need some way to indicate that$his running inside aFiberStack, but without actually being subject to any other handlers. Of course, we may also eventually decide that all host calls switch to the actual main stack for execution.
I think that all of these issues can be resolved, but that these solutions possibly interact with future design decisions. Therefore, I suggest that we simply disallow this for now by enforcing the current rule in the implementation: Re-entering wasm from a host call is only permitted when not already running inside a continuation. Or in other words, the host call from which we want to re-enter wasm must have been running on the main stack. We can then ease these restrictions at a later point.