Skip to content

Commit 1de837a

Browse files
sunfishcodelannlukewagner
authored
Document what "specialized" means. (#320)
* Document what "specialized" means. Add a paragraph documenting specialized types and their relationship to despecialized types. This is intended to help with #319. * Update design/mvp/Explainer.md Co-authored-by: Lann <[email protected]> * Mention that Canonical ABI has custom reprs for string and flags. * Update design/mvp/Explainer.md Co-authored-by: Luke Wagner <[email protected]> * A few wording adjustments. * Split a sentance with a semicolon into two sentences. This makes the sentence structure more consistent. --------- Co-authored-by: Lann <[email protected]> Co-authored-by: Luke Wagner <[email protected]>
1 parent 1bd7817 commit 1de837a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

design/mvp/Explainer.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,20 @@ defined by the following mapping:
647647
(result <valtype>? (error <valtype>)?) ↦ (variant (case "ok" <valtype>?) (case "error" <valtype>?))
648648
string ↦ (list char)
649649
```
650+
651+
Specialized value types have the same set of semantic values as their
652+
corresponding despecialized types, but have distinct type constructors
653+
(which are not type-equal to the unspecialized type constructors) and
654+
thus have distinct binary encodings. This allows specialized value types to
655+
convey a more specific intent. For example, `result` isn't just a variant,
656+
it's a variant that *means* success or failure, so source-code bindings
657+
can expose it via idiomatic source-language error reporting. Additionally,
658+
this can sometimes allow values to be represented differently. For example,
659+
`string` in the Canonical ABI uses various Unicode encodings while
660+
`list<char>` uses a sequence of 4-byte `char` code points. Similarly,
661+
`flags` in the Canonical ABI uses a bit-vector while an equivalent record
662+
of boolean fields uses a sequence of boolean-valued bytes.
663+
650664
Note that, at least initially, variants are required to have a non-empty list of
651665
cases. This could be relaxed in the future to allow an empty list of cases, with
652666
the empty `(variant)` effectively serving as a [empty type] and indicating

0 commit comments

Comments
 (0)