Split out compileAndInstantiate from instantiate #999
Closed
+88
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I think there would be a number of benefits from having
instantiate
always return aPromise<Instance>
and having a separatecompileAndInstantiate
that returns thePromise<{module,instance}>
. In this PR,instantiate
is still able to take all the same things it does now, and thus, this PR is strictly more expressive than the current state. (It's also a pretty simple change to implement.)The benefits I see of this PR are:
instantiate
is less surprising;compileAndInstantiate
returning a pair is implied by the name.instantiate
is just a sink for all manner of byte-y things that always produces anInstance
. I was feeling this acutely while writing MDN docs/tutorials recently.instantiate
, the engine would know up front that theModule
won't be needed and that the generated code can't be instantiated multiple times, serialized or shared. This can allow for more efficient compilation, more aggressive specialization and less garbage generated by compilation.instantiateGroup
(Support multi-module 1-step Instantiate with dependencies #997): given that this function takes a map of inputs and produces a map of outputs: are the output valuesInstance
s or{module,instance}
pairs? Do we have it depend on the dynamic types of values in the input map? What if some of the input values areModule
s and some are not? Do we instead break symmetry and have it always return a{module,instance}
pair? After this PR, the obvious, symmetric thing would be to have bothinstantiateGroup
andcompileAndInstantiateGroup
which makes the output type clear.