Skip to content

Commit 6a82bd7

Browse files
authored
Add a few doc comments around validation, and fix some typos. (#2154)
1 parent a55cb83 commit 6a82bd7

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

crates/wasm-encoder/src/component/builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl ComponentBuilder {
134134
/// Instantiates a core wasm module at `module_index` with the `args`
135135
/// provided.
136136
///
137-
/// Returns the index of the core wasm instance crated.
137+
/// Returns the index of the core wasm instance created.
138138
pub fn core_instantiate<'a, A>(&mut self, module_index: u32, args: A) -> u32
139139
where
140140
A: IntoIterator<Item = (&'a str, ModuleArg)>,
@@ -146,7 +146,7 @@ impl ComponentBuilder {
146146

147147
/// Creates a new core wasm instance from the `exports` provided.
148148
///
149-
/// Returns the index of the core wasm instance crated.
149+
/// Returns the index of the core wasm instance created.
150150
pub fn core_instantiate_exports<'a, E>(&mut self, exports: E) -> u32
151151
where
152152
E: IntoIterator<Item = (&'a str, ExportKind, u32)>,
@@ -159,7 +159,7 @@ impl ComponentBuilder {
159159
/// Creates a new aliased item where the core `instance` specified has its
160160
/// export `name` aliased out with the `kind` specified.
161161
///
162-
/// Returns the index of the item crated.
162+
/// Returns the index of the item created.
163163
pub fn core_alias_export(&mut self, instance: u32, name: &str, kind: ExportKind) -> u32 {
164164
self.alias(Alias::CoreInstanceExport {
165165
instance,

crates/wasm-encoder/src/reencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ pub enum Error<E = Infallible> {
548548
InvalidCodeSectionSize,
549549
/// There was a section that does not belong into a core wasm module.
550550
UnexpectedNonCoreModuleSection,
551-
/// There was a section that does not belong into a compoennt module.
551+
/// There was a section that does not belong into a component module.
552552
UnexpectedNonComponentSection,
553553
/// A core type definition was found in a component that's not supported.
554554
UnsupportedCoreTypeInComponent,

crates/wasmparser/src/validator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ pub enum ValidPayload<'a> {
346346
/// This result indicates that the specified parser should be used instead
347347
/// of the currently-used parser until this returned one ends.
348348
Parser(Parser),
349-
/// A function was found to be validate.
349+
/// A function was found to be validated.
350350
Func(FuncToValidate<ValidatorResources>, FunctionBody<'a>),
351351
/// The end payload was validated and the types known to the validator
352352
/// are provided.

crates/wit-component/src/encoding.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ impl<'a> EncodingState<'a> {
15261526
// For import modules that are a "bag of names" iterate over
15271527
// each name and materialize it into this component with the
15281528
// `materialize_import` helper. This is then all bottled up into
1529-
// a bag-of-exports instances which is then used for
1529+
// a bag-of-exports instance which is then used for
15301530
// instantiation.
15311531
ImportInstance::Names(names) => {
15321532
let mut exports = Vec::new();
@@ -1585,7 +1585,7 @@ impl<'a> EncodingState<'a> {
15851585
))
15861586
}
15871587

1588-
// Adapters might uset he main module's memory, in which case it
1588+
// Adapters might use the main module's memory, in which case it
15891589
// should have been previously instantiated.
15901590
Import::MainModuleMemory => {
15911591
let index = self
@@ -2681,7 +2681,7 @@ pub struct ComponentEncoder {
26812681
impl ComponentEncoder {
26822682
/// Set the core module to encode as a component.
26832683
/// This method will also parse any component type information stored in custom sections
2684-
/// inside the module, and add them as the interface, imports, and exports.
2684+
/// inside the module and add them as the interface, imports, and exports.
26852685
/// It will also add any producers information inside the component type information to the
26862686
/// core module.
26872687
pub fn module(mut self, module: &[u8]) -> Result<Self> {

crates/wit-component/src/validation.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ impl Hash for PayloadInfo {
181181
/// The different kinds of items that a module or an adapter can import.
182182
///
183183
/// This is intended to be an exhaustive definition of what can be imported into
184-
/// core modules within a component that wit-component supports.
184+
/// core modules within a component that wit-component supports. This doesn't
185+
/// get down to the level of storing any idx numbers; at its most specific, it
186+
/// gives a name.
185187
#[derive(Debug, Clone)]
186188
pub enum Import {
187189
/// A top-level world function, with the name provided here, is imported
@@ -449,7 +451,8 @@ impl ImportMap {
449451
&self.names
450452
}
451453

452-
/// Helper function used during validation to build up this `ImportMap`.
454+
/// Classify an import and call `insert_import()` on it. Used during
455+
/// validation to build up this `ImportMap`.
453456
fn add(
454457
&mut self,
455458
import: wasmparser::Import<'_>,
@@ -469,6 +472,11 @@ impl ImportMap {
469472
self.insert_import(import, item)
470473
}
471474

475+
/// Determines what kind of thing is being imported: maps it from the
476+
/// module/name/type triple in the raw wasm module to an enum.
477+
///
478+
/// Handles a few special cases, then delegates to
479+
/// `classify_component_model_import()`.
472480
fn classify(
473481
&self,
474482
import: wasmparser::Import<'_>,
@@ -980,6 +988,9 @@ impl ImportMap {
980988
Ok(true)
981989
}
982990

991+
/// Map an imported item, by module and field name in `self.names`, to the
992+
/// kind of `Import` it is: for example, a certain-typed function from an
993+
/// adapter.
983994
fn insert_import(&mut self, import: wasmparser::Import<'_>, item: Import) -> Result<()> {
984995
let entry = self
985996
.names

0 commit comments

Comments
 (0)