jrandolf opened PR #14891 from jrandolf:bindgen-name-collisions-shared to bytecodealliance:main:
This builds on #14867, so only the last commit is new here. It fixes the rest of #14856: labels and other names in a world clashing with the names
bindgen!generates.In review of #14867 the suggestion was that
bindgen!should generate bindings that can represent any valid WIT, rather than detecting clashes and erroring. This does that. All the names generated for a world's imports and exports are now chosen in one place,WorldNames, before any bindings are generated. That covers:
- the root and
exportsmodules,- the world struct's accessors and
call_*/func_*methods,- its fields.
When two names would collide, the one claimed later gets a trailing
_. The order is fixed and documented in a new "Generated names" section of thebindgen!docs: reserved names first (exports,named_imports,new,instantiate, ...), then namespaces and plain exports, then exported functions, then labels. Names that don't collide stay the same, so none of the existing expanded snapshots change.Some examples, in package
foo:foo:
WIT Generated export foo: greeter;+export greeter;exports::foo_with accessorfoo(), next toexports::foo::foo::greeterexport foo-foo-greeter: greeter;+export greeter;accessors foo_foo_greeter_()andfoo_foo_greeter()export new: interface {}accessor new_()export call-run: interface {}+export run: func();call_run()for the function,call_run_()for the labelimport foo: interface { ... }module foo_, next to the namespacefooimport exports: interface { ... }module exports__While here, this also fixes keyword escaping for uppercase names like
TYPEand for keyword namespaces and packages (package %use:%fn), which produced invalid identifiers in the same places.The new
name-collisions.witcodegen test covers these. Without this change, the macro panics on it or the output fails to compile.Closes #14856
jrandolf updated PR #14891.
github-actions[bot] added the label wasmtime:api on PR #14891.
jrandolf updated PR #14891.
jrandolf edited PR #14891:
This fixes the rest of #14856: labels and other names in a world clashing with the names
bindgen!generates.In review of #14867 the suggestion was that
bindgen!should generate bindings that can represent any valid WIT, rather than detecting clashes and erroring. This does that. All the names generated for a world's imports and exports are now chosen in one place,WorldNames, before any bindings are generated. That covers:
- the root and
exportsmodules,- the world struct's accessors and
call_*/func_*methods,- its fields.
When two names would collide, the one claimed later gets a trailing
_. The order is fixed and documented in a new "Generated names" section of thebindgen!docs: reserved names first (exports,named_imports,new,instantiate, ...), then namespaces and plain exports, then exported functions, then labels. Names that don't collide stay the same, so none of the existing expanded snapshots change.Some examples, in package
foo:foo:
WIT Generated export foo: greeter;+export greeter;exports::foo_with accessorfoo(), next toexports::foo::foo::greeterexport foo-foo-greeter: greeter;+export greeter;accessors foo_foo_greeter_()andfoo_foo_greeter()export new: interface {}accessor new_()export call-run: interface {}+export run: func();call_run()for the function,call_run_()for the labelimport foo: interface { ... }module foo_, next to the namespacefooimport exports: interface { ... }module exports__While here, this also fixes keyword escaping for uppercase names like
TYPEand for keyword namespaces and packages (package %use:%fn), which produced invalid identifiers in the same places.The new
name-collisions.witcodegen test covers these. Without this change, the macro panics on it or the output fails to compile.Closes #14856
jrandolf has marked PR #14891 as ready for review.
jrandolf removed the review request for wasmtime-core-reviewers from PR #14891.
jrandolf requested wasmtime-core-reviewers for a review on PR #14891.
jrandolf requested pchickey for a review on PR #14891.
Last updated: Oct 31 2026 at 23:03 UTC