From 9fcc12767ce15d137b9e82096c9bb194ec19b088 Mon Sep 17 00:00:00 2001 From: dcode Date: Thu, 20 Apr 2023 15:01:22 +0200 Subject: [PATCH 1/4] Unify reference types --- src/types.md | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/types.md b/src/types.md index fd1541251..0d3e02e9a 100644 --- a/src/types.md +++ b/src/types.md @@ -30,23 +30,25 @@ AssemblyScript inherits WebAssembly's more specific integer, floating point and | *Vector types* | | `v128` | v128 | - | A 128-bit vector. || -| *Reference types* | -| `externref` | externref | Object | An external reference. -| `funcref` | funcref | Function | A function reference. -|| -| *Wasm GC types* 🦄 | -| `anyref` | anyref | Object | An internal reference. -| `eqref` | eqref | Object | An equatable reference. -| `dataref` | dataref | Object | A data reference. -| `arrayref` | arrayref | Array | An array reference. -| `stringref` | stringref | string | A string reference. -| `stringview_wtf8` | stringview_wtf8 | string | A string view reference ([WTF-8](https://simonsapin.github.io/wtf-8/)). -| `stringview_wtf16` | stringview_wtf16 | string | A string view reference ([WTF-16](https://simonsapin.github.io/wtf-8/#wtf-16)). -| `stringview_iter` | stringview_iter | - | A string iterator reference. +| *Reference / GC types* | +| `ref_extern` | ref extern | Object | An external reference. +| `ref_func` | ref func | Function | A function reference. +| `ref_any` | ref any | Object | An internal reference. 🦄 +| `ref_eq` | ref eq | Object | An equatable reference. 🦄 +| `ref_struct` | ref struct | Object | A data reference. 🦄 +| `ref_array` | ref array | Array | An array reference. 🦄 +| `ref_string` | ref string | string | A string reference. 🦄 +| `ref_stringview_wtf8` | ref stringview_wtf8 | - | A WTF-8 string view reference. 🦄 +| `ref_stringview_wtf16` | ref stringview_wtf16 | string | A WTF-16 string view reference. 🦄 +| `ref_stringview_iter` | ref stringview_iter | - | A string iterator reference. 🦄 || | *Special types* | | `void` | - | void | Indicates no return value. +::: tip Note +The base reference types above are non-nullable. Canonical aliases, as per the spec, are available as well and refer to the respective nullable type, e.g. `type externref = ref_extern | null` mapping to `externref := ref null extern` in Wasm. The `ref_` prefix avoids naming collisions for the time being and might be dropped in the future. +::: + Just like in TypeScript, types are annotated after variable, function argument or class member names, separated by `:`, like so: ```ts @@ -100,7 +102,7 @@ Wasm reference, GC and string types are anticipated to adhere to the following h Diagram of anticipated reference types hierarchy. -Dashed elements are not exposed (yet) or unclear. Exposed types have a `*ref` suffix (e.g. `anyref`) and are nullable. `(...)`-placeholders indicate the concrete subtypes, e.g. an array of a specific element type, a struct with specific field types and potentially a supertype, or a function with specific parameter and return types. For details, see [Wasm GC's subtyping rules](https://github.com/WebAssembly/gc/blob/main/proposals/gc/MVP.md#structural-types). +Dashed elements are not exposed. `(...)`-placeholders indicate the concrete subtypes, e.g. an array of a specific element type, a struct with specific field types and potentially a supertype, or a function with specific parameter and return types. For details, see [Wasm GC's subtyping rules](https://github.com/WebAssembly/gc/blob/main/proposals/gc/MVP.md#structural-types). ### Comparability From fd03b5a7d92695bd958c5a82fda8a278eba1e033 Mon Sep 17 00:00:00 2001 From: dcode Date: Thu, 20 Apr 2023 16:39:54 +0200 Subject: [PATCH 2/4] update notation and anticipated hierarchy --- .../public/images/reference-hierarchy.svg | 2 +- src/types.md | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/.vuepress/public/images/reference-hierarchy.svg b/src/.vuepress/public/images/reference-hierarchy.svg index 3a5525e13..941edf8de 100644 --- a/src/.vuepress/public/images/reference-hierarchy.svg +++ b/src/.vuepress/public/images/reference-hierarchy.svg @@ -1,4 +1,4 @@ -Wasm-internal references
any
any
eq
eq
i31
i31
struct
struct
array
array
none
none
(...)
(...)
none
none
(...)
(...)
none
none
string
string
?
?
External references
extern
extern
noextern
noextern
Function references
func
func
(...)
(...)
nofunc
nofunc
Working draft. The design is still in flux and support is incomplete / preliminary.
Working draft. The design is still in flux and support is incomplete / preliminary.
Text is not SVG - cannot display
\ No newline at end of file +Wasm-internal references
any
any
eq
eq
i31
i31
struct
struct
array
array
null
null
(...)
(...)
null
null
(...)
(...)
null
null
string
string
null
null
External references
extern
extern
nullextern
nullextern
Function references
func
func
(...)
(...)
nullfunc
nullfunc
Working draft. The design is still in flux and support is incomplete / preliminary.
Working draft. The design is still in flux and support is incomplete / preliminary.
String references
stringview_wtf8
stringview_wtf8
?
?
stringview_wtf16
stringview_wtf16
?
?
stringview_iter
stringview_iter
?
?
Text is not SVG - cannot display
\ No newline at end of file diff --git a/src/types.md b/src/types.md index 0d3e02e9a..40d4d895c 100644 --- a/src/types.md +++ b/src/types.md @@ -31,22 +31,22 @@ AssemblyScript inherits WebAssembly's more specific integer, floating point and | `v128` | v128 | - | A 128-bit vector. || | *Reference / GC types* | -| `ref_extern` | ref extern | Object | An external reference. -| `ref_func` | ref func | Function | A function reference. -| `ref_any` | ref any | Object | An internal reference. 🦄 -| `ref_eq` | ref eq | Object | An equatable reference. 🦄 -| `ref_struct` | ref struct | Object | A data reference. 🦄 -| `ref_array` | ref array | Array | An array reference. 🦄 -| `ref_string` | ref string | string | A string reference. 🦄 -| `ref_stringview_wtf8` | ref stringview_wtf8 | - | A WTF-8 string view reference. 🦄 -| `ref_stringview_wtf16` | ref stringview_wtf16 | string | A WTF-16 string view reference. 🦄 -| `ref_stringview_iter` | ref stringview_iter | - | A string iterator reference. 🦄 +| `ref_extern` | (ref extern) | Object | An external reference. +| `ref_func` | (ref func) | Function | A function reference. +| `ref_any` | (ref any) | Object | An internal reference. 🦄 +| `ref_eq` | (ref eq) | Object | An equatable reference. 🦄 +| `ref_struct` | (ref struct) | Object | A data reference. 🦄 +| `ref_array` | (ref array) | Array | An array reference. 🦄 +| `ref_string` | (ref string) | string | A string reference. 🦄 +| `ref_stringview_wtf8` | (ref stringview_wtf8) | - | A WTF-8 string view reference. 🦄 +| `ref_stringview_wtf16` | (ref stringview_wtf16) | string | A WTF-16 string view reference. 🦄 +| `ref_stringview_iter` | (ref stringview_iter) | - | A string iterator reference. 🦄 || | *Special types* | | `void` | - | void | Indicates no return value. ::: tip Note -The base reference types above are non-nullable. Canonical aliases, as per the spec, are available as well and refer to the respective nullable type, e.g. `type externref = ref_extern | null` mapping to `externref := ref null extern` in Wasm. The `ref_` prefix avoids naming collisions for the time being and might be dropped in the future. +The base reference types above are non-nullable. Canonical aliases, as per the spec, are available as well and refer to the respective nullable type, e.g. `type externref = ref_extern | null` mapping to `externref == (ref null extern)` in Wasm. The `ref_` prefix avoids naming collisions for the time being and might be dropped in the future. ::: Just like in TypeScript, types are annotated after variable, function argument or class member names, separated by `:`, like so: @@ -98,11 +98,11 @@ var u16val: u16 = i8val // becomes 65408 through masking (0xFF80) var f32val: f32 = i8val // becomes -128.0 ``` -Wasm reference, GC and string types are anticipated to adhere to the following hierarchy 🦄: +Wasm reference and GC types are anticipated to adhere to the following hierarchy 🦄: Diagram of anticipated reference types hierarchy. -Dashed elements are not exposed. `(...)`-placeholders indicate the concrete subtypes, e.g. an array of a specific element type, a struct with specific field types and potentially a supertype, or a function with specific parameter and return types. For details, see [Wasm GC's subtyping rules](https://github.com/WebAssembly/gc/blob/main/proposals/gc/MVP.md#structural-types). +Dashed elements are not exposed and/or unclear. `(...)`-placeholders indicate the concrete subtypes, e.g. an array of a specific element type, a struct with specific field types and potentially a supertype, or a function with specific parameter and return types. For details, see [Wasm GC's subtyping rules](https://github.com/WebAssembly/gc/blob/main/proposals/gc/MVP.md#structural-types). ### Comparability From dff2d3110ca6d75121803ef73db7eabdcbc3e060 Mon Sep 17 00:00:00 2001 From: dcode Date: Thu, 20 Apr 2023 16:47:28 +0200 Subject: [PATCH 3/4] string is subtype of any --- src/.vuepress/public/images/reference-hierarchy.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/.vuepress/public/images/reference-hierarchy.svg b/src/.vuepress/public/images/reference-hierarchy.svg index 941edf8de..b7327ac73 100644 --- a/src/.vuepress/public/images/reference-hierarchy.svg +++ b/src/.vuepress/public/images/reference-hierarchy.svg @@ -1,4 +1,4 @@ -Wasm-internal references
any
any
eq
eq
i31
i31
struct
struct
array
array
null
null
(...)
(...)
null
null
(...)
(...)
null
null
string
string
null
null
External references
extern
extern
nullextern
nullextern
Function references
func
func
(...)
(...)
nullfunc
nullfunc
Working draft. The design is still in flux and support is incomplete / preliminary.
Working draft. The design is still in flux and support is incomplete / preliminary.
String references
stringview_wtf8
stringview_wtf8
?
?
stringview_wtf16
stringview_wtf16
?
?
stringview_iter
stringview_iter
?
?
Text is not SVG - cannot display
\ No newline at end of file +Wasm-internal references
any
any
eq
eq
i31
i31
struct
struct
array
array
null
null
(...)
(...)
null
null
(...)
(...)
null
null
string
string
null
null
External references
extern
extern
nullextern
nullextern
Function references
func
func
(...)
(...)
nullfunc
nullfunc
Working draft. The design is still in flux and support is incomplete / preliminary.
Working draft. The design is still in flux and support is incomplete / preliminary.
String references
stringview_wtf8
stringview_wtf8
?
?
stringview_wtf16
stringview_wtf16
?
?
stringview_iter
stringview_iter
?
?
Text is not SVG - cannot display
\ No newline at end of file From e0b61bfd5f158723cbabc665cdb9c0f2078d5734 Mon Sep 17 00:00:00 2001 From: dcode Date: Thu, 20 Apr 2023 16:49:18 +0200 Subject: [PATCH 4/4] dashed to solid, as per v8 --- src/.vuepress/public/images/reference-hierarchy.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/.vuepress/public/images/reference-hierarchy.svg b/src/.vuepress/public/images/reference-hierarchy.svg index b7327ac73..11559dab5 100644 --- a/src/.vuepress/public/images/reference-hierarchy.svg +++ b/src/.vuepress/public/images/reference-hierarchy.svg @@ -1,4 +1,4 @@ -Wasm-internal references
any
any
eq
eq
i31
i31
struct
struct
array
array
null
null
(...)
(...)
null
null
(...)
(...)
null
null
string
string
null
null
External references
extern
extern
nullextern
nullextern
Function references
func
func
(...)
(...)
nullfunc
nullfunc
Working draft. The design is still in flux and support is incomplete / preliminary.
Working draft. The design is still in flux and support is incomplete / preliminary.
String references
stringview_wtf8
stringview_wtf8
?
?
stringview_wtf16
stringview_wtf16
?
?
stringview_iter
stringview_iter
?
?
Text is not SVG - cannot display
\ No newline at end of file +Wasm-internal references
any
any
eq
eq
i31
i31
struct
struct
array
array
null
null
(...)
(...)
null
null
(...)
(...)
null
null
string
string
null
null
External references
extern
extern
nullextern
nullextern
Function references
func
func
(...)
(...)
nullfunc
nullfunc
Working draft. The design is still in flux and support is incomplete / preliminary.
Working draft. The design is still in flux and support is incomplete / preliminary.
String references
stringview_wtf8
stringview_wtf8
?
?
stringview_wtf16
stringview_wtf16
?
?
stringview_iter
stringview_iter
?
?
Text is not SVG - cannot display
\ No newline at end of file