Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Writable/readable-end management mismatch with the specification #53

@alexcrichton

Description

@alexcrichton

This test

(component definition $a
  (component $C
    (core module $m
      (global $g (mut i32) (i32.const 0))
      (func (export "take") (param i32) local.get 0 global.set $g)
      (func (export "give") (result i32) global.get $g)
    )
    (core instance $i (instantiate $m))

    (func (export "take") (param "f" (future)) (canon lift (core func $i "take")))
    (func (export "give") (result (future)) (canon lift (core func $i "give")))
  )
  (instance $C (instantiate $C))

  (core func $take (canon lower (func $C "take")))
  (core func $give (canon lower (func $C "give")))
  (type $t (future))
  (core func $new (canon future.new $t))
  (core func $close-readable (canon future.close-readable $t))
  (core func $close-writable (canon future.close-writable $t))

  (core module $m
    (import "" "take" (func $take (param i32)))
    (import "" "give" (func $give (result i32)))
    (import "" "new" (func $new (result i32)))
    (import "" "close-readable" (func $close-readable (param i32)))
    (import "" "close-writable" (func $close-writable (param i32 i32)))

    (func (export "close-readable")
      (call $close-readable (call $new))
    )

    (func (export "close-writable")
      (call $close-writable (call $new) (i32.const 0))
    )

    (func (export "close-readable-after-roundtrip")
      (call $take (call $new))
      (call $close-readable (call $give))
    )

    (func (export "close-writable-after-roundtrip")
      (call $take (call $new))
      (call $close-writable (call $give) (i32.const 0))
    )
  )

  (core instance $i (instantiate $m
    (with "" (instance
      (export "take" (func $take))
      (export "give" (func $give))
      (export "new" (func $new))
      (export "close-readable" (func $close-readable))
      (export "close-writable" (func $close-writable))
    ))
  ))

  (func (export "close-readable") (canon lift (core func $i "close-readable")))
  (func (export "close-writable") (canon lift (core func $i "close-writable")))
  (func (export "close-readable-after-roundtrip") (canon lift (core func $i "close-readable-after-roundtrip")))
  (func (export "close-writable-after-roundtrip") (canon lift (core func $i "close-writable-after-roundtrip")))
)

(component instance $A1 $a)
(assert_trap (invoke "close-readable") "write end")
(component instance $A1 $a)
(assert_return (invoke "close-writable"))
(component instance $A1 $a)
(assert_return (invoke "close-readable-after-roundtrip"))
(component instance $A2 $a)
(assert_trap (invoke "close-writable-after-roundtrip") "write end")

currently fails with:

$ cargo run --features component-model-async wast foo.wast -W component-model-async
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/wasmtime wast foo.wast -W component-model-async`
Error: failed to run script file 'foo.wast'

Caused by:
    0: failed directive on foo.wast:65:1
    1: expected trap, got Component([])

Specifically close-readable, which should trap, is not trapping. Additionally close-writable-after-roundtrip, which should trap, is also not trapping.

I found this poking around conceptually in the spec about what happens if you lower a writable end as a readable end, then close the writable end, then get back the readable end.

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