Commit 92f238b
align multithreading and trap behavior with CM spec (bytecodealliance#14146)
* align multithreading and trap behavior with CM spec
This updates Wasmtime's Component Model async and cooperative multithreading
support to match the current specification, including:
- Refined rules for trapping when a sync-typed function blocks. We now enforce
this "lazily" rather than "eagerly", mwaning a sync-typed function is allowed
to call an async-typed function or blocking intrinsic, and if it doesn't
actually block, we won't trap. And if the call _does_ block, we will look for
any eligible threads to run and run them until no such threads remain, only
trapping if and when we still need to block and have no more threads to run.
- Allow reentrance in all cases except when the instance has trapped.
- Remove the previous "may block" bookkeeping at the task and root instance
level, replacing it with (sub-)instance level tracking of whether any
sync-typed function is running in that instance.
- Run the event loop during start function calls since they are now allowed to
call async-typed functions, create and resume threads, etc. I've also added
some code to assert that the event loop is running when it is required.
- Add `ConcurrentState::switch_item` for use when we need to run a specific work
item at the next turn of the event loop, regardless of what's already in the
`high_priority` queue. This is necessary because the spec is particular about
which thread to switch to e.g. when calling a function or promoting a thread,
and it won't allow us to run any other threads first.
Note that this includes `test/component-model` submodule updates which haven't
yet been merged to the main branch of the upstream repo, but should be merged
soon. See WebAssembly/component-model#705
Fixes bytecodealliance#14117
Co-authored-by: Alex Crichton <alex@alexcrichton.com>
* Avoid `Send`-related changes (#7)
Accept an `unsafe` block which I believe is correct and still otherwise
safe at the invocation site. The main hidden constraint now is that we
can't transfer fibers to other non-store-bound-locations but that's
effectively already true so shouldn't be too onerous to uphold.
* align more scheduler details with the spec
- Ensure that subtask status updates are delivered promptly and
deterministically according to the spec by using
`ConcurrentState::switch_item` instead of `ConcurrentState::high_priority`
- Fix reentrance scenarious involving `subtask.cancel` where the subtask tries
to add itself to a waitable set before or after being canceled
- Refine rules for switching-or-trapping on thread exit when the current
instance has a sync-typed call in progress
- Misc. bug fixes
* fix test regressions
Notably, this makes Wasmtime more aggressive about poisoning the store if an
error happens when e.g. lifting a result (e.g. due to a misaligned pointer), and
the tests have been updated accordingly.
* address review feedback
* update tests/component-model submodule
* address review feedback
* add comments to `any_may_not_suspend`
* avoid triggering rustc's recursion limit in `serve.rs` (again)
* another rustc overflow workaround
---------
Co-authored-by: Alex Crichton <alex@alexcrichton.com>1 parent 30cdd8d commit 92f238b
55 files changed
Lines changed: 1590 additions & 1362 deletions
File tree
- crates
- cranelift/src
- compiler
- environ/src
- compile
- component
- translate
- fact
- misc/component-async-tests/tests/scenario
- test-util/src
- wasmtime/src/runtime
- component
- concurrent
- func
- resources
- externals
- vm
- component
- src/commands
- tests
- all
- component_model
- disas
- component-model
- misc_testsuite/component-model
- async
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1129 | 1129 | | |
1130 | 1130 | | |
1131 | 1131 | | |
1132 | | - | |
1133 | | - | |
1134 | | - | |
1135 | | - | |
1136 | | - | |
1137 | | - | |
1138 | 1132 | | |
1139 | 1133 | | |
1140 | 1134 | | |
| |||
1158 | 1152 | | |
1159 | 1153 | | |
1160 | 1154 | | |
1161 | | - | |
1162 | | - | |
1163 | | - | |
1164 | | - | |
1165 | | - | |
1166 | 1155 | | |
1167 | 1156 | | |
1168 | 1157 | | |
| |||
1191 | 1180 | | |
1192 | 1181 | | |
1193 | 1182 | | |
1194 | | - | |
1195 | | - | |
| 1183 | + | |
| 1184 | + | |
1196 | 1185 | | |
1197 | 1186 | | |
1198 | 1187 | | |
1199 | 1188 | | |
1200 | 1189 | | |
1201 | 1190 | | |
1202 | 1191 | | |
1203 | | - | |
1204 | | - | |
1205 | | - | |
1206 | | - | |
1207 | | - | |
1208 | | - | |
1209 | | - | |
1210 | | - | |
1211 | | - | |
1212 | | - | |
1213 | | - | |
1214 | | - | |
1215 | | - | |
1216 | | - | |
1217 | | - | |
1218 | | - | |
1219 | | - | |
| 1192 | + | |
1220 | 1193 | | |
1221 | 1194 | | |
1222 | 1195 | | |
| |||
1296 | 1269 | | |
1297 | 1270 | | |
1298 | 1271 | | |
1299 | | - | |
| 1272 | + | |
1300 | 1273 | | |
1301 | | - | |
1302 | | - | |
1303 | | - | |
1304 | | - | |
1305 | | - | |
1306 | | - | |
1307 | | - | |
1308 | 1274 | | |
1309 | 1275 | | |
1310 | 1276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
455 | 455 | | |
456 | 456 | | |
457 | 457 | | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | 458 | | |
464 | 459 | | |
465 | 460 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | 95 | | |
101 | 96 | | |
102 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
270 | | - | |
271 | 270 | | |
272 | 271 | | |
273 | 272 | | |
| |||
913 | 912 | | |
914 | 913 | | |
915 | 914 | | |
916 | | - | |
917 | 915 | | |
918 | 916 | | |
919 | 917 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | 395 | | |
400 | 396 | | |
401 | 397 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
691 | 691 | | |
692 | 692 | | |
693 | 693 | | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | 694 | | |
698 | 695 | | |
699 | 696 | | |
| |||
1976 | 1973 | | |
1977 | 1974 | | |
1978 | 1975 | | |
1979 | | - | |
1980 | 1976 | | |
1981 | 1977 | | |
1982 | 1978 | | |
| |||
2043 | 2039 | | |
2044 | 2040 | | |
2045 | 2041 | | |
2046 | | - | |
2047 | | - | |
2048 | | - | |
2049 | | - | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
2050 | 2045 | | |
2051 | 2046 | | |
2052 | 2047 | | |
| |||
2111 | 2106 | | |
2112 | 2107 | | |
2113 | 2108 | | |
2114 | | - | |
| 2109 | + | |
2115 | 2110 | | |
2116 | 2111 | | |
2117 | 2112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | 167 | | |
171 | 168 | | |
172 | 169 | | |
| |||
455 | 452 | | |
456 | 453 | | |
457 | 454 | | |
458 | | - | |
459 | | - | |
| 455 | + | |
460 | 456 | | |
461 | 457 | | |
462 | 458 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1583 | 1583 | | |
1584 | 1584 | | |
1585 | 1585 | | |
1586 | | - | |
1587 | | - | |
1588 | | - | |
1589 | | - | |
1590 | | - | |
1591 | | - | |
1592 | 1586 | | |
1593 | 1587 | | |
1594 | 1588 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | 52 | | |
54 | 53 | | |
55 | 54 | | |
| |||
165 | 164 | | |
166 | 165 | | |
167 | 166 | | |
168 | | - | |
169 | 167 | | |
170 | 168 | | |
171 | 169 | | |
| |||
183 | 181 | | |
184 | 182 | | |
185 | 183 | | |
186 | | - | |
187 | 184 | | |
188 | 185 | | |
189 | 186 | | |
| |||
248 | 245 | | |
249 | 246 | | |
250 | 247 | | |
251 | | - | |
252 | | - | |
253 | 248 | | |
254 | 249 | | |
255 | 250 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
117 | | - | |
118 | 116 | | |
119 | 117 | | |
120 | 118 | | |
| |||
137 | 135 | | |
138 | 136 | | |
139 | 137 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | 138 | | |
144 | 139 | | |
145 | 140 | | |
| |||
298 | 293 | | |
299 | 294 | | |
300 | 295 | | |
301 | | - | |
302 | 296 | | |
303 | 297 | | |
304 | 298 | | |
| |||
352 | 346 | | |
353 | 347 | | |
354 | 348 | | |
355 | | - | |
356 | 349 | | |
357 | 350 | | |
358 | 351 | | |
| |||
429 | 422 | | |
430 | 423 | | |
431 | 424 | | |
432 | | - | |
433 | 425 | | |
434 | 426 | | |
435 | 427 | | |
| |||
491 | 483 | | |
492 | 484 | | |
493 | 485 | | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | 486 | | |
514 | 487 | | |
515 | 488 | | |
| |||
0 commit comments