Commit 39b8954
runtime,internal/poll,loader: wasip2 pollable poll-integration + TCP I/O
Mirrors PR #5386's wasip1 work for wasip2. The cooperative scheduler's
idle path now calls wasi:io/poll.Poll over a combined list of (clock
pollable, registered pollables) instead of blocking the wasm module on
a single monotonic-clock subscription, so goroutines doing TCP I/O can
park while the scheduler runs other goroutines.
Plumbing components:
- runtime/netpoll_wasip2.go: pollable-keyed pollDesc registry; pollIO
builds one combined wasi:io/poll.Poll call (clock pollable + active
pollables). Linkname-exposed runtime_netpoll_addpollable_wasip2 /
done / pdfired / wake for internal/poll and future net.
- runtime/scheduler_idle_wasip2.go + scheduler_idle_wasip2_none.go:
cooperative-variant sleepTicks / waitForEvents that route through
pollIO; non-coop fallback uses monotonicclock.Block. Mirrors the
wasip1 structure introduced in 7000e7b.
- runtime/runtime_wasip2.go: sleepTicks moved out to the
scheduler_idle_wasip2*.go files.
- runtime/wait_other.go: build tag tightened to exclude wasip2.
internal/poll surface:
- internal/poll/fd_wasip2.go: WasipNFD wraps a (TcpSocket, InputStream,
OutputStream) triple. DialTCPWasip2, ListenTCPWasip2, Accept, Read,
Write, Close, SetDeadline*. Each blocking op tries the wasi call,
on would-block subscribes, parks, retries — same pattern as the
wasip1 internal/poll.FD but pollable-keyed. Linkname-friendly
Wasip2TCP{Listen,Dial,Accept,Read,Write,Close,SetDeadline} wrappers
for test / future net callers.
- internal/poll/errors_wasip.go: ErrFileClosing / ErrNetClosing /
ErrDeadlineExceeded / ErrNoDeadline extracted from fd_wasip1.go to
a wasip1||wasip2 shared file.
Loader change:
- loader/goroot.go: listGorootMergeLinks now filters TinyGo files by
//go:build constraints (via go/build.Context.MatchFile) before
deciding "TinyGo owns this directory". Files that don't match the
current target no longer cause upstream Go files at the same level
to be dropped. Unblocks per-target overrides in directories like
src/net/ for future net.wasip2 work without disturbing wasip1.
End-to-end verification:
$ wasmtime run -Sinherit-network -Stcp ./tcpecho_wasip2.wasm &
listening on 127.0.0.1:9999
tick 1
tick 2
tick 3
$ echo hello | nc 127.0.0.1 9999
hello # echoed by the wasm
$ # two concurrent clients echo cleanly while ticker keeps ticking
The test program (not shipped) uses //go:linkname to drive the
internal/poll TCP helpers directly, since TinyGo doesn't yet have a
net.Listen / net.Dial path on wasip2 (upstream Go's net doesn't build
for wasip2 due to cgo_linux.go reaching for Linux headers). The
src/net/ wasip2 wrappers are out of scope for this PR and tracked as
follow-up — once they land, callers will use net.Listen / Dial
directly and the linkname wrappers can drop.
Wasip1 regression sweep: tcpecho.wasm still passes; time.Sleep / parkfile
/ parksynth unchanged.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 81b2957 commit 39b8954
10 files changed
Lines changed: 823 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | | - | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
143 | 144 | | |
144 | 145 | | |
145 | 146 | | |
146 | | - | |
| 147 | + | |
147 | 148 | | |
148 | 149 | | |
149 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
150 | 163 | | |
151 | 164 | | |
152 | 165 | | |
| |||
168 | 181 | | |
169 | 182 | | |
170 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
171 | 192 | | |
172 | 193 | | |
173 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | 29 | | |
45 | 30 | | |
46 | 31 | | |
| |||
0 commit comments