Skip to content

Commit e24cc1e

Browse files
authored
Drop stability for external package includes (#2159)
* Use the include stablity instead of the item's stablity Signed-off-by: James Sturtevant <[email protected]> * The include uses its stability info, which is unknown Signed-off-by: James Sturtevant <[email protected]> * If the include is external, don't include stability Signed-off-by: James Sturtevant <[email protected]> --------- Signed-off-by: James Sturtevant <[email protected]>
1 parent 358ed21 commit e24cc1e

File tree

6 files changed

+690
-51
lines changed

6 files changed

+690
-51
lines changed

crates/wit-parser/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,10 @@ impl Stability {
12431243
pub fn is_unknown(&self) -> bool {
12441244
matches!(self, Stability::Unknown)
12451245
}
1246+
1247+
pub fn is_stable(&self) -> bool {
1248+
matches!(self, Stability::Stable { .. })
1249+
}
12461250
}
12471251

12481252
impl Default for Stability {

crates/wit-parser/src/resolve.rs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3448,6 +3448,7 @@ impl Remap {
34483448
let include_world_id = self.map_world(include_world, Some(span))?;
34493449
let include_world = &resolve.worlds[include_world_id];
34503450
let mut names_ = names.to_owned();
3451+
let is_external_include = world.package != include_world.package;
34513452

34523453
// remove all imports and exports that match the names we're including
34533454
for import in include_world.imports.iter() {
@@ -3465,11 +3466,25 @@ impl Remap {
34653466

34663467
// copy the imports and exports from the included world into the current world
34673468
for import in include_world.imports.iter() {
3468-
self.resolve_include_item(names, &mut world.imports, import, span, "import")?;
3469+
self.resolve_include_item(
3470+
names,
3471+
&mut world.imports,
3472+
import,
3473+
span,
3474+
"import",
3475+
is_external_include,
3476+
)?;
34693477
}
34703478

34713479
for export in include_world.exports.iter() {
3472-
self.resolve_include_item(names, &mut world.exports, export, span, "export")?;
3480+
self.resolve_include_item(
3481+
names,
3482+
&mut world.exports,
3483+
export,
3484+
span,
3485+
"export",
3486+
is_external_include,
3487+
)?;
34733488
}
34743489
Ok(())
34753490
}
@@ -3481,6 +3496,7 @@ impl Remap {
34813496
item: (&WorldKey, &WorldItem),
34823497
span: Span,
34833498
item_type: &str,
3499+
is_external_include: bool,
34843500
) -> Result<()> {
34853501
match item.0 {
34863502
WorldKey::Name(n) => {
@@ -3515,7 +3531,7 @@ impl Remap {
35153531
},
35163532
) => {
35173533
assert_eq!(*aid, *bid);
3518-
merge_stability(astability, bstability)?;
3534+
merge_include_stability(astability, bstability, is_external_include)?;
35193535
}
35203536
(WorldItem::Interface { .. }, _) => unreachable!(),
35213537
(WorldItem::Function(_), _) => unreachable!(),
@@ -3948,25 +3964,18 @@ fn update_stability(from: &Stability, into: &mut Stability) -> Result<()> {
39483964
bail!("mismatch in stability from '{:?}' to '{:?}'", from, into)
39493965
}
39503966

3951-
/// Compares the two attributes and if the `from` is more stable than the `into` then
3952-
/// it will elevate the `into` to the same stability.
3953-
/// This should be used after its already been confirmed that the types are the same and
3954-
/// should be apart of the component because versions/features are enabled.
3955-
fn merge_stability(from: &Stability, into: &mut Stability) -> Result<()> {
3956-
// If the two stability annotations are equal then
3957-
// there's nothing to do here.
3958-
if from == into {
3959-
return Ok(());
3960-
}
3961-
3962-
// if the from is more stable elevate stability of into
3963-
if from > into {
3964-
*into = from.clone();
3967+
fn merge_include_stability(
3968+
from: &Stability,
3969+
into: &mut Stability,
3970+
is_external_include: bool,
3971+
) -> Result<()> {
3972+
if is_external_include && from.is_stable() {
3973+
log::trace!("dropped stability from external package");
3974+
*into = Stability::Unknown;
39653975
return Ok(());
39663976
}
39673977

3968-
// otherwise `into`` already has higher stability
3969-
return Ok(());
3978+
return update_stability(from, into);
39703979
}
39713980

39723981
/// An error that can be returned during "world elaboration" during various
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package wasmtime:test@0.1.0;
2+
3+
interface unknown-stability-interface {
4+
resource unknown-stability-resource {
5+
}
6+
stable-func: func();
7+
}
8+
9+
@unstable(feature = active)
10+
interface unstable-interface {
11+
@unstable(feature = active)
12+
resource unstable-resource {
13+
}
14+
@unstable(feature = active)
15+
unstable-func: func();
16+
}
17+
18+
@since(version = 0.1.0)
19+
interface stable-interface {
20+
@since(version = 0.1.0)
21+
resource stable-resource {
22+
}
23+
@since(version = 0.1.0)
24+
stable-func: func();
25+
}
26+
27+
world unknown-stability {
28+
import unknown-stability-interface;
29+
}
30+
31+
world unstable {
32+
@unstable(feature = active)
33+
import unstable-interface;
34+
}
35+
36+
world stable{
37+
@since(version = 0.1.0)
38+
import stable-interface;
39+
}
40+
41+
world simple-include {
42+
include unstable;
43+
include stable;
44+
include unknown-stability;
45+
}
46+
47+
world unstable-include-in-package
48+
{
49+
include unstable;
50+
}
51+
52+
world dup-include-in-package {
53+
include simple-include;
54+
include unstable-include-in-package;
55+
}
56+
57+
world dup-use-package {
58+
@unstable(feature = active)
59+
use stable-interface.{stable-resource};
60+
include simple-include;
61+
}
62+
63+
world dup-use-package-ordered {
64+
include simple-include;
65+
@unstable(feature = active)
66+
use stable-interface.{stable-resource};
67+
}

0 commit comments

Comments
 (0)