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

@@ -15,7 +15,6 @@ pub trait RustGenerator<'a> {
fn push_str(&mut self, s: &str);
fn info(&self, ty: TypeId) -> TypeInfo;
fn default_param_mode(&self) -> TypeMode;
fn current_interface(&self) -> Option<InterfaceId>;
fn print_ty(&mut self, ty: &Type, mode: TypeMode) {
@@ -209,10 +208,10 @@ pub trait RustGenerator<'a> {
fn modes_of(&self, ty: TypeId) -> Vec<(String, TypeMode)> {
let info = self.info(ty);
let mut result = Vec::new();
if info.param {
result.push((self.param_name(ty), self.default_param_mode()));
if info.borrowed {
result.push((self.param_name(ty), TypeMode::AllBorrowed("'a")));
}
if info.result && (!info.param || self.uses_two_names(&info)) {
if info.owned && (!info.borrowed || self.uses_two_names(&info)) {
result.push((self.result_name(ty), TypeMode::Owned));
}
return result;
@@ -358,13 +357,7 @@ pub trait RustGenerator<'a> {
}
fn uses_two_names(&self, info: &TypeInfo) -> bool {
info.has_list
&& info.param
&& info.result
&& match self.default_param_mode() {
TypeMode::AllBorrowed(_) => true,
TypeMode::Owned => false,
}
info.has_list && info.borrowed && info.owned
}
fn lifetime_for(&self, info: &TypeInfo, mode: TypeMode) -> Option<&'static str> {