Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed Imports.md update #101

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ Then, one iterates over each segment from left to right, and looks it up one by
1. We start with the first segment.
- `super` refers to the parent module. Can be repeated to go up multiple parent modules. Exiting the root is an error.
- `package` refers to the top level module of the current package.
- `ident` must be a known package, usually found in the `wgsl.toml` file. It refers to the top level module of that package.
- `ident` refers to an identifier that is in scope. If there is none. it falls back to a package.
- Packages are usually found in the `wgsl.toml` file. It refers to the top level module of that package.
2. We take that as the "current module".
3. We repeatedly look at the next segment.
1. Item in current module: Take that item. We must be at the last segment, otherwise it's an error.
Expand All @@ -116,6 +117,11 @@ Then, one iterates over each segment from left to right, and looks it up one by
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.
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.

Once the import has been resolved, the last segment, or its alias, is brought into scope.

The order of the scopes is "user declarations and imported items > package names > predeclared items".
This lets WGSL add more predeclared items without breaking existing WESL code. Package names can shadow predeclared items, and authors are encouraged to avoid doing that.

For example

```wgsl
Expand Down Expand Up @@ -191,6 +197,16 @@ type_specifier:
| full_ident ...
```

Examples
```wesl
import foo::bar;

fn main() {
let a = bar::baz; // Uses bar from the import above
let b = bevy::main(); // Uses the known bevy package
}
```

## Cyclic Imports

Cyclic imports are allowed.
Expand Down