Skip to content

Commit 32b991c

Browse files
wit-parser: Use stability info when processing foreign deps
Previously, the process_foreign_interfaces function would receive unresolved interfaces with their stability values set to Unknown This made it hard to distinguish between interfaces which had been feature gated out, and genuinely nonexistent interfaces This commit records the stability of a foreign dependency when populating the self.foreign_{deps, interfaces, worlds} maps, which enables process_foreign_interfaces to push a placeholder for a feature-gated interface, and fail on non-existent interfaces Fixes issue 2285
1 parent adcfce7 commit 32b991c

File tree

6 files changed

+129
-1
lines changed

6 files changed

+129
-1
lines changed

crates/wit-parser/src/ast/resolve.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl<'a> Resolver<'a> {
257257
let mut foreign_worlds = mem::take(&mut self.foreign_worlds);
258258
for decl_list in decl_lists {
259259
decl_list
260-
.for_each_path(&mut |_, _attrs, path, _names, world_or_iface| {
260+
.for_each_path(&mut |_, attrs, path, _names, world_or_iface| {
261261
let (id, name) = match path {
262262
ast::UsePath::Package { id, name } => (id, name),
263263
_ => return Ok(()),
@@ -290,6 +290,14 @@ impl<'a> Resolver<'a> {
290290
}
291291
});
292292

293+
let stability = self.stability(attrs)?;
294+
if stability != Stability::Unknown {
295+
match id {
296+
AstItem::Interface(id) => self.interfaces[id].stability = stability,
297+
AstItem::World(id) => self.worlds[id].stability = stability,
298+
}
299+
}
300+
293301
let _ = match id {
294302
AstItem::Interface(id) => foreign_interfaces.insert(id),
295303
AstItem::World(id) => foreign_worlds.insert(id),

crates/wit-parser/src/resolve.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,6 +3157,14 @@ impl Remap {
31573157
// further interfaces will be non-foreign as well.
31583158
None => break,
31593159
};
3160+
3161+
if let Stability::Unstable { feature, .. } = &unresolved_iface.stability {
3162+
if !resolve.features.contains(feature) && !resolve.all_features {
3163+
self.interfaces.push(None);
3164+
continue;
3165+
}
3166+
}
3167+
31603168
let pkgid = resolve
31613169
.package_names
31623170
.get(pkg_name)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package a:b1;
2+
3+
world the-world {
4+
include a:b2/the-world;
5+
}
6+
7+
package a:b2 {
8+
world the-world {
9+
@unstable(feature = disabled)
10+
import a:b3/thing;
11+
}
12+
}
13+
14+
package a:b3 {
15+
@unstable(feature = disabled)
16+
interface thing {}
17+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"worlds": [
3+
{
4+
"name": "the-world",
5+
"imports": {},
6+
"exports": {},
7+
"package": 1
8+
},
9+
{
10+
"name": "the-world",
11+
"imports": {},
12+
"exports": {},
13+
"package": 2
14+
}
15+
],
16+
"interfaces": [],
17+
"types": [],
18+
"packages": [
19+
{
20+
"name": "a:b3",
21+
"interfaces": {},
22+
"worlds": {}
23+
},
24+
{
25+
"name": "a:b2",
26+
"interfaces": {},
27+
"worlds": {
28+
"the-world": 0
29+
}
30+
},
31+
{
32+
"name": "a:b1",
33+
"interfaces": {},
34+
"worlds": {
35+
"the-world": 1
36+
}
37+
}
38+
]
39+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package a:b1;
2+
3+
world the-world {
4+
include a:b2/the-world;
5+
}
6+
7+
package a:b2 {
8+
world the-world {
9+
@unstable(feature = disabled)
10+
import a:b3/another-world;
11+
}
12+
}
13+
14+
package a:b3 {
15+
@unstable(feature = disabled)
16+
world another-world {}
17+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"worlds": [
3+
{
4+
"name": "the-world",
5+
"imports": {},
6+
"exports": {},
7+
"package": 1
8+
},
9+
{
10+
"name": "the-world",
11+
"imports": {},
12+
"exports": {},
13+
"package": 2
14+
}
15+
],
16+
"interfaces": [],
17+
"types": [],
18+
"packages": [
19+
{
20+
"name": "a:b3",
21+
"interfaces": {},
22+
"worlds": {}
23+
},
24+
{
25+
"name": "a:b2",
26+
"interfaces": {},
27+
"worlds": {
28+
"the-world": 0
29+
}
30+
},
31+
{
32+
"name": "a:b1",
33+
"interfaces": {},
34+
"worlds": {
35+
"the-world": 1
36+
}
37+
}
38+
]
39+
}

0 commit comments

Comments
 (0)