Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Guaranteeing additional soundness properties #128

@tlively

Description

@tlively

After a few recent conversations with @RossTate and @fgmccabe where this came up, I wanted to share my thoughts about how I see the relationship between Interface Types and core WebAssembly and see if it is in line with how other folks see that relationship. If so, I hope that making these design principles explicit in the IT explainer will help guide the design of stack switching and other proposals that create new risks at coordination boundaries.

Optionally guaranteeing type soundness

An important feature of core WebAssembly is that its type system is sound. It guarantees that if a function expects to receive an i32 as an argument, it will never receive some other type. Most of this soundness is guaranteed by the static type system, but sometimes there need to be dynamic checks to ensure soundness. For example for indirect calls, soundness is ensured by runtime checks that trap if type soundness would be violated. However, there are many useful soundness properties that core WebAssembly does not and cannot enforce.

Consider a module that uses the pair of i32s (address, length) to represent strings in memory and another module that uses the pair of i32s (start address, end address) to represent strings in memory. When these modules call into each other, core WebAssembly cannot guarantee the soundness property that each module receives strings in the format it expects. Interface Types, however, is able to provide this guarantee. Note that IT does not necessarily provide this guarantee, though — the module authors could have chosen to continue exposing their string functions as taking pairs of i32s. Interface Types is therefore able to optionally guarantee this type soundness property for strings (and other IT types) at the module author's discretion.

Other soundness properties

Consider a language that exclusively uses return values to propagate error conditions. The IT interface of that language's modules will include in the return types of its imported functions the error conditions it handles. The exported functions of modules it links with must include those same error conditions in the return types of their exported functions. If those linked modules internally use the EH proposal to signal error conditions, their export adapters would be responsible for catching those exceptions and turning them into the error codes specified in the IT signature. Today there is no way for IT to guarantee that the export adapters correctly do so.

The specific soundness property in question that the first module wants to enforce is that an exception will never propagate into it. This property is desirable because all error conditions should be made explicit in the interface types signature of the module and none should be able to sneak over the boundary via other means. In this specific case, IT could enforce the soundness property dynamically by inserting a catch_all and trap as part of the adapter fusion algorithm.

This soundness property is not a type soundness property per se, but IT still seems like the perfect place to enforce it. I propose that we expand IT's mandate to cover additional soundness properties beyond type soundness (starting with the example above) according to the following principles.

Design principles

  1. To the extent possible, soundness properties involving toolchain coordination boundaries are enforced at the IT layer, not the core WebAssembly layer.

  2. IT should always lower to core WebAssembly, so all the primitives IT needs to dynamically enforce its supported soundness properties should be specified in core WebAssembly.

  3. IT lowering should not require rewriting arbitrary WebAssembly code in the participating modules.

  4. Module authors should be able to control the soundness properties they are enforcing. (Otherwise IT would be too inflexible, as noted in Interface Types and Isolation? #99)

  5. To the extent possible, all cross-module interactions should be opt-in (i.e. all supported soundness properties should be opt-out) at the IT layer so that module authors don't have to worry about unwanted interactions with future proposals.

The only exceptions to (1) should be when it is incompatible with WebAssembly's other goals, such as if the property could not be enforced solely at the IT layer without an unacceptable performance overhead.

The only exceptions to (5) should be to introduce support for a new soundness property without a corresponding new core WebAssembly feature, since making such properties opt-out would be a breaking change. This should be avoided by making the identification and standardization of relevant IT soundness properties part of the design and standardization of core WebAssembly proposals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions