A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Match canonical implements names in `is_implements` (#14866)
Randolf J.199abd8b5bfc
diff --git a/crates/wasmtime/src/runtime/component/types.rs b/crates/wasmtime/src/runtime/component/types.rsindex c7a8f09650..6a3dc5fa26 100644--- a/crates/wasmtime/src/runtime/component/types.rs+++ b/crates/wasmtime/src/runtime/component/types.rs@@ -1331,7 +1331,8 @@ impl<'a> ComponentExtern<'a> {/// returned. Failing that, this attempts to perform version-matching to see/// if a compatible version of this item is implemented. For example if/// `(implements "a:b/[email protected]")` is specified then this will return `true`- /// for `a:b/[email protected]` and `a:b/[email protected]` as well.+ /// for `a:b/[email protected]` and `a:b/[email protected]` as well. The same goes for a+ /// canonical name such as `(implements "a:b/c@1")`.pub fn is_implements(&self, name: &str) -> bool {let implements = match self.implements {Some(s) => s,@@ -1341,10 +1342,11 @@ impl<'a> ComponentExtern<'a> {return true;}- match (alternate_lookup_key(implements), alternate_lookup_key(name)) {- (Some((alt_implements, _)), Some((alt_name, _))) => alt_implements == alt_name,- _ => false,- }+ // Compare semver-compatible versions in their reduced form, for+ // example `a:b/[email protected]` as `a:b/c@1`. Canonical names are already in+ // that form, so they're compared as-is.+ let reduced = |name| alternate_lookup_key(name).map_or(name, |(name, _)| name);+ reduced(implements) == reduced(name)}}diff --git a/tests/all/component_model/aot.rs b/tests/all/component_model/aot.rsindex 687c64bbd0..436bf21951 100644--- a/tests/all/component_model/aot.rs+++ b/tests/all/component_model/aot.rs@@ -248,6 +248,29 @@ fn implements_shows_up() -> Result<()> {Ok(())}+#[test]+#[cfg_attr(miri, ignore)]+fn implements_with_canonical_names() -> Result<()> {+ let mut config = Config::new();+ config.wasm_component_model_implements(true);+ config.wasm_component_model_canonical_names(true);+ let engine = Engine::new(&config)?;+ let component = Component::new(+ &engine,+ r#"(component+ (import "p" (implements "a:b/c@1") (version-suffix ".2.3") (instance))+ )"#,+ )?;++ let ty = component.component_type();+ let (_, p) = ty.imports(&engine).next().unwrap();+ assert_eq!(p.implements.as_deref(), Some("a:b/c@1"));+ assert!(p.is_implements("a:b/[email protected]"));+ assert!(p.is_implements("a:b/[email protected]"));+ assert!(!p.is_implements("a:b/[email protected]"));+ Ok(())+}+#[test]#[cfg_attr(miri, ignore)]fn external_id_shows_up() -> Result<()> {