From 1d6566dd894cfa326a10814cecf0c77419a99ebb Mon Sep 17 00:00:00 2001 From: Aster Date: Wed, 13 Mar 2024 14:11:26 +0800 Subject: [PATCH 1/4] Add reference type mapping --- design/mvp/Binary.md | 1 + design/mvp/Explainer.md | 31 +++++++++++++++++++++++++++++++ design/mvp/FutureFeatures.md | 9 +++++++++ 3 files changed, 41 insertions(+) diff --git a/design/mvp/Binary.md b/design/mvp/Binary.md index 48cf1b72..1159ea2f 100644 --- a/design/mvp/Binary.md +++ b/design/mvp/Binary.md @@ -276,6 +276,7 @@ canonopt ::= 0x00 => string-encod | 0x03 m: => (memory m) | 0x04 f: => (realloc f) | 0x05 f: => (post-return f) + | 0x06 vec() => (reference-type opt*) πŸ“‘ ``` Notes: * The second `0x00` byte in `canon` stands for the `func` sort and thus the diff --git a/design/mvp/Explainer.md b/design/mvp/Explainer.md index dbfd8362..c733bc8e 100644 --- a/design/mvp/Explainer.md +++ b/design/mvp/Explainer.md @@ -43,6 +43,7 @@ implemented, considered stable and included in a future milestone: * πŸͺ™: value imports/exports and component-level start function * πŸͺΊ: nested namespaces and packages in import/export names * 🧡: threading built-ins +* πŸ“‘: reference types ([gc] proposal integration) (Based on the previous [scoping and layering] proposal to the WebAssembly CG, this repo merges and supersedes the [module-linking] and [interface-types] @@ -591,6 +592,7 @@ sets of abstract values: | `own` | a unique, opaque address of a resource that will be destroyed when this value is dropped | | `borrow` | an opaque address of a resource that must be dropped before the current export call returns | + How these abstract values are produced and consumed from Core WebAssembly values and linear memory is configured by the component via *canonical lifting and lowering definitions*, which are introduced [below](#canonical-definitions). @@ -1142,6 +1144,7 @@ canonopt ::= string-encoding=utf8 | (memory ) | (realloc ) | (post-return ) + | (reference-type *) πŸ“‘ ``` While the production `externdesc` accepts any `sort`, the validation rules for `canon lift` would only allow the `func` sort. In the future, other sorts @@ -1173,6 +1176,34 @@ The Canonical ABI will use `realloc` both to allocate (passing `0` for the first two parameters) and reallocate. If the Canonical ABI needs `realloc`, validation requires this option to be present (there is no default). +πŸ“‘ `(reference-type ...)` requires Canonical ABI to pass parameters and +results by reference type, which is not used by default. This option is the +same as (memory ...) and `(realloc ...) ` cannot be used at the same time. +In the MVP version, the reference type refers to the specific monomorphic +type, such as `(ref array (mut u8))` or `(ref $definded)` where +`(type $definded (struct (mut f32) (mut f32)))`, instead of type-erased +`(ref eq)`. In the MVP version, no mutability constraints are included, +and all fields are of mutable type. + +πŸ“‘ When `reference-type` is enabled, the parameter type will change as follows: + +| wit type | wasm w/o `reference-type` | wasm w/ `reference-type` | +| :------------------- | :-------------------------- | :------------------------------- | +| `bool` | `(i32,)` | `(i32,)` | +| `char` | `(i32,)` | `(i32,)` | +| `u8` | `(i32,)` | `(i32,)` | +| `u16` | `(i32,)` | `(i32,)` | +| `u32` | `(i32,)` | `(i32,)` | +| `u64` | `(i32,)` | `(i32,)` | +| `resource` | `(ptr: i32)` | `(ref extern,)` | +| `list` | `(ptr: i32, len: i32)` | `(ref array (mut $t),)` | +| `record { a, b }` | `(a: A, b: B)` (flatten) | `(ref struct $record,)` | +| `tuple`(inβ©½16) | `(a: A, b: B)` (flatten) | `(a: A, b: B)` (flatten) | +| `tuple`(out>1) | `(ptr: i32)` | `(ref struct (mut $a)(mut $b),)` | +| `option` | `(i32, i32)` | `(ref null $t,)` | +| `result` | `(i32, i32)` | `(i32, (ref eq))` | +| `variant` | `(i32, [MAX_VARIANT_SIZE])` | `(i32, (ref eq))` | + The `(post-return ...)` option may only be present in `canon lift` and specifies a core function to be called with the original return values after they have finished being read, allowing memory to be deallocated and diff --git a/design/mvp/FutureFeatures.md b/design/mvp/FutureFeatures.md index 4b94f3b7..68ff8e6e 100644 --- a/design/mvp/FutureFeatures.md +++ b/design/mvp/FutureFeatures.md @@ -38,6 +38,15 @@ to and from the statically-compiled host implementation language). See [`list.lift_canon` and `list.lower_canon`] for more details. +## Mutability constraints on reference types πŸ“‘ + +Mutability constraints are a complex issue, especially in oop languages. For +example, whether array is internally mutable determines whether some operations +can accept specific subtypes. There are no constraints in the current MVP +version, which may lead to unexpected semantic damage. This can only be +guaranteed by the language compiler for the time being, and it is not +cross-language safe. + ## Shared-some-things linking via "adapter modules" The original [Interface Types proposal] and the re-layered [Module Linking From a48d24c8bfa1e65c426d9221eb3d9327b6c94def Mon Sep 17 00:00:00 2001 From: Aster Date: Thu, 14 Mar 2024 19:42:27 +0800 Subject: [PATCH 2/4] distinguish the layout of option scalar and option reference types --- design/mvp/Explainer.md | 67 +++++++++++++++++++++++------------- design/mvp/FutureFeatures.md | 8 +++++ 2 files changed, 51 insertions(+), 24 deletions(-) diff --git a/design/mvp/Explainer.md b/design/mvp/Explainer.md index c733bc8e..f698eb88 100644 --- a/design/mvp/Explainer.md +++ b/design/mvp/Explainer.md @@ -1150,6 +1150,8 @@ While the production `externdesc` accepts any `sort`, the validation rules for `canon lift` would only allow the `func` sort. In the future, other sorts may be added (viz., types), hence the explicit sort. +##### `string-encoding` options + The `string-encoding` option specifies the encoding the Canonical ABI will use for the `string` type. The `latin1+utf16` encoding captures a common string encoding across Java, JavaScript and .NET VMs and allows a dynamic choice @@ -1159,6 +1161,8 @@ Point range) or UTF-16 (which can express all Code Points, but uses either default is UTF-8. It is a validation error to include more than one `string-encoding` option. +##### `memory` options + The `(memory ...)` option specifies the memory that the Canonical ABI will use to load and store values. If the Canonical ABI needs to load or store, validation requires this option to be present (there is no default). @@ -1176,33 +1180,48 @@ The Canonical ABI will use `realloc` both to allocate (passing `0` for the first two parameters) and reallocate. If the Canonical ABI needs `realloc`, validation requires this option to be present (there is no default). -πŸ“‘ `(reference-type ...)` requires Canonical ABI to pass parameters and -results by reference type, which is not used by default. This option is the -same as (memory ...) and `(realloc ...) ` cannot be used at the same time. -In the MVP version, the reference type refers to the specific monomorphic -type, such as `(ref array (mut u8))` or `(ref $definded)` where -`(type $definded (struct (mut f32) (mut f32)))`, instead of type-erased -`(ref eq)`. In the MVP version, no mutability constraints are included, -and all fields are of mutable type. +##### `reference-type` options + +πŸ“‘ `(reference-type ...)` does not take effect by default. When this option +is turned on, Canonical ABI will be required to use reference types to pass +parameters. This option conflicts with `memory` and `realloc` and cannot +exist at the same time. + +πŸ“‘ In the MVP version, the reference type refers to the specific monomorphic +type, such as `(ref array (mut u8))`, instead of type-erased +`(ref eq)`. πŸ“‘ When `reference-type` is enabled, the parameter type will change as follows: -| wit type | wasm w/o `reference-type` | wasm w/ `reference-type` | -| :------------------- | :-------------------------- | :------------------------------- | -| `bool` | `(i32,)` | `(i32,)` | -| `char` | `(i32,)` | `(i32,)` | -| `u8` | `(i32,)` | `(i32,)` | -| `u16` | `(i32,)` | `(i32,)` | -| `u32` | `(i32,)` | `(i32,)` | -| `u64` | `(i32,)` | `(i32,)` | -| `resource` | `(ptr: i32)` | `(ref extern,)` | -| `list` | `(ptr: i32, len: i32)` | `(ref array (mut $t),)` | -| `record { a, b }` | `(a: A, b: B)` (flatten) | `(ref struct $record,)` | -| `tuple`(inβ©½16) | `(a: A, b: B)` (flatten) | `(a: A, b: B)` (flatten) | -| `tuple`(out>1) | `(ptr: i32)` | `(ref struct (mut $a)(mut $b),)` | -| `option` | `(i32, i32)` | `(ref null $t,)` | -| `result` | `(i32, i32)` | `(i32, (ref eq))` | -| `variant` | `(i32, [MAX_VARIANT_SIZE])` | `(i32, (ref eq))` | +| wit type | wasm w/o `reference-type` | wasm w/ `reference-type` | +| :------------------- | :-------------------------- | :-------------------------------- | +| `bool` | `(i32,)` | `(i32,)` | +| `char` | `(i32,)` | `(i32,)` | +| `u8` | `(i32,)` | `(i32,)` | +| `u16` | `(i32,)` | `(i32,)` | +| `u32` | `(i32,)` | `(i32,)` | +| `u64` | `(i32,)` | `(i32,)` | +| `resource` | `(ptr: i32)` | `(ref extern,)` | +| `list` | `(ptr: i32, len: i32)` | `(ref array (mut $t),)` | +| `record { a, b }` | `(a: A, b: B)` (flatten) | `(ref struct $record,)` | +| `tuple`(inβ©½16) | `(a: A, b: B)` (flatten) | `(a: A, b: B)` (flatten) | +| `tuple`(out>1) | `(ptr: i32)` | `(ref struct (mut $a) (mut $b),)` | +| `result` | `(i32, i32)` | `(i32, (ref eq))` | +| `variant` | `(i32, [MAX_VARIANT_SIZE])` | `(i32, (ref eq))` | + +πŸ“‘ Nullable types are treated specially in many languages and are therefore not +considered variants when the `reference-types` option is on. + +| wit type | wasm w/o `reference-type` | wasm w/ `reference-type` | +|:-----------------------|:--------------------------|:-------------------------| +| `option` | `(i32, i32)` | `(ref null i31)` | +| `option` | `(i32, i32)` | `(ref null i32)` | +| `option` | `(i32, i32)` | `(ref null i31)` | +| `option` | `(i32, i32)` | `(ref null i32)` | +| `option` | `(i32, i64)` | `(ref null i64)` | +| `option` (ref type) | `(i32, SIZE_OF_T)` | `(ref null $t)` | + +##### `post-return` options The `(post-return ...)` option may only be present in `canon lift` and specifies a core function to be called with the original return values diff --git a/design/mvp/FutureFeatures.md b/design/mvp/FutureFeatures.md index 68ff8e6e..5a28fff5 100644 --- a/design/mvp/FutureFeatures.md +++ b/design/mvp/FutureFeatures.md @@ -47,6 +47,14 @@ version, which may lead to unexpected semantic damage. This can only be guaranteed by the language compiler for the time being, and it is not cross-language safe. +## Integrate `stringref` with reference types πŸ“‘ + +The current wit `string` type is regarded as `(array (u8))` or `(array (mut u8))`. +When the `stringref` proposal is stable, it can be considered to be mapped to +`stringref`. In other words, the `reference-type` option can work together with +the `string-encoding` option. + + ## Shared-some-things linking via "adapter modules" The original [Interface Types proposal] and the re-layered [Module Linking From 75d592501305f21d25db7e9f5837eed682c0a175 Mon Sep 17 00:00:00 2001 From: Aster Date: Mon, 18 Mar 2024 11:06:11 +0800 Subject: [PATCH 3/4] Remove reference type options --- design/mvp/Binary.md | 2 +- design/mvp/Explainer.md | 34 +++--- design/mvp/FutureFeatures.md | 8 -- design/mvp/canonical-abi/definitions.py | 132 ++++++++++++++---------- design/mvp/canonical-abi/run_tests.py | 11 +- 5 files changed, 98 insertions(+), 89 deletions(-) diff --git a/design/mvp/Binary.md b/design/mvp/Binary.md index 1159ea2f..9037ef95 100644 --- a/design/mvp/Binary.md +++ b/design/mvp/Binary.md @@ -276,7 +276,7 @@ canonopt ::= 0x00 => string-encod | 0x03 m: => (memory m) | 0x04 f: => (realloc f) | 0x05 f: => (post-return f) - | 0x06 vec() => (reference-type opt*) πŸ“‘ + | 0x06 => reference-type πŸ“‘ ``` Notes: * The second `0x00` byte in `canon` stands for the `func` sort and thus the diff --git a/design/mvp/Explainer.md b/design/mvp/Explainer.md index f698eb88..30865acd 100644 --- a/design/mvp/Explainer.md +++ b/design/mvp/Explainer.md @@ -1144,7 +1144,7 @@ canonopt ::= string-encoding=utf8 | (memory ) | (realloc ) | (post-return ) - | (reference-type *) πŸ“‘ + | reference-type πŸ“‘ ``` While the production `externdesc` accepts any `sort`, the validation rules for `canon lift` would only allow the `func` sort. In the future, other sorts @@ -1182,15 +1182,11 @@ validation requires this option to be present (there is no default). ##### `reference-type` options -πŸ“‘ `(reference-type ...)` does not take effect by default. When this option +πŸ“‘ `reference-type` does not take effect by default. When this option is turned on, Canonical ABI will be required to use reference types to pass parameters. This option conflicts with `memory` and `realloc` and cannot exist at the same time. -πŸ“‘ In the MVP version, the reference type refers to the specific monomorphic -type, such as `(ref array (mut u8))`, instead of type-erased -`(ref eq)`. - πŸ“‘ When `reference-type` is enabled, the parameter type will change as follows: | wit type | wasm w/o `reference-type` | wasm w/ `reference-type` | @@ -1206,20 +1202,18 @@ type, such as `(ref array (mut u8))`, instead of type-erased | `record { a, b }` | `(a: A, b: B)` (flatten) | `(ref struct $record,)` | | `tuple`(inβ©½16) | `(a: A, b: B)` (flatten) | `(a: A, b: B)` (flatten) | | `tuple`(out>1) | `(ptr: i32)` | `(ref struct (mut $a) (mut $b),)` | -| `result` | `(i32, i32)` | `(i32, (ref eq))` | -| `variant` | `(i32, [MAX_VARIANT_SIZE])` | `(i32, (ref eq))` | - -πŸ“‘ Nullable types are treated specially in many languages and are therefore not -considered variants when the `reference-types` option is on. - -| wit type | wasm w/o `reference-type` | wasm w/ `reference-type` | -|:-----------------------|:--------------------------|:-------------------------| -| `option` | `(i32, i32)` | `(ref null i31)` | -| `option` | `(i32, i32)` | `(ref null i32)` | -| `option` | `(i32, i32)` | `(ref null i31)` | -| `option` | `(i32, i32)` | `(ref null i32)` | -| `option` | `(i32, i64)` | `(ref null i64)` | -| `option` (ref type) | `(i32, SIZE_OF_T)` | `(ref null $t)` | + +πŸ“‘ For variant types, they will be unpacked into two parts: enumeration and data. + +| wit type | wasm w/o `reference-type` | wasm w/ `reference-type` | +| :---------------------- | :-------------------------- | :----------------------- | +| `option` (heap type) | `(i32, [A_SIZE])` | `(i32, (ref null eq))` | +| `none` (heap type) | `(0, [FILL_ZEROES])` | `(1, null)` | +| `(some A)` (heap type) | `(1, [A_SIZE])` | `(0, ref $a)` | +| `result` | `(i32, [MAX_VARIANT_SIZE])` | `(i32, (ref null eq))` | +| `(ok A)` | `(0, [A_SIZE])` | `(0, ref $a)` | +| `(err B)` | `(1, [B_SIZE])` | `(1, ref $b)` | +| `variant` | `(i32, [MAX_VARIANT_SIZE])` | `(i32, (ref null eq))` | ##### `post-return` options diff --git a/design/mvp/FutureFeatures.md b/design/mvp/FutureFeatures.md index 5a28fff5..68ff8e6e 100644 --- a/design/mvp/FutureFeatures.md +++ b/design/mvp/FutureFeatures.md @@ -47,14 +47,6 @@ version, which may lead to unexpected semantic damage. This can only be guaranteed by the language compiler for the time being, and it is not cross-language safe. -## Integrate `stringref` with reference types πŸ“‘ - -The current wit `string` type is regarded as `(array (u8))` or `(array (mut u8))`. -When the `stringref` proposal is stable, it can be considered to be mapped to -`stringref`. In other words, the `reference-type` option can work together with -the `string-encoding` option. - - ## Shared-some-things linking via "adapter modules" The original [Interface Types proposal] and the re-layered [Module Linking diff --git a/design/mvp/canonical-abi/definitions.py b/design/mvp/canonical-abi/definitions.py index 3c1aae96..6be4e0ee 100644 --- a/design/mvp/canonical-abi/definitions.py +++ b/design/mvp/canonical-abi/definitions.py @@ -300,6 +300,7 @@ class CanonicalOptions: string_encoding: str realloc: Callable[[int,int,int,int],int] post_return: Callable[[],None] + reference_type: bool class ComponentInstance: may_leave: bool @@ -941,44 +942,56 @@ def lift_flat_signed(vi, core_width, t_width): return i def lift_flat_string(cx, vi): - ptr = vi.next('i32') - packed_length = vi.next('i32') - return load_string_from_range(cx, ptr, packed_length) + if cx.opts.reference_type: + raise NotImplementedError + else: + ptr = vi.next('i32') + packed_length = vi.next('i32') + return load_string_from_range(cx, ptr, packed_length) def lift_flat_list(cx, vi, elem_type): - ptr = vi.next('i32') - length = vi.next('i32') - return load_list_from_range(cx, ptr, length, elem_type) + if cx.opts.reference_type: + raise NotImplementedError + else: + ptr = vi.next('i32') + length = vi.next('i32') + return load_list_from_range(cx, ptr, length, elem_type) def lift_flat_record(cx, vi, fields): - record = {} - for f in fields: - record[f.label] = lift_flat(cx, vi, f.t) - return record + if cx.opts.reference_type: + raise NotImplementedError + else: + record = {} + for f in fields: + record[f.label] = lift_flat(cx, vi, f.t) + return record def lift_flat_variant(cx, vi, cases): - flat_types = flatten_variant(cases) - assert(flat_types.pop(0) == 'i32') - case_index = vi.next('i32') - trap_if(case_index >= len(cases)) - class CoerceValueIter: - def next(self, want): - have = flat_types.pop(0) - x = vi.next(have) - match (have, want): - case ('i32', 'f32') : return decode_i32_as_float(x) - case ('i64', 'i32') : return wrap_i64_to_i32(x) - case ('i64', 'f32') : return decode_i32_as_float(wrap_i64_to_i32(x)) - case ('i64', 'f64') : return decode_i64_as_float(x) - case _ : return x - c = cases[case_index] - if c.t is None: - v = None + if cx.opts.reference_type: + raise NotImplementedError else: - v = lift_flat(cx, CoerceValueIter(), c.t) - for have in flat_types: - _ = vi.next(have) - return { case_label_with_refinements(c, cases): v } + flat_types = flatten_variant(cases) + assert(flat_types.pop(0) == 'i32') + case_index = vi.next('i32') + trap_if(case_index >= len(cases)) + class CoerceValueIter: + def next(self, want): + have = flat_types.pop(0) + x = vi.next(have) + match (have, want): + case ('i32', 'f32') : return decode_i32_as_float(x) + case ('i64', 'i32') : return wrap_i64_to_i32(x) + case ('i64', 'f32') : return decode_i32_as_float(wrap_i64_to_i32(x)) + case ('i64', 'f64') : return decode_i64_as_float(x) + case _ : return x + c = cases[case_index] + if c.t is None: + v = None + else: + v = lift_flat(cx, CoerceValueIter(), c.t) + for have in flat_types: + _ = vi.next(have) + return { case_label_with_refinements(c, cases): v } def wrap_i64_to_i32(i): assert(0 <= i < (1 << 64)) @@ -1026,35 +1039,44 @@ def lower_flat_string(cx, v): return [Value('i32', ptr), Value('i32', packed_length)] def lower_flat_list(cx, v, elem_type): - (ptr, length) = store_list_into_range(cx, v, elem_type) - return [Value('i32', ptr), Value('i32', length)] + if cx.opts.reference_type: + raise NotImplementedError + else: + (ptr, length) = store_list_into_range(cx, v, elem_type) + return [Value('i32', ptr), Value('i32', length)] def lower_flat_record(cx, v, fields): - flat = [] - for f in fields: - flat += lower_flat(cx, v[f.label], f.t) - return flat + if cx.opts.reference_type: + raise NotImplementedError + else: + flat = [] + for f in fields: + flat += lower_flat(cx, v[f.label], f.t) + return flat def lower_flat_variant(cx, v, cases): - case_index, case_value = match_case(v, cases) - flat_types = flatten_variant(cases) - assert(flat_types.pop(0) == 'i32') - c = cases[case_index] - if c.t is None: - payload = [] + if cx.opts.reference_type: + raise NotImplementedError else: - payload = lower_flat(cx, case_value, c.t) - for i,have in enumerate(payload): - want = flat_types.pop(0) - match (have.t, want): - case ('f32', 'i32') : payload[i] = Value('i32', encode_float_as_i32(have.v)) - case ('i32', 'i64') : payload[i] = Value('i64', have.v) - case ('f32', 'i64') : payload[i] = Value('i64', encode_float_as_i32(have.v)) - case ('f64', 'i64') : payload[i] = Value('i64', encode_float_as_i64(have.v)) - case _ : pass - for want in flat_types: - payload.append(Value(want, 0)) - return [Value('i32', case_index)] + payload + case_index, case_value = match_case(v, cases) + flat_types = flatten_variant(cases) + assert(flat_types.pop(0) == 'i32') + c = cases[case_index] + if c.t is None: + payload = [] + else: + payload = lower_flat(cx, case_value, c.t) + for i,have in enumerate(payload): + want = flat_types.pop(0) + match (have.t, want): + case ('f32', 'i32') : payload[i] = Value('i32', encode_float_as_i32(have.v)) + case ('i32', 'i64') : payload[i] = Value('i64', have.v) + case ('f32', 'i64') : payload[i] = Value('i64', encode_float_as_i32(have.v)) + case ('f64', 'i64') : payload[i] = Value('i64', encode_float_as_i64(have.v)) + case _ : pass + for want in flat_types: + payload.append(Value(want, 0)) + return [Value('i32', case_index)] + payload def lower_flat_flags(v, labels): i = pack_flags_into_int(v, labels) diff --git a/design/mvp/canonical-abi/run_tests.py b/design/mvp/canonical-abi/run_tests.py index ff04bf57..00a43cc8 100644 --- a/design/mvp/canonical-abi/run_tests.py +++ b/design/mvp/canonical-abi/run_tests.py @@ -32,16 +32,17 @@ def realloc(self, original_ptr, original_size, alignment, new_size): self.memory[ret : ret + original_size] = self.memory[original_ptr : original_ptr + original_size] return ret -def mk_opts(memory = bytearray(), encoding = 'utf8', realloc = None, post_return = None): +def mk_opts(memory = bytearray(), encoding = 'utf8', realloc = None, post_return = None, reference_type = False): opts = CanonicalOptions() opts.memory = memory opts.string_encoding = encoding opts.realloc = realloc opts.post_return = post_return + opts.reference_type = reference_type return opts -def mk_cx(memory = bytearray(), encoding = 'utf8', realloc = None, post_return = None): - opts = mk_opts(memory, encoding, realloc, post_return) +def mk_cx(memory = bytearray(), encoding = 'utf8', realloc = None, post_return = None, reference_type = False): + opts = mk_opts(memory, encoding, realloc, post_return, reference_type) return CallContext(opts, ComponentInstance()) def mk_str(s): @@ -234,9 +235,9 @@ def test_string(src_encoding, dst_encoding, s): for s in fun_strings: test_string(src_encoding, dst_encoding, s) -def test_heap(t, expect, args, byte_array): +def test_heap(t, expect, args, byte_array, reference_type=False): heap = Heap(byte_array) - cx = mk_cx(heap.memory) + cx = mk_cx(heap.memory, reference_type=reference_type) test(t, args, expect, cx) # Empty record types are not permitted yet. From 1f7445696647363e35f3f9cd7859b5d9dc8db379 Mon Sep 17 00:00:00 2001 From: Aster Date: Tue, 25 Jun 2024 14:27:10 +0800 Subject: [PATCH 4/4] revert python changes --- design/mvp/canonical-abi/run_tests.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/design/mvp/canonical-abi/run_tests.py b/design/mvp/canonical-abi/run_tests.py index 0daa58c6..b3d55b27 100644 --- a/design/mvp/canonical-abi/run_tests.py +++ b/design/mvp/canonical-abi/run_tests.py @@ -33,17 +33,16 @@ def realloc(self, original_ptr, original_size, alignment, new_size): self.memory[ret : ret + original_size] = self.memory[original_ptr : original_ptr + original_size] return ret -def mk_opts(memory = bytearray(), encoding = 'utf8', realloc = None, post_return = None, reference_type = False): +def mk_opts(memory = bytearray(), encoding = 'utf8', realloc = None, post_return = None): opts = CanonicalOptions() opts.memory = memory opts.string_encoding = encoding opts.realloc = realloc opts.post_return = post_return - opts.reference_type = reference_type return opts -def mk_cx(memory = bytearray(), encoding = 'utf8', realloc = None, post_return = None, reference_type = False): - opts = mk_opts(memory, encoding, realloc, post_return, reference_type) +def mk_cx(memory = bytearray(), encoding = 'utf8', realloc = None, post_return = None): + opts = mk_opts(memory, encoding, realloc, post_return) return CallContext(opts, ComponentInstance()) def mk_str(s): @@ -235,9 +234,9 @@ def test_string(src_encoding, dst_encoding, s): for s in fun_strings: test_string(src_encoding, dst_encoding, s) -def test_heap(t, expect, args, byte_array, reference_type=False): +def test_heap(t, expect, args, byte_array): heap = Heap(byte_array) - cx = mk_cx(heap.memory, reference_type=reference_type) + cx = mk_cx(heap.memory) test(t, args, expect, cx) # Empty record types are not permitted yet.