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:
@@ -101,7 +101,7 @@ impl Wasmtime {
|
||||
|
||||
fn import(&mut self, resolve: &Resolve, name: &str, item: &WorldItem) {
|
||||
let snake = name.to_snake_case();
|
||||
let mut gen = InterfaceGenerator::new(self, resolve, TypeMode::Owned);
|
||||
let mut gen = InterfaceGenerator::new(self, resolve);
|
||||
let import = match item {
|
||||
WorldItem::Function(func) => {
|
||||
gen.generate_function_trait_sig(TypeOwner::None, &func);
|
||||
@@ -139,7 +139,7 @@ impl Wasmtime {
|
||||
|
||||
fn export(&mut self, resolve: &Resolve, name: &str, item: &WorldItem) {
|
||||
let snake = name.to_snake_case();
|
||||
let mut gen = InterfaceGenerator::new(self, resolve, TypeMode::AllBorrowed("'a"));
|
||||
let mut gen = InterfaceGenerator::new(self, resolve);
|
||||
let (ty, getter) = match item {
|
||||
WorldItem::Function(func) => {
|
||||
gen.define_rust_guest_export(None, func);
|
||||
@@ -450,21 +450,15 @@ struct InterfaceGenerator<'a> {
|
||||
src: Source,
|
||||
gen: &'a mut Wasmtime,
|
||||
resolve: &'a Resolve,
|
||||
default_param_mode: TypeMode,
|
||||
current_interface: Option<InterfaceId>,
|
||||
}
|
||||
|
||||
impl<'a> InterfaceGenerator<'a> {
|
||||
fn new(
|
||||
gen: &'a mut Wasmtime,
|
||||
resolve: &'a Resolve,
|
||||
default_param_mode: TypeMode,
|
||||
) -> InterfaceGenerator<'a> {
|
||||
fn new(gen: &'a mut Wasmtime, resolve: &'a Resolve) -> InterfaceGenerator<'a> {
|
||||
InterfaceGenerator {
|
||||
src: Source::default(),
|
||||
gen,
|
||||
resolve,
|
||||
default_param_mode,
|
||||
current_interface: None,
|
||||
}
|
||||
}
|
||||
@@ -1159,7 +1153,7 @@ impl<'a> InterfaceGenerator<'a> {
|
||||
self.rustdoc(&func.docs);
|
||||
uwrite!(
|
||||
self.src,
|
||||
"pub {async_} fn {}<S: wasmtime::AsContextMut>(&self, mut store: S, ",
|
||||
"pub {async_} fn call_{}<S: wasmtime::AsContextMut>(&self, mut store: S, ",
|
||||
func.name.to_snake_case(),
|
||||
);
|
||||
for (i, param) in func.params.iter().enumerate() {
|
||||
@@ -1351,10 +1345,6 @@ impl<'a> RustGenerator<'a> for InterfaceGenerator<'a> {
|
||||
self.current_interface
|
||||
}
|
||||
|
||||
fn default_param_mode(&self) -> TypeMode {
|
||||
self.default_param_mode
|
||||
}
|
||||
|
||||
fn push_str(&mut self, s: &str) {
|
||||
self.src.push_str(s);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user