-
Notifications
You must be signed in to change notification settings - Fork 3
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
Unified imports proposal #53
Comments
Great, this proposal is roughly what I want too! Some comments:
what if the file does not exist? do we throw or do we try the next path component? In my understanding, a project could get away with not writing a single Proposal A
Proposal B
Additional notes
|
That is a really good question. Initially I was assuming that it's an immediate error, but after thinking about it for a bit, I don't actually see an issue with "just continue and try the next path component". Maybe that should be proposal C?
Yes, pretty much
No, it doesn't bring
Yes, exactly
I'm thinking that we should only pick one of them. Currently I prefer proposal A over proposal B.
Yes. That's a major limitation of proposal B. I actually haven't thought about this limitation, I only thought about the limitation below vvv.
Also yes. Also a limitation of proposal B.
Oh yes, that would also work! We could also do
Similarly to above, we could let the syntax be |
I think there are concerns here we might discuss separately, maybe as separate github issues. But I may be misunderstanding too. Anyway, here's my first take:
|
LGTM |
Background
For future features, such as re-exports, and inline modules, we want an import system that has a concept of a module! One where
import foo::bar::baz
does not necessarily translate tofoo/bar/baz.wesl
. There could have been a re-export after all.The basic idea of an import is
import a::b
can mean, depending on the rest of the codea/b.wesl
.b
froma.wesl
a/utils/b.wesl
e.g.
import a::b
can bring a module namedb
into scope. Or a function namedb
Caching import resolutions is explicitly an implementation detail. The algorithms described below will work without caching, but caching can speed them up considerably.
Resolving the source of an import is not always obvious. So here is a proposed algorithm.
Sparse Web Projects
Some web projects scatter
.wesl
files throughout their hierarchy. Usually the.wesl
files are reasonably concentrated, but there occasionally are folders do not have a wesl file.e.g.
Basic Observation
Even without re-exports, or anything advanced, we need a resolution algorithm for
import a::b
!It can either import the module
b
, from the filea/b.wesl
.Or it can import the function
b
, from the filea.wesl
.To solve that, we go over the import, step by step. At each step, we decide where to go next to find the correct module.
Step by step resolution
At the end of the resolution, we have a tree of modules. Each module has exactly one fully qualified path.
(Future: Module re-exports will get resolved to the fully qualified path.)
First comes the root step.
.
means "absolute path of the current module"self
means the same thing.self
is a reserved word in WGSL, so it'd work.)..
is a shorthand for./..
super
)some_name
will look at thewesl.toml
wesl.toml for LSPs #57Now we are at a valid module that we can parse.
Then comes the next step.
..
means "go one up in the tree of modules". If we escape the root folder of a dependency, we throw an error.super
means the same thing.super
is also a reserved word in WGSL.)some_name
. Now we look at the current module.current/module/path/some_name.wesl
Finally, we repeat that step until we are finished with our import. At the end, we either found a valid import, or ran into an error.
The text was updated successfully, but these errors were encountered: