Skip to content

Drop stability for external package includes #2159

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

Merged
Merged
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
4 changes: 4 additions & 0 deletions crates/wit-parser/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1243,6 +1243,10 @@ impl Stability {
pub fn is_unknown(&self) -> bool {
matches!(self, Stability::Unknown)
}

pub fn is_stable(&self) -> bool {
matches!(self, Stability::Stable { .. })
}
}

impl Default for Stability {
47 changes: 28 additions & 19 deletions crates/wit-parser/src/resolve.rs
Original file line number Diff line number Diff line change
@@ -3448,6 +3448,7 @@ impl Remap {
let include_world_id = self.map_world(include_world, Some(span))?;
let include_world = &resolve.worlds[include_world_id];
let mut names_ = names.to_owned();
let is_external_include = world.package != include_world.package;

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

// copy the imports and exports from the included world into the current world
for import in include_world.imports.iter() {
self.resolve_include_item(names, &mut world.imports, import, span, "import")?;
self.resolve_include_item(
names,
&mut world.imports,
import,
span,
"import",
is_external_include,
)?;
}

for export in include_world.exports.iter() {
self.resolve_include_item(names, &mut world.exports, export, span, "export")?;
self.resolve_include_item(
names,
&mut world.exports,
export,
span,
"export",
is_external_include,
)?;
}
Ok(())
}
@@ -3481,6 +3496,7 @@ impl Remap {
item: (&WorldKey, &WorldItem),
span: Span,
item_type: &str,
is_external_include: bool,
) -> Result<()> {
match item.0 {
WorldKey::Name(n) => {
@@ -3515,7 +3531,7 @@ impl Remap {
},
) => {
assert_eq!(*aid, *bid);
merge_stability(astability, bstability)?;
merge_include_stability(astability, bstability, is_external_include)?;
}
(WorldItem::Interface { .. }, _) => unreachable!(),
(WorldItem::Function(_), _) => unreachable!(),
@@ -3948,25 +3964,18 @@ fn update_stability(from: &Stability, into: &mut Stability) -> Result<()> {
bail!("mismatch in stability from '{:?}' to '{:?}'", from, into)
}

/// Compares the two attributes and if the `from` is more stable than the `into` then
/// it will elevate the `into` to the same stability.
/// This should be used after its already been confirmed that the types are the same and
/// should be apart of the component because versions/features are enabled.
fn merge_stability(from: &Stability, into: &mut Stability) -> Result<()> {
// If the two stability annotations are equal then
// there's nothing to do here.
if from == into {
return Ok(());
}

// if the from is more stable elevate stability of into
if from > into {
*into = from.clone();
fn merge_include_stability(
from: &Stability,
into: &mut Stability,
is_external_include: bool,
) -> Result<()> {
if is_external_include && from.is_stable() {
log::trace!("dropped stability from external package");
*into = Stability::Unknown;
return Ok(());
}

// otherwise `into`` already has higher stability
return Ok(());
return update_stability(from, into);
}

/// An error that can be returned during "world elaboration" during various
67 changes: 67 additions & 0 deletions crates/wit-parser/tests/ui/gated-include.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package wasmtime:test@0.1.0;

interface unknown-stability-interface {
resource unknown-stability-resource {
}
stable-func: func();
}

@unstable(feature = active)
interface unstable-interface {
@unstable(feature = active)
resource unstable-resource {
}
@unstable(feature = active)
unstable-func: func();
}

@since(version = 0.1.0)
interface stable-interface {
@since(version = 0.1.0)
resource stable-resource {
}
@since(version = 0.1.0)
stable-func: func();
}

world unknown-stability {
import unknown-stability-interface;
}

world unstable {
@unstable(feature = active)
import unstable-interface;
}

world stable{
@since(version = 0.1.0)
import stable-interface;
}

world simple-include {
include unstable;
include stable;
include unknown-stability;
}

world unstable-include-in-package
{
include unstable;
}

world dup-include-in-package {
include simple-include;
include unstable-include-in-package;
}

world dup-use-package {
@unstable(feature = active)
use stable-interface.{stable-resource};
include simple-include;
}

world dup-use-package-ordered {
include simple-include;
@unstable(feature = active)
use stable-interface.{stable-resource};
}
Loading
Oops, something went wrong.