You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Where `translation_unit` and `ident` are defined in the WGSL grammar.
88
-
`ident`s must not be current WGSL keywords. `ident`s also must not be
89
-
current WESL keywords: `as`, `import`, `module`, `package`, `super`, or`self`.
88
+
`ident`s must not be current WGSL keywords. `ident`s also must not be
89
+
current WESL keywords: `as`, `import`, `module`, `package`, `private`, `public`,`self`, or `super`.
90
90
Reserved words that are
91
91
not current keywords are allowed,
92
92
but not recommended.
@@ -98,6 +98,9 @@ An import collection imports multiple items, and allows for nested imports.
98
98
99
99
A wildcard import imports all top-level declarations from a module. Submodule names and submodule contents are not imported.
100
100
101
+
The optional `public` prefix also re-exports the imported names under the importing module's path; see
102
+
[Visibility.md](Visibility.md).
103
+
101
104
WESL also extends WGSL's `global_directive` rule with a `module_declaration` form, used by `@wildcardable` (see [Wildcard imports](#wildcard-imports)) and reserved for future module-level metadata. `attribute` is the WGSL attribute rule.
102
105
103
106
```ebnf
@@ -125,22 +128,18 @@ import a::c::e as f;
125
128
Then, one iterates over each segment from left to right, and looks it up one by one.
126
129
127
130
1. We start with the first segment.
128
-
*`super` refers to the parent module. Can be repeated to go up multiple parent modules. Exiting the root is an error.
129
131
*`package` refers to the top level module of the current package.
132
+
*`super` refers to the parent module, so `super::sibling` reaches a module alongside the current one. Can be repeated to climb further; climbing out of the current package is an error.
130
133
*`ident` must be a known package, usually found in the `wesl.toml` file. It refers to the top level module of that package.
131
134
2. We take that as the "current module".
132
135
3. We repeatedly look at the next segment.
133
-
1. Item in current module: Take that item. We must be at the last segment, otherwise it's an error.
136
+
1. Item in current module (declared or re-exported via `public import`): Take that item. We must be at the last segment, otherwise it's an error.
134
137
2. Wildcard import: Take all items in the current module.
135
-
3. (Else if re-exported or inline module in current module: We continue with that module.)
136
-
4. Else go to `current module path/ident.wesl`
138
+
3. Else go to `current module path/ident.wesl` (or `.wgsl` if `.wesl` is not found)
137
139
* File found: We take that file as the current module.
138
140
* File not found: We assume an empty module as the current module, and continue with that.
139
-
* (Re-exporting changes the path.)
140
-
* (Inline modules do not have a path.)
141
141
142
-
To get an absolute path to a module, one follows the algorithm above. In step 1, one takes the known absolute path of the `super` module, or the package.
143
-
The absolute path of the `super` module is always known, since the first loaded WESL file must always be the root module, and children are only discovered from there.
142
+
The steps above resolve a path; whether the referencing module may then use the result is governed by [visibility](Visibility.md).
144
143
145
144
Once the import has been resolved, the last segment, or its `as` alias, is brought into scope.
To resolve a module on a filesystem, one follows the algorithm above.
178
-
The root folder, or the root module, needs to be provided to the linker. This is currently a linker-specific API, and may change once we introduce a `wesl.toml`.
179
176
180
-
Linkers should fall back to `.wgsl` files when a `.wesl` file cannot be found.
177
+
To resolve a module on a filesystem, one follows the [import resolution
178
+
algorithm](#import-resolution-algorithm). It traces a path from a known starting
179
+
directory (a package's root directory, or for `super` an enclosing directory of
180
+
the current module) through any subdirectories to the module's `.wesl` or
181
+
`.wgsl` file. The starting directory is always known: each module's path is
182
+
fixed relative to its package's root directory, which the linker takes from a
183
+
`wesl.toml` file or its own configuration.
184
+
185
+
### `package.wesl`
186
+
187
+
`package.wesl` is the file backing a package's top-level module, placed at the
188
+
package's root directory. Items declared in or `public import`ed from
189
+
`package.wesl` are reachable as `<package>::item`.
190
+
191
+
### Reserved file names
181
192
182
193
Due to filesystem limitations, it can happen that WESL idents are invalid file or folder names.
183
194
Notable examples are `CON, PRN, AUX, NUL, COM1 - COM9, LPT1 - LPT9` on Windows, and Windows being case-insensitive.
@@ -323,7 +334,7 @@ version bumps but can break users who have local declarations or import other
323
334
-**Document** additions clearly in changelogs so downstream users debugging
324
335
unexpected name resolution can trace them.
325
336
326
-
**Compose with re-exports.** See [Re-exports](#re-exports) (TBD) to collect
337
+
**Compose with re-exports.** See [Re-exports](Visibility.md#re-exports) to collect
327
338
items from other modules into a single `@wildcardable` module for user
328
339
convenience.
329
340
@@ -487,11 +498,6 @@ Linkers may choose to do dead code elimination, but it is a non-observable imple
487
498
488
499
`const_assert` statements inside of functions need special treatment, see relevant section.
489
500
490
-
## Visibility
491
-
Everything is public by default.
492
-
493
-
Future proposals will introduce visibility (privacy) for items and/or modules.
494
-
495
501
# Drawbacks
496
502
Are there reasons as to why we should not do this?
0 commit comments