New keyword mod
allows declaration of a sub-module. This allows discovery of modules within a crate as well as providing a single entry point for processing preprocessor directives. Modules follow rust rules such that if a crate is called x
which has a sub-module a
, the canonical name for the module will be x::a
. x::a
is added to x
's symbol scope. Additional keywords self
, super
, and crate
allow users to refer to modules relative to the current module.
- Allowing declaration of sub module code inline to the parent module
- Rust macro that creates a set of shader modules embedded in the code based off of rust/cargo file resolution logic. These would also include the encased shader types in the rust code if no preprocessor directives would influence the result.
- Allow modules in the same crate to mutually import symbols from one another. This will require parsing wgsl to generate the headers.
- Later: Extension to the language to allow for definition of module and struct "shapes" and module constructors that take in modules as arguments and return a new module based off of these arguments.
- Generic functions
Introduction of the pub
keyword that can be applied to modules, functions and other root elements to control access to each element. Visibility is first tested on the module level and then the element level. Glsl modules expose everything as they do not have support for advanced naga oil syntax. Only public entrypoints declared in the main module are exposed by the system, with the rest being demoted to a function.
- Addition of the other visibility modifiers present in Rust
- Support type aliasing
The import syntax has been changed to be use <elements>
.
Rexports from a module can be done by specifying pub use
. Reexports don't change the symbol name in the generated code and mainly serves to better control visibility. In addition to the new use
syntax, wildcard imports have been added. These follow the rust syntax and bring all exported symbols into the current module scope.
- Scoped imports to be closer to the rust syntax
The extend
keyword will soon be added to the mvp branch. This essentially will bring all the referenced module's symbols into the current scope but unlike use
, copies/ renames the symbols to be relative to the current module. Extend acts recursively so will also apply to submodules. Extend can also apply to functions provided the base function has been declared virtual
and the module the function comes from has been extended in the current module. The base function can still be called using a normal use
statement. The extend
keyword is the only way to expose an entrypoint from another module.
The patch
and use patchset
expressions have been added to the language and replace the current function overrides. The primary difference (other than the keyword change to avoid clashes with override constants), is that patches are hygienic in the sense that they only apply to their particular subset of the import tree and respect visibility rules. This allows them to be better language citizens.
@robtfm I understand your concerns but also would like to keep the behaviour unsurprising to users: It's quite unusual to have public by default. And in general I've been trying to keep the behaviour close to rust.
I also looked through some of the bevy shaders and while it's true that a lot should be mostly public, not sure that's the case for the broader ecosystem. Consider a noise library. A lot of the time, there'll be a fair amount of functions there that are irrelevant to users.
Regarding plain wgsl files, I think a new extension would make sense for the extended syntax. The plain files would behave as expected then automatically.