Skip to content

Forbidding handles within the values of map<K, V> #751

Open

Description

@alexcrichton

I'd like to float the idea of adding further restrictions to the V in map<K, V> type, specifically forbidding any type that transitively includes a handle where a handle here is any of own<T>, borrow<T>, future<T>, stream<T>, error-context, etc. The original motivation for me bringing this up is bytecodealliance/wasmtime#14812, but the general problem is that map<K, V> is ABI-wise just a sequence of tuples, and there's nothing preventing overlap of the keys. Bindings generators thus need to handle the case of overlapping K values and properly destroy the provided V value. In the case of resource this might involve running destructors (own<T>), updating internal metadata in a store (borrow<T>), or possibly delivering async events (future<T> and stream<T>). These are all relatively weighty operations which are easy to forget (as Wasmtime has) and not always easy to integrate.

To address this I'd like to propose an interim workaround in the meantime of forbidding these types in the V of a map<K, V>. This would be a temporary restriction until someone has a compelling use case to support this and help fill out the implementation. This would be similar to how the K type is currently limited as well.

Activity

  1. added a commit that references this issue on Oct 23, 2026
    1f102b8
  2. lukewagner commented on Oct 23, 2026

    @lukewagner
    Member

    Makes sense, especially since we can relax the restriction later if we think it's useful and worth the effort to deal with these handle issues. PR proposing the rules with WAST tests in #756

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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