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:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user