Skip to content

witx should permit defining typename inside modules #157

@pchickey

Description

@pchickey

As we modularize the WASI APIs (see #98 for a strawman), it will be nice to transition using the global namespace for typenames into modules.

Permitting a typename construct inside module is easy. The bigger issue is dealing with scope, because suddenly there are non-local names you may want to refer to, e.g. we may want to move the definition of (typename $fd ...) into (module $wasi_filesystem ...), but other modules may define additional functions that take file descriptors.

I propose the following scoping rules:

  • for now, all names are public. any module can use a typename defined in any other module. I don't anticipate needing rules for private identifiers, since witx is a description language for interfaces, and privacy is typically for the encapsulation of implementations.
  • : is a scope separator inside identifiers.
  • $:fully:qualified:identifier has a leading :. $:wasi_filesystem:fd would refer to the fd name inside the wasi_filesystem module.
  • Identifiers without a leading : search the local scope.

If we adopt those rules, it would make sense to introduce a leading : in identifiers inside modules that refer to typenames defined at the top-level scope. That is a pretty simple change.

This change will be more invasive to witx crate users. The witx::ast::Id type will be changed to contain a Vec<String> with the fully qualified name. The validator will need some work to track scopes, and hopefully we can keep the define-before-use rules of identifiers for now. (Recursive and mutually recursive types are ruled out by this rule during validation.) Luckily, there are only two witx crate users that I know of, and both of them have been good about merging my PRs when I break their stuff by changing witx, so we'll just stick with that process for now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    toolingIssues related to wasi-tools

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions