Skip to content

Commit bcc2002

Browse files
authored
Merge pull request #29 from WebAssembly/core-split
Split core definitions out into separate index spaces
2 parents 18399df + 49fb117 commit bcc2002

File tree

8 files changed

+849
-693
lines changed

8 files changed

+849
-693
lines changed

design/mvp/Binary.md

Lines changed: 190 additions & 153 deletions
Large diffs are not rendered by default.

design/mvp/CanonicalABI.md

Lines changed: 80 additions & 81 deletions
Large diffs are not rendered by default.

design/mvp/Explainer.md

Lines changed: 511 additions & 390 deletions
Large diffs are not rendered by default.

design/mvp/FutureFeatures.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,22 @@ serialization format, as this often incurs extra copying when the source or
1515
destination language-runtime data structures don't precisely match the fixed
1616
serialization format. A significant amount of work was spent designing a
1717
language of [adapter functions] that provided fairly general programmatic
18-
control over the process of serializing and deserializing interface-typed values.
18+
control over the process of serializing and deserializing high-level values.
1919
(The Interface Types Explainer currently contains a snapshot of this design.)
2020
However, a significant amount of additional design work remained, including
2121
(likely) changing the underlying semantic foundations from lazy evaluation to
2222
algebraic effects.
2323

24-
In pursuit of a timely MVP and as part of the overall [scoping and layering proposal],
25-
the goal of avoiding a fixed serialization format was dropped from the MVP, by
26-
instead defining a [Canonical ABI](CanonicalABI.md) in the MVP. However, the
27-
current design of [function definitions](Explainer.md#function-definitions)
28-
anticipates a future extension whereby function bodies can contain not just the
29-
fixed Canonical ABI-following `canon.lift` and `canon.lower` but,
30-
alternatively, general adapter function code.
24+
In pursuit of a timely MVP and as part of the overall [scoping and layering
25+
proposal], the goal of avoiding a fixed serialization format was dropped from
26+
the MVP by instead defining a [Canonical ABI](CanonicalABI.md) in the MVP.
27+
However, the current design anticipates a future extension whereby lifting and
28+
lowering functions can be generated not just from `canon lift` and `canon
29+
lower`, but, alternatively, general-purpose serialization/deserialization code.
3130

32-
In this future state, `canon.lift` and `canon.lower` could be specified by
33-
simple expansion into the adapter code, making these instructions effectively
34-
macros. However, even in this future state, there is still concrete value in
31+
In this future state, `canon lift` and `canon lower` could be specified by
32+
simple expansion into the general-purpose code, making these instructions
33+
effectively macros. However, even in this future state, there is still value in
3534
having a fixedly-defined Canonical ABI as it allows more-aggressive
3635
optimization of calls between components (which both use the Canonical ABI) and
3736
between a component and the host (which often must use a fixed ABI for calling
@@ -53,8 +52,8 @@ Additionally, having two similar-but-different, partially-overlapping concepts
5352
makes the whole proposal harder to explain. Thus, the MVP drops the concept of
5453
"adapter modules", including only shared-nothing "components". However, if
5554
concrete future use cases emerged for creating modules that partially used
56-
interface types and partially shared linear memory, "adapter modules" could be
57-
added as a future feature.
55+
shared-nothing component values and partially shared linear memory, "adapter
56+
modules" could be added as a future feature.
5857

5958

6059
## Shared-everything Module Linking in Core WebAssembly

design/mvp/Subtyping.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ But roughly speaking:
66

77
| Type | Subtyping |
88
| ------------------------- | --------- |
9-
| `unit` | every interface type is a subtype of `unit` |
9+
| `unit` | every value type is a subtype of `unit` |
1010
| `bool` | |
1111
| `s8`, `s16`, `s32`, `s64`, `u8`, `u16`, `u32`, `u64` | lossless coercions are allowed |
1212
| `float32`, `float64` | `float32 <: float64` |
@@ -20,5 +20,5 @@ But roughly speaking:
2020
| `union` | `T <: (union ... T ...)` |
2121
| `func` | parameter names must match in order; contravariant parameter subtyping; superfluous parameters can be ignored in the subtype; `option` parameters can be ignored in the supertype; covariant result subtyping |
2222

23-
The remaining specialized interface types inherit their subtyping from their
24-
fundamental interface types.
23+
The remaining specialized value types inherit their subtyping from their
24+
fundamental value types.

design/mvp/canonical-abi/definitions.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,74 +19,74 @@ def trap_if(cond):
1919
if cond:
2020
raise Trap()
2121

22-
class InterfaceType: pass
23-
class Unit(InterfaceType): pass
24-
class Bool(InterfaceType): pass
25-
class S8(InterfaceType): pass
26-
class U8(InterfaceType): pass
27-
class S16(InterfaceType): pass
28-
class U16(InterfaceType): pass
29-
class S32(InterfaceType): pass
30-
class U32(InterfaceType): pass
31-
class S64(InterfaceType): pass
32-
class U64(InterfaceType): pass
33-
class Float32(InterfaceType): pass
34-
class Float64(InterfaceType): pass
35-
class Char(InterfaceType): pass
36-
class String(InterfaceType): pass
22+
class ValType: pass
23+
class Unit(ValType): pass
24+
class Bool(ValType): pass
25+
class S8(ValType): pass
26+
class U8(ValType): pass
27+
class S16(ValType): pass
28+
class U16(ValType): pass
29+
class S32(ValType): pass
30+
class U32(ValType): pass
31+
class S64(ValType): pass
32+
class U64(ValType): pass
33+
class Float32(ValType): pass
34+
class Float64(ValType): pass
35+
class Char(ValType): pass
36+
class String(ValType): pass
3737

3838
@dataclass
39-
class List(InterfaceType):
40-
t: InterfaceType
39+
class List(ValType):
40+
t: ValType
4141

4242
@dataclass
4343
class Field:
4444
label: str
45-
t: InterfaceType
45+
t: ValType
4646

4747
@dataclass
48-
class Record(InterfaceType):
48+
class Record(ValType):
4949
fields: [Field]
5050

5151
@dataclass
52-
class Tuple(InterfaceType):
53-
ts: [InterfaceType]
52+
class Tuple(ValType):
53+
ts: [ValType]
5454

5555
@dataclass
56-
class Flags(InterfaceType):
56+
class Flags(ValType):
5757
labels: [str]
5858

5959
@dataclass
6060
class Case:
6161
label: str
62-
t: InterfaceType
62+
t: ValType
6363
refines: str = None
6464

6565
@dataclass
66-
class Variant(InterfaceType):
66+
class Variant(ValType):
6767
cases: [Case]
6868

6969
@dataclass
70-
class Enum(InterfaceType):
70+
class Enum(ValType):
7171
labels: [str]
7272

7373
@dataclass
74-
class Union(InterfaceType):
75-
ts: [InterfaceType]
74+
class Union(ValType):
75+
ts: [ValType]
7676

7777
@dataclass
78-
class Option(InterfaceType):
79-
t: InterfaceType
78+
class Option(ValType):
79+
t: ValType
8080

8181
@dataclass
82-
class Expected(InterfaceType):
83-
ok: InterfaceType
84-
error: InterfaceType
82+
class Expected(ValType):
83+
ok: ValType
84+
error: ValType
8585

8686
@dataclass
8787
class Func:
88-
params: [InterfaceType]
89-
result: InterfaceType
88+
params: [ValType]
89+
result: ValType
9090

9191
### Despecialization
9292

@@ -603,9 +603,9 @@ def flatten(functype, context):
603603
flat_results = flatten_type(functype.result)
604604
if len(flat_results) > MAX_FLAT_RESULTS:
605605
match context:
606-
case 'canon.lift':
606+
case 'lift':
607607
flat_results = ['i32']
608-
case 'canon.lower':
608+
case 'lower':
609609
flat_params += ['i32']
610610
flat_results = []
611611

@@ -869,7 +869,7 @@ def lower(opts, max_flat, vs, ts, out_param = None):
869869
flat_vals += lower_flat(opts, vs[i], ts[i])
870870
return flat_vals
871871

872-
### `canon.lift`
872+
### `lift`
873873

874874
class Instance:
875875
may_leave = True
@@ -898,7 +898,7 @@ def post_return():
898898

899899
return (result, post_return)
900900

901-
### `canon.lower`
901+
### `lower`
902902

903903
def canon_lower(caller_opts, caller_instance, callee, functype, flat_args):
904904
trap_if(not caller_instance.may_leave)

design/mvp/canonical-abi/run_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,13 @@ def test_flatten(t, params, results):
312312

313313
if len(results) > definitions.MAX_FLAT_RESULTS:
314314
expect['results'] = ['i32']
315-
got = flatten(t, 'canon.lift')
315+
got = flatten(t, 'lift')
316316
assert(got == expect)
317317

318318
if len(results) > definitions.MAX_FLAT_RESULTS:
319319
expect['params'] += ['i32']
320320
expect['results'] = []
321-
got = flatten(t, 'canon.lower')
321+
got = flatten(t, 'lower')
322322
assert(got == expect)
323323

324324
test_flatten(Func([U8(),Float32(),Float64()],Unit()), ['i32','f32','f64'], [])

design/mvp/examples/SharedEverythingDynamicLinking.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ would look like:
157157
(with "libc" (instance $libc))
158158
(with "libzip" (instance $libzip))
159159
))
160-
(func (export "zip") (canon.lift
161-
(func (param (list u8)) (result (list u8)))
162-
(memory (memory $libc "memory")) (realloc (func $libc "realloc"))
160+
(func $zip (param (list u8)) (result (list u8)) (canon lift
163161
(func $main "zip")
162+
(memory (memory $libc "memory")) (realloc (func $libc "realloc"))
164163
))
164+
(export "zip" (func $zip))
165165
)
166166
```
167167
Here, `zipper` links its own private module code (`$Main`) with the shareable
@@ -236,11 +236,11 @@ component-aware `clang`, the resulting component would look like:
236236
(with "libc" (instance $libc))
237237
(with "libimg" (instance $libimg))
238238
))
239-
(func (export "transform") (canon.lift
240-
(func (param (list u8)) (result (list u8)))
241-
(memory (memory $libc "memory")) (realloc (func $libc "realloc"))
239+
(func $transform (param (list u8)) (result (list u8)) (canon lift
242240
(func $main "transform")
241+
(memory (memory $libc "memory")) (realloc (func $libc "realloc"))
243242
))
243+
(export "transform" (func $transform))
244244
)
245245
```
246246
Here, we see the general pattern emerging of the dependency DAG between
@@ -283,24 +283,24 @@ components. The resulting component could look like:
283283
))
284284
285285
(instance $libc (instantiate (module $Libc)))
286-
(func $zip (canon.lower
287-
(memory (memory $libc "memory")) (realloc (func $libc "realloc"))
286+
(func $zip (canon lower
288287
(func $zipper "zip")
289-
))
290-
(func $transform (canon.lower
291288
(memory (memory $libc "memory")) (realloc (func $libc "realloc"))
289+
))
290+
(func $transform (canon lower
292291
(func $imgmgk "transform")
292+
(memory (memory $libc "memory")) (realloc (func $libc "realloc"))
293293
))
294294
(instance $main (instantiate (module $Main)
295295
(with "libc" (instance $libc))
296296
(with "zipper" (instance (export "zip" (func $zipper "zip"))))
297297
(with "imgmgk" (instance (export "transform" (func $imgmgk "transform"))))
298298
))
299-
(func (export "run") (canon.lift
300-
(func (param string) (result string))
301-
(memory (memory $libc "memory")) (realloc (func $libc "realloc"))
299+
(func $run (param string) (result string) (canon lift
302300
(func $main "run")
301+
(memory (memory $libc "memory")) (realloc (func $libc "realloc"))
303302
))
303+
(export "run" (func $run))
304304
)
305305
```
306306
Note here that `$Libc` is passed to the nested `zipper` and `imgmgk` instances

0 commit comments

Comments
 (0)