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

Remove implicit import behavior of 'use' #402

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
57 changes: 52 additions & 5 deletions design/mvp/WIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,37 @@ interface my-interface {
}
```

Worlds may import and export the same interface which can be useful for
creating components that can be linked together in a call chain. For example:
```wit
interface processor {
resource datum { ... }
process: func(d: datum);
}

world layer {
import processor;
export processor;
}
```
Components targeting this `layer` world can be linked together,
export-to-import.

If a `world` contains a `use` of an interface that is both imported and
exported, this is currently rejected as ambiguous. For example, this world
is ambiguous:
```wit
world invalid {
import processor;
export processor;
use processor.{datum};
frob: func(d: datum) -> datum;
}
```
> **Note**: It's planned in the future to allow `use` to explicitly specify
> whether to use the imported or exported version of the named interface.


#### Top-level `use`

If a package being referred to has a version number, then using the above syntax
Expand Down Expand Up @@ -638,9 +669,13 @@ imported into the component as well.
Note that the name `"local:demo/shared"` here is derived from the name of the
`interface` plus the package name `local:demo`.

For `export`ed interfaces, any transitively `use`d interface is assumed to be an
import unless it's explicitly listed as an export. For example, here `w1` is
equivalent to `w2`:
For `export`ed interfaces, any transitively `use`d interface must have already
been either imported or exported. If not, the `world` is invalid because it's
ambiguous whether the `use`d interface was meant to be imported or exported. If
a `use`d interface is *both* imported and exported, the export takes
precedence, "shadowing" the import.

For example, the following worlds are valid and resolved as commented:
```wit
interface a {
resource r;
Expand All @@ -651,11 +686,23 @@ interface b {
}

world w1 {
export b;
import a;
export b; // b ~~> imported a.r
}
world w2 {
export a;
export b; // b ~~> exported a.r
}
world w3 {
import a;
export b;
export a;
export b; // b ~~> exported a.r
}
```
whereas the following world would be invalid:
```wit
world invalid {
export b; // error: unresolved 'use' of 'a' in 'b'
}
```

Expand Down
Loading