wit-bindgen icon indicating copy to clipboard operation
wit-bindgen copied to clipboard

Improve identifier generation across languages

Open alexcrichton opened this issue 4 years ago • 0 comments

Right now generating identifiers is pretty ad-hoc across all the language bindings. I created a Ns type for use in the C bindings generator but even then it's only lightly used and not to its fullest extent. I think that identifier generation should be improved across all languages and centralized into one location to make it easier to work with:

  • All identifiers generated should go through some sort of "namespace" (the Ns type). Every, single, identifier.
  • Languages can configure Ns to do the right thing, but otherwise it'd have methods for snake/camel/mixed case verisons of identifiers.
  • All intrinsics used by language bindings should be "temporary" symbols that can be renamed to give prioritization to user-defined symbols via witx.
  • Types like Ns could automatically handle language keywords and language identifier rules (e.g. can't start an identifier with a digit)

In theory this should just be a refactoring, but I think it would help improve code generation by ensuring that there aren't weird bugs in the generated code where a witx symbol accidentally overlaps with some sort of intrinsic or something like that.

alexcrichton avatar Jul 26 '21 14:07 alexcrichton