Repository navigation
Add 'optional' imports/exports - #775
Open
lukewagner wants to merge 1 commit into
Open
lukewagner wants to merge 1 commit into
lukewagner wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds the ability to declare function, value, instance and resource types as
optional(in both WIT and in the CM type constructors), allowing optional imports and exports of these sorts of definitions. At the ABI level, there is a newoptional.presentbuilt-in that generates aglobal i32boolean that core wasm can import to test whether a givenoptionaldefinition is present or not. If a function is not present and called, it traps, so that the burden is on the guest code to not do that. The other details are explained with examples in a newText.md#-optionalitysection.There's already some motivation listed in #555, but to restate and expand here, the goals are to:
A valid question is why we can't just use the existing
(option T)value type. Some answers are:optionalon functions, types and instances, which aren't first-class values (or values at all)(option (option T))or(list (option T))optionalfunction, we want to get afuncidx(that can henceforth be used like a regular function for lifting/lowering), not avalueidx(and similarly for each otheroptionalsort).Due that last bullet, it seems like we need
optionalto go on the {function,value,instance} type constructor (and, forresourcetypes, on thesubtype bound) b/c we're talking about a special "not present" value/type in the respective index space.Also in the PR:
(type $T)ascription added toinstancedefinitions that allows more coercion involvingoptionalthan would otherwise be sound to add to pure subtyping.(I'm planning to keep this PR open for a while until someone gets a chance to work on an experimental implementation since it seems like this feature would benefit from that.)