diff --git a/crates/wit-component/src/encoding.rs b/crates/wit-component/src/encoding.rs index 5e29ced9eb..5fc6b02a5c 100644 --- a/crates/wit-component/src/encoding.rs +++ b/crates/wit-component/src/encoding.rs @@ -71,11 +71,11 @@ //! otherwise there's no way to run a `wasi_snapshot_preview1` module within the //! component model. -use crate::StringEncoding; use crate::metadata::{self, Bindgen, ModuleMetadata}; use crate::validation::{ Export, ExportMap, Import, ImportInstance, ImportMap, PayloadInfo, PayloadType, }; +use crate::{SemverCompat, StringEncoding}; use anyhow::{Context, Result, anyhow, bail}; use indexmap::{IndexMap, IndexSet}; use std::borrow::Cow; @@ -577,12 +577,18 @@ impl<'a> EncodingState<'a> { let instance_type_idx = self .component .type_instance(Some(&format!("ty-{name}")), &ty); + let version_suffix = if resolve.use_canonical_names { + resolve.version_suffix_of(interface_id) + } else { + None + }; + let instance_idx = self.component.import( wasm_encoder::ComponentExternName { name: name.into(), implements: info.implements.as_deref().map(|s| s.into()), external_id: info.external_id.as_deref().map(|s| s.into()), - version_suffix: None, + version_suffix: version_suffix.as_deref().map(|s| s.into()), }, ComponentTypeRef::Instance(instance_type_idx), ); @@ -746,7 +752,11 @@ impl<'a> EncodingState<'a> { let world = &resolve.worlds[self.info.encoder.metadata.world]; for export_name in exports { - let export_string = resolve.name_world_key(export_name); + let export_string = if resolve.use_canonical_names { + resolve.name_canonicalized_world_key(export_name) + } else { + resolve.name_world_key(export_name) + }; match &world.exports[export_name] { WorldItem::Function(func) => { let ty = self @@ -977,12 +987,18 @@ impl<'a> EncodingState<'a> { component_index, imports, ); + let version_suffix = if resolve.use_canonical_names { + resolve.version_suffix_of(export) + } else { + None + }; + let idx = self.component.export( wasm_encoder::ComponentExternName { name: export_name.into(), implements: resolve.implements_value(key, item).map(|s| s.into()), external_id: resolve.external_id_value(key, item).map(|s| s.into()), - version_suffix: None, + version_suffix: version_suffix.as_deref().map(|s| s.into()), }, ComponentExportKind::Instance, instance_index, @@ -1808,7 +1824,13 @@ impl<'a> EncodingState<'a> { self.materialize_wit_import( shims, for_module, - iface.map(|_| resolve.name_world_key(key)), + iface.map(|_| { + if resolve.use_canonical_names { + resolve.name_canonicalized_world_key(key) + } else { + resolve.name_world_key(key) + } + }), &format!("{name}_drop"), key, AbiVariant::GuestImport, @@ -1978,7 +2000,11 @@ impl<'a> EncodingState<'a> { Import::InterfaceFunc(key, _, name, abi) => self.materialize_wit_import( shims, for_module, - Some(resolve.name_world_key(key)), + Some(if resolve.use_canonical_names { + resolve.name_canonicalized_world_key(key) + } else { + resolve.name_world_key(key) + }), name, key, *abi, @@ -3025,7 +3051,11 @@ impl<'a> Shims<'a> { field, key, name, - Some(resolve.name_world_key(key)), + Some(if resolve.use_canonical_names { + resolve.name_canonicalized_world_key(key) + } else { + resolve.name_world_key(key) + }), *abi, )?; } @@ -3300,7 +3330,7 @@ pub struct ComponentEncoder { pub(super) adapters: IndexMap, import_name_map: HashMap, realloc_via_memory_grow: bool, - merge_imports_based_on_semver: Option, + semver_compat: SemverCompat, pub(super) reject_legacy_names: bool, debug_names: bool, } @@ -3336,7 +3366,9 @@ impl ComponentEncoder { } fn merge_metadata(&mut self, metadata: Bindgen) -> Result> { - self.metadata.merge(metadata) + let result = self.metadata.merge(metadata); + self.metadata.resolve.use_canonical_names = self.semver_compat == SemverCompat::Canonical; + result } /// Sets whether or not the encoder will validate its output. @@ -3351,15 +3383,16 @@ impl ComponentEncoder { self } - /// Sets whether to merge imports based on semver to the specified value. - /// - /// This affects how when to WIT worlds are merged together, for example - /// from two different libraries, whether their imports are unified when the - /// semver version ranges for interface allow it. + /// Sets the semver compatibility mode for this encoder. /// - /// This is enabled by default. - pub fn merge_imports_based_on_semver(mut self, merge: bool) -> Self { - self.merge_imports_based_on_semver = Some(merge); + /// - `SemverCompat::None`: exact version matching, no merging. Same as the old flag + /// `merge_imports_based_on_semver(false)`. + /// - `SemverCompat::Merge`: merge imports based on semver. + /// Same as the old flag `merge_imports_based_on_semver(true)`. + /// This is the default behavior. + /// - `SemverCompat::Canonical`: merge imports based on the canonical version prefixes. + pub fn semver_compat(mut self, compat: SemverCompat) -> Self { + self.semver_compat = compat; self } @@ -3497,7 +3530,7 @@ impl ComponentEncoder { bail!("a module is required when encoding a component"); } - if self.merge_imports_based_on_semver.unwrap_or(true) { + if self.semver_compat != SemverCompat::None { self.metadata .resolve .merge_world_imports_based_on_semver(self.metadata.world)?; diff --git a/crates/wit-component/src/encoding/wit.rs b/crates/wit-component/src/encoding/wit.rs index a70f90cc38..f9f05abb16 100644 --- a/crates/wit-component/src/encoding/wit.rs +++ b/crates/wit-component/src/encoding/wit.rs @@ -126,11 +126,22 @@ fn component_extern_name( key: &WorldKey, item: &WorldItem, ) -> wasm_encoder::ComponentExternName<'static> { + let (name, version_suffix) = if resolve.use_canonical_names { + let name = resolve.name_canonicalized_world_key(key); + let suffix = match key { + WorldKey::Interface(id) => resolve.version_suffix_of(*id), + WorldKey::Name(_) => None, + }; + (name, suffix) + } else { + (resolve.name_world_key(key), None) + }; + ComponentExternName { - name: resolve.name_world_key(key).into(), + name: name.into(), implements: resolve.implements_value(key, item).map(|s| s.into()), external_id: resolve.external_id_value(key, item).map(|s| s.into()), - version_suffix: None, + version_suffix: version_suffix.map(|s| s.into()), } } @@ -197,11 +208,29 @@ impl Encoder<'_> { for interface in interfaces { encoder.interface = Some(interface); let iface = &self.resolve.interfaces[interface]; - let name = self.resolve.id_of(interface).unwrap(); + let extern_name = if self.resolve.use_canonical_names { + let name = self.resolve.canonicalized_id_of(interface).unwrap(); + let suffix = self.resolve.version_suffix_of(interface); + ComponentExternName { + name: name.into(), + implements: None, + external_id: None, + version_suffix: suffix.map(|s| s.into()), + } + } else { + ComponentExternName { + name: self.resolve.id_of(interface).unwrap().into(), + implements: None, + external_id: None, + version_suffix: None, + } + }; if interface == id { let idx = encoder.encode_instance(interface)?; log::trace!("exporting self as {idx}"); - encoder.outer.export(name, ComponentTypeRef::Instance(idx)); + encoder + .outer + .export(extern_name, ComponentTypeRef::Instance(idx)); } else { encoder.push_instance(); for (_, id) in iface.types.iter() { @@ -212,7 +241,9 @@ impl Encoder<'_> { encoder.outer.ty().instance(&instance); encoder.import_map.insert(interface, encoder.instances); encoder.instances += 1; - encoder.outer.import(name, ComponentTypeRef::Instance(idx)); + encoder + .outer + .import(extern_name, ComponentTypeRef::Instance(idx)); } } diff --git a/crates/wit-component/src/encoding/world.rs b/crates/wit-component/src/encoding/world.rs index f5c6d32e69..af79d40e70 100644 --- a/crates/wit-component/src/encoding/world.rs +++ b/crates/wit-component/src/encoding/world.rs @@ -265,7 +265,11 @@ impl<'a> ComponentWorld<'a> { item: &WorldItem, required: &Required<'_>, ) -> Result<()> { - let name = resolve.name_world_key(key); + let name = if resolve.use_canonical_names { + resolve.name_canonicalized_world_key(key) + } else { + resolve.name_world_key(key) + }; log::trace!("register import `{name}`"); let import_map_key = match item { WorldItem::Function(_) | WorldItem::Type { .. } => None, diff --git a/crates/wit-component/src/lib.rs b/crates/wit-component/src/lib.rs index 11f57201e5..2b0635e0d9 100644 --- a/crates/wit-component/src/lib.rs +++ b/crates/wit-component/src/lib.rs @@ -81,6 +81,45 @@ impl From for wasm_encoder::CanonicalOption { } } +/// Controls how semver is used when resolving and encoding interfaces. +#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum SemverCompat { + /// Exact version matching everywhere. No merging or canonicalization. + None, + /// Merge imports based on semver. This is the default behavior. + /// Package identity still use exact versions. + #[default] + Merge, + /// Merge imports based on the canonical version prefixes. + /// Package identity uses canonical version prefixes only. + Canonical, +} + +impl Display for SemverCompat { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + SemverCompat::None => write!(f, "none"), + SemverCompat::Merge => write!(f, "merge"), + SemverCompat::Canonical => write!(f, "canonical"), + } + } +} + +impl FromStr for SemverCompat { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result { + match s { + "none" => Ok(SemverCompat::None), + "merge" => Ok(SemverCompat::Merge), + "canonical" => Ok(SemverCompat::Canonical), + _ => { + bail!("unknown semver compat mode `{s}`, expected `none`, `merge`, or `canonical`") + } + } + } +} + /// A producer section to be added to all modules and components synthesized by /// this crate pub(crate) fn base_producers() -> wasm_metadata::Producers { diff --git a/crates/wit-component/src/linking.rs b/crates/wit-component/src/linking.rs index dda280eef7..63a3b1f151 100644 --- a/crates/wit-component/src/linking.rs +++ b/crates/wit-component/src/linking.rs @@ -23,6 +23,7 @@ //! ahead-of-time. use { + crate::SemverCompat, crate::encoding::{ComponentEncoder, Instance, Item, LibraryInfo, MainOrAdapter}, anyhow::{Context, Result, anyhow, bail}, indexmap::{IndexMap, IndexSet, map::Entry}, @@ -1682,10 +1683,8 @@ pub struct Linker { /// If `None`, use `DEFAULT_STACK_SIZE_BYTES`. stack_size: Option, - /// This affects how when to WIT worlds are merged together, for example - /// from two different libraries, whether their imports are unified when the - /// semver version ranges for interface allow it. - merge_imports_based_on_semver: Option, + /// Controls how semver is used when resolving and encoding interfaces. + semver_compat: Option, } impl Linker { @@ -1739,13 +1738,11 @@ impl Linker { self } - /// This affects how when to WIT worlds are merged together, for example - /// from two different libraries, whether their imports are unified when the - /// semver version ranges for interface allow it. + /// Sets the semver compatibility mode for this linker. /// - /// This is enabled by default. - pub fn merge_imports_based_on_semver(mut self, merge: bool) -> Self { - self.merge_imports_based_on_semver = Some(merge); + /// See [`SemverCompat`] for available modes. + pub fn semver_compat(mut self, compat: SemverCompat) -> Self { + self.semver_compat = Some(compat); self } @@ -1895,9 +1892,9 @@ impl Linker { let mut encoder = ComponentEncoder::default() .validate(self.validate) .debug_names(self.debug_names); - if let Some(merge) = self.merge_imports_based_on_semver { - encoder = encoder.merge_imports_based_on_semver(merge); - }; + if let Some(compat) = self.semver_compat { + encoder = encoder.semver_compat(compat); + } encoder = encoder.module(&env_module)?; for (name, module) in &self.adapters { diff --git a/crates/wit-component/tests/components.rs b/crates/wit-component/tests/components.rs index 7f3d79e93b..8e8c673766 100644 --- a/crates/wit-component/tests/components.rs +++ b/crates/wit-component/tests/components.rs @@ -5,7 +5,9 @@ use std::{borrow::Cow, fs, path::Path}; use wasm_encoder::{Encode, Section}; use wasm_metadata::{Metadata, Payload}; use wasmparser::{Parser, Validator, WasmFeatures}; -use wit_component::{ComponentEncoder, DecodedWasm, Linker, StringEncoding, WitPrinter}; +use wit_component::{ + ComponentEncoder, DecodedWasm, Linker, SemverCompat, StringEncoding, WitPrinter, +}; use wit_parser::{PackageId, Resolve, UnresolvedPackageGroup}; /// Tests the encoding of components. @@ -62,10 +64,21 @@ fn main() -> Result<()> { if !path.is_dir() { continue; } - - trials.push(Trial::test(path.to_str().unwrap().to_string(), move || { - run_test(&path).map_err(|e| format!("{e:?}").into()) - })); + let name = path.file_name().unwrap().to_str().unwrap().to_string(); + if name.starts_with("canon-names-") { + trials.push(Trial::test(path.to_str().unwrap().to_string(), move || { + run_test(&path, true).map_err(|e| format!("{e:?}").into()) + })); + } else { + let path2 = path.clone(); + trials.push(Trial::test(path.to_str().unwrap().to_string(), move || { + run_test(&path, false).map_err(|e| format!("{e:?}").into()) + })); + let canon_name = format!("{}@canon-names", path2.to_str().unwrap()); + trials.push(Trial::test(canon_name, move || { + run_test(&path2, true).map_err(|e| format!("{e:?}").into()) + })); + } } let mut args = Arguments::from_args(); @@ -75,10 +88,41 @@ fn main() -> Result<()> { libtest_mimic::run(&args, trials).exit(); } -fn run_test(path: &Path) -> Result<()> { +fn is_error_test(test_case: &str) -> bool { + test_case.starts_with("error-") +} + +fn canon_names_output(path: &Path, name: &str, use_canonical: bool) -> std::path::PathBuf { + if use_canonical { + let parts: Vec<&str> = name.splitn(2, '.').collect(); + let canon_name = if parts.len() == 2 { + format!("{}.canon-names.{}", parts[0], parts[1]) + } else { + format!("{name}.canon-names") + }; + let canon_path = path.join(&canon_name); + if std::env::var_os("BLESS").is_some() || canon_path.exists() { + return canon_path; + } + } + path.join(name) +} + +fn run_test(path: &Path, use_canonical: bool) -> Result<()> { let test_case = path.file_stem().unwrap().to_str().unwrap(); let mut resolve = Resolve::default(); - let (pkg_id, _) = resolve.push_dir(&path)?; + resolve.use_canonical_names = use_canonical; + let (pkg_id, _) = match resolve.push_dir(&path) { + Ok(v) => v, + Err(err) => { + if !is_error_test(test_case) { + return Err(err.into()); + } + let error_path = path.join("error.txt"); + assert_output(&format!("{err:#}"), &error_path)?; + return Ok(()); + } + }; // If this test case contained multiple packages, create separate sub-directories for // each. @@ -93,6 +137,11 @@ fn run_test(path: &Path) -> Result<()> { .try_fold( ComponentEncoder::default() .debug_names(true) + .semver_compat(if use_canonical { + SemverCompat::Canonical + } else { + SemverCompat::Merge + }) .module(&module)?, |encoder, path| { let (name, wasm) = read_name_and_module("adapt-", &path?, &resolve, pkg_id)?; @@ -112,7 +161,14 @@ fn run_test(path: &Path) -> Result<()> { // Sort list to ensure deterministic order, which determines priority in cases of duplicate symbols: libs.sort_by(|(_, a, _), (_, b, _)| a.cmp(b)); - let mut linker = Linker::default().validate(false).debug_names(true); + let mut linker = Linker::default() + .validate(false) + .debug_names(true) + .semver_compat(if use_canonical { + SemverCompat::Canonical + } else { + SemverCompat::Merge + }); if path.join("stub-missing-functions").is_file() { linker = linker.stub_missing_functions(true); @@ -136,19 +192,19 @@ fn run_test(path: &Path) -> Result<()> { })? .encode() }; - let component_path = path.join("component.wat"); - let component_wit_path = path.join("component.wit.print"); + let component_path = canon_names_output(&path, "component.wat", use_canonical); + let component_wit_path = canon_names_output(&path, "component.wit.print", use_canonical); let error_path = path.join("error.txt"); let bytes = match result { Ok(bytes) => { - if test_case.starts_with("error-") { + if is_error_test(test_case) { bail!("expected an error but got success"); } bytes } Err(err) => { - if !test_case.starts_with("error-") { + if !is_error_test(test_case) { return Err(err); } assert_output(&format!("{err:#}"), &error_path)?; diff --git a/crates/wit-component/tests/components/cm32-names/component.canon-names.wat b/crates/wit-component/tests/components/cm32-names/component.canon-names.wat new file mode 100644 index 0000000000..1bdf10cbe7 --- /dev/null +++ b/crates/wit-component/tests/components/cm32-names/component.canon-names.wat @@ -0,0 +1,366 @@ +(component + (type $ty-ns:pkg/i@0.2 (;0;) + (instance + (export (;0;) "r" (type (sub resource))) + (type (;1;) (own 0)) + (type (;2;) (func (param "s" string) (result 1))) + (export (;0;) "[constructor]r" (func (type 2))) + (type (;3;) (borrow 0)) + (type (;4;) (func (param "self" 3) (result string))) + (export (;1;) "[method]r.m" (func (type 4))) + (type (;5;) (func (param "in" 1) (result 1))) + (export (;2;) "frob" (func (type 5))) + ) + ) + (import "ns:pkg/i@0.2" (versionsuffix ".1") (instance $ns:pkg/i@0.2 (;0;) (type $ty-ns:pkg/i@0.2))) + (type $ty-j (;1;) + (instance + (export (;0;) "r" (type (sub resource))) + (type (;1;) (own 0)) + (type (;2;) (func (param "s" string) (result 1))) + (export (;0;) "[constructor]r" (func (type 2))) + (type (;3;) (borrow 0)) + (type (;4;) (func (param "self" 3) (result string))) + (export (;1;) "[method]r.m" (func (type 4))) + (type (;5;) (func (param "in" 1) (result 1))) + (export (;2;) "frob" (func (type 5))) + ) + ) + (import "j" (instance $j (;1;) (type $ty-j))) + (type (;2;) (func (result string))) + (import "f" (func $f (;0;) (type 2))) + (core module $main (;0;) + (type (;0;) (func (param i32))) + (type (;1;) (func (param i32 i32) (result i32))) + (type (;2;) (func (param i32 i32))) + (type (;3;) (func (param i32) (result i32))) + (type (;4;) (func (result i32))) + (type (;5;) (func (param i32 i32 i32 i32) (result i32))) + (type (;6;) (func)) + (import "cm32p2" "f" (func (;0;) (type 0))) + (import "cm32p2|ns:pkg/i@0.2" "[constructor]r" (func (;1;) (type 1))) + (import "cm32p2|ns:pkg/i@0.2" "[method]r.m" (func (;2;) (type 2))) + (import "cm32p2|ns:pkg/i@0.2" "frob" (func (;3;) (type 3))) + (import "cm32p2|ns:pkg/i@0.2" "r_drop" (func (;4;) (type 0))) + (import "cm32p2|j" "[constructor]r" (func (;5;) (type 1))) + (import "cm32p2|j" "[method]r.m" (func (;6;) (type 2))) + (import "cm32p2|j" "frob" (func (;7;) (type 3))) + (import "cm32p2|j" "r_drop" (func (;8;) (type 0))) + (import "cm32p2|_ex_ns:pkg/i@0.2" "r_drop" (func (;9;) (type 0))) + (import "cm32p2|_ex_ns:pkg/i@0.2" "r_new" (func (;10;) (type 3))) + (import "cm32p2|_ex_ns:pkg/i@0.2" "r_rep" (func (;11;) (type 3))) + (import "cm32p2|_ex_j" "r_drop" (func (;12;) (type 0))) + (import "cm32p2|_ex_j" "r_new" (func (;13;) (type 3))) + (import "cm32p2|_ex_j" "r_rep" (func (;14;) (type 3))) + (memory (;0;) 0) + (export "cm32p2_memory" (memory 0)) + (export "cm32p2||g" (func 15)) + (export "cm32p2||g_post" (func 16)) + (export "cm32p2|ns:pkg/i@0.2|[constructor]r" (func 17)) + (export "cm32p2|ns:pkg/i@0.2|[method]r.m" (func 18)) + (export "cm32p2|ns:pkg/i@0.2|frob" (func 19)) + (export "cm32p2|ns:pkg/i@0.2|r_dtor" (func 20)) + (export "cm32p2|j|[constructor]r" (func 21)) + (export "cm32p2|j|[method]r.m" (func 22)) + (export "cm32p2|j|frob" (func 23)) + (export "cm32p2|j|r_dtor" (func 24)) + (export "cm32p2_realloc" (func 25)) + (export "cm32p2_initialize" (func 26)) + (func (;15;) (type 4) (result i32) + unreachable + ) + (func (;16;) (type 0) (param i32) + unreachable + ) + (func (;17;) (type 1) (param i32 i32) (result i32) + unreachable + ) + (func (;18;) (type 3) (param i32) (result i32) + unreachable + ) + (func (;19;) (type 3) (param i32) (result i32) + unreachable + ) + (func (;20;) (type 0) (param i32) + unreachable + ) + (func (;21;) (type 1) (param i32 i32) (result i32) + unreachable + ) + (func (;22;) (type 3) (param i32) (result i32) + unreachable + ) + (func (;23;) (type 3) (param i32) (result i32) + unreachable + ) + (func (;24;) (type 0) (param i32) + unreachable + ) + (func (;25;) (type 5) (param i32 i32 i32 i32) (result i32) + unreachable + ) + (func (;26;) (type 6)) + (@producers + (processed-by "wit-component" "$CARGO_PKG_VERSION") + (processed-by "my-fake-bindgen" "123.45") + ) + ) + (core module $wit-component-shim-module (;1;) + (type (;0;) (func (param i32))) + (type (;1;) (func (param i32 i32) (result i32))) + (type (;2;) (func (param i32 i32))) + (type (;3;) (func (param i32))) + (table (;0;) 7 7 funcref) + (export "0" (func $indirect-cm32p2-f)) + (export "1" (func $"indirect-cm32p2|ns:pkg/i@0.2-[constructor]r")) + (export "2" (func $"indirect-cm32p2|ns:pkg/i@0.2-[method]r.m")) + (export "3" (func $"indirect-cm32p2|j-[constructor]r")) + (export "4" (func $"indirect-cm32p2|j-[method]r.m")) + (export "5" (func $dtor-r)) + (export "6" (func $"#func6 dtor-r")) + (export "$imports" (table 0)) + (func $indirect-cm32p2-f (;0;) (type 0) (param i32) + local.get 0 + i32.const 0 + call_indirect (type 0) + ) + (func $"indirect-cm32p2|ns:pkg/i@0.2-[constructor]r" (;1;) (type 1) (param i32 i32) (result i32) + local.get 0 + local.get 1 + i32.const 1 + call_indirect (type 1) + ) + (func $"indirect-cm32p2|ns:pkg/i@0.2-[method]r.m" (;2;) (type 2) (param i32 i32) + local.get 0 + local.get 1 + i32.const 2 + call_indirect (type 2) + ) + (func $"indirect-cm32p2|j-[constructor]r" (;3;) (type 1) (param i32 i32) (result i32) + local.get 0 + local.get 1 + i32.const 3 + call_indirect (type 1) + ) + (func $"indirect-cm32p2|j-[method]r.m" (;4;) (type 2) (param i32 i32) + local.get 0 + local.get 1 + i32.const 4 + call_indirect (type 2) + ) + (func $dtor-r (;5;) (type 3) (param i32) + local.get 0 + i32.const 5 + call_indirect (type 3) + ) + (func $"#func6 dtor-r" (@name "dtor-r") (;6;) (type 3) (param i32) + local.get 0 + i32.const 6 + call_indirect (type 3) + ) + (@producers + (processed-by "wit-component" "$CARGO_PKG_VERSION") + ) + ) + (core module $wit-component-fixup (;2;) + (type (;0;) (func (param i32))) + (type (;1;) (func (param i32 i32) (result i32))) + (type (;2;) (func (param i32 i32))) + (type (;3;) (func (param i32))) + (import "" "0" (func (;0;) (type 0))) + (import "" "1" (func (;1;) (type 1))) + (import "" "2" (func (;2;) (type 2))) + (import "" "3" (func (;3;) (type 1))) + (import "" "4" (func (;4;) (type 2))) + (import "" "5" (func (;5;) (type 3))) + (import "" "6" (func (;6;) (type 3))) + (import "" "$imports" (table (;0;) 7 7 funcref)) + (elem (;0;) (i32.const 0) func 0 1 2 3 4 5 6) + (@producers + (processed-by "wit-component" "$CARGO_PKG_VERSION") + ) + ) + (core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module)) + (alias core export $wit-component-shim-instance "5" (core func $dtor-r (;0;))) + (type $r (;3;) (resource (rep i32) (dtor $dtor-r))) + (alias core export $wit-component-shim-instance "6" (core func $"#core-func1 dtor-r" (@name "dtor-r") (;1;))) + (type $"#type4 r" (@name "r") (;4;) (resource (rep i32) (dtor $"#core-func1 dtor-r"))) + (alias core export $wit-component-shim-instance "0" (core func $indirect-cm32p2-f (;2;))) + (core instance $cm32p2 (;1;) + (export "f" (func $indirect-cm32p2-f)) + ) + (alias core export $wit-component-shim-instance "1" (core func $"indirect-cm32p2|ns:pkg/i@0.2-[constructor]r" (;3;))) + (alias core export $wit-component-shim-instance "2" (core func $"indirect-cm32p2|ns:pkg/i@0.2-[method]r.m" (;4;))) + (alias export $ns:pkg/i@0.2 "frob" (func $frob (;1;))) + (core func $frob (;5;) (canon lower (func $frob))) + (alias export $ns:pkg/i@0.2 "r" (type $"#type5 r" (@name "r") (;5;))) + (core func $resource.drop (;6;) (canon resource.drop $"#type5 r")) + (core instance $cm32p2|ns:pkg/i@0.2 (;2;) + (export "[constructor]r" (func $"indirect-cm32p2|ns:pkg/i@0.2-[constructor]r")) + (export "[method]r.m" (func $"indirect-cm32p2|ns:pkg/i@0.2-[method]r.m")) + (export "frob" (func $frob)) + (export "r_drop" (func $resource.drop)) + ) + (alias core export $wit-component-shim-instance "3" (core func $"indirect-cm32p2|j-[constructor]r" (;7;))) + (alias core export $wit-component-shim-instance "4" (core func $"indirect-cm32p2|j-[method]r.m" (;8;))) + (alias export $j "frob" (func $"#func2 frob" (@name "frob") (;2;))) + (core func $"#core-func9 frob" (@name "frob") (;9;) (canon lower (func $"#func2 frob"))) + (alias export $j "r" (type $"#type6 r" (@name "r") (;6;))) + (core func $"#core-func10 resource.drop" (@name "resource.drop") (;10;) (canon resource.drop $"#type6 r")) + (core instance $cm32p2|j (;3;) + (export "[constructor]r" (func $"indirect-cm32p2|j-[constructor]r")) + (export "[method]r.m" (func $"indirect-cm32p2|j-[method]r.m")) + (export "frob" (func $"#core-func9 frob")) + (export "r_drop" (func $"#core-func10 resource.drop")) + ) + (core func $"#core-func11 resource.drop" (@name "resource.drop") (;11;) (canon resource.drop $r)) + (core func $resource.new (;12;) (canon resource.new $r)) + (core func $resource.rep (;13;) (canon resource.rep $r)) + (core instance $cm32p2|_ex_ns:pkg/i@0.2 (;4;) + (export "r_drop" (func $"#core-func11 resource.drop")) + (export "r_new" (func $resource.new)) + (export "r_rep" (func $resource.rep)) + ) + (core func $"#core-func14 resource.drop" (@name "resource.drop") (;14;) (canon resource.drop $"#type4 r")) + (core func $"#core-func15 resource.new" (@name "resource.new") (;15;) (canon resource.new $"#type4 r")) + (core func $"#core-func16 resource.rep" (@name "resource.rep") (;16;) (canon resource.rep $"#type4 r")) + (core instance $cm32p2|_ex_j (;5;) + (export "r_drop" (func $"#core-func14 resource.drop")) + (export "r_new" (func $"#core-func15 resource.new")) + (export "r_rep" (func $"#core-func16 resource.rep")) + ) + (core instance $main (;6;) (instantiate $main + (with "cm32p2" (instance $cm32p2)) + (with "cm32p2|ns:pkg/i@0.2" (instance $cm32p2|ns:pkg/i@0.2)) + (with "cm32p2|j" (instance $cm32p2|j)) + (with "cm32p2|_ex_ns:pkg/i@0.2" (instance $cm32p2|_ex_ns:pkg/i@0.2)) + (with "cm32p2|_ex_j" (instance $cm32p2|_ex_j)) + ) + ) + (alias core export $main "cm32p2_memory" (core memory $memory (;0;))) + (alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;))) + (alias core export $main "cm32p2_realloc" (core func $realloc (;17;))) + (core func $"#core-func18 indirect-cm32p2-f" (@name "indirect-cm32p2-f") (;18;) (canon lower (func $f) (memory $memory) (realloc $realloc) string-encoding=utf8)) + (alias export $ns:pkg/i@0.2 "[constructor]r" (func $"[constructor]r" (;3;))) + (core func $"#core-func19 indirect-cm32p2|ns:pkg/i@0.2-[constructor]r" (@name "indirect-cm32p2|ns:pkg/i@0.2-[constructor]r") (;19;) (canon lower (func $"[constructor]r") (memory $memory) string-encoding=utf8)) + (alias export $ns:pkg/i@0.2 "[method]r.m" (func $"[method]r.m" (;4;))) + (core func $"#core-func20 indirect-cm32p2|ns:pkg/i@0.2-[method]r.m" (@name "indirect-cm32p2|ns:pkg/i@0.2-[method]r.m") (;20;) (canon lower (func $"[method]r.m") (memory $memory) (realloc $realloc) string-encoding=utf8)) + (alias export $j "[constructor]r" (func $"#func5 [constructor]r" (@name "[constructor]r") (;5;))) + (core func $"#core-func21 indirect-cm32p2|j-[constructor]r" (@name "indirect-cm32p2|j-[constructor]r") (;21;) (canon lower (func $"#func5 [constructor]r") (memory $memory) string-encoding=utf8)) + (alias export $j "[method]r.m" (func $"#func6 [method]r.m" (@name "[method]r.m") (;6;))) + (core func $"#core-func22 indirect-cm32p2|j-[method]r.m" (@name "indirect-cm32p2|j-[method]r.m") (;22;) (canon lower (func $"#func6 [method]r.m") (memory $memory) (realloc $realloc) string-encoding=utf8)) + (alias core export $main "cm32p2|ns:pkg/i@0.2|r_dtor" (core func $cm32p2|ns:pkg/i@0.2|r_dtor (;23;))) + (alias core export $main "cm32p2|j|r_dtor" (core func $cm32p2|j|r_dtor (;24;))) + (core instance $fixup-args (;7;) + (export "$imports" (table $"shim table")) + (export "0" (func $"#core-func18 indirect-cm32p2-f")) + (export "1" (func $"#core-func19 indirect-cm32p2|ns:pkg/i@0.2-[constructor]r")) + (export "2" (func $"#core-func20 indirect-cm32p2|ns:pkg/i@0.2-[method]r.m")) + (export "3" (func $"#core-func21 indirect-cm32p2|j-[constructor]r")) + (export "4" (func $"#core-func22 indirect-cm32p2|j-[method]r.m")) + (export "5" (func $cm32p2|ns:pkg/i@0.2|r_dtor)) + (export "6" (func $cm32p2|j|r_dtor)) + ) + (core instance $fixup (;8;) (instantiate $wit-component-fixup + (with "" (instance $fixup-args)) + ) + ) + (alias core export $main "cm32p2_initialize" (core func $start (;25;))) + (core module $start-shim-module (;3;) + (type (;0;) (func)) + (import "" "" (func (;0;) (type 0))) + (start 0) + ) + (core instance $start-shim-args (;9;) + (export "" (func $start)) + ) + (core instance $start-shim-instance (;10;) (instantiate $start-shim-module + (with "" (instance $start-shim-args)) + ) + ) + (alias core export $main "cm32p2||g" (core func $cm32p2||g (;26;))) + (alias core export $main "cm32p2||g_post" (core func $cm32p2||g_post (;27;))) + (func $g (;7;) (type 2) (canon lift (core func $cm32p2||g) (memory $memory) string-encoding=utf8 (post-return $cm32p2||g_post))) + (export $"#func8 g" (@name "g") (;8;) "g" (func $g)) + (type (;7;) (own $r)) + (type (;8;) (func (param "s" string) (result 7))) + (alias core export $main "cm32p2|ns:pkg/i@0.2|[constructor]r" (core func $"cm32p2|ns:pkg/i@0.2|[constructor]r" (;28;))) + (func $"#func9 [constructor]r" (@name "[constructor]r") (;9;) (type 8) (canon lift (core func $"cm32p2|ns:pkg/i@0.2|[constructor]r") (memory $memory) (realloc $realloc) string-encoding=utf8)) + (type (;9;) (borrow $r)) + (type (;10;) (func (param "self" 9) (result string))) + (alias core export $main "cm32p2|ns:pkg/i@0.2|[method]r.m" (core func $"cm32p2|ns:pkg/i@0.2|[method]r.m" (;29;))) + (func $"#func10 [method]r.m" (@name "[method]r.m") (;10;) (type 10) (canon lift (core func $"cm32p2|ns:pkg/i@0.2|[method]r.m") (memory $memory) string-encoding=utf8)) + (type (;11;) (func (param "in" 7) (result 7))) + (alias core export $main "cm32p2|ns:pkg/i@0.2|frob" (core func $cm32p2|ns:pkg/i@0.2|frob (;30;))) + (func $"#func11 frob" (@name "frob") (;11;) (type 11) (canon lift (core func $cm32p2|ns:pkg/i@0.2|frob))) + (component $ns:pkg/i@0.2-shim-component (;0;) + (import "import-type-r" (type (;0;) (sub resource))) + (type (;1;) (own 0)) + (type (;2;) (func (param "s" string) (result 1))) + (import "import-constructor-r" (func (;0;) (type 2))) + (type (;3;) (borrow 0)) + (type (;4;) (func (param "self" 3) (result string))) + (import "import-method-r-m" (func (;1;) (type 4))) + (type (;5;) (func (param "in" 1) (result 1))) + (import "import-func-frob" (func (;2;) (type 5))) + (export (;6;) "r" (type 0)) + (type (;7;) (own 6)) + (type (;8;) (func (param "s" string) (result 7))) + (export (;3;) "[constructor]r" (func 0) (func (type 8))) + (type (;9;) (borrow 6)) + (type (;10;) (func (param "self" 9) (result string))) + (export (;4;) "[method]r.m" (func 1) (func (type 10))) + (type (;11;) (func (param "in" 7) (result 7))) + (export (;5;) "frob" (func 2) (func (type 11))) + ) + (instance $ns:pkg/i@0.2-shim-instance (;2;) (instantiate $ns:pkg/i@0.2-shim-component + (with "import-constructor-r" (func $"#func9 [constructor]r")) + (with "import-method-r-m" (func $"#func10 [method]r.m")) + (with "import-func-frob" (func $"#func11 frob")) + (with "import-type-r" (type $r)) + ) + ) + (export $"#instance3 ns:pkg/i@0.2" (@name "ns:pkg/i@0.2") (;3;) "ns:pkg/i@0.2" (versionsuffix ".1") (instance $ns:pkg/i@0.2-shim-instance)) + (type (;12;) (own $"#type4 r")) + (type (;13;) (func (param "s" string) (result 12))) + (alias core export $main "cm32p2|j|[constructor]r" (core func $"cm32p2|j|[constructor]r" (;31;))) + (func $"#func12 [constructor]r" (@name "[constructor]r") (;12;) (type 13) (canon lift (core func $"cm32p2|j|[constructor]r") (memory $memory) (realloc $realloc) string-encoding=utf8)) + (type (;14;) (borrow $"#type4 r")) + (type (;15;) (func (param "self" 14) (result string))) + (alias core export $main "cm32p2|j|[method]r.m" (core func $"cm32p2|j|[method]r.m" (;32;))) + (func $"#func13 [method]r.m" (@name "[method]r.m") (;13;) (type 15) (canon lift (core func $"cm32p2|j|[method]r.m") (memory $memory) string-encoding=utf8)) + (type (;16;) (func (param "in" 12) (result 12))) + (alias core export $main "cm32p2|j|frob" (core func $cm32p2|j|frob (;33;))) + (func $"#func14 frob" (@name "frob") (;14;) (type 16) (canon lift (core func $cm32p2|j|frob))) + (component $j-shim-component (;1;) + (import "import-type-r" (type (;0;) (sub resource))) + (type (;1;) (own 0)) + (type (;2;) (func (param "s" string) (result 1))) + (import "import-constructor-r" (func (;0;) (type 2))) + (type (;3;) (borrow 0)) + (type (;4;) (func (param "self" 3) (result string))) + (import "import-method-r-m" (func (;1;) (type 4))) + (type (;5;) (func (param "in" 1) (result 1))) + (import "import-func-frob" (func (;2;) (type 5))) + (export (;6;) "r" (type 0)) + (type (;7;) (own 6)) + (type (;8;) (func (param "s" string) (result 7))) + (export (;3;) "[constructor]r" (func 0) (func (type 8))) + (type (;9;) (borrow 6)) + (type (;10;) (func (param "self" 9) (result string))) + (export (;4;) "[method]r.m" (func 1) (func (type 10))) + (type (;11;) (func (param "in" 7) (result 7))) + (export (;5;) "frob" (func 2) (func (type 11))) + ) + (instance $j-shim-instance (;4;) (instantiate $j-shim-component + (with "import-constructor-r" (func $"#func12 [constructor]r")) + (with "import-method-r-m" (func $"#func13 [method]r.m")) + (with "import-func-frob" (func $"#func14 frob")) + (with "import-type-r" (type $"#type4 r")) + ) + ) + (export $"#instance5 j" (@name "j") (;5;) "j" (instance $j-shim-instance)) + (@producers + (processed-by "wit-component" "$CARGO_PKG_VERSION") + ) +) diff --git a/crates/wit-component/tests/components/cm32-names/component.canon-names.wit.print b/crates/wit-component/tests/components/cm32-names/component.canon-names.wit.print new file mode 100644 index 0000000000..a01bff8de2 --- /dev/null +++ b/crates/wit-component/tests/components/cm32-names/component.canon-names.wit.print @@ -0,0 +1,25 @@ +package root:component; + +world root { + import ns:pkg/i@0.2.1; + import j: interface { + resource r { + constructor(s: string); + m: func() -> string; + } + + frob: func(in: r) -> r; + } + import f: func() -> string; + + export g: func() -> string; + export ns:pkg/i@0.2.1; + export j: interface { + resource r { + constructor(s: string); + m: func() -> string; + } + + frob: func(in: r) -> r; + } +} diff --git a/crates/wit-component/tests/components/merge-import-versions-with-adapter/component.canon-names.wat b/crates/wit-component/tests/components/merge-import-versions-with-adapter/component.canon-names.wat new file mode 100644 index 0000000000..cff4614b2d --- /dev/null +++ b/crates/wit-component/tests/components/merge-import-versions-with-adapter/component.canon-names.wat @@ -0,0 +1,104 @@ +(component + (type $ty-a:b/c@0.1 (;0;) + (instance + (export (;0;) "r" (type (sub resource))) + (type (;1;) (own 0)) + (type (;2;) (func (result 1))) + (export (;0;) "[constructor]r" (func (type 2))) + (type (;3;) (func (param "x" string))) + (export (;1;) "x" (func (type 3))) + ) + ) + (import "a:b/c@0.1" (versionsuffix ".1") (instance $a:b/c@0.1 (;0;) (type $ty-a:b/c@0.1))) + (core module $main (;0;) + (type (;0;) (func)) + (type (;1;) (func (result i32))) + (type (;2;) (func (param i32))) + (type (;3;) (func (param i32 i32))) + (import "old" "f" (func (;0;) (type 0))) + (import "a:b/c@0.1.0" "[constructor]r" (func (;1;) (type 1))) + (import "a:b/c@0.1.0" "[resource-drop]r" (func (;2;) (type 2))) + (import "a:b/c@0.1.0" "x" (func (;3;) (type 3))) + (memory (;0;) 1) + (export "memory" (memory 0)) + (@producers + (processed-by "wit-component" "$CARGO_PKG_VERSION") + (processed-by "my-fake-bindgen" "123.45") + ) + ) + (core module $wit-component:adapter:old (;1;) + (type (;0;) (func)) + (export "f" (func 0)) + (func (;0;) (type 0)) + ) + (core module $wit-component-shim-module (;2;) + (type (;0;) (func)) + (type (;1;) (func (param i32 i32))) + (table (;0;) 2 2 funcref) + (export "0" (func $adapt-old-f)) + (export "1" (func $indirect-a:b/c@0.1.0-x)) + (export "$imports" (table 0)) + (func $adapt-old-f (;0;) (type 0) + i32.const 0 + call_indirect (type 0) + ) + (func $indirect-a:b/c@0.1.0-x (;1;) (type 1) (param i32 i32) + local.get 0 + local.get 1 + i32.const 1 + call_indirect (type 1) + ) + (@producers + (processed-by "wit-component" "$CARGO_PKG_VERSION") + ) + ) + (core module $wit-component-fixup (;3;) + (type (;0;) (func)) + (type (;1;) (func (param i32 i32))) + (import "" "0" (func (;0;) (type 0))) + (import "" "1" (func (;1;) (type 1))) + (import "" "$imports" (table (;0;) 2 2 funcref)) + (elem (;0;) (i32.const 0) func 0 1) + (@producers + (processed-by "wit-component" "$CARGO_PKG_VERSION") + ) + ) + (core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module)) + (alias core export $wit-component-shim-instance "0" (core func $adapt-old-f (;0;))) + (core instance $old (;1;) + (export "f" (func $adapt-old-f)) + ) + (alias export $a:b/c@0.1 "[constructor]r" (func $"[constructor]r" (;0;))) + (core func $"[constructor]r" (;1;) (canon lower (func $"[constructor]r"))) + (alias export $a:b/c@0.1 "r" (type $r (;1;))) + (core func $resource.drop (;2;) (canon resource.drop $r)) + (alias core export $wit-component-shim-instance "1" (core func $indirect-a:b/c@0.1.0-x (;3;))) + (core instance $a:b/c@0.1.0 (;2;) + (export "[constructor]r" (func $"[constructor]r")) + (export "[resource-drop]r" (func $resource.drop)) + (export "x" (func $indirect-a:b/c@0.1.0-x)) + ) + (core instance $main (;3;) (instantiate $main + (with "old" (instance $old)) + (with "a:b/c@0.1.0" (instance $a:b/c@0.1.0)) + ) + ) + (alias core export $main "memory" (core memory $memory (;0;))) + (core instance $"#core-instance4 old" (@name "old") (;4;) (instantiate $wit-component:adapter:old)) + (alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;))) + (alias core export $"#core-instance4 old" "f" (core func $f (;4;))) + (alias export $a:b/c@0.1 "x" (func $x (;1;))) + (core func $"#core-func5 indirect-a:b/c@0.1.0-x" (@name "indirect-a:b/c@0.1.0-x") (;5;) (canon lower (func $x) (memory $memory) string-encoding=utf8)) + (core instance $fixup-args (;5;) + (export "$imports" (table $"shim table")) + (export "0" (func $f)) + (export "1" (func $"#core-func5 indirect-a:b/c@0.1.0-x")) + ) + (core instance $fixup (;6;) (instantiate $wit-component-fixup + (with "" (instance $fixup-args)) + ) + ) + (@producers + (processed-by "wit-component" "$CARGO_PKG_VERSION") + ) +) diff --git a/crates/wit-component/tests/components/merge-import-versions-with-adapter/component.canon-names.wit.print b/crates/wit-component/tests/components/merge-import-versions-with-adapter/component.canon-names.wit.print new file mode 100644 index 0000000000..1a2ed3c569 --- /dev/null +++ b/crates/wit-component/tests/components/merge-import-versions-with-adapter/component.canon-names.wit.print @@ -0,0 +1,5 @@ +package root:component; + +world root { + import a:b/c@0.1.1; +} diff --git a/crates/wit-component/tests/components/merge-import-versions/component.canon-names.wat b/crates/wit-component/tests/components/merge-import-versions/component.canon-names.wat new file mode 100644 index 0000000000..376ab17ca8 --- /dev/null +++ b/crates/wit-component/tests/components/merge-import-versions/component.canon-names.wat @@ -0,0 +1,161 @@ +(component + (type $ty-a:b/c@0.1 (;0;) + (instance + (export (;0;) "r" (type (sub resource))) + (type (;1;) (own 0)) + (type (;2;) (func (result 1))) + (export (;0;) "[constructor]r" (func (type 2))) + (type (;3;) (func (param "x" string))) + (export (;1;) "x" (func (type 3))) + (export (;2;) "x2" (func (type 3))) + ) + ) + (import "a:b/c@0.1" (versionsuffix ".0") (instance $a:b/c@0.1 (;0;) (type $ty-a:b/c@0.1))) + (type $ty-a:b/c@0.2 (;1;) + (instance + (export (;0;) "r" (type (sub resource))) + (type (;1;) (own 0)) + (type (;2;) (func (result 1))) + (export (;0;) "[constructor]r" (func (type 2))) + (type (;3;) (borrow 0)) + (type (;4;) (func (param "self" 3))) + (export (;1;) "[method]r.x" (func (type 4))) + (type (;5;) (func (param "x" string))) + (export (;2;) "x" (func (type 5))) + (export (;3;) "x2" (func (type 5))) + (type (;6;) (func)) + (export (;4;) "y" (func (type 6))) + ) + ) + (import "a:b/c@0.2" (versionsuffix ".1") (instance $a:b/c@0.2 (;1;) (type $ty-a:b/c@0.2))) + (core module $main (;0;) + (type (;0;) (func (result i32))) + (type (;1;) (func (param i32))) + (type (;2;) (func (param i32 i32))) + (type (;3;) (func)) + (import "a:b/c@0.1.0" "[constructor]r" (func (;0;) (type 0))) + (import "a:b/c@0.1.0" "[resource-drop]r" (func (;1;) (type 1))) + (import "a:b/c@0.1.0" "x" (func (;2;) (type 2))) + (import "a:b/c@0.1.0" "x2" (func (;3;) (type 2))) + (import "a:b/c@0.2.1" "[constructor]r" (func (;4;) (type 0))) + (import "a:b/c@0.2.1" "[resource-drop]r" (func (;5;) (type 1))) + (import "a:b/c@0.2.1" "[method]r.x" (func (;6;) (type 1))) + (import "a:b/c@0.2.1" "x" (func (;7;) (type 2))) + (import "a:b/c@0.2.1" "x2" (func (;8;) (type 2))) + (import "a:b/c@0.2.1" "y" (func (;9;) (type 3))) + (memory (;0;) 1) + (export "memory" (memory 0)) + (@producers + (processed-by "wit-component" "$CARGO_PKG_VERSION") + (processed-by "my-fake-bindgen" "123.45") + ) + ) + (core module $wit-component-shim-module (;1;) + (type (;0;) (func (param i32 i32))) + (table (;0;) 4 4 funcref) + (export "0" (func $indirect-a:b/c@0.1.0-x)) + (export "1" (func $indirect-a:b/c@0.1.0-x2)) + (export "2" (func $indirect-a:b/c@0.2.1-x)) + (export "3" (func $indirect-a:b/c@0.2.1-x2)) + (export "$imports" (table 0)) + (func $indirect-a:b/c@0.1.0-x (;0;) (type 0) (param i32 i32) + local.get 0 + local.get 1 + i32.const 0 + call_indirect (type 0) + ) + (func $indirect-a:b/c@0.1.0-x2 (;1;) (type 0) (param i32 i32) + local.get 0 + local.get 1 + i32.const 1 + call_indirect (type 0) + ) + (func $indirect-a:b/c@0.2.1-x (;2;) (type 0) (param i32 i32) + local.get 0 + local.get 1 + i32.const 2 + call_indirect (type 0) + ) + (func $indirect-a:b/c@0.2.1-x2 (;3;) (type 0) (param i32 i32) + local.get 0 + local.get 1 + i32.const 3 + call_indirect (type 0) + ) + (@producers + (processed-by "wit-component" "$CARGO_PKG_VERSION") + ) + ) + (core module $wit-component-fixup (;2;) + (type (;0;) (func (param i32 i32))) + (import "" "0" (func (;0;) (type 0))) + (import "" "1" (func (;1;) (type 0))) + (import "" "2" (func (;2;) (type 0))) + (import "" "3" (func (;3;) (type 0))) + (import "" "$imports" (table (;0;) 4 4 funcref)) + (elem (;0;) (i32.const 0) func 0 1 2 3) + (@producers + (processed-by "wit-component" "$CARGO_PKG_VERSION") + ) + ) + (core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module)) + (alias export $a:b/c@0.1 "[constructor]r" (func $"[constructor]r" (;0;))) + (core func $"[constructor]r" (;0;) (canon lower (func $"[constructor]r"))) + (alias export $a:b/c@0.1 "r" (type $r (;2;))) + (core func $resource.drop (;1;) (canon resource.drop $r)) + (alias core export $wit-component-shim-instance "0" (core func $indirect-a:b/c@0.1.0-x (;2;))) + (alias core export $wit-component-shim-instance "1" (core func $indirect-a:b/c@0.1.0-x2 (;3;))) + (core instance $a:b/c@0.1.0 (;1;) + (export "[constructor]r" (func $"[constructor]r")) + (export "[resource-drop]r" (func $resource.drop)) + (export "x" (func $indirect-a:b/c@0.1.0-x)) + (export "x2" (func $indirect-a:b/c@0.1.0-x2)) + ) + (alias export $a:b/c@0.2 "[constructor]r" (func $"#func1 [constructor]r" (@name "[constructor]r") (;1;))) + (core func $"#core-func4 [constructor]r" (@name "[constructor]r") (;4;) (canon lower (func $"#func1 [constructor]r"))) + (alias export $a:b/c@0.2 "r" (type $"#type3 r" (@name "r") (;3;))) + (core func $"#core-func5 resource.drop" (@name "resource.drop") (;5;) (canon resource.drop $"#type3 r")) + (alias export $a:b/c@0.2 "[method]r.x" (func $"[method]r.x" (;2;))) + (core func $"[method]r.x" (;6;) (canon lower (func $"[method]r.x"))) + (alias core export $wit-component-shim-instance "2" (core func $indirect-a:b/c@0.2.1-x (;7;))) + (alias core export $wit-component-shim-instance "3" (core func $indirect-a:b/c@0.2.1-x2 (;8;))) + (alias export $a:b/c@0.2 "y" (func $y (;3;))) + (core func $y (;9;) (canon lower (func $y))) + (core instance $a:b/c@0.2.1 (;2;) + (export "[constructor]r" (func $"#core-func4 [constructor]r")) + (export "[resource-drop]r" (func $"#core-func5 resource.drop")) + (export "[method]r.x" (func $"[method]r.x")) + (export "x" (func $indirect-a:b/c@0.2.1-x)) + (export "x2" (func $indirect-a:b/c@0.2.1-x2)) + (export "y" (func $y)) + ) + (core instance $main (;3;) (instantiate $main + (with "a:b/c@0.1.0" (instance $a:b/c@0.1.0)) + (with "a:b/c@0.2.1" (instance $a:b/c@0.2.1)) + ) + ) + (alias core export $main "memory" (core memory $memory (;0;))) + (alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;))) + (alias export $a:b/c@0.1 "x" (func $x (;4;))) + (core func $"#core-func10 indirect-a:b/c@0.1.0-x" (@name "indirect-a:b/c@0.1.0-x") (;10;) (canon lower (func $x) (memory $memory) string-encoding=utf8)) + (alias export $a:b/c@0.1 "x2" (func $x2 (;5;))) + (core func $"#core-func11 indirect-a:b/c@0.1.0-x2" (@name "indirect-a:b/c@0.1.0-x2") (;11;) (canon lower (func $x2) (memory $memory) string-encoding=utf8)) + (alias export $a:b/c@0.2 "x" (func $"#func6 x" (@name "x") (;6;))) + (core func $"#core-func12 indirect-a:b/c@0.2.1-x" (@name "indirect-a:b/c@0.2.1-x") (;12;) (canon lower (func $"#func6 x") (memory $memory) string-encoding=utf8)) + (alias export $a:b/c@0.2 "x2" (func $"#func7 x2" (@name "x2") (;7;))) + (core func $"#core-func13 indirect-a:b/c@0.2.1-x2" (@name "indirect-a:b/c@0.2.1-x2") (;13;) (canon lower (func $"#func7 x2") (memory $memory) string-encoding=utf8)) + (core instance $fixup-args (;4;) + (export "$imports" (table $"shim table")) + (export "0" (func $"#core-func10 indirect-a:b/c@0.1.0-x")) + (export "1" (func $"#core-func11 indirect-a:b/c@0.1.0-x2")) + (export "2" (func $"#core-func12 indirect-a:b/c@0.2.1-x")) + (export "3" (func $"#core-func13 indirect-a:b/c@0.2.1-x2")) + ) + (core instance $fixup (;5;) (instantiate $wit-component-fixup + (with "" (instance $fixup-args)) + ) + ) + (@producers + (processed-by "wit-component" "$CARGO_PKG_VERSION") + ) +) diff --git a/crates/wit-component/tests/components/merge-import-versions/component.canon-names.wit.print b/crates/wit-component/tests/components/merge-import-versions/component.canon-names.wit.print new file mode 100644 index 0000000000..1da1fb1e42 --- /dev/null +++ b/crates/wit-component/tests/components/merge-import-versions/component.canon-names.wit.print @@ -0,0 +1,6 @@ +package root:component; + +world root { + import a:b/c@0.1.0; + import a:b/c@0.2.1; +} diff --git a/crates/wit-component/tests/components/merge-import-versions/component.wat b/crates/wit-component/tests/components/merge-import-versions/component.wat index 49aaa1b655..3f73faf4a1 100644 --- a/crates/wit-component/tests/components/merge-import-versions/component.wat +++ b/crates/wit-component/tests/components/merge-import-versions/component.wat @@ -1,5 +1,17 @@ (component - (type $ty-a:b/c@0.1.1 (;0;) + (type $ty-a:b/c@0.1.0 (;0;) + (instance + (export (;0;) "r" (type (sub resource))) + (type (;1;) (own 0)) + (type (;2;) (func (result 1))) + (export (;0;) "[constructor]r" (func (type 2))) + (type (;3;) (func (param "x" string))) + (export (;1;) "x" (func (type 3))) + (export (;2;) "x2" (func (type 3))) + ) + ) + (import "a:b/c@0.1.0" (instance $a:b/c@0.1.0 (;0;) (type $ty-a:b/c@0.1.0))) + (type $ty-a:b/c@0.2.1 (;1;) (instance (export (;0;) "r" (type (sub resource))) (type (;1;) (own 0)) @@ -15,7 +27,7 @@ (export (;4;) "y" (func (type 6))) ) ) - (import "a:b/c@0.1.1" (instance $a:b/c@0.1.1 (;0;) (type $ty-a:b/c@0.1.1))) + (import "a:b/c@0.2.1" (instance $a:b/c@0.2.1 (;1;) (type $ty-a:b/c@0.2.1))) (core module $main (;0;) (type (;0;) (func (result i32))) (type (;1;) (func (param i32))) @@ -25,12 +37,12 @@ (import "a:b/c@0.1.0" "[resource-drop]r" (func (;1;) (type 1))) (import "a:b/c@0.1.0" "x" (func (;2;) (type 2))) (import "a:b/c@0.1.0" "x2" (func (;3;) (type 2))) - (import "a:b/c@0.1.1" "[constructor]r" (func (;4;) (type 0))) - (import "a:b/c@0.1.1" "[resource-drop]r" (func (;5;) (type 1))) - (import "a:b/c@0.1.1" "[method]r.x" (func (;6;) (type 1))) - (import "a:b/c@0.1.1" "x" (func (;7;) (type 2))) - (import "a:b/c@0.1.1" "x2" (func (;8;) (type 2))) - (import "a:b/c@0.1.1" "y" (func (;9;) (type 3))) + (import "a:b/c@0.2.1" "[constructor]r" (func (;4;) (type 0))) + (import "a:b/c@0.2.1" "[resource-drop]r" (func (;5;) (type 1))) + (import "a:b/c@0.2.1" "[method]r.x" (func (;6;) (type 1))) + (import "a:b/c@0.2.1" "x" (func (;7;) (type 2))) + (import "a:b/c@0.2.1" "x2" (func (;8;) (type 2))) + (import "a:b/c@0.2.1" "y" (func (;9;) (type 3))) (memory (;0;) 1) (export "memory" (memory 0)) (@producers @@ -40,9 +52,11 @@ ) (core module $wit-component-shim-module (;1;) (type (;0;) (func (param i32 i32))) - (table (;0;) 2 2 funcref) + (table (;0;) 4 4 funcref) (export "0" (func $indirect-a:b/c@0.1.0-x)) (export "1" (func $indirect-a:b/c@0.1.0-x2)) + (export "2" (func $indirect-a:b/c@0.2.1-x)) + (export "3" (func $indirect-a:b/c@0.2.1-x2)) (export "$imports" (table 0)) (func $indirect-a:b/c@0.1.0-x (;0;) (type 0) (param i32 i32) local.get 0 @@ -56,6 +70,18 @@ i32.const 1 call_indirect (type 0) ) + (func $indirect-a:b/c@0.2.1-x (;2;) (type 0) (param i32 i32) + local.get 0 + local.get 1 + i32.const 2 + call_indirect (type 0) + ) + (func $indirect-a:b/c@0.2.1-x2 (;3;) (type 0) (param i32 i32) + local.get 0 + local.get 1 + i32.const 3 + call_indirect (type 0) + ) (@producers (processed-by "wit-component" "$CARGO_PKG_VERSION") ) @@ -64,16 +90,18 @@ (type (;0;) (func (param i32 i32))) (import "" "0" (func (;0;) (type 0))) (import "" "1" (func (;1;) (type 0))) - (import "" "$imports" (table (;0;) 2 2 funcref)) - (elem (;0;) (i32.const 0) func 0 1) + (import "" "2" (func (;2;) (type 0))) + (import "" "3" (func (;3;) (type 0))) + (import "" "$imports" (table (;0;) 4 4 funcref)) + (elem (;0;) (i32.const 0) func 0 1 2 3) (@producers (processed-by "wit-component" "$CARGO_PKG_VERSION") ) ) (core instance $wit-component-shim-instance (;0;) (instantiate $wit-component-shim-module)) - (alias export $a:b/c@0.1.1 "[constructor]r" (func $"[constructor]r" (;0;))) + (alias export $a:b/c@0.1.0 "[constructor]r" (func $"[constructor]r" (;0;))) (core func $"[constructor]r" (;0;) (canon lower (func $"[constructor]r"))) - (alias export $a:b/c@0.1.1 "r" (type $r (;1;))) + (alias export $a:b/c@0.1.0 "r" (type $r (;2;))) (core func $resource.drop (;1;) (canon resource.drop $r)) (alias core export $wit-component-shim-instance "0" (core func $indirect-a:b/c@0.1.0-x (;2;))) (alias core export $wit-component-shim-instance "1" (core func $indirect-a:b/c@0.1.0-x2 (;3;))) @@ -83,37 +111,45 @@ (export "x" (func $indirect-a:b/c@0.1.0-x)) (export "x2" (func $indirect-a:b/c@0.1.0-x2)) ) - (alias export $a:b/c@0.1.1 "[constructor]r" (func $"#func1 [constructor]r" (@name "[constructor]r") (;1;))) + (alias export $a:b/c@0.2.1 "[constructor]r" (func $"#func1 [constructor]r" (@name "[constructor]r") (;1;))) (core func $"#core-func4 [constructor]r" (@name "[constructor]r") (;4;) (canon lower (func $"#func1 [constructor]r"))) - (alias export $a:b/c@0.1.1 "r" (type $"#type2 r" (@name "r") (;2;))) - (core func $"#core-func5 resource.drop" (@name "resource.drop") (;5;) (canon resource.drop $"#type2 r")) - (alias export $a:b/c@0.1.1 "[method]r.x" (func $"[method]r.x" (;2;))) + (alias export $a:b/c@0.2.1 "r" (type $"#type3 r" (@name "r") (;3;))) + (core func $"#core-func5 resource.drop" (@name "resource.drop") (;5;) (canon resource.drop $"#type3 r")) + (alias export $a:b/c@0.2.1 "[method]r.x" (func $"[method]r.x" (;2;))) (core func $"[method]r.x" (;6;) (canon lower (func $"[method]r.x"))) - (alias export $a:b/c@0.1.1 "y" (func $y (;3;))) - (core func $y (;7;) (canon lower (func $y))) - (core instance $a:b/c@0.1.1 (;2;) + (alias core export $wit-component-shim-instance "2" (core func $indirect-a:b/c@0.2.1-x (;7;))) + (alias core export $wit-component-shim-instance "3" (core func $indirect-a:b/c@0.2.1-x2 (;8;))) + (alias export $a:b/c@0.2.1 "y" (func $y (;3;))) + (core func $y (;9;) (canon lower (func $y))) + (core instance $a:b/c@0.2.1 (;2;) (export "[constructor]r" (func $"#core-func4 [constructor]r")) (export "[resource-drop]r" (func $"#core-func5 resource.drop")) (export "[method]r.x" (func $"[method]r.x")) - (export "x" (func $indirect-a:b/c@0.1.0-x)) - (export "x2" (func $indirect-a:b/c@0.1.0-x2)) + (export "x" (func $indirect-a:b/c@0.2.1-x)) + (export "x2" (func $indirect-a:b/c@0.2.1-x2)) (export "y" (func $y)) ) (core instance $main (;3;) (instantiate $main (with "a:b/c@0.1.0" (instance $a:b/c@0.1.0)) - (with "a:b/c@0.1.1" (instance $a:b/c@0.1.1)) + (with "a:b/c@0.2.1" (instance $a:b/c@0.2.1)) ) ) (alias core export $main "memory" (core memory $memory (;0;))) (alias core export $wit-component-shim-instance "$imports" (core table $"shim table" (;0;))) - (alias export $a:b/c@0.1.1 "x" (func $x (;4;))) - (core func $"#core-func8 indirect-a:b/c@0.1.0-x" (@name "indirect-a:b/c@0.1.0-x") (;8;) (canon lower (func $x) (memory $memory) string-encoding=utf8)) - (alias export $a:b/c@0.1.1 "x2" (func $x2 (;5;))) - (core func $"#core-func9 indirect-a:b/c@0.1.0-x2" (@name "indirect-a:b/c@0.1.0-x2") (;9;) (canon lower (func $x2) (memory $memory) string-encoding=utf8)) + (alias export $a:b/c@0.1.0 "x" (func $x (;4;))) + (core func $"#core-func10 indirect-a:b/c@0.1.0-x" (@name "indirect-a:b/c@0.1.0-x") (;10;) (canon lower (func $x) (memory $memory) string-encoding=utf8)) + (alias export $a:b/c@0.1.0 "x2" (func $x2 (;5;))) + (core func $"#core-func11 indirect-a:b/c@0.1.0-x2" (@name "indirect-a:b/c@0.1.0-x2") (;11;) (canon lower (func $x2) (memory $memory) string-encoding=utf8)) + (alias export $a:b/c@0.2.1 "x" (func $"#func6 x" (@name "x") (;6;))) + (core func $"#core-func12 indirect-a:b/c@0.2.1-x" (@name "indirect-a:b/c@0.2.1-x") (;12;) (canon lower (func $"#func6 x") (memory $memory) string-encoding=utf8)) + (alias export $a:b/c@0.2.1 "x2" (func $"#func7 x2" (@name "x2") (;7;))) + (core func $"#core-func13 indirect-a:b/c@0.2.1-x2" (@name "indirect-a:b/c@0.2.1-x2") (;13;) (canon lower (func $"#func7 x2") (memory $memory) string-encoding=utf8)) (core instance $fixup-args (;4;) (export "$imports" (table $"shim table")) - (export "0" (func $"#core-func8 indirect-a:b/c@0.1.0-x")) - (export "1" (func $"#core-func9 indirect-a:b/c@0.1.0-x2")) + (export "0" (func $"#core-func10 indirect-a:b/c@0.1.0-x")) + (export "1" (func $"#core-func11 indirect-a:b/c@0.1.0-x2")) + (export "2" (func $"#core-func12 indirect-a:b/c@0.2.1-x")) + (export "3" (func $"#core-func13 indirect-a:b/c@0.2.1-x2")) ) (core instance $fixup (;5;) (instantiate $wit-component-fixup (with "" (instance $fixup-args)) diff --git a/crates/wit-component/tests/components/merge-import-versions/component.wit.print b/crates/wit-component/tests/components/merge-import-versions/component.wit.print index 1a2ed3c569..1da1fb1e42 100644 --- a/crates/wit-component/tests/components/merge-import-versions/component.wit.print +++ b/crates/wit-component/tests/components/merge-import-versions/component.wit.print @@ -1,5 +1,6 @@ package root:component; world root { - import a:b/c@0.1.1; + import a:b/c@0.1.0; + import a:b/c@0.2.1; } diff --git a/crates/wit-component/tests/components/merge-import-versions/module.wat b/crates/wit-component/tests/components/merge-import-versions/module.wat index b23e81cc96..690c8a370a 100644 --- a/crates/wit-component/tests/components/merge-import-versions/module.wat +++ b/crates/wit-component/tests/components/merge-import-versions/module.wat @@ -4,12 +4,12 @@ (import "a:b/c@0.1.0" "x" (func (param i32 i32))) (import "a:b/c@0.1.0" "x2" (func (param i32 i32))) - (import "a:b/c@0.1.1" "[constructor]r" (func (result i32))) - (import "a:b/c@0.1.1" "[resource-drop]r" (func (param i32))) - (import "a:b/c@0.1.1" "[method]r.x" (func (param i32))) - (import "a:b/c@0.1.1" "x" (func (param i32 i32))) - (import "a:b/c@0.1.1" "x2" (func (param i32 i32))) - (import "a:b/c@0.1.1" "y" (func)) + (import "a:b/c@0.2.1" "[constructor]r" (func (result i32))) + (import "a:b/c@0.2.1" "[resource-drop]r" (func (param i32))) + (import "a:b/c@0.2.1" "[method]r.x" (func (param i32))) + (import "a:b/c@0.2.1" "x" (func (param i32 i32))) + (import "a:b/c@0.2.1" "x2" (func (param i32 i32))) + (import "a:b/c@0.2.1" "y" (func)) (memory (export "memory") 1) ) diff --git a/crates/wit-component/tests/components/merge-import-versions/module.wit b/crates/wit-component/tests/components/merge-import-versions/module.wit index 63dacf4115..dc97b1a4a3 100644 --- a/crates/wit-component/tests/components/merge-import-versions/module.wit +++ b/crates/wit-component/tests/components/merge-import-versions/module.wit @@ -2,7 +2,7 @@ package foo:foo; world module { import a:b/c@0.1.0; - import a:b/c@0.1.1; + import a:b/c@0.2.1; } package a:b@0.1.0 { @@ -15,7 +15,7 @@ package a:b@0.1.0 { } } -package a:b@0.1.1 { +package a:b@0.2.1 { interface c { x: func(x: string); x2: func(x: string); diff --git a/crates/wit-component/tests/interfaces.rs b/crates/wit-component/tests/interfaces.rs index d89676df1b..e87061e7ff 100644 --- a/crates/wit-component/tests/interfaces.rs +++ b/crates/wit-component/tests/interfaces.rs @@ -25,17 +25,32 @@ fn main() -> Result<()> { for entry in fs::read_dir("tests/interfaces")? { let path = entry?.path(); let name = match path.file_name().and_then(|s| s.to_str()) { - Some(s) => s, + Some(s) => s.to_string(), None => continue, }; let is_dir = path.is_dir(); let is_test = is_dir || name.ends_with(".wit"); - if is_test { - trials.push(Trial::test(name.to_string(), move || { - run_test(&path, is_dir) + if !is_test { + continue; + } + if name.starts_with("canon-names-") { + trials.push(Trial::test(name, move || { + run_test(&path, is_dir, true) + .context(format!("failed test `{}`", path.display())) + .map_err(|e| format!("{e:?}").into()) + })); + } else { + let path2 = path.clone(); + trials.push(Trial::test(name.clone(), move || { + run_test(&path, is_dir, false) .context(format!("failed test `{}`", path.display())) .map_err(|e| format!("{e:?}").into()) })); + trials.push(Trial::test(format!("{name}@canon-names"), move || { + run_test(&path2, is_dir, true) + .context(format!("failed test `{}`", path2.display())) + .map_err(|e| format!("{e:?}").into()) + })); } } @@ -46,22 +61,34 @@ fn main() -> Result<()> { libtest_mimic::run(&args, trials).exit(); } -fn run_test(path: &Path, is_dir: bool) -> Result<()> { +fn canon_names_path(path: &Path, ext: &str, use_canonical: bool) -> std::path::PathBuf { + if use_canonical { + let canon_ext = format!("canon-names.{ext}"); + let canon_path = path.with_extension(&canon_ext); + if std::env::var_os("BLESS").is_some() || canon_path.exists() { + return canon_path; + } + } + path.with_extension(ext) +} + +fn run_test(path: &Path, is_dir: bool, use_canonical: bool) -> Result<()> { let mut resolve = Resolve::new(); + resolve.use_canonical_names = use_canonical; let package = if is_dir { resolve.push_dir(path)?.0 } else { resolve.push_file(path)? }; - assert_print(&resolve, package, path, is_dir)?; + assert_print(&resolve, package, path, is_dir, use_canonical)?; // First convert the WIT package to a binary WebAssembly output, then // convert that binary wasm to textual wasm, then assert it matches the // expectation. let wasm = wit_component::encode(&resolve, package)?; let wat = wasmprinter::print_bytes(&wasm)?; - assert_output(&path.with_extension("wat"), &wat)?; + assert_output(&canon_names_path(path, "wat", use_canonical), &wat)?; wasmparser::Validator::new_with_features(WasmFeatures::all()) .validate_all(&wasm) .context("failed to validate wasm output")?; @@ -73,7 +100,7 @@ fn run_test(path: &Path, is_dir: bool) -> Result<()> { let decoded_package = decoded.package(); let resolve = decoded.resolve(); - assert_print(resolve, decoded.package(), path, is_dir)?; + assert_print(resolve, decoded.package(), path, is_dir, use_canonical)?; // Finally convert the decoded package to wasm again and make sure it // matches the prior wasm. @@ -86,15 +113,31 @@ fn run_test(path: &Path, is_dir: bool) -> Result<()> { Ok(()) } -fn assert_print(resolve: &Resolve, pkg_id: PackageId, path: &Path, is_dir: bool) -> Result<()> { +fn assert_print( + resolve: &Resolve, + pkg_id: PackageId, + path: &Path, + is_dir: bool, + use_canonical: bool, +) -> Result<()> { let mut printer = WitPrinter::default(); printer.print(resolve, pkg_id, &[])?; let output = printer.output.to_string(); let pkg = &resolve.packages[pkg_id]; let expected = if is_dir { - path.join(format!("{}.wit.print", &pkg.name.name)) + let base = path.join(format!("{}.wit.print", &pkg.name.name)); + if use_canonical { + let canon = path.join(format!("{}.canon-names.wit.print", &pkg.name.name)); + if std::env::var_os("BLESS").is_some() || canon.exists() { + canon + } else { + base + } + } else { + base + } } else { - path.with_extension("wit.print") + canon_names_path(path, "wit.print", use_canonical) }; assert_output(&expected, &output)?; diff --git a/crates/wit-component/tests/interfaces/canon-names-merge.canon-names.wat b/crates/wit-component/tests/interfaces/canon-names-merge.canon-names.wat new file mode 100644 index 0000000000..2cc004636d --- /dev/null +++ b/crates/wit-component/tests/interfaces/canon-names-merge.canon-names.wat @@ -0,0 +1,25 @@ +(component + (type (;0;) + (component + (type (;0;) + (component + (type (;0;) + (instance + (type (;0;) (record (field "name" string))) + (export (;1;) "info" (type (eq 0))) + (type (;2;) (func (result 1))) + (export (;0;) "get-info" (func (type 2))) + ) + ) + (import "test:lib/api@1" (versionsuffix ".2.2") (instance (;0;) (type 0))) + ) + ) + (export (;0;) "test:app/app@1.0.0" (component (type 0))) + ) + ) + (export (;1;) "app" (type 0)) + (@custom "package-docs" "\01{}") + (@producers + (processed-by "wit-component" "$CARGO_PKG_VERSION") + ) +) diff --git a/crates/wit-component/tests/interfaces/canon-names-merge/app.canon-names.wit.print b/crates/wit-component/tests/interfaces/canon-names-merge/app.canon-names.wit.print new file mode 100644 index 0000000000..ed56295187 --- /dev/null +++ b/crates/wit-component/tests/interfaces/canon-names-merge/app.canon-names.wit.print @@ -0,0 +1,5 @@ +package test:app@1.0.0; + +world app { + import test:lib/api@1.2.2; +} diff --git a/crates/wit-component/tests/interfaces/canon-names-merge/app.wit b/crates/wit-component/tests/interfaces/canon-names-merge/app.wit new file mode 100644 index 0000000000..5565ad65d0 --- /dev/null +++ b/crates/wit-component/tests/interfaces/canon-names-merge/app.wit @@ -0,0 +1,5 @@ +package test:app@1.0.0; + +world app { + import test:lib/api@1.2.0; +} diff --git a/crates/wit-component/tests/interfaces/canon-names-merge/deps/lib-v1/lib.wit b/crates/wit-component/tests/interfaces/canon-names-merge/deps/lib-v1/lib.wit new file mode 100644 index 0000000000..5306a47a97 --- /dev/null +++ b/crates/wit-component/tests/interfaces/canon-names-merge/deps/lib-v1/lib.wit @@ -0,0 +1,8 @@ +package test:lib@1.0.1; + +interface api { + record info { + name: string, + } + get-info: func() -> info; +} diff --git a/crates/wit-component/tests/interfaces/canon-names-merge/deps/lib-v2/lib.wit b/crates/wit-component/tests/interfaces/canon-names-merge/deps/lib-v2/lib.wit new file mode 100644 index 0000000000..d47b191cde --- /dev/null +++ b/crates/wit-component/tests/interfaces/canon-names-merge/deps/lib-v2/lib.wit @@ -0,0 +1,8 @@ +package test:lib@1.2.2; + +interface api { + record info { + name: string, + } + get-info: func() -> info; +} diff --git a/crates/wit-component/tests/interfaces/wasi-http.canon-names.wat b/crates/wit-component/tests/interfaces/wasi-http.canon-names.wat new file mode 100644 index 0000000000..5bc86427c0 --- /dev/null +++ b/crates/wit-component/tests/interfaces/wasi-http.canon-names.wat @@ -0,0 +1,881 @@ +(component + (type (;0;) + (component + (type (;0;) + (instance + (export (;0;) "pollable" (type (sub resource))) + ) + ) + (import "wasi:io/poll@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;0;) (type 0))) + (alias export 0 "pollable" (type (;1;))) + (type (;2;) + (instance + (alias outer 1 1 (type (;0;))) + (export (;1;) "pollable" (type (eq 0))) + (type (;2;) u64) + (export (;3;) "instant" (type (eq 2))) + (type (;4;) u64) + (export (;5;) "duration" (type (eq 4))) + ) + ) + (import "wasi:clocks/monotonic-clock@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;1;) (type 2))) + (type (;3;) + (instance + (export (;0;) "error" (type (sub resource))) + ) + ) + (import "wasi:io/error@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;2;) (type 3))) + (alias export 2 "error" (type (;4;))) + (type (;5;) + (instance + (alias outer 1 4 (type (;0;))) + (export (;1;) "error" (type (eq 0))) + (alias outer 1 1 (type (;2;))) + (export (;3;) "pollable" (type (eq 2))) + (type (;4;) (own 1)) + (type (;5;) (variant (case "last-operation-failed" 4) (case "closed"))) + (export (;6;) "stream-error" (type (eq 5))) + (export (;7;) "input-stream" (type (sub resource))) + (export (;8;) "output-stream" (type (sub resource))) + ) + ) + (import "wasi:io/streams@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;3;) (type 5))) + (alias export 1 "duration" (type (;6;))) + (alias export 3 "input-stream" (type (;7;))) + (alias export 3 "output-stream" (type (;8;))) + (type (;9;) + (instance + (alias outer 1 6 (type (;0;))) + (export (;1;) "duration" (type (eq 0))) + (alias outer 1 7 (type (;2;))) + (export (;3;) "input-stream" (type (eq 2))) + (alias outer 1 8 (type (;4;))) + (export (;5;) "output-stream" (type (eq 4))) + (alias outer 1 4 (type (;6;))) + (export (;7;) "io-error" (type (eq 6))) + (alias outer 1 1 (type (;8;))) + (export (;9;) "pollable" (type (eq 8))) + (type (;10;) (variant (case "get") (case "head") (case "post") (case "put") (case "delete") (case "connect") (case "options") (case "trace") (case "patch") (case "other" string))) + (export (;11;) "method" (type (eq 10))) + (type (;12;) (variant (case "HTTP") (case "HTTPS") (case "other" string))) + (export (;13;) "scheme" (type (eq 12))) + (type (;14;) (option string)) + (type (;15;) (option u16)) + (type (;16;) (record (field "rcode" 14) (field "info-code" 15))) + (export (;17;) "DNS-error-payload" (type (eq 16))) + (type (;18;) (option u8)) + (type (;19;) (record (field "alert-id" 18) (field "alert-message" 14))) + (export (;20;) "TLS-alert-received-payload" (type (eq 19))) + (type (;21;) (option u32)) + (type (;22;) (record (field "field-name" 14) (field "field-size" 21))) + (export (;23;) "field-size-payload" (type (eq 22))) + (type (;24;) (option u64)) + (type (;25;) (option 23)) + (type (;26;) (variant (case "DNS-timeout") (case "DNS-error" 17) (case "destination-not-found") (case "destination-unavailable") (case "destination-IP-prohibited") (case "destination-IP-unroutable") (case "connection-refused") (case "connection-terminated") (case "connection-timeout") (case "connection-read-timeout") (case "connection-write-timeout") (case "connection-limit-reached") (case "TLS-protocol-error") (case "TLS-certificate-error") (case "TLS-alert-received" 20) (case "HTTP-request-denied") (case "HTTP-request-length-required") (case "HTTP-request-body-size" 24) (case "HTTP-request-method-invalid") (case "HTTP-request-URI-invalid") (case "HTTP-request-URI-too-long") (case "HTTP-request-header-section-size" 21) (case "HTTP-request-header-size" 25) (case "HTTP-request-trailer-section-size" 21) (case "HTTP-request-trailer-size" 23) (case "HTTP-response-incomplete") (case "HTTP-response-header-section-size" 21) (case "HTTP-response-header-size" 23) (case "HTTP-response-body-size" 24) (case "HTTP-response-trailer-section-size" 21) (case "HTTP-response-trailer-size" 23) (case "HTTP-response-transfer-coding" 14) (case "HTTP-response-content-coding" 14) (case "HTTP-response-timeout") (case "HTTP-upgrade-failed") (case "HTTP-protocol-error") (case "loop-detected") (case "configuration-error") (case "internal-error" 14))) + (export (;27;) "error-code" (type (eq 26))) + (type (;28;) (variant (case "invalid-syntax") (case "forbidden") (case "immutable"))) + (export (;29;) "header-error" (type (eq 28))) + (type (;30;) string) + (export (;31;) "field-key" (type (eq 30))) + (type (;32;) (list u8)) + (export (;33;) "field-value" (type (eq 32))) + (export (;34;) "fields" (type (sub resource))) + (export (;35;) "headers" (type (eq 34))) + (export (;36;) "trailers" (type (eq 34))) + (export (;37;) "incoming-request" (type (sub resource))) + (export (;38;) "outgoing-request" (type (sub resource))) + (export (;39;) "request-options" (type (sub resource))) + (export (;40;) "response-outparam" (type (sub resource))) + (type (;41;) u16) + (export (;42;) "status-code" (type (eq 41))) + (export (;43;) "incoming-response" (type (sub resource))) + (export (;44;) "incoming-body" (type (sub resource))) + (export (;45;) "future-trailers" (type (sub resource))) + (export (;46;) "outgoing-response" (type (sub resource))) + (export (;47;) "outgoing-body" (type (sub resource))) + (export (;48;) "future-incoming-response" (type (sub resource))) + (type (;49;) (own 34)) + (type (;50;) (func (result 49))) + (export (;0;) "[constructor]fields" (func (type 50))) + (type (;51;) (tuple 31 33)) + (type (;52;) (list 51)) + (type (;53;) (result 49 (error 29))) + (type (;54;) (func (param "entries" 52) (result 53))) + (export (;1;) "[static]fields.from-list" (func (type 54))) + (type (;55;) (borrow 34)) + (type (;56;) (list 33)) + (type (;57;) (func (param "self" 55) (param "name" 31) (result 56))) + (export (;2;) "[method]fields.get" (func (type 57))) + (type (;58;) (func (param "self" 55) (param "name" 31) (result bool))) + (export (;3;) "[method]fields.has" (func (type 58))) + (type (;59;) (result (error 29))) + (type (;60;) (func (param "self" 55) (param "name" 31) (param "value" 56) (result 59))) + (export (;4;) "[method]fields.set" (func (type 60))) + (type (;61;) (func (param "self" 55) (param "name" 31) (result 59))) + (export (;5;) "[method]fields.delete" (func (type 61))) + (type (;62;) (func (param "self" 55) (param "name" 31) (param "value" 33) (result 59))) + (export (;6;) "[method]fields.append" (func (type 62))) + (type (;63;) (func (param "self" 55) (result 52))) + (export (;7;) "[method]fields.entries" (func (type 63))) + (type (;64;) (func (param "self" 55) (result 49))) + (export (;8;) "[method]fields.clone" (func (type 64))) + (type (;65;) (borrow 37)) + (type (;66;) (func (param "self" 65) (result 11))) + (export (;9;) "[method]incoming-request.method" (func (type 66))) + (type (;67;) (func (param "self" 65) (result 14))) + (export (;10;) "[method]incoming-request.path-with-query" (func (type 67))) + (type (;68;) (option 13)) + (type (;69;) (func (param "self" 65) (result 68))) + (export (;11;) "[method]incoming-request.scheme" (func (type 69))) + (export (;12;) "[method]incoming-request.authority" (func (type 67))) + (type (;70;) (own 35)) + (type (;71;) (func (param "self" 65) (result 70))) + (export (;13;) "[method]incoming-request.headers" (func (type 71))) + (type (;72;) (own 44)) + (type (;73;) (result 72)) + (type (;74;) (func (param "self" 65) (result 73))) + (export (;14;) "[method]incoming-request.consume" (func (type 74))) + (type (;75;) (own 38)) + (type (;76;) (func (param "headers" 70) (result 75))) + (export (;15;) "[constructor]outgoing-request" (func (type 76))) + (type (;77;) (borrow 38)) + (type (;78;) (own 47)) + (type (;79;) (result 78)) + (type (;80;) (func (param "self" 77) (result 79))) + (export (;16;) "[method]outgoing-request.body" (func (type 80))) + (type (;81;) (func (param "self" 77) (result 11))) + (export (;17;) "[method]outgoing-request.method" (func (type 81))) + (type (;82;) (result)) + (type (;83;) (func (param "self" 77) (param "method" 11) (result 82))) + (export (;18;) "[method]outgoing-request.set-method" (func (type 83))) + (type (;84;) (func (param "self" 77) (result 14))) + (export (;19;) "[method]outgoing-request.path-with-query" (func (type 84))) + (type (;85;) (func (param "self" 77) (param "path-with-query" 14) (result 82))) + (export (;20;) "[method]outgoing-request.set-path-with-query" (func (type 85))) + (type (;86;) (func (param "self" 77) (result 68))) + (export (;21;) "[method]outgoing-request.scheme" (func (type 86))) + (type (;87;) (func (param "self" 77) (param "scheme" 68) (result 82))) + (export (;22;) "[method]outgoing-request.set-scheme" (func (type 87))) + (export (;23;) "[method]outgoing-request.authority" (func (type 84))) + (type (;88;) (func (param "self" 77) (param "authority" 14) (result 82))) + (export (;24;) "[method]outgoing-request.set-authority" (func (type 88))) + (type (;89;) (func (param "self" 77) (result 70))) + (export (;25;) "[method]outgoing-request.headers" (func (type 89))) + (type (;90;) (own 39)) + (type (;91;) (func (result 90))) + (export (;26;) "[constructor]request-options" (func (type 91))) + (type (;92;) (borrow 39)) + (type (;93;) (option 1)) + (type (;94;) (func (param "self" 92) (result 93))) + (export (;27;) "[method]request-options.connect-timeout" (func (type 94))) + (type (;95;) (func (param "self" 92) (param "duration" 93) (result 82))) + (export (;28;) "[method]request-options.set-connect-timeout" (func (type 95))) + (export (;29;) "[method]request-options.first-byte-timeout" (func (type 94))) + (export (;30;) "[method]request-options.set-first-byte-timeout" (func (type 95))) + (export (;31;) "[method]request-options.between-bytes-timeout" (func (type 94))) + (export (;32;) "[method]request-options.set-between-bytes-timeout" (func (type 95))) + (type (;96;) (own 40)) + (type (;97;) (own 46)) + (type (;98;) (result 97 (error 27))) + (type (;99;) (func (param "param" 96) (param "response" 98))) + (export (;33;) "[static]response-outparam.set" (func (type 99))) + (type (;100;) (borrow 43)) + (type (;101;) (func (param "self" 100) (result 42))) + (export (;34;) "[method]incoming-response.status" (func (type 101))) + (type (;102;) (func (param "self" 100) (result 70))) + (export (;35;) "[method]incoming-response.headers" (func (type 102))) + (type (;103;) (func (param "self" 100) (result 73))) + (export (;36;) "[method]incoming-response.consume" (func (type 103))) + (type (;104;) (borrow 44)) + (type (;105;) (own 3)) + (type (;106;) (result 105)) + (type (;107;) (func (param "self" 104) (result 106))) + (export (;37;) "[method]incoming-body.stream" (func (type 107))) + (type (;108;) (own 45)) + (type (;109;) (func (param "this" 72) (result 108))) + (export (;38;) "[static]incoming-body.finish" (func (type 109))) + (type (;110;) (borrow 45)) + (type (;111;) (own 9)) + (type (;112;) (func (param "self" 110) (result 111))) + (export (;39;) "[method]future-trailers.subscribe" (func (type 112))) + (type (;113;) (own 36)) + (type (;114;) (option 113)) + (type (;115;) (result 114 (error 27))) + (type (;116;) (result 115)) + (type (;117;) (option 116)) + (type (;118;) (func (param "self" 110) (result 117))) + (export (;40;) "[method]future-trailers.get" (func (type 118))) + (type (;119;) (func (param "headers" 70) (result 97))) + (export (;41;) "[constructor]outgoing-response" (func (type 119))) + (type (;120;) (borrow 46)) + (type (;121;) (func (param "self" 120) (result 42))) + (export (;42;) "[method]outgoing-response.status-code" (func (type 121))) + (type (;122;) (func (param "self" 120) (param "status-code" 42) (result 82))) + (export (;43;) "[method]outgoing-response.set-status-code" (func (type 122))) + (type (;123;) (func (param "self" 120) (result 70))) + (export (;44;) "[method]outgoing-response.headers" (func (type 123))) + (type (;124;) (func (param "self" 120) (result 79))) + (export (;45;) "[method]outgoing-response.body" (func (type 124))) + (type (;125;) (borrow 47)) + (type (;126;) (own 5)) + (type (;127;) (result 126)) + (type (;128;) (func (param "self" 125) (result 127))) + (export (;46;) "[method]outgoing-body.write" (func (type 128))) + (type (;129;) (result (error 27))) + (type (;130;) (func (param "this" 78) (param "trailers" 114) (result 129))) + (export (;47;) "[static]outgoing-body.finish" (func (type 130))) + (type (;131;) (borrow 48)) + (type (;132;) (func (param "self" 131) (result 111))) + (export (;48;) "[method]future-incoming-response.subscribe" (func (type 132))) + (type (;133;) (own 43)) + (type (;134;) (result 133 (error 27))) + (type (;135;) (result 134)) + (type (;136;) (option 135)) + (type (;137;) (func (param "self" 131) (result 136))) + (export (;49;) "[method]future-incoming-response.get" (func (type 137))) + (type (;138;) (borrow 7)) + (type (;139;) (option 27)) + (type (;140;) (func (param "err" 138) (result 139))) + (export (;50;) "http-error-code" (func (type 140))) + ) + ) + (export (;4;) "wasi:http/types@0.2" (versionsuffix ".0-rc-2023-12-05") (instance (type 9))) + ) + ) + (export (;1;) "types" (type 0)) + (type (;2;) + (component + (type (;0;) + (instance + (export (;0;) "pollable" (type (sub resource))) + ) + ) + (import "wasi:io/poll@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;0;) (type 0))) + (alias export 0 "pollable" (type (;1;))) + (type (;2;) + (instance + (alias outer 1 1 (type (;0;))) + (export (;1;) "pollable" (type (eq 0))) + (type (;2;) u64) + (export (;3;) "instant" (type (eq 2))) + (type (;4;) u64) + (export (;5;) "duration" (type (eq 4))) + ) + ) + (import "wasi:clocks/monotonic-clock@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;1;) (type 2))) + (type (;3;) + (instance + (export (;0;) "error" (type (sub resource))) + ) + ) + (import "wasi:io/error@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;2;) (type 3))) + (alias export 2 "error" (type (;4;))) + (type (;5;) + (instance + (alias outer 1 4 (type (;0;))) + (export (;1;) "error" (type (eq 0))) + (alias outer 1 1 (type (;2;))) + (export (;3;) "pollable" (type (eq 2))) + (type (;4;) (own 1)) + (type (;5;) (variant (case "last-operation-failed" 4) (case "closed"))) + (export (;6;) "stream-error" (type (eq 5))) + (export (;7;) "input-stream" (type (sub resource))) + (export (;8;) "output-stream" (type (sub resource))) + ) + ) + (import "wasi:io/streams@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;3;) (type 5))) + (alias export 1 "duration" (type (;6;))) + (alias export 3 "input-stream" (type (;7;))) + (alias export 3 "output-stream" (type (;8;))) + (type (;9;) + (instance + (alias outer 1 6 (type (;0;))) + (export (;1;) "duration" (type (eq 0))) + (alias outer 1 7 (type (;2;))) + (export (;3;) "input-stream" (type (eq 2))) + (alias outer 1 8 (type (;4;))) + (export (;5;) "output-stream" (type (eq 4))) + (alias outer 1 4 (type (;6;))) + (export (;7;) "io-error" (type (eq 6))) + (alias outer 1 1 (type (;8;))) + (export (;9;) "pollable" (type (eq 8))) + (type (;10;) (variant (case "get") (case "head") (case "post") (case "put") (case "delete") (case "connect") (case "options") (case "trace") (case "patch") (case "other" string))) + (export (;11;) "method" (type (eq 10))) + (type (;12;) (variant (case "HTTP") (case "HTTPS") (case "other" string))) + (export (;13;) "scheme" (type (eq 12))) + (type (;14;) (option string)) + (type (;15;) (option u16)) + (type (;16;) (record (field "rcode" 14) (field "info-code" 15))) + (export (;17;) "DNS-error-payload" (type (eq 16))) + (type (;18;) (option u8)) + (type (;19;) (record (field "alert-id" 18) (field "alert-message" 14))) + (export (;20;) "TLS-alert-received-payload" (type (eq 19))) + (type (;21;) (option u32)) + (type (;22;) (record (field "field-name" 14) (field "field-size" 21))) + (export (;23;) "field-size-payload" (type (eq 22))) + (type (;24;) (option u64)) + (type (;25;) (option 23)) + (type (;26;) (variant (case "DNS-timeout") (case "DNS-error" 17) (case "destination-not-found") (case "destination-unavailable") (case "destination-IP-prohibited") (case "destination-IP-unroutable") (case "connection-refused") (case "connection-terminated") (case "connection-timeout") (case "connection-read-timeout") (case "connection-write-timeout") (case "connection-limit-reached") (case "TLS-protocol-error") (case "TLS-certificate-error") (case "TLS-alert-received" 20) (case "HTTP-request-denied") (case "HTTP-request-length-required") (case "HTTP-request-body-size" 24) (case "HTTP-request-method-invalid") (case "HTTP-request-URI-invalid") (case "HTTP-request-URI-too-long") (case "HTTP-request-header-section-size" 21) (case "HTTP-request-header-size" 25) (case "HTTP-request-trailer-section-size" 21) (case "HTTP-request-trailer-size" 23) (case "HTTP-response-incomplete") (case "HTTP-response-header-section-size" 21) (case "HTTP-response-header-size" 23) (case "HTTP-response-body-size" 24) (case "HTTP-response-trailer-section-size" 21) (case "HTTP-response-trailer-size" 23) (case "HTTP-response-transfer-coding" 14) (case "HTTP-response-content-coding" 14) (case "HTTP-response-timeout") (case "HTTP-upgrade-failed") (case "HTTP-protocol-error") (case "loop-detected") (case "configuration-error") (case "internal-error" 14))) + (export (;27;) "error-code" (type (eq 26))) + (type (;28;) (variant (case "invalid-syntax") (case "forbidden") (case "immutable"))) + (export (;29;) "header-error" (type (eq 28))) + (type (;30;) string) + (export (;31;) "field-key" (type (eq 30))) + (type (;32;) (list u8)) + (export (;33;) "field-value" (type (eq 32))) + (export (;34;) "fields" (type (sub resource))) + (export (;35;) "headers" (type (eq 34))) + (export (;36;) "trailers" (type (eq 34))) + (export (;37;) "incoming-request" (type (sub resource))) + (export (;38;) "outgoing-request" (type (sub resource))) + (export (;39;) "request-options" (type (sub resource))) + (export (;40;) "response-outparam" (type (sub resource))) + (type (;41;) u16) + (export (;42;) "status-code" (type (eq 41))) + (export (;43;) "incoming-response" (type (sub resource))) + (export (;44;) "incoming-body" (type (sub resource))) + (export (;45;) "future-trailers" (type (sub resource))) + (export (;46;) "outgoing-response" (type (sub resource))) + (export (;47;) "outgoing-body" (type (sub resource))) + (export (;48;) "future-incoming-response" (type (sub resource))) + ) + ) + (import "wasi:http/types@0.2" (versionsuffix ".0-rc-2023-12-05") (instance (;4;) (type 9))) + (alias export 4 "incoming-request" (type (;10;))) + (alias export 4 "response-outparam" (type (;11;))) + (type (;12;) + (instance + (alias outer 1 10 (type (;0;))) + (export (;1;) "incoming-request" (type (eq 0))) + (alias outer 1 11 (type (;2;))) + (export (;3;) "response-outparam" (type (eq 2))) + (type (;4;) (own 1)) + (type (;5;) (own 3)) + (type (;6;) (func (param "request" 4) (param "response-out" 5))) + (export (;0;) "handle" (func (type 6))) + ) + ) + (export (;5;) "wasi:http/incoming-handler@0.2" (versionsuffix ".0-rc-2023-12-05") (instance (type 12))) + ) + ) + (export (;3;) "incoming-handler" (type 2)) + (type (;4;) + (component + (type (;0;) + (instance + (export (;0;) "pollable" (type (sub resource))) + ) + ) + (import "wasi:io/poll@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;0;) (type 0))) + (alias export 0 "pollable" (type (;1;))) + (type (;2;) + (instance + (alias outer 1 1 (type (;0;))) + (export (;1;) "pollable" (type (eq 0))) + (type (;2;) u64) + (export (;3;) "instant" (type (eq 2))) + (type (;4;) u64) + (export (;5;) "duration" (type (eq 4))) + ) + ) + (import "wasi:clocks/monotonic-clock@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;1;) (type 2))) + (type (;3;) + (instance + (export (;0;) "error" (type (sub resource))) + ) + ) + (import "wasi:io/error@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;2;) (type 3))) + (alias export 2 "error" (type (;4;))) + (type (;5;) + (instance + (alias outer 1 4 (type (;0;))) + (export (;1;) "error" (type (eq 0))) + (alias outer 1 1 (type (;2;))) + (export (;3;) "pollable" (type (eq 2))) + (type (;4;) (own 1)) + (type (;5;) (variant (case "last-operation-failed" 4) (case "closed"))) + (export (;6;) "stream-error" (type (eq 5))) + (export (;7;) "input-stream" (type (sub resource))) + (export (;8;) "output-stream" (type (sub resource))) + ) + ) + (import "wasi:io/streams@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;3;) (type 5))) + (alias export 1 "duration" (type (;6;))) + (alias export 3 "input-stream" (type (;7;))) + (alias export 3 "output-stream" (type (;8;))) + (type (;9;) + (instance + (alias outer 1 6 (type (;0;))) + (export (;1;) "duration" (type (eq 0))) + (alias outer 1 7 (type (;2;))) + (export (;3;) "input-stream" (type (eq 2))) + (alias outer 1 8 (type (;4;))) + (export (;5;) "output-stream" (type (eq 4))) + (alias outer 1 4 (type (;6;))) + (export (;7;) "io-error" (type (eq 6))) + (alias outer 1 1 (type (;8;))) + (export (;9;) "pollable" (type (eq 8))) + (type (;10;) (variant (case "get") (case "head") (case "post") (case "put") (case "delete") (case "connect") (case "options") (case "trace") (case "patch") (case "other" string))) + (export (;11;) "method" (type (eq 10))) + (type (;12;) (variant (case "HTTP") (case "HTTPS") (case "other" string))) + (export (;13;) "scheme" (type (eq 12))) + (type (;14;) (option string)) + (type (;15;) (option u16)) + (type (;16;) (record (field "rcode" 14) (field "info-code" 15))) + (export (;17;) "DNS-error-payload" (type (eq 16))) + (type (;18;) (option u8)) + (type (;19;) (record (field "alert-id" 18) (field "alert-message" 14))) + (export (;20;) "TLS-alert-received-payload" (type (eq 19))) + (type (;21;) (option u32)) + (type (;22;) (record (field "field-name" 14) (field "field-size" 21))) + (export (;23;) "field-size-payload" (type (eq 22))) + (type (;24;) (option u64)) + (type (;25;) (option 23)) + (type (;26;) (variant (case "DNS-timeout") (case "DNS-error" 17) (case "destination-not-found") (case "destination-unavailable") (case "destination-IP-prohibited") (case "destination-IP-unroutable") (case "connection-refused") (case "connection-terminated") (case "connection-timeout") (case "connection-read-timeout") (case "connection-write-timeout") (case "connection-limit-reached") (case "TLS-protocol-error") (case "TLS-certificate-error") (case "TLS-alert-received" 20) (case "HTTP-request-denied") (case "HTTP-request-length-required") (case "HTTP-request-body-size" 24) (case "HTTP-request-method-invalid") (case "HTTP-request-URI-invalid") (case "HTTP-request-URI-too-long") (case "HTTP-request-header-section-size" 21) (case "HTTP-request-header-size" 25) (case "HTTP-request-trailer-section-size" 21) (case "HTTP-request-trailer-size" 23) (case "HTTP-response-incomplete") (case "HTTP-response-header-section-size" 21) (case "HTTP-response-header-size" 23) (case "HTTP-response-body-size" 24) (case "HTTP-response-trailer-section-size" 21) (case "HTTP-response-trailer-size" 23) (case "HTTP-response-transfer-coding" 14) (case "HTTP-response-content-coding" 14) (case "HTTP-response-timeout") (case "HTTP-upgrade-failed") (case "HTTP-protocol-error") (case "loop-detected") (case "configuration-error") (case "internal-error" 14))) + (export (;27;) "error-code" (type (eq 26))) + (type (;28;) (variant (case "invalid-syntax") (case "forbidden") (case "immutable"))) + (export (;29;) "header-error" (type (eq 28))) + (type (;30;) string) + (export (;31;) "field-key" (type (eq 30))) + (type (;32;) (list u8)) + (export (;33;) "field-value" (type (eq 32))) + (export (;34;) "fields" (type (sub resource))) + (export (;35;) "headers" (type (eq 34))) + (export (;36;) "trailers" (type (eq 34))) + (export (;37;) "incoming-request" (type (sub resource))) + (export (;38;) "outgoing-request" (type (sub resource))) + (export (;39;) "request-options" (type (sub resource))) + (export (;40;) "response-outparam" (type (sub resource))) + (type (;41;) u16) + (export (;42;) "status-code" (type (eq 41))) + (export (;43;) "incoming-response" (type (sub resource))) + (export (;44;) "incoming-body" (type (sub resource))) + (export (;45;) "future-trailers" (type (sub resource))) + (export (;46;) "outgoing-response" (type (sub resource))) + (export (;47;) "outgoing-body" (type (sub resource))) + (export (;48;) "future-incoming-response" (type (sub resource))) + ) + ) + (import "wasi:http/types@0.2" (versionsuffix ".0-rc-2023-12-05") (instance (;4;) (type 9))) + (alias export 4 "outgoing-request" (type (;10;))) + (alias export 4 "request-options" (type (;11;))) + (alias export 4 "future-incoming-response" (type (;12;))) + (alias export 4 "error-code" (type (;13;))) + (type (;14;) + (instance + (alias outer 1 10 (type (;0;))) + (export (;1;) "outgoing-request" (type (eq 0))) + (alias outer 1 11 (type (;2;))) + (export (;3;) "request-options" (type (eq 2))) + (alias outer 1 12 (type (;4;))) + (export (;5;) "future-incoming-response" (type (eq 4))) + (alias outer 1 13 (type (;6;))) + (export (;7;) "error-code" (type (eq 6))) + (type (;8;) (own 1)) + (type (;9;) (own 3)) + (type (;10;) (option 9)) + (type (;11;) (own 5)) + (type (;12;) (result 11 (error 7))) + (type (;13;) (func (param "request" 8) (param "options" 10) (result 12))) + (export (;0;) "handle" (func (type 13))) + ) + ) + (export (;5;) "wasi:http/outgoing-handler@0.2" (versionsuffix ".0-rc-2023-12-05") (instance (type 14))) + ) + ) + (export (;5;) "outgoing-handler" (type 4)) + (type (;6;) + (component + (type (;0;) + (component + (type (;0;) + (instance + (type (;0;) (list u8)) + (type (;1;) (func (param "len" u64) (result 0))) + (export (;0;) "get-random-bytes" (func (type 1))) + (type (;2;) (func (result u64))) + (export (;1;) "get-random-u64" (func (type 2))) + ) + ) + (import "wasi:random/random@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;0;) (type 0))) + (type (;1;) + (instance + (export (;0;) "error" (type (sub resource))) + (type (;1;) (borrow 0)) + (type (;2;) (func (param "self" 1) (result string))) + (export (;0;) "[method]error.to-debug-string" (func (type 2))) + ) + ) + (import "wasi:io/error@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;1;) (type 1))) + (type (;2;) + (instance + (export (;0;) "pollable" (type (sub resource))) + (type (;1;) (borrow 0)) + (type (;2;) (func (param "self" 1) (result bool))) + (export (;0;) "[method]pollable.ready" (func (type 2))) + (type (;3;) (func (param "self" 1))) + (export (;1;) "[method]pollable.block" (func (type 3))) + (type (;4;) (list 1)) + (type (;5;) (list u32)) + (type (;6;) (func (param "in" 4) (result 5))) + (export (;2;) "poll" (func (type 6))) + ) + ) + (import "wasi:io/poll@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;2;) (type 2))) + (alias export 1 "error" (type (;3;))) + (alias export 2 "pollable" (type (;4;))) + (type (;5;) + (instance + (alias outer 1 3 (type (;0;))) + (export (;1;) "error" (type (eq 0))) + (alias outer 1 4 (type (;2;))) + (export (;3;) "pollable" (type (eq 2))) + (type (;4;) (own 1)) + (type (;5;) (variant (case "last-operation-failed" 4) (case "closed"))) + (export (;6;) "stream-error" (type (eq 5))) + (export (;7;) "input-stream" (type (sub resource))) + (export (;8;) "output-stream" (type (sub resource))) + (type (;9;) (borrow 7)) + (type (;10;) (list u8)) + (type (;11;) (result 10 (error 6))) + (type (;12;) (func (param "self" 9) (param "len" u64) (result 11))) + (export (;0;) "[method]input-stream.read" (func (type 12))) + (export (;1;) "[method]input-stream.blocking-read" (func (type 12))) + (type (;13;) (result u64 (error 6))) + (type (;14;) (func (param "self" 9) (param "len" u64) (result 13))) + (export (;2;) "[method]input-stream.skip" (func (type 14))) + (export (;3;) "[method]input-stream.blocking-skip" (func (type 14))) + (type (;15;) (own 3)) + (type (;16;) (func (param "self" 9) (result 15))) + (export (;4;) "[method]input-stream.subscribe" (func (type 16))) + (type (;17;) (borrow 8)) + (type (;18;) (func (param "self" 17) (result 13))) + (export (;5;) "[method]output-stream.check-write" (func (type 18))) + (type (;19;) (result (error 6))) + (type (;20;) (func (param "self" 17) (param "contents" 10) (result 19))) + (export (;6;) "[method]output-stream.write" (func (type 20))) + (export (;7;) "[method]output-stream.blocking-write-and-flush" (func (type 20))) + (type (;21;) (func (param "self" 17) (result 19))) + (export (;8;) "[method]output-stream.flush" (func (type 21))) + (export (;9;) "[method]output-stream.blocking-flush" (func (type 21))) + (type (;22;) (func (param "self" 17) (result 15))) + (export (;10;) "[method]output-stream.subscribe" (func (type 22))) + (type (;23;) (func (param "self" 17) (param "len" u64) (result 19))) + (export (;11;) "[method]output-stream.write-zeroes" (func (type 23))) + (export (;12;) "[method]output-stream.blocking-write-zeroes-and-flush" (func (type 23))) + (type (;24;) (func (param "self" 17) (param "src" 9) (param "len" u64) (result 13))) + (export (;13;) "[method]output-stream.splice" (func (type 24))) + (export (;14;) "[method]output-stream.blocking-splice" (func (type 24))) + ) + ) + (import "wasi:io/streams@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;3;) (type 5))) + (alias export 3 "output-stream" (type (;6;))) + (type (;7;) + (instance + (alias outer 1 6 (type (;0;))) + (export (;1;) "output-stream" (type (eq 0))) + (type (;2;) (own 1)) + (type (;3;) (func (result 2))) + (export (;0;) "get-stdout" (func (type 3))) + ) + ) + (import "wasi:cli/stdout@0.2" (versionsuffix ".0-rc-2023-12-05") (instance (;4;) (type 7))) + (type (;8;) + (instance + (alias outer 1 6 (type (;0;))) + (export (;1;) "output-stream" (type (eq 0))) + (type (;2;) (own 1)) + (type (;3;) (func (result 2))) + (export (;0;) "get-stderr" (func (type 3))) + ) + ) + (import "wasi:cli/stderr@0.2" (versionsuffix ".0-rc-2023-12-05") (instance (;5;) (type 8))) + (alias export 3 "input-stream" (type (;9;))) + (type (;10;) + (instance + (alias outer 1 9 (type (;0;))) + (export (;1;) "input-stream" (type (eq 0))) + (type (;2;) (own 1)) + (type (;3;) (func (result 2))) + (export (;0;) "get-stdin" (func (type 3))) + ) + ) + (import "wasi:cli/stdin@0.2" (versionsuffix ".0-rc-2023-12-05") (instance (;6;) (type 10))) + (type (;11;) + (instance + (alias outer 1 4 (type (;0;))) + (export (;1;) "pollable" (type (eq 0))) + (type (;2;) u64) + (export (;3;) "instant" (type (eq 2))) + (type (;4;) u64) + (export (;5;) "duration" (type (eq 4))) + (type (;6;) (func (result 3))) + (export (;0;) "now" (func (type 6))) + (type (;7;) (func (result 5))) + (export (;1;) "resolution" (func (type 7))) + (type (;8;) (own 1)) + (type (;9;) (func (param "when" 3) (result 8))) + (export (;2;) "subscribe-instant" (func (type 9))) + (type (;10;) (func (param "when" 5) (result 8))) + (export (;3;) "subscribe-duration" (func (type 10))) + ) + ) + (import "wasi:clocks/monotonic-clock@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;7;) (type 11))) + (alias export 7 "duration" (type (;12;))) + (type (;13;) + (instance + (alias outer 1 12 (type (;0;))) + (export (;1;) "duration" (type (eq 0))) + (alias outer 1 9 (type (;2;))) + (export (;3;) "input-stream" (type (eq 2))) + (alias outer 1 6 (type (;4;))) + (export (;5;) "output-stream" (type (eq 4))) + (alias outer 1 3 (type (;6;))) + (export (;7;) "io-error" (type (eq 6))) + (alias outer 1 4 (type (;8;))) + (export (;9;) "pollable" (type (eq 8))) + (type (;10;) (variant (case "get") (case "head") (case "post") (case "put") (case "delete") (case "connect") (case "options") (case "trace") (case "patch") (case "other" string))) + (export (;11;) "method" (type (eq 10))) + (type (;12;) (variant (case "HTTP") (case "HTTPS") (case "other" string))) + (export (;13;) "scheme" (type (eq 12))) + (type (;14;) (option string)) + (type (;15;) (option u16)) + (type (;16;) (record (field "rcode" 14) (field "info-code" 15))) + (export (;17;) "DNS-error-payload" (type (eq 16))) + (type (;18;) (option u8)) + (type (;19;) (record (field "alert-id" 18) (field "alert-message" 14))) + (export (;20;) "TLS-alert-received-payload" (type (eq 19))) + (type (;21;) (option u32)) + (type (;22;) (record (field "field-name" 14) (field "field-size" 21))) + (export (;23;) "field-size-payload" (type (eq 22))) + (type (;24;) (option u64)) + (type (;25;) (option 23)) + (type (;26;) (variant (case "DNS-timeout") (case "DNS-error" 17) (case "destination-not-found") (case "destination-unavailable") (case "destination-IP-prohibited") (case "destination-IP-unroutable") (case "connection-refused") (case "connection-terminated") (case "connection-timeout") (case "connection-read-timeout") (case "connection-write-timeout") (case "connection-limit-reached") (case "TLS-protocol-error") (case "TLS-certificate-error") (case "TLS-alert-received" 20) (case "HTTP-request-denied") (case "HTTP-request-length-required") (case "HTTP-request-body-size" 24) (case "HTTP-request-method-invalid") (case "HTTP-request-URI-invalid") (case "HTTP-request-URI-too-long") (case "HTTP-request-header-section-size" 21) (case "HTTP-request-header-size" 25) (case "HTTP-request-trailer-section-size" 21) (case "HTTP-request-trailer-size" 23) (case "HTTP-response-incomplete") (case "HTTP-response-header-section-size" 21) (case "HTTP-response-header-size" 23) (case "HTTP-response-body-size" 24) (case "HTTP-response-trailer-section-size" 21) (case "HTTP-response-trailer-size" 23) (case "HTTP-response-transfer-coding" 14) (case "HTTP-response-content-coding" 14) (case "HTTP-response-timeout") (case "HTTP-upgrade-failed") (case "HTTP-protocol-error") (case "loop-detected") (case "configuration-error") (case "internal-error" 14))) + (export (;27;) "error-code" (type (eq 26))) + (type (;28;) (variant (case "invalid-syntax") (case "forbidden") (case "immutable"))) + (export (;29;) "header-error" (type (eq 28))) + (type (;30;) string) + (export (;31;) "field-key" (type (eq 30))) + (type (;32;) (list u8)) + (export (;33;) "field-value" (type (eq 32))) + (export (;34;) "fields" (type (sub resource))) + (export (;35;) "headers" (type (eq 34))) + (export (;36;) "trailers" (type (eq 34))) + (export (;37;) "incoming-request" (type (sub resource))) + (export (;38;) "outgoing-request" (type (sub resource))) + (export (;39;) "request-options" (type (sub resource))) + (export (;40;) "response-outparam" (type (sub resource))) + (type (;41;) u16) + (export (;42;) "status-code" (type (eq 41))) + (export (;43;) "incoming-response" (type (sub resource))) + (export (;44;) "incoming-body" (type (sub resource))) + (export (;45;) "future-trailers" (type (sub resource))) + (export (;46;) "outgoing-response" (type (sub resource))) + (export (;47;) "outgoing-body" (type (sub resource))) + (export (;48;) "future-incoming-response" (type (sub resource))) + (type (;49;) (own 34)) + (type (;50;) (func (result 49))) + (export (;0;) "[constructor]fields" (func (type 50))) + (type (;51;) (tuple 31 33)) + (type (;52;) (list 51)) + (type (;53;) (result 49 (error 29))) + (type (;54;) (func (param "entries" 52) (result 53))) + (export (;1;) "[static]fields.from-list" (func (type 54))) + (type (;55;) (borrow 34)) + (type (;56;) (list 33)) + (type (;57;) (func (param "self" 55) (param "name" 31) (result 56))) + (export (;2;) "[method]fields.get" (func (type 57))) + (type (;58;) (func (param "self" 55) (param "name" 31) (result bool))) + (export (;3;) "[method]fields.has" (func (type 58))) + (type (;59;) (result (error 29))) + (type (;60;) (func (param "self" 55) (param "name" 31) (param "value" 56) (result 59))) + (export (;4;) "[method]fields.set" (func (type 60))) + (type (;61;) (func (param "self" 55) (param "name" 31) (result 59))) + (export (;5;) "[method]fields.delete" (func (type 61))) + (type (;62;) (func (param "self" 55) (param "name" 31) (param "value" 33) (result 59))) + (export (;6;) "[method]fields.append" (func (type 62))) + (type (;63;) (func (param "self" 55) (result 52))) + (export (;7;) "[method]fields.entries" (func (type 63))) + (type (;64;) (func (param "self" 55) (result 49))) + (export (;8;) "[method]fields.clone" (func (type 64))) + (type (;65;) (borrow 37)) + (type (;66;) (func (param "self" 65) (result 11))) + (export (;9;) "[method]incoming-request.method" (func (type 66))) + (type (;67;) (func (param "self" 65) (result 14))) + (export (;10;) "[method]incoming-request.path-with-query" (func (type 67))) + (type (;68;) (option 13)) + (type (;69;) (func (param "self" 65) (result 68))) + (export (;11;) "[method]incoming-request.scheme" (func (type 69))) + (export (;12;) "[method]incoming-request.authority" (func (type 67))) + (type (;70;) (own 35)) + (type (;71;) (func (param "self" 65) (result 70))) + (export (;13;) "[method]incoming-request.headers" (func (type 71))) + (type (;72;) (own 44)) + (type (;73;) (result 72)) + (type (;74;) (func (param "self" 65) (result 73))) + (export (;14;) "[method]incoming-request.consume" (func (type 74))) + (type (;75;) (own 38)) + (type (;76;) (func (param "headers" 70) (result 75))) + (export (;15;) "[constructor]outgoing-request" (func (type 76))) + (type (;77;) (borrow 38)) + (type (;78;) (own 47)) + (type (;79;) (result 78)) + (type (;80;) (func (param "self" 77) (result 79))) + (export (;16;) "[method]outgoing-request.body" (func (type 80))) + (type (;81;) (func (param "self" 77) (result 11))) + (export (;17;) "[method]outgoing-request.method" (func (type 81))) + (type (;82;) (result)) + (type (;83;) (func (param "self" 77) (param "method" 11) (result 82))) + (export (;18;) "[method]outgoing-request.set-method" (func (type 83))) + (type (;84;) (func (param "self" 77) (result 14))) + (export (;19;) "[method]outgoing-request.path-with-query" (func (type 84))) + (type (;85;) (func (param "self" 77) (param "path-with-query" 14) (result 82))) + (export (;20;) "[method]outgoing-request.set-path-with-query" (func (type 85))) + (type (;86;) (func (param "self" 77) (result 68))) + (export (;21;) "[method]outgoing-request.scheme" (func (type 86))) + (type (;87;) (func (param "self" 77) (param "scheme" 68) (result 82))) + (export (;22;) "[method]outgoing-request.set-scheme" (func (type 87))) + (export (;23;) "[method]outgoing-request.authority" (func (type 84))) + (type (;88;) (func (param "self" 77) (param "authority" 14) (result 82))) + (export (;24;) "[method]outgoing-request.set-authority" (func (type 88))) + (type (;89;) (func (param "self" 77) (result 70))) + (export (;25;) "[method]outgoing-request.headers" (func (type 89))) + (type (;90;) (own 39)) + (type (;91;) (func (result 90))) + (export (;26;) "[constructor]request-options" (func (type 91))) + (type (;92;) (borrow 39)) + (type (;93;) (option 1)) + (type (;94;) (func (param "self" 92) (result 93))) + (export (;27;) "[method]request-options.connect-timeout" (func (type 94))) + (type (;95;) (func (param "self" 92) (param "duration" 93) (result 82))) + (export (;28;) "[method]request-options.set-connect-timeout" (func (type 95))) + (export (;29;) "[method]request-options.first-byte-timeout" (func (type 94))) + (export (;30;) "[method]request-options.set-first-byte-timeout" (func (type 95))) + (export (;31;) "[method]request-options.between-bytes-timeout" (func (type 94))) + (export (;32;) "[method]request-options.set-between-bytes-timeout" (func (type 95))) + (type (;96;) (own 40)) + (type (;97;) (own 46)) + (type (;98;) (result 97 (error 27))) + (type (;99;) (func (param "param" 96) (param "response" 98))) + (export (;33;) "[static]response-outparam.set" (func (type 99))) + (type (;100;) (borrow 43)) + (type (;101;) (func (param "self" 100) (result 42))) + (export (;34;) "[method]incoming-response.status" (func (type 101))) + (type (;102;) (func (param "self" 100) (result 70))) + (export (;35;) "[method]incoming-response.headers" (func (type 102))) + (type (;103;) (func (param "self" 100) (result 73))) + (export (;36;) "[method]incoming-response.consume" (func (type 103))) + (type (;104;) (borrow 44)) + (type (;105;) (own 3)) + (type (;106;) (result 105)) + (type (;107;) (func (param "self" 104) (result 106))) + (export (;37;) "[method]incoming-body.stream" (func (type 107))) + (type (;108;) (own 45)) + (type (;109;) (func (param "this" 72) (result 108))) + (export (;38;) "[static]incoming-body.finish" (func (type 109))) + (type (;110;) (borrow 45)) + (type (;111;) (own 9)) + (type (;112;) (func (param "self" 110) (result 111))) + (export (;39;) "[method]future-trailers.subscribe" (func (type 112))) + (type (;113;) (own 36)) + (type (;114;) (option 113)) + (type (;115;) (result 114 (error 27))) + (type (;116;) (result 115)) + (type (;117;) (option 116)) + (type (;118;) (func (param "self" 110) (result 117))) + (export (;40;) "[method]future-trailers.get" (func (type 118))) + (type (;119;) (func (param "headers" 70) (result 97))) + (export (;41;) "[constructor]outgoing-response" (func (type 119))) + (type (;120;) (borrow 46)) + (type (;121;) (func (param "self" 120) (result 42))) + (export (;42;) "[method]outgoing-response.status-code" (func (type 121))) + (type (;122;) (func (param "self" 120) (param "status-code" 42) (result 82))) + (export (;43;) "[method]outgoing-response.set-status-code" (func (type 122))) + (type (;123;) (func (param "self" 120) (result 70))) + (export (;44;) "[method]outgoing-response.headers" (func (type 123))) + (type (;124;) (func (param "self" 120) (result 79))) + (export (;45;) "[method]outgoing-response.body" (func (type 124))) + (type (;125;) (borrow 47)) + (type (;126;) (own 5)) + (type (;127;) (result 126)) + (type (;128;) (func (param "self" 125) (result 127))) + (export (;46;) "[method]outgoing-body.write" (func (type 128))) + (type (;129;) (result (error 27))) + (type (;130;) (func (param "this" 78) (param "trailers" 114) (result 129))) + (export (;47;) "[static]outgoing-body.finish" (func (type 130))) + (type (;131;) (borrow 48)) + (type (;132;) (func (param "self" 131) (result 111))) + (export (;48;) "[method]future-incoming-response.subscribe" (func (type 132))) + (type (;133;) (own 43)) + (type (;134;) (result 133 (error 27))) + (type (;135;) (result 134)) + (type (;136;) (option 135)) + (type (;137;) (func (param "self" 131) (result 136))) + (export (;49;) "[method]future-incoming-response.get" (func (type 137))) + (type (;138;) (borrow 7)) + (type (;139;) (option 27)) + (type (;140;) (func (param "err" 138) (result 139))) + (export (;50;) "http-error-code" (func (type 140))) + ) + ) + (import "wasi:http/types@0.2" (versionsuffix ".0-rc-2023-12-05") (instance (;8;) (type 13))) + (alias export 8 "outgoing-request" (type (;14;))) + (alias export 8 "request-options" (type (;15;))) + (alias export 8 "future-incoming-response" (type (;16;))) + (alias export 8 "error-code" (type (;17;))) + (type (;18;) + (instance + (alias outer 1 14 (type (;0;))) + (export (;1;) "outgoing-request" (type (eq 0))) + (alias outer 1 15 (type (;2;))) + (export (;3;) "request-options" (type (eq 2))) + (alias outer 1 16 (type (;4;))) + (export (;5;) "future-incoming-response" (type (eq 4))) + (alias outer 1 17 (type (;6;))) + (export (;7;) "error-code" (type (eq 6))) + (type (;8;) (own 1)) + (type (;9;) (own 3)) + (type (;10;) (option 9)) + (type (;11;) (own 5)) + (type (;12;) (result 11 (error 7))) + (type (;13;) (func (param "request" 8) (param "options" 10) (result 12))) + (export (;0;) "handle" (func (type 13))) + ) + ) + (import "wasi:http/outgoing-handler@0.2" (versionsuffix ".0-rc-2023-12-05") (instance (;9;) (type 18))) + (type (;19;) + (instance + (type (;0;) (record (field "seconds" u64) (field "nanoseconds" u32))) + (export (;1;) "datetime" (type (eq 0))) + (type (;2;) (func (result 1))) + (export (;0;) "now" (func (type 2))) + (export (;1;) "resolution" (func (type 2))) + ) + ) + (import "wasi:clocks/wall-clock@0.2" (versionsuffix ".0-rc-2023-11-10") (instance (;10;) (type 19))) + (alias export 8 "incoming-request" (type (;20;))) + (alias export 8 "response-outparam" (type (;21;))) + (type (;22;) + (instance + (alias outer 1 20 (type (;0;))) + (export (;1;) "incoming-request" (type (eq 0))) + (alias outer 1 21 (type (;2;))) + (export (;3;) "response-outparam" (type (eq 2))) + (type (;4;) (own 1)) + (type (;5;) (own 3)) + (type (;6;) (func (param "request" 4) (param "response-out" 5))) + (export (;0;) "handle" (func (type 6))) + ) + ) + (export (;11;) "wasi:http/incoming-handler@0.2" (versionsuffix ".0-rc-2023-12-05") (instance (type 22))) + ) + ) + (export (;0;) "wasi:http/proxy@0.2.0-rc-2023-12-05" (component (type 0))) + ) + ) + (export (;7;) "proxy" (type 6)) + (@custom "package-docs" "\01{\22worlds\22:{\22proxy\22:{\22docs\22:\22The `wasi:http/proxy` world captures a widely-implementable intersection of\5cnhosts that includes HTTP forward and reverse proxies. Components targeting\5cnthis world may concurrently stream in and out any number of incoming and\5cnoutgoing HTTP requests.\22,\22interface_import_docs\22:{\22wasi:cli/stdout@0.2.0-rc-2023-12-05\22:\22Proxies have standard output and error streams which are expected to\5cnterminate in a developer-facing console provided by the host.\22,\22wasi:cli/stdin@0.2.0-rc-2023-12-05\22:\22TODO: this is a temporary workaround until component tooling is able to\5cngracefully handle the absence of stdin. Hosts must return an eof stream\5cnfor this import, which is what wasi-libc + tooling will do automatically\5cnwhen this import is properly removed.\22,\22wasi:http/outgoing-handler@0.2.0-rc-2023-12-05\22:\22This is the default handler to use when user code simply wants to make an\5cnHTTP request (e.g., via `fetch()`).\22},\22interface_export_docs\22:{\22wasi:http/incoming-handler@0.2.0-rc-2023-12-05\22:\22The host delivers incoming HTTP requests to a component by calling the\5cn`handle` function of this exported interface. A host may arbitrarily reuse\5cnor not reuse component instance when delivering incoming HTTP requests and\5cnthus a component must be able to handle 0..N calls to `handle`.\22}}},\22interfaces\22:{\22types\22:{\22docs\22:\22This interface defines all of the types and methods for implementing\5cnHTTP Requests and Responses, both incoming and outgoing, as well as\5cntheir headers, trailers, and bodies.\22,\22funcs\22:{\22http-error-code\22:{\22docs\22:\22Attempts to extract a http-related `error` from the wasi:io `error`\5cnprovided.\5cn\5cnStream operations which return\5cn`wasi:io/stream/stream-error::last-operation-failed` have a payload of\5cntype `wasi:io/error/error` with more information about the operation\5cnthat failed. This payload can be passed through to this function to see\5cnif there's http-related information about the error to return.\5cn\5cnNote that this function is fallible because not all io-errors are\5cnhttp-related errors.\22},\22[constructor]fields\22:{\22docs\22:\22Construct an empty HTTP Fields.\5cn\5cnThe resulting `fields` is mutable.\22},\22[static]fields.from-list\22:{\22docs\22:\22Construct an HTTP Fields.\5cn\5cnThe resulting `fields` is mutable.\5cn\5cnThe list represents each key-value pair in the Fields. Keys\5cnwhich have multiple values are represented by multiple entries in this\5cnlist with the same key.\5cn\5cnThe tuple is a pair of the field key, represented as a string, and\5cnValue, represented as a list of bytes. In a valid Fields, all keys\5cnand values are valid UTF-8 strings. However, values are not always\5cnwell-formed, so they are represented as a raw list of bytes.\5cn\5cnAn error result will be returned if any header or value was\5cnsyntactically invalid, or if a header was forbidden.\22},\22[method]fields.get\22:{\22docs\22:\22Get all of the values corresponding to a key. If the key is not present\5cnin this `fields`, an empty list is returned. However, if the key is\5cnpresent but empty, this is represented by a list with one or more\5cnempty field-values present.\22},\22[method]fields.has\22:{\22docs\22:\22Returns `true` when the key is present in this `fields`. If the key is\5cnsyntactically invalid, `false` is returned.\22},\22[method]fields.set\22:{\22docs\22:\22Set all of the values for a key. Clears any existing values for that\5cnkey, if they have been set.\5cn\5cnFails with `header-error.immutable` if the `fields` are immutable.\22},\22[method]fields.delete\22:{\22docs\22:\22Delete all values for a key. Does nothing if no values for the key\5cnexist.\5cn\5cnFails with `header-error.immutable` if the `fields` are immutable.\22},\22[method]fields.append\22:{\22docs\22:\22Append a value for a key. Does not change or delete any existing\5cnvalues for that key.\5cn\5cnFails with `header-error.immutable` if the `fields` are immutable.\22},\22[method]fields.entries\22:{\22docs\22:\22Retrieve the full set of keys and values in the Fields. Like the\5cnconstructor, the list represents each key-value pair.\5cn\5cnThe outer list represents each key-value pair in the Fields. Keys\5cnwhich have multiple values are represented by multiple entries in this\5cnlist with the same key.\22},\22[method]fields.clone\22:{\22docs\22:\22Make a deep copy of the Fields. Equivalent in behavior to calling the\5cn`fields` constructor on the return value of `entries`. The resulting\5cn`fields` is mutable.\22},\22[method]incoming-request.method\22:{\22docs\22:\22Returns the method of the incoming request.\22},\22[method]incoming-request.path-with-query\22:{\22docs\22:\22Returns the path with query parameters from the request, as a string.\22},\22[method]incoming-request.scheme\22:{\22docs\22:\22Returns the protocol scheme from the request.\22},\22[method]incoming-request.authority\22:{\22docs\22:\22Returns the authority from the request, if it was present.\22},\22[method]incoming-request.headers\22:{\22docs\22:\22Get the `headers` associated with the request.\5cn\5cnThe returned `headers` resource is immutable: `set`, `append`, and\5cn`delete` operations will fail with `header-error.immutable`.\5cn\5cnThe `headers` returned are a child resource: it must be dropped before\5cnthe parent `incoming-request` is dropped. Dropping this\5cn`incoming-request` before all children are dropped will trap.\22},\22[method]incoming-request.consume\22:{\22docs\22:\22Gives the `incoming-body` associated with this request. Will only\5cnreturn success at most once, and subsequent calls will return error.\22},\22[constructor]outgoing-request\22:{\22docs\22:\22Construct a new `outgoing-request` with a default `method` of `GET`, and\5cn`none` values for `path-with-query`, `scheme`, and `authority`.\5cn\5cn* `headers` is the HTTP Headers for the Request.\5cn\5cnIt is possible to construct, or manipulate with the accessor functions\5cnbelow, an `outgoing-request` with an invalid combination of `scheme`\5cnand `authority`, or `headers` which are not permitted to be sent.\5cnIt is the obligation of the `outgoing-handler.handle` implementation\5cnto reject invalid constructions of `outgoing-request`.\22},\22[method]outgoing-request.body\22:{\22docs\22:\22Returns the resource corresponding to the outgoing Body for this\5cnRequest.\5cn\5cnReturns success on the first call: the `outgoing-body` resource for\5cnthis `outgoing-request` can be retrieved at most once. Subsequent\5cncalls will return error.\22},\22[method]outgoing-request.method\22:{\22docs\22:\22Get the Method for the Request.\22},\22[method]outgoing-request.set-method\22:{\22docs\22:\22Set the Method for the Request. Fails if the string present in a\5cn`method.other` argument is not a syntactically valid method.\22},\22[method]outgoing-request.path-with-query\22:{\22docs\22:\22Get the combination of the HTTP Path and Query for the Request.\5cnWhen `none`, this represents an empty Path and empty Query.\22},\22[method]outgoing-request.set-path-with-query\22:{\22docs\22:\22Set the combination of the HTTP Path and Query for the Request.\5cnWhen `none`, this represents an empty Path and empty Query. Fails is the\5cnstring given is not a syntactically valid path and query uri component.\22},\22[method]outgoing-request.scheme\22:{\22docs\22:\22Get the HTTP Related Scheme for the Request. When `none`, the\5cnimplementation may choose an appropriate default scheme.\22},\22[method]outgoing-request.set-scheme\22:{\22docs\22:\22Set the HTTP Related Scheme for the Request. When `none`, the\5cnimplementation may choose an appropriate default scheme. Fails if the\5cnstring given is not a syntactically valid uri scheme.\22},\22[method]outgoing-request.authority\22:{\22docs\22:\22Get the HTTP Authority for the Request. A value of `none` may be used\5cnwith Related Schemes which do not require an Authority. The HTTP and\5cnHTTPS schemes always require an authority.\22},\22[method]outgoing-request.set-authority\22:{\22docs\22:\22Set the HTTP Authority for the Request. A value of `none` may be used\5cnwith Related Schemes which do not require an Authority. The HTTP and\5cnHTTPS schemes always require an authority. Fails if the string given is\5cnnot a syntactically valid uri authority.\22},\22[method]outgoing-request.headers\22:{\22docs\22:\22Get the headers associated with the Request.\5cn\5cnThe returned `headers` resource is immutable: `set`, `append`, and\5cn`delete` operations will fail with `header-error.immutable`.\5cn\5cnThis headers resource is a child: it must be dropped before the parent\5cn`outgoing-request` is dropped, or its ownership is transferred to\5cnanother component by e.g. `outgoing-handler.handle`.\22},\22[constructor]request-options\22:{\22docs\22:\22Construct a default `request-options` value.\22},\22[method]request-options.connect-timeout\22:{\22docs\22:\22The timeout for the initial connect to the HTTP Server.\22},\22[method]request-options.set-connect-timeout\22:{\22docs\22:\22Set the timeout for the initial connect to the HTTP Server. An error\5cnreturn value indicates that this timeout is not supported.\22},\22[method]request-options.first-byte-timeout\22:{\22docs\22:\22The timeout for receiving the first byte of the Response body.\22},\22[method]request-options.set-first-byte-timeout\22:{\22docs\22:\22Set the timeout for receiving the first byte of the Response body. An\5cnerror return value indicates that this timeout is not supported.\22},\22[method]request-options.between-bytes-timeout\22:{\22docs\22:\22The timeout for receiving subsequent chunks of bytes in the Response\5cnbody stream.\22},\22[method]request-options.set-between-bytes-timeout\22:{\22docs\22:\22Set the timeout for receiving subsequent chunks of bytes in the Response\5cnbody stream. An error return value indicates that this timeout is not\5cnsupported.\22},\22[static]response-outparam.set\22:{\22docs\22:\22Set the value of the `response-outparam` to either send a response,\5cnor indicate an error.\5cn\5cnThis method consumes the `response-outparam` to ensure that it is\5cncalled at most once. If it is never called, the implementation\5cnwill respond with an error.\5cn\5cnThe user may provide an `error` to `response` to allow the\5cnimplementation determine how to respond with an HTTP error response.\22},\22[method]incoming-response.status\22:{\22docs\22:\22Returns the status code from the incoming response.\22},\22[method]incoming-response.headers\22:{\22docs\22:\22Returns the headers from the incoming response.\5cn\5cnThe returned `headers` resource is immutable: `set`, `append`, and\5cn`delete` operations will fail with `header-error.immutable`.\5cn\5cnThis headers resource is a child: it must be dropped before the parent\5cn`incoming-response` is dropped.\22},\22[method]incoming-response.consume\22:{\22docs\22:\22Returns the incoming body. May be called at most once. Returns error\5cnif called additional times.\22},\22[method]incoming-body.stream\22:{\22docs\22:\22Returns the contents of the body, as a stream of bytes.\5cn\5cnReturns success on first call: the stream representing the contents\5cncan be retrieved at most once. Subsequent calls will return error.\5cn\5cnThe returned `input-stream` resource is a child: it must be dropped\5cnbefore the parent `incoming-body` is dropped, or consumed by\5cn`incoming-body.finish`.\5cn\5cnThis invariant ensures that the implementation can determine whether\5cnthe user is consuming the contents of the body, waiting on the\5cn`future-trailers` to be ready, or neither. This allows for network\5cnbackpressure is to be applied when the user is consuming the body,\5cnand for that backpressure to not inhibit delivery of the trailers if\5cnthe user does not read the entire body.\22},\22[static]incoming-body.finish\22:{\22docs\22:\22Takes ownership of `incoming-body`, and returns a `future-trailers`.\5cnThis function will trap if the `input-stream` child is still alive.\22},\22[method]future-trailers.subscribe\22:{\22docs\22:\22Returns a pollable which becomes ready when either the trailers have\5cnbeen received, or an error has occurred. When this pollable is ready,\5cnthe `get` method will return `some`.\22},\22[method]future-trailers.get\22:{\22docs\22:\22Returns the contents of the trailers, or an error which occurred,\5cnonce the future is ready.\5cn\5cnThe outer `option` represents future readiness. Users can wait on this\5cn`option` to become `some` using the `subscribe` method.\5cn\5cnThe outer `result` is used to retrieve the trailers or error at most\5cnonce. It will be success on the first call in which the outer option\5cnis `some`, and error on subsequent calls.\5cn\5cnThe inner `result` represents that either the HTTP Request or Response\5cnbody, as well as any trailers, were received successfully, or that an\5cnerror occurred receiving them. The optional `trailers` indicates whether\5cnor not trailers were present in the body.\5cn\5cnWhen some `trailers` are returned by this method, the `trailers`\5cnresource is immutable, and a child. Use of the `set`, `append`, or\5cn`delete` methods will return an error, and the resource must be\5cndropped before the parent `future-trailers` is dropped.\22},\22[constructor]outgoing-response\22:{\22docs\22:\22Construct an `outgoing-response`, with a default `status-code` of `200`.\5cnIf a different `status-code` is needed, it must be set via the\5cn`set-status-code` method.\5cn\5cn* `headers` is the HTTP Headers for the Response.\22},\22[method]outgoing-response.status-code\22:{\22docs\22:\22Get the HTTP Status Code for the Response.\22},\22[method]outgoing-response.set-status-code\22:{\22docs\22:\22Set the HTTP Status Code for the Response. Fails if the status-code\5cngiven is not a valid http status code.\22},\22[method]outgoing-response.headers\22:{\22docs\22:\22Get the headers associated with the Request.\5cn\5cnThe returned `headers` resource is immutable: `set`, `append`, and\5cn`delete` operations will fail with `header-error.immutable`.\5cn\5cnThis headers resource is a child: it must be dropped before the parent\5cn`outgoing-request` is dropped, or its ownership is transferred to\5cnanother component by e.g. `outgoing-handler.handle`.\22},\22[method]outgoing-response.body\22:{\22docs\22:\22Returns the resource corresponding to the outgoing Body for this Response.\5cn\5cnReturns success on the first call: the `outgoing-body` resource for\5cnthis `outgoing-response` can be retrieved at most once. Subsequent\5cncalls will return error.\22},\22[method]outgoing-body.write\22:{\22docs\22:\22Returns a stream for writing the body contents.\5cn\5cnThe returned `output-stream` is a child resource: it must be dropped\5cnbefore the parent `outgoing-body` resource is dropped (or finished),\5cnotherwise the `outgoing-body` drop or `finish` will trap.\5cn\5cnReturns success on the first call: the `output-stream` resource for\5cnthis `outgoing-body` may be retrieved at most once. Subsequent calls\5cnwill return error.\22},\22[static]outgoing-body.finish\22:{\22docs\22:\22Finalize an outgoing body, optionally providing trailers. This must be\5cncalled to signal that the response is complete. If the `outgoing-body`\5cnis dropped without calling `outgoing-body.finalize`, the implementation\5cnshould treat the body as corrupted.\5cn\5cnFails if the body's `outgoing-request` or `outgoing-response` was\5cnconstructed with a Content-Length header, and the contents written\5cnto the body (via `write`) does not match the value given in the\5cnContent-Length.\22},\22[method]future-incoming-response.subscribe\22:{\22docs\22:\22Returns a pollable which becomes ready when either the Response has\5cnbeen received, or an error has occurred. When this pollable is ready,\5cnthe `get` method will return `some`.\22},\22[method]future-incoming-response.get\22:{\22docs\22:\22Returns the incoming HTTP Response, or an error, once one is ready.\5cn\5cnThe outer `option` represents future readiness. Users can wait on this\5cn`option` to become `some` using the `subscribe` method.\5cn\5cnThe outer `result` is used to retrieve the response or error at most\5cnonce. It will be success on the first call in which the outer option\5cnis `some`, and error on subsequent calls.\5cn\5cnThe inner `result` represents that either the incoming HTTP Response\5cnstatus and headers have received successfully, or that an error\5cnoccurred. Errors may also occur while consuming the response body,\5cnbut those will be reported by the `incoming-body` and its\5cn`output-stream` child.\22}},\22types\22:{\22method\22:{\22docs\22:\22This type corresponds to HTTP standard Methods.\22},\22scheme\22:{\22docs\22:\22This type corresponds to HTTP standard Related Schemes.\22},\22DNS-error-payload\22:{\22docs\22:\22Defines the case payload type for `DNS-error` above:\22},\22TLS-alert-received-payload\22:{\22docs\22:\22Defines the case payload type for `TLS-alert-received` above:\22},\22field-size-payload\22:{\22docs\22:\22Defines the case payload type for `HTTP-response-{header,trailer}-size` above:\22},\22error-code\22:{\22docs\22:\22These cases are inspired by the IANA HTTP Proxy Error Types:\5cn https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types\22,\22items\22:{\22internal-error\22:\22This is a catch-all error for anything that doesn't fit cleanly into a\5cnmore specific case. It also includes an optional string for an\5cnunstructured description of the error. Users should not depend on the\5cnstring for diagnosing errors, as it's not required to be consistent\5cnbetween implementations.\22}},\22header-error\22:{\22docs\22:\22This type enumerates the different kinds of errors that may occur when\5cnsetting or appending to a `fields` resource.\22,\22items\22:{\22invalid-syntax\22:\22This error indicates that a `field-key` or `field-value` was\5cnsyntactically invalid when used with an operation that sets headers in a\5cn`fields`.\22,\22forbidden\22:\22This error indicates that a forbidden `field-key` was used when trying\5cnto set a header in a `fields`.\22,\22immutable\22:\22This error indicates that the operation on the `fields` was not\5cnpermitted because the fields are immutable.\22}},\22field-key\22:{\22docs\22:\22Field keys are always strings.\22},\22field-value\22:{\22docs\22:\22Field values should always be ASCII strings. However, in\5cnreality, HTTP implementations often have to interpret malformed values,\5cnso they are provided as a list of bytes.\22},\22fields\22:{\22docs\22:\22This following block defines the `fields` resource which corresponds to\5cnHTTP standard Fields. Fields are a common representation used for both\5cnHeaders and Trailers.\5cn\5cnA `fields` may be mutable or immutable. A `fields` created using the\5cnconstructor, `from-list`, or `clone` will be mutable, but a `fields`\5cnresource given by other means (including, but not limited to,\5cn`incoming-request.headers`, `outgoing-request.headers`) might be be\5cnimmutable. In an immutable fields, the `set`, `append`, and `delete`\5cnoperations will fail with `header-error.immutable`.\22},\22headers\22:{\22docs\22:\22Headers is an alias for Fields.\22},\22trailers\22:{\22docs\22:\22Trailers is an alias for Fields.\22},\22incoming-request\22:{\22docs\22:\22Represents an incoming HTTP Request.\22},\22outgoing-request\22:{\22docs\22:\22Represents an outgoing HTTP Request.\22},\22request-options\22:{\22docs\22:\22Parameters for making an HTTP Request. Each of these parameters is\5cncurrently an optional timeout applicable to the transport layer of the\5cnHTTP protocol.\5cn\5cnThese timeouts are separate from any the user may use to bound a\5cnblocking call to `wasi:io/poll.poll`.\22},\22response-outparam\22:{\22docs\22:\22Represents the ability to send an HTTP Response.\5cn\5cnThis resource is used by the `wasi:http/incoming-handler` interface to\5cnallow a Response to be sent corresponding to the Request provided as the\5cnother argument to `incoming-handler.handle`.\22},\22status-code\22:{\22docs\22:\22This type corresponds to the HTTP standard Status Code.\22},\22incoming-response\22:{\22docs\22:\22Represents an incoming HTTP Response.\22},\22incoming-body\22:{\22docs\22:\22Represents an incoming HTTP Request or Response's Body.\5cn\5cnA body has both its contents - a stream of bytes - and a (possibly\5cnempty) set of trailers, indicating that the full contents of the\5cnbody have been received. This resource represents the contents as\5cnan `input-stream` and the delivery of trailers as a `future-trailers`,\5cnand ensures that the user of this interface may only be consuming either\5cnthe body contents or waiting on trailers at any given time.\22},\22future-trailers\22:{\22docs\22:\22Represents a future which may eventually return trailers, or an error.\5cn\5cnIn the case that the incoming HTTP Request or Response did not have any\5cntrailers, this future will resolve to the empty set of trailers once the\5cncomplete Request or Response body has been received.\22},\22outgoing-response\22:{\22docs\22:\22Represents an outgoing HTTP Response.\22},\22outgoing-body\22:{\22docs\22:\22Represents an outgoing HTTP Request or Response's Body.\5cn\5cnA body has both its contents - a stream of bytes - and a (possibly\5cnempty) set of trailers, inducating the full contents of the body\5cnhave been sent. This resource represents the contents as an\5cn`output-stream` child resource, and the completion of the body (with\5cnoptional trailers) with a static function that consumes the\5cn`outgoing-body` resource, and ensures that the user of this interface\5cnmay not write to the body contents after the body has been finished.\5cn\5cnIf the user code drops this resource, as opposed to calling the static\5cnmethod `finish`, the implementation should treat the body as incomplete,\5cnand that an error has occurred. The implementation should propagate this\5cnerror to the HTTP protocol by whatever means it has available,\5cnincluding: corrupting the body on the wire, aborting the associated\5cnRequest, or sending a late status code for the Response.\22},\22future-incoming-response\22:{\22docs\22:\22Represents a future which may eventually return an incoming HTTP\5cnResponse, or an error.\5cn\5cnThis resource is returned by the `wasi:http/outgoing-handler` interface to\5cnprovide the HTTP Response corresponding to the sent Request.\22}}},\22incoming-handler\22:{\22docs\22:\22This interface defines a handler of incoming HTTP Requests. It should\5cnbe exported by components which can respond to HTTP Requests.\22,\22funcs\22:{\22handle\22:{\22docs\22:\22This function is invoked with an incoming HTTP Request, and a resource\5cn`response-outparam` which provides the capability to reply with an HTTP\5cnResponse. The response is sent by calling the `response-outparam.set`\5cnmethod, which allows execution to continue after the response has been\5cnsent. This enables both streaming to the response body, and performing other\5cnwork.\5cn\5cnThe implementor of this function must write a response to the\5cn`response-outparam` before returning, or else the caller will respond\5cnwith an error on its behalf.\22}}},\22outgoing-handler\22:{\22docs\22:\22This interface defines a handler of outgoing HTTP Requests. It should be\5cnimported by components which wish to make HTTP Requests.\22,\22funcs\22:{\22handle\22:{\22docs\22:\22This function is invoked with an outgoing HTTP Request, and it returns\5cna resource `future-incoming-response` which represents an HTTP Response\5cnwhich may arrive in the future.\5cn\5cnThe `options` argument accepts optional parameters for the HTTP\5cnprotocol's transport layer.\5cn\5cnThis function may return an error if the `outgoing-request` is invalid\5cnor not allowed to be made. Otherwise, protocol errors are reported\5cnthrough the `future-incoming-response`.\22}}}}}") + (@producers + (processed-by "wit-component" "$CARGO_PKG_VERSION") + ) +) diff --git a/crates/wit-component/tests/interfaces/wasi-http/http.canon-names.wit.print b/crates/wit-component/tests/interfaces/wasi-http/http.canon-names.wit.print new file mode 100644 index 0000000000..bdfbde3140 --- /dev/null +++ b/crates/wit-component/tests/interfaces/wasi-http/http.canon-names.wit.print @@ -0,0 +1,583 @@ +package wasi:http@0.2.0-rc-2023-12-05; + +/// This interface defines all of the types and methods for implementing +/// HTTP Requests and Responses, both incoming and outgoing, as well as +/// their headers, trailers, and bodies. +interface types { + use wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10.{duration}; + use wasi:io/streams@0.2.0-rc-2023-11-10.{input-stream, output-stream}; + use wasi:io/error@0.2.0-rc-2023-11-10.{error as io-error}; + use wasi:io/poll@0.2.0-rc-2023-11-10.{pollable}; + + /// This type corresponds to HTTP standard Methods. + variant method { + get, + head, + post, + put, + delete, + connect, + options, + trace, + patch, + other(string), + } + + /// This type corresponds to HTTP standard Related Schemes. + variant scheme { + HTTP, + HTTPS, + other(string), + } + + /// Defines the case payload type for `DNS-error` above: + record DNS-error-payload { + rcode: option, + info-code: option, + } + + /// Defines the case payload type for `TLS-alert-received` above: + record TLS-alert-received-payload { + alert-id: option, + alert-message: option, + } + + /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: + record field-size-payload { + field-name: option, + field-size: option, + } + + /// These cases are inspired by the IANA HTTP Proxy Error Types: + /// https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types + variant error-code { + DNS-timeout, + DNS-error(DNS-error-payload), + destination-not-found, + destination-unavailable, + destination-IP-prohibited, + destination-IP-unroutable, + connection-refused, + connection-terminated, + connection-timeout, + connection-read-timeout, + connection-write-timeout, + connection-limit-reached, + TLS-protocol-error, + TLS-certificate-error, + TLS-alert-received(TLS-alert-received-payload), + HTTP-request-denied, + HTTP-request-length-required, + HTTP-request-body-size(option), + HTTP-request-method-invalid, + HTTP-request-URI-invalid, + HTTP-request-URI-too-long, + HTTP-request-header-section-size(option), + HTTP-request-header-size(option), + HTTP-request-trailer-section-size(option), + HTTP-request-trailer-size(field-size-payload), + HTTP-response-incomplete, + HTTP-response-header-section-size(option), + HTTP-response-header-size(field-size-payload), + HTTP-response-body-size(option), + HTTP-response-trailer-section-size(option), + HTTP-response-trailer-size(field-size-payload), + HTTP-response-transfer-coding(option), + HTTP-response-content-coding(option), + HTTP-response-timeout, + HTTP-upgrade-failed, + HTTP-protocol-error, + loop-detected, + configuration-error, + /// This is a catch-all error for anything that doesn't fit cleanly into a + /// more specific case. It also includes an optional string for an + /// unstructured description of the error. Users should not depend on the + /// string for diagnosing errors, as it's not required to be consistent + /// between implementations. + internal-error(option), + } + + /// This type enumerates the different kinds of errors that may occur when + /// setting or appending to a `fields` resource. + variant header-error { + /// This error indicates that a `field-key` or `field-value` was + /// syntactically invalid when used with an operation that sets headers in a + /// `fields`. + invalid-syntax, + /// This error indicates that a forbidden `field-key` was used when trying + /// to set a header in a `fields`. + forbidden, + /// This error indicates that the operation on the `fields` was not + /// permitted because the fields are immutable. + immutable, + } + + /// Field keys are always strings. + type field-key = string; + + /// Field values should always be ASCII strings. However, in + /// reality, HTTP implementations often have to interpret malformed values, + /// so they are provided as a list of bytes. + type field-value = list; + + /// This following block defines the `fields` resource which corresponds to + /// HTTP standard Fields. Fields are a common representation used for both + /// Headers and Trailers. + /// + /// A `fields` may be mutable or immutable. A `fields` created using the + /// constructor, `from-list`, or `clone` will be mutable, but a `fields` + /// resource given by other means (including, but not limited to, + /// `incoming-request.headers`, `outgoing-request.headers`) might be be + /// immutable. In an immutable fields, the `set`, `append`, and `delete` + /// operations will fail with `header-error.immutable`. + resource fields { + /// Construct an empty HTTP Fields. + /// + /// The resulting `fields` is mutable. + constructor(); + /// Construct an HTTP Fields. + /// + /// The resulting `fields` is mutable. + /// + /// The list represents each key-value pair in the Fields. Keys + /// which have multiple values are represented by multiple entries in this + /// list with the same key. + /// + /// The tuple is a pair of the field key, represented as a string, and + /// Value, represented as a list of bytes. In a valid Fields, all keys + /// and values are valid UTF-8 strings. However, values are not always + /// well-formed, so they are represented as a raw list of bytes. + /// + /// An error result will be returned if any header or value was + /// syntactically invalid, or if a header was forbidden. + from-list: static func(entries: list>) -> result; + /// Get all of the values corresponding to a key. If the key is not present + /// in this `fields`, an empty list is returned. However, if the key is + /// present but empty, this is represented by a list with one or more + /// empty field-values present. + get: func(name: field-key) -> list; + /// Returns `true` when the key is present in this `fields`. If the key is + /// syntactically invalid, `false` is returned. + has: func(name: field-key) -> bool; + /// Set all of the values for a key. Clears any existing values for that + /// key, if they have been set. + /// + /// Fails with `header-error.immutable` if the `fields` are immutable. + set: func(name: field-key, value: list) -> result<_, header-error>; + /// Delete all values for a key. Does nothing if no values for the key + /// exist. + /// + /// Fails with `header-error.immutable` if the `fields` are immutable. + delete: func(name: field-key) -> result<_, header-error>; + /// Append a value for a key. Does not change or delete any existing + /// values for that key. + /// + /// Fails with `header-error.immutable` if the `fields` are immutable. + append: func(name: field-key, value: field-value) -> result<_, header-error>; + /// Retrieve the full set of keys and values in the Fields. Like the + /// constructor, the list represents each key-value pair. + /// + /// The outer list represents each key-value pair in the Fields. Keys + /// which have multiple values are represented by multiple entries in this + /// list with the same key. + entries: func() -> list>; + /// Make a deep copy of the Fields. Equivalent in behavior to calling the + /// `fields` constructor on the return value of `entries`. The resulting + /// `fields` is mutable. + clone: func() -> fields; + } + + /// Headers is an alias for Fields. + type headers = fields; + + /// Trailers is an alias for Fields. + type trailers = fields; + + /// Represents an incoming HTTP Request. + resource incoming-request { + /// Returns the method of the incoming request. + method: func() -> method; + /// Returns the path with query parameters from the request, as a string. + path-with-query: func() -> option; + /// Returns the protocol scheme from the request. + scheme: func() -> option; + /// Returns the authority from the request, if it was present. + authority: func() -> option; + /// Get the `headers` associated with the request. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// The `headers` returned are a child resource: it must be dropped before + /// the parent `incoming-request` is dropped. Dropping this + /// `incoming-request` before all children are dropped will trap. + headers: func() -> headers; + /// Gives the `incoming-body` associated with this request. Will only + /// return success at most once, and subsequent calls will return error. + consume: func() -> result; + } + + /// Represents an outgoing HTTP Request. + resource outgoing-request { + /// Construct a new `outgoing-request` with a default `method` of `GET`, and + /// `none` values for `path-with-query`, `scheme`, and `authority`. + /// + /// * `headers` is the HTTP Headers for the Request. + /// + /// It is possible to construct, or manipulate with the accessor functions + /// below, an `outgoing-request` with an invalid combination of `scheme` + /// and `authority`, or `headers` which are not permitted to be sent. + /// It is the obligation of the `outgoing-handler.handle` implementation + /// to reject invalid constructions of `outgoing-request`. + constructor(headers: headers); + /// Returns the resource corresponding to the outgoing Body for this + /// Request. + /// + /// Returns success on the first call: the `outgoing-body` resource for + /// this `outgoing-request` can be retrieved at most once. Subsequent + /// calls will return error. + body: func() -> result; + /// Get the Method for the Request. + method: func() -> method; + /// Set the Method for the Request. Fails if the string present in a + /// `method.other` argument is not a syntactically valid method. + set-method: func(method: method) -> result; + /// Get the combination of the HTTP Path and Query for the Request. + /// When `none`, this represents an empty Path and empty Query. + path-with-query: func() -> option; + /// Set the combination of the HTTP Path and Query for the Request. + /// When `none`, this represents an empty Path and empty Query. Fails is the + /// string given is not a syntactically valid path and query uri component. + set-path-with-query: func(path-with-query: option) -> result; + /// Get the HTTP Related Scheme for the Request. When `none`, the + /// implementation may choose an appropriate default scheme. + scheme: func() -> option; + /// Set the HTTP Related Scheme for the Request. When `none`, the + /// implementation may choose an appropriate default scheme. Fails if the + /// string given is not a syntactically valid uri scheme. + set-scheme: func(scheme: option) -> result; + /// Get the HTTP Authority for the Request. A value of `none` may be used + /// with Related Schemes which do not require an Authority. The HTTP and + /// HTTPS schemes always require an authority. + authority: func() -> option; + /// Set the HTTP Authority for the Request. A value of `none` may be used + /// with Related Schemes which do not require an Authority. The HTTP and + /// HTTPS schemes always require an authority. Fails if the string given is + /// not a syntactically valid uri authority. + set-authority: func(authority: option) -> result; + /// Get the headers associated with the Request. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// This headers resource is a child: it must be dropped before the parent + /// `outgoing-request` is dropped, or its ownership is transferred to + /// another component by e.g. `outgoing-handler.handle`. + headers: func() -> headers; + } + + /// Parameters for making an HTTP Request. Each of these parameters is + /// currently an optional timeout applicable to the transport layer of the + /// HTTP protocol. + /// + /// These timeouts are separate from any the user may use to bound a + /// blocking call to `wasi:io/poll.poll`. + resource request-options { + /// Construct a default `request-options` value. + constructor(); + /// The timeout for the initial connect to the HTTP Server. + connect-timeout: func() -> option; + /// Set the timeout for the initial connect to the HTTP Server. An error + /// return value indicates that this timeout is not supported. + set-connect-timeout: func(duration: option) -> result; + /// The timeout for receiving the first byte of the Response body. + first-byte-timeout: func() -> option; + /// Set the timeout for receiving the first byte of the Response body. An + /// error return value indicates that this timeout is not supported. + set-first-byte-timeout: func(duration: option) -> result; + /// The timeout for receiving subsequent chunks of bytes in the Response + /// body stream. + between-bytes-timeout: func() -> option; + /// Set the timeout for receiving subsequent chunks of bytes in the Response + /// body stream. An error return value indicates that this timeout is not + /// supported. + set-between-bytes-timeout: func(duration: option) -> result; + } + + /// Represents the ability to send an HTTP Response. + /// + /// This resource is used by the `wasi:http/incoming-handler` interface to + /// allow a Response to be sent corresponding to the Request provided as the + /// other argument to `incoming-handler.handle`. + resource response-outparam { + /// Set the value of the `response-outparam` to either send a response, + /// or indicate an error. + /// + /// This method consumes the `response-outparam` to ensure that it is + /// called at most once. If it is never called, the implementation + /// will respond with an error. + /// + /// The user may provide an `error` to `response` to allow the + /// implementation determine how to respond with an HTTP error response. + set: static func(param: response-outparam, response: result); + } + + /// This type corresponds to the HTTP standard Status Code. + type status-code = u16; + + /// Represents an incoming HTTP Response. + resource incoming-response { + /// Returns the status code from the incoming response. + status: func() -> status-code; + /// Returns the headers from the incoming response. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// This headers resource is a child: it must be dropped before the parent + /// `incoming-response` is dropped. + headers: func() -> headers; + /// Returns the incoming body. May be called at most once. Returns error + /// if called additional times. + consume: func() -> result; + } + + /// Represents an incoming HTTP Request or Response's Body. + /// + /// A body has both its contents - a stream of bytes - and a (possibly + /// empty) set of trailers, indicating that the full contents of the + /// body have been received. This resource represents the contents as + /// an `input-stream` and the delivery of trailers as a `future-trailers`, + /// and ensures that the user of this interface may only be consuming either + /// the body contents or waiting on trailers at any given time. + resource incoming-body { + /// Returns the contents of the body, as a stream of bytes. + /// + /// Returns success on first call: the stream representing the contents + /// can be retrieved at most once. Subsequent calls will return error. + /// + /// The returned `input-stream` resource is a child: it must be dropped + /// before the parent `incoming-body` is dropped, or consumed by + /// `incoming-body.finish`. + /// + /// This invariant ensures that the implementation can determine whether + /// the user is consuming the contents of the body, waiting on the + /// `future-trailers` to be ready, or neither. This allows for network + /// backpressure is to be applied when the user is consuming the body, + /// and for that backpressure to not inhibit delivery of the trailers if + /// the user does not read the entire body. + %stream: func() -> result; + /// Takes ownership of `incoming-body`, and returns a `future-trailers`. + /// This function will trap if the `input-stream` child is still alive. + finish: static func(this: incoming-body) -> future-trailers; + } + + /// Represents a future which may eventually return trailers, or an error. + /// + /// In the case that the incoming HTTP Request or Response did not have any + /// trailers, this future will resolve to the empty set of trailers once the + /// complete Request or Response body has been received. + resource future-trailers { + /// Returns a pollable which becomes ready when either the trailers have + /// been received, or an error has occurred. When this pollable is ready, + /// the `get` method will return `some`. + subscribe: func() -> pollable; + /// Returns the contents of the trailers, or an error which occurred, + /// once the future is ready. + /// + /// The outer `option` represents future readiness. Users can wait on this + /// `option` to become `some` using the `subscribe` method. + /// + /// The outer `result` is used to retrieve the trailers or error at most + /// once. It will be success on the first call in which the outer option + /// is `some`, and error on subsequent calls. + /// + /// The inner `result` represents that either the HTTP Request or Response + /// body, as well as any trailers, were received successfully, or that an + /// error occurred receiving them. The optional `trailers` indicates whether + /// or not trailers were present in the body. + /// + /// When some `trailers` are returned by this method, the `trailers` + /// resource is immutable, and a child. Use of the `set`, `append`, or + /// `delete` methods will return an error, and the resource must be + /// dropped before the parent `future-trailers` is dropped. + get: func() -> option, error-code>>>; + } + + /// Represents an outgoing HTTP Response. + resource outgoing-response { + /// Construct an `outgoing-response`, with a default `status-code` of `200`. + /// If a different `status-code` is needed, it must be set via the + /// `set-status-code` method. + /// + /// * `headers` is the HTTP Headers for the Response. + constructor(headers: headers); + /// Get the HTTP Status Code for the Response. + status-code: func() -> status-code; + /// Set the HTTP Status Code for the Response. Fails if the status-code + /// given is not a valid http status code. + set-status-code: func(status-code: status-code) -> result; + /// Get the headers associated with the Request. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// This headers resource is a child: it must be dropped before the parent + /// `outgoing-request` is dropped, or its ownership is transferred to + /// another component by e.g. `outgoing-handler.handle`. + headers: func() -> headers; + /// Returns the resource corresponding to the outgoing Body for this Response. + /// + /// Returns success on the first call: the `outgoing-body` resource for + /// this `outgoing-response` can be retrieved at most once. Subsequent + /// calls will return error. + body: func() -> result; + } + + /// Represents an outgoing HTTP Request or Response's Body. + /// + /// A body has both its contents - a stream of bytes - and a (possibly + /// empty) set of trailers, inducating the full contents of the body + /// have been sent. This resource represents the contents as an + /// `output-stream` child resource, and the completion of the body (with + /// optional trailers) with a static function that consumes the + /// `outgoing-body` resource, and ensures that the user of this interface + /// may not write to the body contents after the body has been finished. + /// + /// If the user code drops this resource, as opposed to calling the static + /// method `finish`, the implementation should treat the body as incomplete, + /// and that an error has occurred. The implementation should propagate this + /// error to the HTTP protocol by whatever means it has available, + /// including: corrupting the body on the wire, aborting the associated + /// Request, or sending a late status code for the Response. + resource outgoing-body { + /// Returns a stream for writing the body contents. + /// + /// The returned `output-stream` is a child resource: it must be dropped + /// before the parent `outgoing-body` resource is dropped (or finished), + /// otherwise the `outgoing-body` drop or `finish` will trap. + /// + /// Returns success on the first call: the `output-stream` resource for + /// this `outgoing-body` may be retrieved at most once. Subsequent calls + /// will return error. + write: func() -> result; + /// Finalize an outgoing body, optionally providing trailers. This must be + /// called to signal that the response is complete. If the `outgoing-body` + /// is dropped without calling `outgoing-body.finalize`, the implementation + /// should treat the body as corrupted. + /// + /// Fails if the body's `outgoing-request` or `outgoing-response` was + /// constructed with a Content-Length header, and the contents written + /// to the body (via `write`) does not match the value given in the + /// Content-Length. + finish: static func(this: outgoing-body, trailers: option) -> result<_, error-code>; + } + + /// Represents a future which may eventually return an incoming HTTP + /// Response, or an error. + /// + /// This resource is returned by the `wasi:http/outgoing-handler` interface to + /// provide the HTTP Response corresponding to the sent Request. + resource future-incoming-response { + /// Returns a pollable which becomes ready when either the Response has + /// been received, or an error has occurred. When this pollable is ready, + /// the `get` method will return `some`. + subscribe: func() -> pollable; + /// Returns the incoming HTTP Response, or an error, once one is ready. + /// + /// The outer `option` represents future readiness. Users can wait on this + /// `option` to become `some` using the `subscribe` method. + /// + /// The outer `result` is used to retrieve the response or error at most + /// once. It will be success on the first call in which the outer option + /// is `some`, and error on subsequent calls. + /// + /// The inner `result` represents that either the incoming HTTP Response + /// status and headers have received successfully, or that an error + /// occurred. Errors may also occur while consuming the response body, + /// but those will be reported by the `incoming-body` and its + /// `output-stream` child. + get: func() -> option>>; + } + + /// Attempts to extract a http-related `error` from the wasi:io `error` + /// provided. + /// + /// Stream operations which return + /// `wasi:io/stream/stream-error::last-operation-failed` have a payload of + /// type `wasi:io/error/error` with more information about the operation + /// that failed. This payload can be passed through to this function to see + /// if there's http-related information about the error to return. + /// + /// Note that this function is fallible because not all io-errors are + /// http-related errors. + http-error-code: func(err: borrow) -> option; +} + +/// This interface defines a handler of incoming HTTP Requests. It should +/// be exported by components which can respond to HTTP Requests. +interface incoming-handler { + use types.{incoming-request, response-outparam}; + + /// This function is invoked with an incoming HTTP Request, and a resource + /// `response-outparam` which provides the capability to reply with an HTTP + /// Response. The response is sent by calling the `response-outparam.set` + /// method, which allows execution to continue after the response has been + /// sent. This enables both streaming to the response body, and performing other + /// work. + /// + /// The implementor of this function must write a response to the + /// `response-outparam` before returning, or else the caller will respond + /// with an error on its behalf. + handle: func(request: incoming-request, response-out: response-outparam); +} + +/// This interface defines a handler of outgoing HTTP Requests. It should be +/// imported by components which wish to make HTTP Requests. +interface outgoing-handler { + use types.{outgoing-request, request-options, future-incoming-response, error-code}; + + /// This function is invoked with an outgoing HTTP Request, and it returns + /// a resource `future-incoming-response` which represents an HTTP Response + /// which may arrive in the future. + /// + /// The `options` argument accepts optional parameters for the HTTP + /// protocol's transport layer. + /// + /// This function may return an error if the `outgoing-request` is invalid + /// or not allowed to be made. Otherwise, protocol errors are reported + /// through the `future-incoming-response`. + handle: func(request: outgoing-request, options: option) -> result; +} + +/// The `wasi:http/proxy` world captures a widely-implementable intersection of +/// hosts that includes HTTP forward and reverse proxies. Components targeting +/// this world may concurrently stream in and out any number of incoming and +/// outgoing HTTP requests. +world proxy { + import wasi:random/random@0.2.0-rc-2023-11-10; + import wasi:io/error@0.2.0-rc-2023-11-10; + import wasi:io/poll@0.2.0-rc-2023-11-10; + import wasi:io/streams@0.2.0-rc-2023-11-10; + /// Proxies have standard output and error streams which are expected to + /// terminate in a developer-facing console provided by the host. + import wasi:cli/stdout@0.2.0-rc-2023-12-05; + import wasi:cli/stderr@0.2.0-rc-2023-12-05; + /// TODO: this is a temporary workaround until component tooling is able to + /// gracefully handle the absence of stdin. Hosts must return an eof stream + /// for this import, which is what wasi-libc + tooling will do automatically + /// when this import is properly removed. + import wasi:cli/stdin@0.2.0-rc-2023-12-05; + import wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10; + import types; + /// This is the default handler to use when user code simply wants to make an + /// HTTP request (e.g., via `fetch()`). + import outgoing-handler; + import wasi:clocks/wall-clock@0.2.0-rc-2023-11-10; + + /// The host delivers incoming HTTP requests to a component by calling the + /// `handle` function of this exported interface. A host may arbitrarily reuse + /// or not reuse component instance when delivering incoming HTTP requests and + /// thus a component must be able to handle 0..N calls to `handle`. + export incoming-handler; +} diff --git a/crates/wit-parser/src/ast/resolve.rs b/crates/wit-parser/src/ast/resolve.rs index 3ac115a27d..532326e45d 100644 --- a/crates/wit-parser/src/ast/resolve.rs +++ b/crates/wit-parser/src/ast/resolve.rs @@ -711,9 +711,19 @@ impl<'a> Resolver<'a> { }; if let WorldKey::Interface(id) = key { if !interfaces.insert(id) { + let full_name = match kind { + ast::ExternKind::Path(ast::UsePath::Package { id, name }) => { + let pkg = id.package_name(); + format!("{pkg}/{}", name.name) + } + _ => self.interfaces[id] + .name + .clone() + .unwrap_or_else(|| "unnamed".into()), + }; return Err(ParseError::new_syntax( kind.span(), - format!("interface cannot be {desc}ed more than once"), + format!("interface `{full_name}` cannot be {desc}ed more than once",), )); } } diff --git a/crates/wit-parser/src/lib.rs b/crates/wit-parser/src/lib.rs index d1aece5a81..12273f7f93 100644 --- a/crates/wit-parser/src/lib.rs +++ b/crates/wit-parser/src/lib.rs @@ -244,6 +244,123 @@ pub struct PackageName { pub version: Option, } +/// A key type for comparing packages, optionally by canonical version prefix. +/// +/// When `use_canonical` is true, the version is reduced to its canonical +/// prefix (e.g., `1.2.3` → `"1"`, `0.2.1` → `"0.2"`), compared as a string. +/// When false, the full `semver::Version` is used, preserving proper semver +/// ordering. +#[derive(Clone, Debug)] +pub struct PackageKey { + namespace: String, + name: String, + version_key: VersionKey, +} + +#[derive(Clone, Debug)] +enum VersionKey { + Exact(Option), + Canonical(Option), +} + +impl PartialEq for PackageKey { + fn eq(&self, other: &Self) -> bool { + self.namespace == other.namespace + && self.name == other.name + && self.version_key == other.version_key + } +} +impl Eq for PackageKey {} + +impl std::hash::Hash for PackageKey { + fn hash(&self, state: &mut H) { + self.namespace.hash(state); + self.name.hash(state); + self.version_key.hash(state); + } +} + +impl PartialOrd for PackageKey { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for PackageKey { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.namespace + .cmp(&other.namespace) + .then_with(|| self.name.cmp(&other.name)) + .then_with(|| self.version_key.cmp(&other.version_key)) + } +} + +impl PartialEq for VersionKey { + fn eq(&self, other: &Self) -> bool { + match (self, other) { + (VersionKey::Exact(a), VersionKey::Exact(b)) => a == b, + (VersionKey::Canonical(a), VersionKey::Canonical(b)) => a == b, + _ => false, + } + } +} +impl Eq for VersionKey {} + +impl std::hash::Hash for VersionKey { + fn hash(&self, state: &mut H) { + match self { + VersionKey::Exact(v) => { + 0u8.hash(state); + v.hash(state); + } + VersionKey::Canonical(s) => { + 1u8.hash(state); + s.hash(state); + } + } + } +} + +impl PartialOrd for VersionKey { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for VersionKey { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + match (self, other) { + (VersionKey::Exact(a), VersionKey::Exact(b)) => a.cmp(b), + (VersionKey::Canonical(a), VersionKey::Canonical(b)) => a.cmp(b), + (_, _) => unreachable!(), + } + } +} + +impl PackageKey { + /// Creates a new `PackageKey` from a `PackageName`. + /// + /// If `use_canonical` is true, the version is reduced to its canonical + /// prefix for comparison purposes. Otherwise the full semver `Version` is + /// used, preserving proper semver ordering. + pub fn new(pkg: &PackageName, use_canonical: bool) -> Self { + let version_key = if use_canonical { + VersionKey::Canonical( + pkg.version + .as_ref() + .map(|v| PackageName::canon_version_split(v).0), + ) + } else { + VersionKey::Exact(pkg.version.clone()) + }; + PackageKey { + namespace: pkg.namespace.clone(), + name: pkg.name.clone(), + version_key, + } + } +} + impl From for String { fn from(name: PackageName) -> String { name.to_string() @@ -308,6 +425,30 @@ impl PackageName { } version.to_string() } + + /// Splits a semver version into a canonical version prefix and a version + /// suffix according to the component model spec. + /// + /// The split point is: + /// - If `major > 0`: split after major (e.g. `1.2.3` → `("1", ".2.3")`) + /// - If `major == 0` and `minor > 0`: split after minor + /// (e.g. `0.2.6-rc.1` → `("0.2", ".6-rc.1")`) + /// - Otherwise: split after patch (e.g. `0.0.1-alpha` → `("0.0.1", "-alpha")`) + pub fn canon_version_split(version: &Version) -> (String, String) { + let s = version.to_string(); + let split_pos = if version.major > 0 { + version.major.to_string().len() + } else if version.minor > 0 { + // "0.".len() + minor digits + 2 + version.minor.to_string().len() + } else { + // "0.0.".len() + patch digits + 4 + version.patch.to_string().len() + }; + let prefix = s[..split_pos].to_string(); + let suffix = s[split_pos..].to_string(); + (prefix, suffix) + } } impl fmt::Display for PackageName { @@ -1572,4 +1713,55 @@ mod test { assert_eq!(t1, found[1]); assert_eq!(t2, found[2]); } + + #[test] + fn test_canon_version_split() { + use semver::Version; + + // major > 0: split after major + let v = Version::parse("1.2.3").unwrap(); + assert_eq!( + PackageName::canon_version_split(&v), + ("1".to_string(), ".2.3".to_string()) + ); + + let v = Version::parse("2.0.0").unwrap(); + assert_eq!( + PackageName::canon_version_split(&v), + ("2".to_string(), ".0.0".to_string()) + ); + + // major == 0, minor > 0: split after minor + let v = Version::parse("0.2.6-rc.1").unwrap(); + assert_eq!( + PackageName::canon_version_split(&v), + ("0.2".to_string(), ".6-rc.1".to_string()) + ); + + let v = Version::parse("0.1.0").unwrap(); + assert_eq!( + PackageName::canon_version_split(&v), + ("0.1".to_string(), ".0".to_string()) + ); + + // major == 0, minor == 0: split after patch + let v = Version::parse("0.0.1-alpha").unwrap(); + assert_eq!( + PackageName::canon_version_split(&v), + ("0.0.1".to_string(), "-alpha".to_string()) + ); + + let v = Version::parse("0.0.0").unwrap(); + assert_eq!( + PackageName::canon_version_split(&v), + ("0.0.0".to_string(), "".to_string()) + ); + + // Pre-release on major > 0 + let v = Version::parse("1.0.0-beta.1").unwrap(); + assert_eq!( + PackageName::canon_version_split(&v), + ("1".to_string(), ".0.0-beta.1".to_string()) + ); + } } diff --git a/crates/wit-parser/src/resolve/mod.rs b/crates/wit-parser/src/resolve/mod.rs index 388e2767b7..4ebe20bf3a 100644 --- a/crates/wit-parser/src/resolve/mod.rs +++ b/crates/wit-parser/src/resolve/mod.rs @@ -104,6 +104,12 @@ pub struct Resolve { /// Source map for converting spans to file locations. #[cfg_attr(feature = "serde", serde(skip))] pub source_map: SourceMap, + + /// When true, packages are compared and encoded using canonical version + /// prefixes (e.g., `1.2.3` and `1.3.0` share the canonical prefix `"1"`). + /// When false (the default), full exact versions are used. + #[cfg_attr(feature = "serde", serde(skip))] + pub use_canonical_names: bool, } /// A WIT package within a `Resolve`. @@ -193,40 +199,44 @@ impl PackageSources { /// Visitor helper for performing topological sort on a group of packages. fn visit<'a>( pkg: &'a UnresolvedPackage, - pkg_details_map: &'a BTreeMap, - order: &mut IndexSet, - visiting: &mut HashSet<&'a PackageName>, + pkg_details_map: &'a BTreeMap, + order: &mut IndexSet, + visiting: &mut HashSet, source_map_offsets: &[u32], + use_canonical: bool, ) -> ResolveResult<()> { - if order.contains(&pkg.name) { + let key = PackageKey::new(&pkg.name, use_canonical); + if order.contains(&key) { return Ok(()); } let (_, source_map_index) = pkg_details_map - .get(&pkg.name) + .get(&key) .expect("No pkg_details found for package when doing topological sort"); let offset = source_map_offsets[*source_map_index]; for (i, (dep, _)) in pkg.foreign_deps.iter().enumerate() { let mut span = pkg.foreign_dep_spans[i]; span.adjust(offset); - if !visiting.insert(dep) { + let dep_key = PackageKey::new(dep, use_canonical); + if !visiting.insert(dep_key.clone()) { return Err(ResolveError::from(ResolveErrorKind::PackageCycle { package: dep.clone(), span, })); } - if let Some((dep_pkg, _)) = pkg_details_map.get(dep) { + if let Some((dep_pkg, _)) = pkg_details_map.get(&dep_key) { visit( dep_pkg, pkg_details_map, order, visiting, source_map_offsets, + use_canonical, )?; } - assert!(visiting.remove(dep)); + assert!(visiting.remove(&dep_key)); } - assert!(order.insert(pkg.name.clone())); + assert!(order.insert(key)); Ok(()) } @@ -236,6 +246,20 @@ impl Resolve { Resolve::default() } + /// Looks up a package ID by name. When `use_canonical_names` is enabled, + /// matches by canonical version prefix rather than exact version. + pub fn find_package(&self, name: &PackageName) -> Option { + if self.use_canonical_names { + let key = PackageKey::new(name, true); + self.package_names + .iter() + .find(|(n, _)| PackageKey::new(n, true) == key) + .map(|(_, id)| *id) + } else { + self.package_names.get(name).copied() + } + } + /// Merge `main` and `deps` into this [`Resolve`], topologically sorting /// them internally. Returns the [`PackageId`] of `main` and a /// [`PackageSources`] covering all groups. @@ -275,25 +299,51 @@ impl Resolve { .map(|sm| self.push_source_map(sm.clone())) .collect(); - let mut pkg_details_map: BTreeMap = - BTreeMap::new(); + let mut pkg_details_map: BTreeMap = BTreeMap::new(); for (pkg, source_map_index) in all_packages { - let name = pkg.name.clone(); + let key = PackageKey::new(&pkg.name, self.use_canonical_names); let my_span = pkg.package_name_span; let offset = source_map_offsets[source_map_index]; if let Some((prev_pkg, prev_source_map_index)) = - pkg_details_map.insert(name.clone(), (pkg, source_map_index)) + pkg_details_map.insert(key.clone(), (pkg, source_map_index)) { - let prev_offset = source_map_offsets[prev_source_map_index]; - let mut span1 = my_span; - span1.adjust(offset); - let mut span2 = prev_pkg.package_name_span; - span2.adjust(prev_offset); - return Err(ResolveError::from(ResolveErrorKind::DuplicatePackage { - name, - span1, - span2, - })); + if self.use_canonical_names { + // When canonical names are enabled, packages with the same + // canonical version prefix are considered equivalent. + // Keep the one with the larger full version. + // If full versions are exactly equal, it's a true duplicate error. + let (current_pkg, _) = pkg_details_map.get(&key).unwrap(); + match prev_pkg.name.version.cmp(¤t_pkg.name.version) { + std::cmp::Ordering::Greater => { + // Previous package had larger version, put it back + pkg_details_map.insert(key, (prev_pkg, prev_source_map_index)); + } + std::cmp::Ordering::Less => {} + std::cmp::Ordering::Equal => { + let prev_offset = source_map_offsets[prev_source_map_index]; + let mut span1 = my_span; + span1.adjust(offset); + let mut span2 = prev_pkg.package_name_span; + span2.adjust(prev_offset); + return Err(ResolveError::from(ResolveErrorKind::DuplicatePackage { + name: prev_pkg.name, + span1, + span2, + })); + } + } + } else { + let prev_offset = source_map_offsets[prev_source_map_index]; + let mut span1 = my_span; + span1.adjust(offset); + let mut span2 = prev_pkg.package_name_span; + span2.adjust(prev_offset); + return Err(ResolveError::from(ResolveErrorKind::DuplicatePackage { + name: prev_pkg.name, + span1, + span2, + })); + } } } @@ -310,14 +360,15 @@ impl Resolve { &mut order, &mut visiting, &source_map_offsets, + self.use_canonical_names, )?; } } let mut package_id_to_source_map_idx = BTreeMap::new(); let mut main_pkg_id = None; - for name in order { - let (pkg, source_map_index) = pkg_details_map.remove(&name).unwrap(); + for key in order { + let (pkg, source_map_index) = pkg_details_map.remove(&key).unwrap(); let span_offset = source_map_offsets[source_map_index]; let is_main = pkg.name == main_name; let id = self.push(pkg, span_offset)?; @@ -515,6 +566,7 @@ impl Resolve { let mut map = MergeMap::new(&resolve, &self); map.build()?; + let version_upgrades = map.version_upgrades.clone(); let MergeMap { package_map, interface_map, @@ -714,6 +766,16 @@ impl Resolve { } } + // When canonical names are enabled and a package from `from` had a + // larger version than the matching package in `into`, upgrade the + // version stored on the `into` package and update the `package_names` + // index. + for (into_id, version) in version_upgrades { + let pkg = &mut self.packages[into_id]; + pkg.name.version = Some(version); + self.package_names.insert(pkg.name.clone(), into_id); + } + // Fixup all "parent" links now. // // Note that this is only done for items that are actually moved from @@ -1293,8 +1355,13 @@ impl Resolve { base.push_str(name); if let Some(version) = &package.name.version { base.push_str("@"); - let string = PackageName::version_compat_track_string(version); - base.push_str(&string); + if self.use_canonical_names { + let (prefix, _) = PackageName::canon_version_split(version); + base.push_str(&prefix); + } else { + let string = PackageName::version_compat_track_string(version); + base.push_str(&string); + } } base } @@ -1453,8 +1520,8 @@ impl Resolve { // The world name is fully-qualified. (_, ParsedUsePath::Package(pkg, world_name)) => { - let pkg = match self.package_names.get(&pkg) { - Some(pkg) => *pkg, + let pkg = match self.find_package(&pkg) { + Some(pkg) => pkg, None => { let mut candidates = self.package_names.iter().filter(|(name, _)| { @@ -1550,6 +1617,17 @@ impl Resolve { } } + /// Returns the version suffix for the given interface's package, if any. + /// + /// See the component model explainer and 🔗 for more information on this feature. + pub fn version_suffix_of(&self, interface: InterfaceId) -> Option { + let iface = &self.interfaces[interface]; + let pkg = &self.packages[iface.package?]; + let version = pkg.name.version.as_ref()?; + let (_, suffix) = PackageName::canon_version_split(version); + Some(suffix) + } + /// Returns the component model `implements` value for the world import of /// `key` and `item`. /// @@ -3750,17 +3828,13 @@ impl Remap { None => break, }; - let pkgid = resolve - .package_names - .get(pkg_name) - .copied() - .ok_or_else(|| { - ResolveError::from(ResolveErrorKind::PackageNotFound { - span, - requested: pkg_name.clone(), - known: resolve.package_names.keys().cloned().collect(), - }) - })?; + let pkgid = resolve.find_package(pkg_name).ok_or_else(|| { + ResolveError::from(ResolveErrorKind::PackageNotFound { + span, + requested: pkg_name.clone(), + known: resolve.package_names.keys().cloned().collect(), + }) + })?; // Functions can't be imported so this should be empty. assert!(unresolved_iface.functions.is_empty()); @@ -3816,17 +3890,13 @@ impl Remap { None => break, }; - let pkgid = resolve - .package_names - .get(pkg_name) - .copied() - .ok_or_else(|| { - ResolveError::from(ResolveErrorKind::PackageNotFound { - span, - requested: pkg_name.clone(), - known: resolve.package_names.keys().cloned().collect(), - }) - })?; + let pkgid = resolve.find_package(pkg_name).ok_or_else(|| { + ResolveError::from(ResolveErrorKind::PackageNotFound { + span, + requested: pkg_name.clone(), + known: resolve.package_names.keys().cloned().collect(), + }) + })?; let pkg = &resolve.packages[pkgid]; let world_span = unresolved_world.span; @@ -4469,6 +4539,11 @@ struct MergeMap<'a> { interfaces_to_add: Vec<(String, PackageId, InterfaceId)>, worlds_to_add: Vec<(String, PackageId, WorldId)>, + /// Packages in `into` whose version should be upgraded because `from` + /// had a larger version on the same canonical track. Maps `into` package + /// ID to the larger version from `from`. + version_upgrades: HashMap, + /// Which `Resolve` is being merged from. from: &'a Resolve, @@ -4485,6 +4560,7 @@ impl<'a> MergeMap<'a> { world_map: Default::default(), interfaces_to_add: Default::default(), worlds_to_add: Default::default(), + version_upgrades: Default::default(), from, into, } @@ -4493,8 +4569,8 @@ impl<'a> MergeMap<'a> { fn build(&mut self) -> anyhow::Result<()> { for from_id in self.from.topological_packages() { let from = &self.from.packages[from_id]; - let into_id = match self.into.package_names.get(&from.name) { - Some(id) => *id, + let into_id = match self.into.find_package(&from.name) { + Some(id) => id, // This package, according to its name and url, is not present // in `self` so it needs to get added below. @@ -4505,6 +4581,15 @@ impl<'a> MergeMap<'a> { }; log::trace!("merging duplicate package {}", from.name); + if self.into.use_canonical_names { + let into = &self.into.packages[into_id]; + if from.name.version.cmp(&into.name.version).is_gt() { + if let Some(version) = from.name.version.clone() { + self.version_upgrades.insert(into_id, version); + } + } + } + self.build_package(from_id, into_id).with_context(|| { format!("failed to merge package `{}` into existing copy", from.name) })?; @@ -6075,4 +6160,141 @@ interface iface { Ok(()) } + + #[test] + fn canon_names_merge_larger_into_smaller() -> Result<()> { + // The larger version (from) is merged into the smaller (into). + // Extra types/functions from the larger version should appear in the result. + let mut resolve1 = Resolve::default(); + resolve1.use_canonical_names = true; + resolve1.push_str( + "a.wit", + r#" + package foo:bar@1.0.0; + + interface my-iface { + type base-type = u32; + base-func: func(); + } + "#, + )?; + + let mut resolve2 = Resolve::default(); + resolve2.push_str( + "b.wit", + r#" + package foo:bar@1.2.3; + + interface my-iface { + type base-type = u32; + base-func: func(); + type new-type = string; + new-func: func() -> string; + } + "#, + )?; + + resolve1.merge(resolve2)?; + + assert_eq!(resolve1.packages.len(), 1); + let (_, pkg) = resolve1.packages.iter().next().unwrap(); + assert_eq!(pkg.name.version.as_ref().unwrap().to_string(), "1.2.3"); + + let iface_id = pkg.interfaces["my-iface"]; + let iface = &resolve1.interfaces[iface_id]; + assert!(iface.types.contains_key("base-type")); + assert!(iface.types.contains_key("new-type")); + assert!(iface.functions.contains_key("base-func")); + assert!(iface.functions.contains_key("new-func")); + + Ok(()) + } + + #[test] + fn canon_names_merge_smaller_into_larger() -> Result<()> { + // The smaller version (from) is merged into the larger (into). + // The larger version's content should be preserved as-is. + let mut resolve1 = Resolve::default(); + resolve1.use_canonical_names = true; + resolve1.push_str( + "a.wit", + r#" + package foo:bar@1.2.3; + + interface my-iface { + type base-type = u32; + base-func: func(); + type new-type = string; + new-func: func() -> string; + } + "#, + )?; + + let mut resolve2 = Resolve::default(); + resolve2.push_str( + "b.wit", + r#" + package foo:bar@1.0.0; + + interface my-iface { + type base-type = u32; + base-func: func(); + } + "#, + )?; + + resolve1.merge(resolve2)?; + + assert_eq!(resolve1.packages.len(), 1); + let (_, pkg) = resolve1.packages.iter().next().unwrap(); + assert_eq!( + pkg.name.version.as_ref().unwrap().to_string(), + "1.2.3", + "should keep the larger version already in into" + ); + + let iface_id = pkg.interfaces["my-iface"]; + let iface = &resolve1.interfaces[iface_id]; + assert!(iface.types.contains_key("base-type")); + assert!(iface.types.contains_key("new-type")); + assert!(iface.functions.contains_key("base-func")); + assert!(iface.functions.contains_key("new-func")); + + Ok(()) + } + + #[test] + fn canon_names_different_tracks_not_merged() -> Result<()> { + let mut resolve1 = Resolve::default(); + resolve1.use_canonical_names = true; + resolve1.push_str( + "a.wit", + r#" + package foo:bar@0.1.0; + + interface iface-a { + type-a: func(); + } + "#, + )?; + + let mut resolve2 = Resolve::default(); + resolve2.push_str( + "b.wit", + r#" + package foo:bar@0.2.0; + + interface iface-b { + type-b: func(); + } + "#, + )?; + + resolve1.merge(resolve2)?; + + // Should have two separate packages + assert_eq!(resolve1.packages.len(), 2); + + Ok(()) + } } diff --git a/crates/wit-parser/tests/all.rs b/crates/wit-parser/tests/all.rs index e24e0e6a50..7b5e55396b 100644 --- a/crates/wit-parser/tests/all.rs +++ b/crates/wit-parser/tests/all.rs @@ -24,13 +24,42 @@ fn main() { let mut trials = Vec::new(); for test in tests { - let trial = Trial::test(format!("{test:?}"), move || { - Runner {} + let name = test + .file_stem() + .and_then(|s| s.to_str()) + .unwrap_or("") + .to_string(); + if name.starts_with("canon-names-") { + let trial = Trial::test(format!("{test:?}"), move || { + Runner { + use_canonical: true, + } .run(&test) .context(format!("test {test:?} failed")) .map_err(|e| format!("{e:?}").into()) - }); - trials.push(trial); + }); + trials.push(trial); + } else { + let test2 = test.clone(); + let trial = Trial::test(format!("{test:?}"), move || { + Runner { + use_canonical: false, + } + .run(&test) + .context(format!("test {test:?} failed")) + .map_err(|e| format!("{e:?}").into()) + }); + trials.push(trial); + let trial = Trial::test(format!("{test2:?}@canon-names"), move || { + Runner { + use_canonical: true, + } + .run(&test2) + .context(format!("test {test2:?}@canon-names failed")) + .map_err(|e| format!("{e:?}").into()) + }); + trials.push(trial); + } } let mut args = Arguments::from_args(); @@ -70,11 +99,14 @@ fn find_tests() -> Vec { } } -struct Runner {} +struct Runner { + use_canonical: bool, +} impl Runner { fn run(&mut self, test: &Path) -> Result<()> { let mut resolve = Resolve::new(); + resolve.use_canonical_names = self.use_canonical; resolve.features.insert("active".to_string()); let result = resolve.push_path(test); let result = if test.iter().any(|s| s == "parse-fail") { @@ -121,6 +153,16 @@ impl Runner { } else { test.with_extension(format!("wit.{extension}")) }; + let result_file = if self.use_canonical { + let canon_file = result_file.with_extension(format!("canon-names.{extension}")); + if env::var_os("BLESS").is_some() || canon_file.exists() { + canon_file + } else { + result_file + } + } else { + result_file + }; if env::var_os("BLESS").is_some() { let normalized = normalize(&result, extension); if let Ok(prev) = fs::read(&result_file) { diff --git a/crates/wit-parser/tests/ui/packages-nested-with-semver.wit.canon-names.json b/crates/wit-parser/tests/ui/packages-nested-with-semver.wit.canon-names.json new file mode 100644 index 0000000000..5cad06b08b --- /dev/null +++ b/crates/wit-parser/tests/ui/packages-nested-with-semver.wit.canon-names.json @@ -0,0 +1,75 @@ +{ + "worlds": [ + { + "name": "w1", + "imports": { + "interface-0": { + "interface": { + "id": 0 + } + }, + "imp1": { + "interface": { + "id": 1 + } + } + }, + "exports": {}, + "package": 0 + } + ], + "interfaces": [ + { + "name": "i1", + "types": { + "a": 0 + }, + "functions": {}, + "package": 0 + }, + { + "name": null, + "types": { + "a": 1 + }, + "functions": {}, + "package": 0 + } + ], + "types": [ + { + "name": "a", + "kind": { + "type": "u32" + }, + "owner": { + "interface": 0 + } + }, + { + "name": "a", + "kind": { + "type": 0 + }, + "owner": { + "interface": 1 + } + } + ], + "packages": [ + { + "name": "foo:name@1.0.1", + "interfaces": { + "i1": 0 + }, + "worlds": { + "w1": 0 + } + }, + { + "name": "foo:root", + "interfaces": {}, + "worlds": {} + } + ] +} \ No newline at end of file diff --git a/crates/wit-parser/tests/ui/parse-fail/export-twice.wit.result b/crates/wit-parser/tests/ui/parse-fail/export-twice.wit.result index ea6d0ecd7c..cc5f58aea4 100644 --- a/crates/wit-parser/tests/ui/parse-fail/export-twice.wit.result +++ b/crates/wit-parser/tests/ui/parse-fail/export-twice.wit.result @@ -1,4 +1,4 @@ -interface cannot be exported more than once +interface `foo` cannot be exported more than once --> tests/ui/parse-fail/export-twice.wit:7:10 | 7 | export foo; diff --git a/crates/wit-parser/tests/ui/parse-fail/import-twice.wit.result b/crates/wit-parser/tests/ui/parse-fail/import-twice.wit.result index d369190755..049391b608 100644 --- a/crates/wit-parser/tests/ui/parse-fail/import-twice.wit.result +++ b/crates/wit-parser/tests/ui/parse-fail/import-twice.wit.result @@ -1,4 +1,4 @@ -interface cannot be imported more than once +interface `foo` cannot be imported more than once --> tests/ui/parse-fail/import-twice.wit:7:10 | 7 | import foo; diff --git a/crates/wit-parser/tests/ui/version-syntax.wit.canon-names.json b/crates/wit-parser/tests/ui/version-syntax.wit.canon-names.json new file mode 100644 index 0000000000..1965925e5f --- /dev/null +++ b/crates/wit-parser/tests/ui/version-syntax.wit.canon-names.json @@ -0,0 +1,17 @@ +{ + "worlds": [], + "interfaces": [], + "types": [], + "packages": [ + { + "name": "a:b@1.0.1", + "interfaces": {}, + "worlds": {} + }, + { + "name": "foo:root", + "interfaces": {}, + "worlds": {} + } + ] +} \ No newline at end of file diff --git a/src/bin/wasm-tools/component.rs b/src/bin/wasm-tools/component.rs index 310658184f..d70b131762 100644 --- a/src/bin/wasm-tools/component.rs +++ b/src/bin/wasm-tools/component.rs @@ -14,8 +14,8 @@ use wasmparser::types::{CoreTypeId, EntityType, Types}; use wasmparser::{Payload, ValidPayload, WasmFeatures}; use wat::Detect; use wit_component::{ - ComponentEncoder, DecodedWasm, Linker, StringEncoding, WitPrinter, embed_component_metadata, - metadata, + ComponentEncoder, DecodedWasm, Linker, SemverCompat, StringEncoding, WitPrinter, + embed_component_metadata, metadata, }; use wit_parser::{LiftLowerAbi, Mangling, ManglingAndAbi, WorldItem, WorldKey}; @@ -148,12 +148,20 @@ pub struct NewOpts { #[clap(long)] realloc_via_memory_grow: bool, - /// Indicates whether imports into the final component are merged based on - /// semver ranges. + /// Controls how semver is used when resolving and encoding interfaces. /// - /// This is enabled by default. - #[clap(long, value_name = "")] - merge_imports_based_on_semver: Option, + /// Possible values: `none`, `merge` (default), `canonical`. + /// + /// - `none`: exact version matching, no merging. Same as the old flag + /// `merge_imports_based_on_semver = false`. + /// + /// - `merge`: merge imports based on semver. + /// Same as the old flag `merge_imports_based_on_semver = true`. + /// This is the default behavior. + /// + /// - `canonical`: merge imports based on the canonical version prefixes. + #[clap(long, value_name = "MODE")] + semver_compat: Option, /// Reject usage of the "legacy" naming scheme of `wit-component` and /// require the new naming scheme to be used. @@ -179,8 +187,8 @@ impl NewOpts { .validate(!self.skip_validation) .reject_legacy_names(self.reject_legacy_names); - if let Some(merge) = self.merge_imports_based_on_semver { - encoder = encoder.merge_imports_based_on_semver(merge); + if let Some(compat) = self.semver_compat { + encoder = encoder.semver_compat(compat); } encoder = encoder.module(&wasm)?; @@ -517,12 +525,11 @@ pub struct LinkOpts { #[clap(long)] use_built_in_libdl: bool, - /// Indicates whether imports into the final component are merged based on - /// semver ranges. + /// Controls how semver is used when resolving and encoding interfaces. /// - /// This is enabled by default. - #[arg(long, require_equals = true, value_name = "true|false")] - merge_imports_based_on_semver: Option>, + /// Possible values: `none`, `merge` (default), `canonical`. + #[arg(long, value_name = "MODE")] + semver_compat: Option, /// Whether or not to add debug names to the generated binary. #[arg(long, require_equals = true, value_name = "true|false")] @@ -554,8 +561,8 @@ impl LinkOpts { linker = linker.stack_size(stack_size); } - if let Some(merge) = self.merge_imports_based_on_semver { - linker = linker.merge_imports_based_on_semver(merge.unwrap_or(true)); + if let Some(compat) = self.semver_compat { + linker = linker.semver_compat(compat); } for (name, wasm) in &self.inputs {