Skip to content

Commit 9ef6717

Browse files
authored
Canonical ABI name mangling (#309)
* Rename `canonical_abi_realloc` to `cabi_realloc`. This follows the current Canonical ABI. This doesn't rename `canonical_abi_free`, as that's expected to be removed when post-return functions are implemented. * Rename the "expected" type to "result". This follows the current Canonical ABI. * Implement function and value type name mangling. This implements the name-mangling scheme in the current canonical ABI, with the modification proposed in WebAssembly/component-model#104, though that can be easily removed if the proposal is declined. * Use name mangling in the bindings generators. * Use the export base name rather than the mangled name for python identifiers.
1 parent 3cdaefa commit 9ef6717

File tree

68 files changed

+965
-392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+965
-392
lines changed

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
* Is there a better representation for flags than simply an integer?
2727

28-
* Should functions returning `expected<T, E>` get translated in JS to functions
28+
* Should functions returning `result<T, E>` get translated in JS to functions
2929
that return `T` and throw `E`?
3030

3131
* Adding imports to an import object is clunky because you need to also pass in

crates/bindgen-core/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ pub trait Generator {
7474
payload: &Type,
7575
docs: &Docs,
7676
);
77-
fn type_expected(
77+
fn type_result(
7878
&mut self,
7979
iface: &Interface,
8080
id: TypeId,
8181
name: &str,
82-
expected: &Expected,
82+
result: &Result_,
8383
docs: &Docs,
8484
);
8585
fn type_union(&mut self, iface: &Interface, id: TypeId, name: &str, union: &Union, docs: &Docs);
@@ -122,7 +122,7 @@ pub trait Generator {
122122
self.type_variant(iface, id, name, variant, &ty.docs)
123123
}
124124
TypeDefKind::Option(t) => self.type_option(iface, id, name, t, &ty.docs),
125-
TypeDefKind::Expected(e) => self.type_expected(iface, id, name, e, &ty.docs),
125+
TypeDefKind::Result(r) => self.type_result(iface, id, name, r, &ty.docs),
126126
TypeDefKind::Union(u) => self.type_union(iface, id, name, u, &ty.docs),
127127
TypeDefKind::List(t) => self.type_list(iface, id, name, t, &ty.docs),
128128
TypeDefKind::Type(t) => self.type_alias(iface, id, name, t, &ty.docs),
@@ -245,9 +245,9 @@ impl Types {
245245
TypeDefKind::Option(ty) => {
246246
info = self.type_info(iface, ty);
247247
}
248-
TypeDefKind::Expected(e) => {
249-
info = self.type_info(iface, &e.ok);
250-
info |= self.type_info(iface, &e.err);
248+
TypeDefKind::Result(r) => {
249+
info = self.type_info(iface, &r.ok);
250+
info |= self.type_info(iface, &r.err);
251251
}
252252
TypeDefKind::Union(u) => {
253253
for case in u.cases.iter() {
@@ -299,9 +299,9 @@ impl Types {
299299
TypeDefKind::List(ty) | TypeDefKind::Type(ty) | TypeDefKind::Option(ty) => {
300300
self.set_param_result_ty(iface, ty, param, result)
301301
}
302-
TypeDefKind::Expected(e) => {
303-
self.set_param_result_ty(iface, &e.ok, param, result);
304-
self.set_param_result_ty(iface, &e.err, param, result);
302+
TypeDefKind::Result(r) => {
303+
self.set_param_result_ty(iface, &r.ok, param, result);
304+
self.set_param_result_ty(iface, &r.err, param, result);
305305
}
306306
TypeDefKind::Union(u) => {
307307
for case in u.cases.iter() {

0 commit comments

Comments
 (0)