From 1e9b6ea4ee836473b0d5cf0e179ebd3bd669fb8d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 21 Nov 2022 10:41:31 -0800 Subject: [PATCH 1/3] Remove the `wit_component::ComponentInterfaces` type This was a temporary holdover until a `World` existed in `wit-parser`, which it now does, so remove the old type. --- crates/wit-component/src/decoding.rs | 54 ++---------------- crates/wit-component/src/encoding.rs | 35 +++++------- crates/wit-component/src/lib.rs | 2 +- crates/wit-component/src/metadata.rs | 70 +++++++++++------------- crates/wit-component/src/validation.rs | 8 +-- crates/wit-component/tests/components.rs | 18 +++--- crates/wit-component/tests/interfaces.rs | 28 +++++----- crates/wit-parser/src/lib.rs | 10 ++++ src/bin/wasm-tools/component.rs | 9 +-- 9 files changed, 89 insertions(+), 145 deletions(-) diff --git a/crates/wit-component/src/decoding.rs b/crates/wit-component/src/decoding.rs index 91dcb668e7..50f3b46494 100644 --- a/crates/wit-component/src/decoding.rs +++ b/crates/wit-component/src/decoding.rs @@ -85,54 +85,6 @@ struct InterfaceDecoder<'a> { name_map: IndexMap, &'a str>, } -/// Parsed representation of interfaces found within a component. -/// -/// This is more-or-less a "world" and will likely be replaced one day with a -/// `wit-parser` representation of a world. -#[derive(Clone, Default)] -pub struct ComponentInterfaces { - /// The "default export" which is the interface directly exported from the - /// component at the top level. - pub default: Option, - /// Imported interfaces, keyed by name, of the component. - pub imports: IndexMap, - /// Exported interfaces, keyed by name, of the component. - pub exports: IndexMap, -} - -impl ComponentInterfaces { - /// Returns an iterator which visits all the exported interfaces, both named - /// and default. The second entry in each pair the export name of the - /// interface, or `None` if it's the default export interface. - pub fn exports(&self) -> impl Iterator)> + '_ { - self.exports - .iter() - .map(|(name, i)| (i, Some(name.as_str()))) - .chain(self.default.iter().map(|i| (i, None))) - } - - /// Converts back into a `wit_parser::World` - pub fn into_world(self, name: &str) -> wit_parser::World { - wit_parser::World { - imports: self.imports, - exports: self.exports, - default: self.default, - name: name.to_string(), - docs: Default::default(), - } - } -} - -impl From for ComponentInterfaces { - fn from(world: wit_parser::World) -> ComponentInterfaces { - ComponentInterfaces { - exports: world.exports, - imports: world.imports, - default: world.default, - } - } -} - /// Decode the interfaces imported and exported by a component. /// /// This function takes a binary component as input and will infer the @@ -146,7 +98,7 @@ impl From for ComponentInterfaces { /// /// This can fail if the input component is invalid or otherwise isn't of the /// expected shape. At this time not all component shapes are supported here. -pub fn decode_component_interfaces(bytes: &[u8]) -> Result { +pub fn decode_world(name: &str, bytes: &[u8]) -> Result { let info = ComponentInfo::new(bytes)?; let mut imports = IndexMap::new(); let mut exports = IndexMap::new(); @@ -224,7 +176,9 @@ pub fn decode_component_interfaces(bytes: &[u8]) -> Result Some(InterfaceDecoder::new(&info).decode(default.iter().map(|(n, t)| (*n, *t)))?) }; - Ok(ComponentInterfaces { + Ok(World { + name: name.to_string(), + docs: Default::default(), imports, exports, default, diff --git a/crates/wit-component/src/encoding.rs b/crates/wit-component/src/encoding.rs index 2af0440240..717e11b477 100644 --- a/crates/wit-component/src/encoding.rs +++ b/crates/wit-component/src/encoding.rs @@ -58,7 +58,7 @@ use crate::{ validate_adapter_module, validate_module, ValidatedAdapter, ValidatedModule, MAIN_MODULE_IMPORT_NAME, }, - ComponentInterfaces, StringEncoding, + StringEncoding, }; use anyhow::{anyhow, bail, Context, Result}; use indexmap::{map::Entry, IndexMap, IndexSet}; @@ -69,7 +69,7 @@ use wasmparser::{FuncType, Validator, WasmFeatures}; use wit_parser::{ abi::{AbiVariant, WasmSignature, WasmType}, Enum, Flags, Function, FunctionKind, Interface, Params, Record, Result_, Results, Tuple, Type, - TypeDef, TypeDefKind, Union, Variant, + TypeDef, TypeDefKind, Union, Variant, World, }; const INDIRECT_TABLE_NAME: &str = "$imports"; @@ -1300,7 +1300,7 @@ impl<'a> EncodingState<'a> { instance_index: u32, realloc_index: Option, ) -> Result<()> { - for (export, export_name) in metadata.interfaces.exports() { + for (export, export_name) in metadata.world.exports() { let mut interface_exports = Vec::new(); // Make sure all named types are present in the exported instance @@ -2169,13 +2169,8 @@ impl ComponentEncoder { /// /// The string encoding of the specified interface set is supplied here as /// well. - pub fn interfaces( - mut self, - interfaces: ComponentInterfaces, - encoding: StringEncoding, - ) -> Result { - self.metadata - .merge(BindgenMetadata::new(interfaces, encoding))?; + pub fn world(mut self, world: World, encoding: StringEncoding) -> Result { + self.metadata.merge(BindgenMetadata::new(world, encoding))?; Ok(self) } @@ -2225,15 +2220,11 @@ impl ComponentEncoder { let mut state = EncodingState::default(); let mut types = TypeEncoder::default(); let mut imports = ImportEncoder::default(); - types.encode_func_types(self.metadata.interfaces.exports().map(|p| p.0))?; - types.encode_instance_imports( - &self.metadata.interfaces.imports, - info.as_ref(), - &mut imports, - )?; + types.encode_func_types(self.metadata.world.exports().map(|p| p.0))?; + types.encode_instance_imports(&self.metadata.world.imports, info.as_ref(), &mut imports)?; for (_name, (_, metadata)) in self.adapters.iter() { - types.encode_func_types(metadata.interfaces.exports().map(|p| p.0))?; + types.encode_func_types(metadata.world.exports().map(|p| p.0))?; } if self.types_only { @@ -2248,7 +2239,7 @@ impl ComponentEncoder { // itself. let mut raw_exports = Vec::new(); let mut default_exports = Vec::new(); - for (interface, name) in self.metadata.interfaces.exports() { + for (interface, name) in self.metadata.world.exports() { match name { Some(name) => { let index = types @@ -2310,13 +2301,13 @@ impl ComponentEncoder { .context("failed to validate the imports of the minimized adapter module")?; state.encode_core_adapter_module(name, &wasm); for (name, required) in info.required_imports.iter() { - let interface = &metadata.interfaces.imports[*name]; + let interface = &metadata.world.imports[*name]; types.encode_instance_import(name, interface, Some(required), &mut imports)?; } imports.adapters.insert(name, info); } - for (interface, _default) in self.metadata.interfaces.exports() { + for (interface, _default) in self.metadata.world.exports() { types.encode_interface_named_types(interface)?; } @@ -2332,7 +2323,7 @@ impl ComponentEncoder { state.realloc_index, )?; for (name, (_, metadata)) in self.adapters.iter() { - if metadata.interfaces.exports().count() == 0 { + if metadata.world.exports().count() == 0 { continue; } state.encode_exports( @@ -2373,7 +2364,7 @@ fn required_adapter_exports( required.insert(name.to_string(), ty.clone()); } } - for (interface, name) in metadata.interfaces.exports() { + for (interface, name) in metadata.world.exports() { for func in interface.functions.iter() { let name = func.core_export_name(name); let ty = interface.wasm_signature(AbiVariant::GuestExport, func); diff --git a/crates/wit-component/src/lib.rs b/crates/wit-component/src/lib.rs index 2b0b8d2e65..bc0161506a 100644 --- a/crates/wit-component/src/lib.rs +++ b/crates/wit-component/src/lib.rs @@ -13,7 +13,7 @@ mod gc; mod printing; mod validation; -pub use decoding::{decode_component_interfaces, ComponentInterfaces}; +pub use decoding::decode_world; pub use encoding::*; pub use printing::*; diff --git a/crates/wit-component/src/metadata.rs b/crates/wit-component/src/metadata.rs index 462b150b3b..cec29c5566 100644 --- a/crates/wit-component/src/metadata.rs +++ b/crates/wit-component/src/metadata.rs @@ -16,9 +16,9 @@ //! per-language-binding-generation and consumed by slurping up all the //! sections during the component creation process. //! -//! The custom section here contains `ComponentInterfaces`, the interpretation -//! of a "world" of a component, along with how strings are encoded for all the -//! specified interfaces. Currently the encoding is: +//! The custom section here contains `World`, the interpretation of a "world" +//! of a component, along with how strings are encoded for all the specified +//! interfaces. Currently the encoding is: //! //! * First, a version byte (`CURRENT_VERSION`). This is intended to detect //! mismatches between different versions of the binding generator and @@ -26,12 +26,15 @@ //! //! * Next a string encoding byte. //! -//! * Afterwards a "types only" component encoding of a `ComponentInterfaces` +//! * Afterwards a "types only" component encoding of a `World` //! package through the `ComponentEncoder::types_only` configuration. -use crate::{decode_component_interfaces, ComponentEncoder, ComponentInterfaces, StringEncoding}; -use anyhow::{anyhow, bail, Context, Result}; +use crate::{decode_world, ComponentEncoder, StringEncoding}; +use anyhow::{bail, Context, Result}; use indexmap::IndexMap; +use wasm_encoder::Encode; +use wasmparser::BinaryReader; +use wit_parser::World; const CURRENT_VERSION: u8 = 0x01; @@ -40,9 +43,8 @@ const CURRENT_VERSION: u8 = 0x01; /// This structure is returned by the [`extract_module_interfaces`] function. #[derive(Default)] pub struct BindgenMetadata { - /// All interfaces found within a module, merged together into one set of - /// `ComponentInterfaces`. - pub interfaces: ComponentInterfaces, + /// All interfaces found within a module, merged together into one `World`. + pub world: World, /// Per-function options imported into the core wasm module, currently only /// related to string encoding. @@ -97,10 +99,10 @@ pub fn decode(wasm: &[u8]) -> Result<(Vec, BindgenMetadata)> { /// into the final core wasm binary. The core wasm binary is later fed /// through `wit-component` to produce the actual component where this returned /// section will be decoded. -pub fn encode(interfaces: &ComponentInterfaces, encoding: StringEncoding) -> Vec { +pub fn encode(world: &World, encoding: StringEncoding) -> Vec { let component = ComponentEncoder::default() .types_only(true) - .interfaces(interfaces.clone(), encoding) + .world(world.clone(), encoding) .unwrap() .encode() .unwrap(); @@ -112,45 +114,42 @@ pub fn encode(interfaces: &ComponentInterfaces, encoding: StringEncoding) -> Vec StringEncoding::UTF16 => 0x01, StringEncoding::CompactUTF16 => 0x02, }); + world.name.encode(&mut ret); ret.extend(component); ret } impl BindgenMetadata { fn decode(data: &[u8]) -> Result { - let mut data = data.iter(); - let version = *data - .next() - .ok_or_else(|| anyhow!("component-type metadata section"))?; + let mut reader = BinaryReader::new(data); + let version = reader.read_u8()?; if version != CURRENT_VERSION { bail!("component-type version {version} does not match supported version {CURRENT_VERSION}"); } - let encoding = match data - .next() - .ok_or_else(|| anyhow!("component-type metadata section"))? - { + let encoding = match reader.read_u8()? { 0x00 => StringEncoding::UTF8, 0x01 => StringEncoding::UTF16, 0x02 => StringEncoding::CompactUTF16, byte => bail!("invalid string encoding {byte:#x}"), }; + let name = reader.read_string()?; Ok(BindgenMetadata::new( - decode_component_interfaces(data.as_slice())?, + decode_world(name, &data[reader.original_position()..])?, encoding, )) } /// Creates a new `BindgenMetadata` instance holding the given set of /// interfaces which are expected to all use the `encoding` specified. - pub fn new(interfaces: ComponentInterfaces, encoding: StringEncoding) -> BindgenMetadata { + pub fn new(world: World, encoding: StringEncoding) -> BindgenMetadata { let mut ret = BindgenMetadata { - interfaces, + world, import_encodings: Default::default(), export_encodings: Default::default(), }; - if let Some(iface) = &ret.interfaces.default { + if let Some(iface) = &ret.world.default { for func in iface.functions.iter() { let name = func.core_export_name(None); let prev = ret.export_encodings.insert(name.to_string(), encoding); @@ -158,14 +157,14 @@ impl BindgenMetadata { } } - for (name, import) in ret.interfaces.imports.iter() { + for (name, import) in ret.world.imports.iter() { for func in import.functions.iter() { let key = (name.clone(), func.name.clone()); let prev = ret.import_encodings.insert(key, encoding); assert!(prev.is_none()); } } - for (name, export) in ret.interfaces.exports.iter() { + for (name, export) in ret.world.exports.iter() { for func in export.functions.iter() { let name = func.core_export_name(Some(name)); let prev = ret.export_encodings.insert(name.to_string(), encoding); @@ -186,12 +185,7 @@ impl BindgenMetadata { /// between metadata. pub fn merge(&mut self, other: BindgenMetadata) -> Result<()> { let BindgenMetadata { - interfaces: - ComponentInterfaces { - imports, - exports, - default, - }, + world, import_encodings, export_encodings, } = other; @@ -199,23 +193,23 @@ impl BindgenMetadata { // TODO: instead of returning an error here on duplicate interfaces // this should merge the two interfaces. This probably requires world // files to exist first though. - for (name, import) in imports { - let prev = self.interfaces.imports.insert(name.clone(), import); + for (name, import) in world.imports { + let prev = self.world.imports.insert(name.clone(), import); if prev.is_some() { bail!("import interface `{name}` specified twice"); } } - for (name, export) in exports { - let prev = self.interfaces.exports.insert(name.clone(), export); + for (name, export) in world.exports { + let prev = self.world.exports.insert(name.clone(), export); if prev.is_some() { bail!("export interface `{name}` specified twice"); } } - if let Some(default) = default { - if self.interfaces.default.is_some() { + if let Some(default) = world.default { + if self.world.default.is_some() { bail!("default export interface specified twice"); } - self.interfaces.default = Some(default); + self.world.default = Some(default); } for (name, encoding) in export_encodings { diff --git a/crates/wit-component/src/validation.rs b/crates/wit-component/src/validation.rs index b6a1d2103a..ffa9091658 100644 --- a/crates/wit-component/src/validation.rs +++ b/crates/wit-component/src/validation.rs @@ -160,7 +160,7 @@ pub fn validate_module<'a>( bail!("module imports from an empty module name"); } - match metadata.interfaces.imports.get(*name) { + match metadata.world.imports.get(*name) { Some(interface) => { validate_imported_interface(interface, name, funcs, &types)?; let funcs = funcs.into_iter().map(|(f, _ty)| *f).collect(); @@ -178,11 +178,11 @@ pub fn validate_module<'a>( } } - if let Some(interface) = &metadata.interfaces.default { + if let Some(interface) = &metadata.world.default { validate_exported_interface(interface, None, &export_funcs, &types)?; } - for (name, interface) in metadata.interfaces.exports.iter() { + for (name, interface) in metadata.world.exports.iter() { if name.is_empty() { bail!("cannot export an interface with an empty name"); } @@ -336,7 +336,7 @@ pub fn validate_adapter_module<'a>( .extend(funcs.iter().map(|(name, _ty)| name.to_string())); } else { let interface = metadata - .interfaces + .world .imports .get(name) .ok_or_else(|| anyhow!("adapter module imports unknown module `{name}`"))?; diff --git a/crates/wit-component/tests/components.rs b/crates/wit-component/tests/components.rs index 27e0da105f..af11ba2ba3 100644 --- a/crates/wit-component/tests/components.rs +++ b/crates/wit-component/tests/components.rs @@ -2,21 +2,21 @@ use anyhow::{bail, Context, Result}; use pretty_assertions::assert_eq; use std::{fs, path::Path}; use wasm_encoder::{Encode, Section}; -use wit_component::{ComponentEncoder, ComponentInterfaces, StringEncoding}; +use wit_component::{ComponentEncoder, StringEncoding}; use wit_parser::World; -fn read_adapters(dir: &Path) -> Result, ComponentInterfaces)>> { +fn read_adapters(dir: &Path) -> Result, World)>> { glob::glob(dir.join("adapt-*.wat").to_str().unwrap())? .map(|p| { let p = p?; let adapter = wat::parse_file(&p).with_context(|| format!("expected file `{}`", p.display()))?; let stem = p.file_stem().unwrap().to_str().unwrap(); - let interfaces = read_component_interfaces(dir, &format!("{stem}-"))?; + let world = read_world(dir, &format!("{stem}-"))?; Ok(( stem.trim_start_matches("adapt-").to_string(), adapter, - interfaces, + world, )) }) .collect::>() @@ -69,7 +69,7 @@ fn component_encoding_via_flags() -> Result<()> { let mut encoder = ComponentEncoder::default() .module(&module)? .validate(true) - .interfaces(read_component_interfaces(&path, "")?, StringEncoding::UTF8)?; + .world(read_world(&path, "")?, StringEncoding::UTF8)?; encoder = add_adapters(encoder, &path)?; assert_output(test_case, &encoder, &component_path, &error_path)?; @@ -112,8 +112,8 @@ fn component_encoding_via_custom_sections() -> Result<()> { // Create the `component-type` custom section which will encode all of // the type information about imported/exported functions. - let interfaces = read_component_interfaces(&path, "")?; - let contents = wit_component::metadata::encode(&interfaces, StringEncoding::UTF8); + let world = read_world(&path, "")?; + let contents = wit_component::metadata::encode(&world, StringEncoding::UTF8); let section = wasm_encoder::CustomSection { name: "component-type", data: &contents, @@ -131,9 +131,9 @@ fn component_encoding_via_custom_sections() -> Result<()> { Ok(()) } -fn read_component_interfaces(path: &Path, prefix: &str) -> Result { +fn read_world(path: &Path, prefix: &str) -> Result { let world_path = path.join(&format!("{prefix}world.wit")); - Ok(World::parse_file(&world_path)?.into()) + World::parse_file(&world_path) } fn add_adapters(mut encoder: ComponentEncoder, path: &Path) -> Result { diff --git a/crates/wit-component/tests/interfaces.rs b/crates/wit-component/tests/interfaces.rs index 63c3cf404b..ea929b6104 100644 --- a/crates/wit-component/tests/interfaces.rs +++ b/crates/wit-component/tests/interfaces.rs @@ -2,7 +2,7 @@ use anyhow::{Context, Result}; use pretty_assertions::assert_eq; use std::fs; use std::path::Path; -use wit_component::{ComponentEncoder, ComponentInterfaces, StringEncoding}; +use wit_component::{ComponentEncoder, StringEncoding}; use wit_parser::abi::{AbiVariant, WasmType}; use wit_parser::{Function, Interface, World}; @@ -43,7 +43,6 @@ fn run_test(path: &Path) -> Result<()> { let world_path = path.join("world.wit"); let world = World::parse_file(&world_path)?; let world_name = world.name.clone(); - let interfaces = ComponentInterfaces::from(world); let assert_output = |wasm: &[u8], wat: &Path| -> Result<()> { let output = wasmprinter::print_bytes(wasm)?; @@ -59,19 +58,18 @@ fn run_test(path: &Path) -> Result<()> { ); } - let decoded = wit_component::decode_component_interfaces(wasm) + let decoded = wit_component::decode_world(&world_name, wasm) .context(format!("failed to decode bytes for test `{test_case}`"))?; if test_case == "empty" { return Ok(()); } - assert_eq!(decoded.imports.len(), interfaces.imports.len()); - assert_eq!(decoded.exports.len(), interfaces.exports.len()); - assert_eq!(decoded.default.is_some(), interfaces.default.is_some()); + assert_eq!(decoded.imports.len(), world.imports.len()); + assert_eq!(decoded.exports.len(), world.exports.len()); + assert_eq!(decoded.default.is_some(), world.default.is_some()); - let world = decoded.into_world(&world_name); - assert_wit(&world_path, &world)?; + assert_wit(&world_path, &decoded)?; Ok(()) }; @@ -83,7 +81,7 @@ fn run_test(path: &Path) -> Result<()> { let bytes = ComponentEncoder::default() .types_only(true) .validate(true) - .interfaces(interfaces.clone(), StringEncoding::UTF8)? + .world(world.clone(), StringEncoding::UTF8)? .encode() .with_context(|| { format!("failed to encode a types-only component for test case `{test_case}`") @@ -95,11 +93,11 @@ fn run_test(path: &Path) -> Result<()> { // recover the original `*.wit` interfaces from the component output. println!("test dummy module"); - let module = dummy_module(&interfaces); + let module = dummy_module(&world); let bytes = ComponentEncoder::default() .module(&module)? .validate(true) - .interfaces(interfaces.clone(), StringEncoding::UTF8)? + .world(world.clone(), StringEncoding::UTF8)? .encode() .with_context(|| format!("failed to encode a component for test case `{test_case}`"))?; assert_output(&bytes, &path.join("component.wat"))?; @@ -124,10 +122,10 @@ fn assert_wit(wit_path: &Path, world: &World) -> Result<()> { Ok(()) } -fn dummy_module(interfaces: &ComponentInterfaces) -> Vec { +fn dummy_module(world: &World) -> Vec { let mut wat = String::new(); wat.push_str("(module\n"); - for (name, import) in interfaces.imports.iter() { + for (name, import) in world.imports.iter() { for func in import.functions.iter() { let sig = import.wasm_signature(AbiVariant::GuestImport, func); @@ -138,14 +136,14 @@ fn dummy_module(interfaces: &ComponentInterfaces) -> Vec { } } - for (name, export) in interfaces.exports.iter() { + for (name, export) in world.exports.iter() { for func in export.functions.iter() { let name = func.core_export_name(Some(name)); push_func(&mut wat, &name, export, func); } } - if let Some(default) = &interfaces.default { + if let Some(default) = &world.default { for func in default.functions.iter() { push_func(&mut wat, &func.name, default, func); } diff --git a/crates/wit-parser/src/lib.rs b/crates/wit-parser/src/lib.rs index f47ccdd88a..f591648736 100644 --- a/crates/wit-parser/src/lib.rs +++ b/crates/wit-parser/src/lib.rs @@ -69,6 +69,16 @@ impl World { } } } + + /// Returns an iterator which visits all the exported interfaces, both named + /// and default. The second entry in each pair the export name of the + /// interface, or `None` if it's the default export interface. + pub fn exports(&self) -> impl Iterator)> + '_ { + self.exports + .iter() + .map(|(name, i)| (i, Some(name.as_str()))) + .chain(self.default.iter().map(|i| (i, None))) + } } #[derive(Debug, Clone, Default, PartialEq)] diff --git a/src/bin/wasm-tools/component.rs b/src/bin/wasm-tools/component.rs index c28d564fd5..6502e82600 100644 --- a/src/bin/wasm-tools/component.rs +++ b/src/bin/wasm-tools/component.rs @@ -4,7 +4,7 @@ use anyhow::{Context, Result}; use clap::Parser; use std::path::{Path, PathBuf}; use wasm_tools::Output; -use wit_component::{decode_component_interfaces, ComponentEncoder, StringEncoding, WorldPrinter}; +use wit_component::{decode_world, ComponentEncoder, StringEncoding, WorldPrinter}; use wit_parser::World; /// WebAssembly wit-based component tooling. @@ -122,7 +122,7 @@ impl NewOpts { if let Some(wit) = &self.wit { let encoding = self.encoding.unwrap_or(StringEncoding::UTF8); let world = World::parse_file(wit)?; - encoder = encoder.interfaces(world.into(), encoding)?; + encoder = encoder.world(world, encoding)?; } for (name, wasm) in self.adapters.iter() { @@ -168,10 +168,7 @@ impl WitOpts { }, }; - let interfaces = - decode_component_interfaces(&bytes).context("failed to decode component")?; - let world = interfaces.into_world(name); - + let world = decode_world(name, &bytes).context("failed to decode world")?; let mut printer = WorldPrinter::default(); let output = printer.print(&world)?; self.io.output(Output::Wat(&output))?; From 6dfc33fa95689ec05292fe5ec867180e3842b578 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 21 Nov 2022 11:41:11 -0800 Subject: [PATCH 2/3] Review comments --- crates/wit-component/src/decoding.rs | 2 +- crates/wit-component/src/encoding.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/wit-component/src/decoding.rs b/crates/wit-component/src/decoding.rs index 50f3b46494..2001423a79 100644 --- a/crates/wit-component/src/decoding.rs +++ b/crates/wit-component/src/decoding.rs @@ -85,7 +85,7 @@ struct InterfaceDecoder<'a> { name_map: IndexMap, &'a str>, } -/// Decode the interfaces imported and exported by a component. +/// Decode the world described by the given component bytes. /// /// This function takes a binary component as input and will infer the /// `Interface` representation of its imports and exports. More-or-less this diff --git a/crates/wit-component/src/encoding.rs b/crates/wit-component/src/encoding.rs index 717e11b477..0626f90e03 100644 --- a/crates/wit-component/src/encoding.rs +++ b/crates/wit-component/src/encoding.rs @@ -2167,7 +2167,7 @@ impl ComponentEncoder { /// Add a "world" of interfaces (exports/imports/default) to this encoder /// to configure what's being imported/exported. /// - /// The string encoding of the specified interface set is supplied here as + /// The string encoding of the specified world is supplied here as /// well. pub fn world(mut self, world: World, encoding: StringEncoding) -> Result { self.metadata.merge(BindgenMetadata::new(world, encoding))?; From fabfd5499cae774a0dd973f57ad7bc2498623233 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 21 Nov 2022 11:42:03 -0800 Subject: [PATCH 3/3] More comment updates --- crates/wit-component/src/decoding.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/wit-component/src/decoding.rs b/crates/wit-component/src/decoding.rs index 2001423a79..a31d05650f 100644 --- a/crates/wit-component/src/decoding.rs +++ b/crates/wit-component/src/decoding.rs @@ -88,12 +88,11 @@ struct InterfaceDecoder<'a> { /// Decode the world described by the given component bytes. /// /// This function takes a binary component as input and will infer the -/// `Interface` representation of its imports and exports. More-or-less this -/// will infer the "world" from a binary component. The binary component at this -/// time is either a "types only" component produced by `wit-component` or an -/// actual output of `wit-component`. +/// `World` representation of its imports and exports. The binary component at +/// this time is either a "types only" component produced by `wit-component` or +/// an actual output of `wit-component`. /// -/// The returned interfaces represent the description of imports and exports +/// The returned world represents the description of imports and exports /// from the component. /// /// This can fail if the input component is invalid or otherwise isn't of the