Fix some wit-bindgen-related issues with generated bindings (#5692)

* Prefix component-bindgen-generated-functions with `call_`

This fixes clashes between Rust-native methods and the methods
themselves. For example right now `new` is a Rust-generated function for
constructing the wrapper but this can conflict with a world-exported
function called `new`.

Closes #5585

* Fix types being both shared and owned

This refactors some inherited cruft from the original `wit-bindgen`
repository to be more Wasmtime-specific and fixes a codegen case where
a type was used in both a shared and an owned context.

Closes #5688
This commit is contained in:
Alex Crichton
2023-02-02 11:54:35 -06:00
committed by GitHub
parent 63d80fc509
commit 545749b279
7 changed files with 79 additions and 57 deletions

View File

@@ -80,19 +80,22 @@ mod empty_error {
assert_eq!(
results
.empty_error(&mut store, 0.0)
.call_empty_error(&mut store, 0.0)
.expect("no trap")
.expect("no error returned"),
0.0
);
results
.empty_error(&mut store, 1.0)
.call_empty_error(&mut store, 1.0)
.expect("no trap")
.err()
.expect("() error returned");
let e = results.empty_error(&mut store, 2.0).err().expect("trap");
let e = results
.call_empty_error(&mut store, 2.0)
.err()
.expect("trap");
assert_eq!(
format!("{}", e.source().expect("trap message is stored in source")),
"empty_error: trap"
@@ -188,20 +191,23 @@ mod string_error {
assert_eq!(
results
.string_error(&mut store, 0.0)
.call_string_error(&mut store, 0.0)
.expect("no trap")
.expect("no error returned"),
0.0
);
let e = results
.string_error(&mut store, 1.0)
.call_string_error(&mut store, 1.0)
.expect("no trap")
.err()
.expect("error returned");
assert_eq!(e, "string_error: error");
let e = results.string_error(&mut store, 2.0).err().expect("trap");
let e = results
.call_string_error(&mut store, 2.0)
.err()
.expect("trap");
assert_eq!(
format!("{}", e.source().expect("trap message is stored in source")),
"string_error: trap"
@@ -328,7 +334,7 @@ mod enum_error {
assert_eq!(
results
.foo()
.enum_error(&mut store, 0.0)
.call_enum_error(&mut store, 0.0)
.expect("no trap")
.expect("no error returned"),
0.0
@@ -336,7 +342,7 @@ mod enum_error {
let e = results
.foo()
.enum_error(&mut store, 1.0)
.call_enum_error(&mut store, 1.0)
.expect("no trap")
.err()
.expect("error returned");
@@ -344,7 +350,7 @@ mod enum_error {
let e = results
.foo()
.enum_error(&mut store, 2.0)
.call_enum_error(&mut store, 2.0)
.err()
.expect("trap");
assert_eq!(
@@ -458,7 +464,7 @@ mod record_error {
assert_eq!(
results
.foo()
.record_error(&mut store, 0.0)
.call_record_error(&mut store, 0.0)
.expect("no trap")
.expect("no error returned"),
0.0
@@ -466,7 +472,7 @@ mod record_error {
let e = results
.foo()
.record_error(&mut store, 1.0)
.call_record_error(&mut store, 1.0)
.expect("no trap")
.err()
.expect("error returned");
@@ -480,7 +486,7 @@ mod record_error {
let e = results
.foo()
.record_error(&mut store, 2.0)
.call_record_error(&mut store, 2.0)
.err()
.expect("trap");
assert_eq!(
@@ -594,7 +600,7 @@ mod variant_error {
assert_eq!(
results
.foo()
.variant_error(&mut store, 0.0)
.call_variant_error(&mut store, 0.0)
.expect("no trap")
.expect("no error returned"),
0.0
@@ -602,7 +608,7 @@ mod variant_error {
let e = results
.foo()
.variant_error(&mut store, 1.0)
.call_variant_error(&mut store, 1.0)
.expect("no trap")
.err()
.expect("error returned");
@@ -616,7 +622,7 @@ mod variant_error {
let e = results
.foo()
.variant_error(&mut store, 2.0)
.call_variant_error(&mut store, 2.0)
.err()
.expect("trap");
assert_eq!(