Skip to content

Commit 7b724e1

Browse files
committed
Clarify the string-encoding=utf8 default in Binary.md and CanonicalABI.md
1 parent e660009 commit 7b724e1

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

design/mvp/Binary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ Notes:
335335
* The second `0x00` byte in `canon` stands for the `func` sort and thus the
336336
`0x00 <u32>` pair standards for a `func` `sortidx` or `core:sortidx`.
337337
* Validation prevents duplicate or conflicting `canonopt`.
338+
* When there is no `string-encoding` present, the default value is `utf8`.
339+
For all other values, the default value is "none".
338340
* Validation of the individual canonical definitions is described in
339341
[`CanonicalABI.md`](CanonicalABI.md#canonical-definitions).
340342

design/mvp/CanonicalABI.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,23 +127,28 @@ known to not contain `borrow`. The `CanonicalOptions`, `ComponentInstance`,
127127

128128
### Canonical ABI Options
129129

130+
The following two classes list the various Canonical ABI options ([`canonopt`])
131+
that can be set on various Canonical ABI definitions. The default values of the
132+
Python fields are the default values when the associated `canonopt` is not
133+
present in the binary or text format definition.
134+
130135
The `LiftLowerContext` class contains the subset of [`canonopt`] which are
131136
used to lift and lower the individual parameters and results of function
132137
calls:
133138
```python
134139
@dataclass
135140
class LiftLowerOptions:
141+
string_encoding: str = 'utf8'
136142
memory: Optional[bytearray] = None
137-
string_encoding: Optional[str] = None
138143
realloc: Optional[Callable] = None
139144

140145
def __eq__(self, other):
141-
return self.memory is other.memory and \
142-
self.string_encoding == other.string_encoding and \
146+
return self.string_encoding == other.string_encoding and \
147+
self.memory is other.memory and \
143148
self.realloc is other.realloc
144149

145150
def copy(opts):
146-
return LiftLowerOptions(opts.memory, opts.string_encoding, opts.realloc)
151+
return LiftLowerOptions(opts.string_encoding, opts.memory, opts.realloc)
147152
```
148153
The `__eq__` override specifies that equality of `LiftLowerOptions` (as used
149154
by, e.g., `canon_task_return` below) is defined in terms of the identity of

design/mvp/Explainer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ encoding across Java, JavaScript and .NET VMs and allows a dynamic choice
12761276
between either Latin-1 (which has a fixed 1-byte encoding, but limited Code
12771277
Point range) or UTF-16 (which can express all Code Points, but uses either
12781278
2 or 4 bytes per Code Point). If no `string-encoding` option is specified, the
1279-
default is UTF-8. It is a validation error to include more than one
1279+
default is `utf8`. It is a validation error to include more than one
12801280
`string-encoding` option.
12811281

12821282
The `(memory ...)` option specifies the memory that the Canonical ABI will

design/mvp/canonical-abi/definitions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,17 @@ def __init__(self, opts, inst, borrow_scope = None):
193193

194194
@dataclass
195195
class LiftLowerOptions:
196+
string_encoding: str = 'utf8'
196197
memory: Optional[bytearray] = None
197-
string_encoding: Optional[str] = None
198198
realloc: Optional[Callable] = None
199199

200200
def __eq__(self, other):
201-
return self.memory is other.memory and \
202-
self.string_encoding == other.string_encoding and \
201+
return self.string_encoding == other.string_encoding and \
202+
self.memory is other.memory and \
203203
self.realloc is other.realloc
204204

205205
def copy(opts):
206-
return LiftLowerOptions(opts.memory, opts.string_encoding, opts.realloc)
206+
return LiftLowerOptions(opts.string_encoding, opts.memory, opts.realloc)
207207

208208
@dataclass
209209
class CanonicalOptions(LiftLowerOptions):

0 commit comments

Comments
 (0)