Skip to content

Latest commit

 

History

History
42 lines (28 loc) · 1.47 KB

ModuleAttributes.md

File metadata and controls

42 lines (28 loc) · 1.47 KB

Module Attributes

Motivation

We need a way of tagging modules as being permissible for wildcard imports.

In the future, adding module level metadata enables better tools. For example, one can imagine marking a module as deprecated or as containing test code.

Example

Wildcards in libraries are a semver hazard. More concretely, adding a name to a wildcardable module can break importers. Thus, opting into them is done explicitly. A module level attribute is used.

// math.wesl  (in a library)
@!wildcardable;

public fn dot2(a: vec2f, b: vec2f) -> f32 { return a.x*b.x + a.y*b.y; }
public fn cross2(a: vec2f, b: vec2f) -> f32 { return a.x*b.y - a.y*b.x; }

Guide-level explanation

WESL extends WGSL's global_directive rule with a module attribute: a @!-prefixed attribute that carries module-level metadata. It is used by @!wildcardable (see Wildcard imports) and is otherwise reserved for future use.

Grammar

global_directive:
| ... // existing WGSL forms
| module_attribute_directive

module_attribute_directive:
| '@' '!' ident_pattern_token argument_expression_list? ';'

A module attribute is written like a WGSL attribute with a ! immediately after the @, and is terminated with ;; ident_pattern_token and argument_expression_list are the WGSL rules. Like other global directives, module attributes appear after any imports and before any global declarations, and apply to the module they appear in.