Skip to content

Commit 74bf019

Browse files
committed
Merge with WebAssembly/stack-switching
2 parents 15ec7d1 + 5010b4e commit 74bf019

File tree

24 files changed

+161
-40
lines changed

24 files changed

+161
-40
lines changed

README.md

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,13 @@
1+
[![CI for specs](https://github.com/WebAssembly/stack-switching/actions/workflows/ci-spec.yml/badge.svg)](https://github.com/WebAssembly/stack-switching/actions/workflows/ci-spec.yml)
2+
[![CI for interpreter & tests](https://github.com/WebAssembly/stack-switching/actions/workflows/ci-interpreter.yml/badge.svg)](https://github.com/WebAssembly/stack-switching/actions/workflows/ci-interpreter.yml)
3+
14
# Stack-Switching Proposal for WebAssembly
25

36
This repository is a clone of [`WebAssembly/spec`](https://github.com/WebAssembly/spec/). It is meant for discussion, prototype specification, and implementation of a proposal to add
47
support for stack-switching.
58

69
See the [explainer](proposals/stack-switching/Explainer.md) for a high-level summary of the proposal.
710

8-
## Previous proposals
9-
10-
The current explainer represents the unification of two previous proposals: Typed Continuations (wasmfx) and Bag of Stacks (bos). (The explainers have now been unified. Once the reference interpreter and examples are adapted for the unified proposal this section will be removed from the README.)
11-
12-
#### Typed Continuations
13-
14-
* See the [explainer](proposals/continuations/Explainer.md) for a high-level summary of the proposal.
15-
16-
* See the [overview](proposals/continuations/Overview.md) for a more formal description of the proposal.
17-
18-
* An [implementation](https://github.com/WebAssembly/stack-switching/tree/wasmfx) is available as an extension to the reference interpreter. It is accesible from the `wasmfx` branch of this repository.
19-
20-
* See the [examples](proposals/continuations/examples) for Wasm code for implementing various different features including lightweight threads, actors, and async/await.
21-
22-
#### Bag of Stacks Proposal
23-
24-
* See the [explainer](proposals/bag-o-stacks/Explainer.md) for a high-level summary of the proposal.
25-
26-
Original README from upstream repository follows.
27-
28-
--------------------------------------------------------------------------------
29-
30-
[![CI for specs](https://github.com/WebAssembly/stack-switching/actions/workflows/ci-spec.yml/badge.svg)](https://github.com/WebAssembly/stack-switching/actions/workflows/ci-spec.yml)
31-
[![CI for interpreter & tests](https://github.com/WebAssembly/stack-switching/actions/workflows/ci-interpreter.yml/badge.svg)](https://github.com/WebAssembly/stack-switching/actions/workflows/ci-interpreter.yml)
32-
3311
# spec
3412

3513
This repository holds the sources for the WebAssembly specification,

interpreter/binary/decode.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ let import_desc s =
11071107
| 0x01 -> TableImport (table_type s)
11081108
| 0x02 -> MemoryImport (memory_type s)
11091109
| 0x03 -> GlobalImport (global_type s)
1110-
| 0x04 -> TagImport (at var s)
1110+
| 0x04 -> TagImport (tag_type s)
11111111
| _ -> error s (pos s - 1) "malformed import kind"
11121112

11131113
let import s =

interpreter/binary/encode.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ struct
974974
| TableImport t -> byte 0x01; table_type t
975975
| MemoryImport t -> byte 0x02; memory_type t
976976
| GlobalImport t -> byte 0x03; global_type t
977-
| TagImport t -> byte 0x04; var t
977+
| TagImport t -> byte 0x04; tag_type t
978978

979979
let import im =
980980
let {module_name; item_name; idesc} = im.it in
@@ -1025,8 +1025,8 @@ struct
10251025
section 6 (vec global) gs (gs <> [])
10261026

10271027
(* Tag section *)
1028-
let tag tag =
1029-
tag_type tag.it.tgtype
1028+
let tag (t : tag) =
1029+
byte 0x00; var t.it.tgtype
10301030

10311031
let tag_section ts =
10321032
section 13 (vec tag) ts (ts <> [])

interpreter/text/parser.mly

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ instr_list :
591591
| instr1 instr_list { fun c -> $1 c @ $2 c }
592592
| select_instr_instr_list { $1 }
593593
| call_instr_instr_list { $1 }
594-
| resume_instr_instr { fun c -> let e, es = $1 c in e :: es }
594+
| resume_instr_instr_list { $1 }
595595

596596
instr1 :
597597
| plain_instr { fun c -> [$1 c @@ $sloc] }
@@ -769,25 +769,25 @@ call_instr_results_instr_list :
769769
| instr_list
770770
{ fun c -> [], $1 c }
771771

772-
resume_instr_instr :
772+
resume_instr_instr_list :
773773
| RESUME var resume_instr_handler_instr
774774
{ let loc1 = $loc($1) in
775775
fun c ->
776776
let x = $2 c type_ in
777-
let hs, es = $3 c in resume x hs @@ loc1, es }
777+
let hs, es = $3 c in (resume x hs @@ loc1) :: es }
778778
| RESUME_THROW var var resume_instr_handler_instr
779779
{ let loc1 = $loc($1) in
780780
fun c ->
781781
let x = $2 c type_ in
782782
let tag = $3 c tag in
783-
let hs, es = $4 c in resume_throw x tag hs @@ loc1, es }
783+
let hs, es = $4 c in (resume_throw x tag hs @@ loc1) :: es }
784784

785785
resume_instr_handler_instr :
786786
| LPAR ON var var RPAR resume_instr_handler_instr
787787
{ fun c -> let hs, es = $6 c in ($3 c tag, OnLabel ($4 c label)) :: hs, es }
788788
| LPAR ON var SWITCH RPAR resume_instr_handler_instr
789789
{ fun c -> let hs, es = $6 c in ($3 c tag, OnSwitch) :: hs, es }
790-
| instr1
790+
| instr_list
791791
{ fun c -> [], $1 c }
792792

793793
block_instr :

interpreter/valid/valid.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,14 +651,15 @@ let rec check_instr (c : context) (e : instr) (s : infer_result_type) : infer_in
651651
" but the type annotation has " ^ string_of_result_type ts11)
652652
in
653653
let et = tag c y in
654-
let FuncT (_, t) as ft = func_type_of_tag_type c et y.at in
655-
require (match_func_type c.types (FuncT ([], t)) ft) y.at
654+
let FuncT (ts31, t) = func_type_of_tag_type c et y.at in
655+
require (ts31 = []) y.at
656656
"type mismatch in switch tag";
657657
require (match_result_type c.types ts12 t) y.at
658658
"type mismatch in continuation types";
659659
require (match_result_type c.types t ts22) y.at
660660
"type mismatch in continuation types";
661-
ts11 --> ts21, []
661+
let ts11' = Lib.List.lead ts11 in
662+
(ts11' @ [RefT (Null, VarHT (StatX x.it))]) --> ts21, []
662663

663664
| Throw x ->
664665
let FuncT (ts1, ts2) = func_type_of_tag_type c (tag c x) x.at in

proposals/stack-switching/Explainer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ We extend the binary format of composite types, heap types, and instructions.
842842
| Opcode | Type | Parameters | Note |
843843
| ------ | --------------- | ---------- |------|
844844
| -0x20 | `func t1* t2*` | `t1* : vec(valtype)` `t2* : vec(valtype)` | from Wasm 1.0 |
845-
| -0x23 | `cont $ft` | `$ft : typeidx` | new |
845+
| -0x23 | `cont $ft` | `$ft : s33` | new |
846846

847847
#### Heap Types
848848

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)