Skip to content

Commit ae0905d

Browse files
committed
Resolve straightforward comments
1 parent df6d920 commit ae0905d

File tree

25 files changed

+146
-112
lines changed

25 files changed

+146
-112
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cli-flags/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ wasmtime_option_group! {
501501
#[derive(PartialEq, Clone, Deserialize)]
502502
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
503503
pub struct RecordOptions {
504-
/// Filesystem endpoint to store the recorded execution trace (empty string "" for void endpoint)
504+
/// Filename for the recorded execution trace (or empty string to skip writing a file).
505505
pub path: Option<String>,
506506
/// Include (optional) signatures to facilitate validation checks during replay
507507
/// (see `wasmtime replay` for details).
@@ -568,12 +568,12 @@ pub struct CommonOptions {
568568

569569
/// Options to enable and configure execution recording, `-R help` to see all.
570570
///
571-
/// Generates of a serialized trace of the Wasm module execution that captures all
571+
/// Generates a serialized trace of the Wasm module execution that captures all
572572
/// non-determinism observable by the module. This trace can subsequently be
573573
/// re-executed in a determinstic, embedding-agnostic manner (see the `wasmtime replay` command).
574574
///
575-
/// Note: Minimal configs for deterministic Wasm semantics will be
576-
/// enforced during recording by default (NaN canonicalization, deterministic relaxed SIMD)
575+
/// Note: Minimal configuration options for deterministic Wasm semantics will be
576+
/// enforced during recording by default (NaN canonicalization, deterministic relaxed SIMD).
577577
#[arg(short = 'R', long = "record", value_name = "KEY[=VAL[,..]]")]
578578
#[serde(skip)]
579579
record_raw: Vec<opt::CommaSeparated<Record>>,

crates/environ/src/compile/module_artifacts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Definitions of runtime structures and metadata which are serialized into ELF
22
//! with `postcard` as part of a module's compilation process.
33
4+
use crate::WasmChecksum;
45
use crate::prelude::*;
56
use crate::{
67
CompiledModuleInfo, DebugInfoData, FunctionName, MemoryInitialization, Metadata,
@@ -9,7 +10,6 @@ use crate::{
910
use anyhow::{Result, bail};
1011
use object::SectionKind;
1112
use object::write::{Object, SectionId, StandardSegment, WritableBuffer};
12-
use sha2::{Digest, Sha256};
1313
use std::ops::Range;
1414

1515
/// Helper structure to create an ELF file as a compilation artifact.
@@ -222,7 +222,7 @@ impl<'a> ObjectBuilder<'a> {
222222
has_wasm_debuginfo: self.tunables.parse_wasm_debuginfo,
223223
dwarf,
224224
},
225-
checksum: Sha256::digest(wasm).into(),
225+
checksum: WasmChecksum::from_binary(wasm),
226226
})
227227
}
228228

crates/environ/src/component/artifacts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! which are serialized with `bincode` into output ELF files.
33
44
use crate::{
5-
CompiledFunctionsTable, CompiledModuleInfo, PrimaryMap, StaticModuleIndex,
5+
CompiledFunctionsTable, CompiledModuleInfo, PrimaryMap, StaticModuleIndex, WasmChecksum,
66
component::{Component, ComponentTypes, TypeComponentIndex},
77
};
88
use serde_derive::{Deserialize, Serialize};
@@ -20,8 +20,8 @@ pub struct ComponentArtifacts {
2020
pub types: ComponentTypes,
2121
/// Serialized metadata about all included core wasm modules.
2222
pub static_modules: PrimaryMap<StaticModuleIndex, CompiledModuleInfo>,
23-
/// A SHA-256 checksum of the source Wasm binary from which the component was compiled
24-
pub checksum: [u8; 32],
23+
/// A checksum of the source Wasm binary from which the component was compiled.
24+
pub checksum: WasmChecksum,
2525
}
2626

2727
/// Runtime state that a component retains to support its operation.

crates/environ/src/component/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl ComponentTypes {
379379
/// The intention of this method is to determine the flat ABI on host-to-wasm
380380
/// transitions (return from hostcall, or entry into wasmcall). When the type is
381381
/// not encodable in flat types, the values are all lowered to memory, implied by
382-
/// the pointer storage
382+
/// the pointer storage.
383383
pub fn flat_types_storage_or_pointer(
384384
&self,
385385
ty: &InterfaceType,
@@ -391,6 +391,7 @@ impl ComponentTypes {
391391
);
392392
self.flat_types_storage_inner(ty, limit).unwrap_or_else(|| {
393393
let mut flat = FlatTypesStorage::new();
394+
// Pointer representation for wasm32 and wasm64 respectively
394395
flat.push(FlatType::I32, FlatType::I64);
395396
flat
396397
})

crates/environ/src/module_artifacts.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use core::{fmt, u32};
88
use core::{iter, str};
99
use cranelift_entity::{EntityRef, PrimaryMap};
1010
use serde_derive::{Deserialize, Serialize};
11+
use sha2::{Digest, Sha256};
1112

1213
/// Description of where a function is located in the text section of a
1314
/// compiled image.
@@ -28,6 +29,28 @@ impl FunctionLoc {
2829
}
2930
}
3031

32+
/// The checksum of a Wasm binary.
33+
///
34+
/// Allows for features requiring the exact same Wasm Module (e.g. deterministic replay)
35+
/// to verify that the binary used matches the one originally compiled.
36+
#[derive(Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Debug, Serialize, Deserialize)]
37+
pub struct WasmChecksum([u8; 32]);
38+
39+
impl WasmChecksum {
40+
/// Construct a [`WasmChecksum`] from the given wasm binary.
41+
pub fn from_binary(bin: &[u8]) -> WasmChecksum {
42+
WasmChecksum(Sha256::digest(bin).into())
43+
}
44+
}
45+
46+
impl core::ops::Deref for WasmChecksum {
47+
type Target = [u8; 32];
48+
49+
fn deref(&self) -> &Self::Target {
50+
&self.0
51+
}
52+
}
53+
3154
/// A builder for a `CompiledFunctionsTable`.
3255
pub struct CompiledFunctionsTableBuilder {
3356
inner: CompiledFunctionsTable,
@@ -546,8 +569,8 @@ pub struct CompiledModuleInfo {
546569
/// Sorted list, by function index, of names we have for this module.
547570
pub func_names: Vec<FunctionName>,
548571

549-
/// Checksum of the source Wasm binary from which this module was compiled
550-
pub checksum: [u8; 32],
572+
/// Checksum of the source Wasm binary from which this module was compiled.
573+
pub checksum: WasmChecksum,
551574
}
552575

553576
/// The name of a function stored in the

crates/wasmtime/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ bitflags = { workspace = true }
6464
futures = { workspace = true, features = ["alloc"], optional = true }
6565
bytes = { workspace = true, optional = true }
6666
embedded-io = { version = "0.6.1", features = ["alloc"], optional = true }
67-
sha2 = { workspace = true }
6867

6968
[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
7069
workspace = true

crates/wasmtime/src/compile.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ use crate::Engine;
2626
use crate::hash_map::HashMap;
2727
use crate::hash_set::HashSet;
2828
use crate::prelude::*;
29-
#[cfg(feature = "component-model")]
30-
use sha2::{Digest, Sha256};
3129
use std::{any::Any, borrow::Cow, collections::BTreeMap, mem, ops::Range};
3230

3331
use call_graph::CallGraph;
@@ -38,7 +36,7 @@ use wasmtime_environ::{
3836
CompiledFunctionsTableBuilder, CompiledModuleInfo, Compiler, DefinedFuncIndex, FilePos,
3937
FinishedObject, FuncKey, FunctionBodyData, InliningCompiler, IntraModuleInlining,
4038
ModuleEnvironment, ModuleTranslation, ModuleTypes, ModuleTypesBuilder, ObjectKind, PrimaryMap,
41-
StaticModuleIndex, Tunables,
39+
StaticModuleIndex, Tunables, WasmChecksum,
4240
};
4341

4442
mod call_graph;
@@ -208,7 +206,7 @@ pub(crate) fn build_component_artifacts<T: FinishedObject>(
208206
ty,
209207
types,
210208
static_modules: compilation_artifacts.modules,
211-
checksum: Sha256::digest(binary).into(),
209+
checksum: WasmChecksum::from_binary(binary),
212210
};
213211
object.serialize_info(&artifacts);
214212

crates/wasmtime/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl Default for ModuleVersionStrategy {
9292
impl core::hash::Hash for ModuleVersionStrategy {
9393
fn hash<H: core::hash::Hasher>(&self, hasher: &mut H) {
9494
match self {
95-
Self::WasmtimeVersion => env!("CARGO_PKG_VERSION_MAJOR").hash(hasher),
95+
Self::WasmtimeVersion => env!("CARGO_PKG_VERSION").hash(hasher),
9696
Self::Custom(s) => s.hash(hasher),
9797
Self::None => {}
9898
};

crates/wasmtime/src/runtime/component/component.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use wasmtime_environ::component::{
2020
GlobalInitializer, InstantiateModule, NameMapNoIntern, OptionsIndex, StaticModuleIndex,
2121
TrampolineIndex, TypeComponentIndex, TypeFuncIndex, UnsafeIntrinsic, VMComponentOffsets,
2222
};
23-
use wasmtime_environ::{Abi, CompiledFunctionsTable, FuncKey, TypeTrace};
23+
use wasmtime_environ::{Abi, CompiledFunctionsTable, FuncKey, TypeTrace, WasmChecksum};
2424
use wasmtime_environ::{FunctionLoc, HostPtr, ObjectKind, PrimaryMap};
2525

2626
/// A compiled WebAssembly Component.
@@ -95,8 +95,8 @@ struct ComponentInner {
9595
/// locks when calling `realloc` via `TypedFunc::call_raw`.
9696
realloc_func_type: Arc<FuncType>,
9797

98-
/// The SHA-256 checksum of the source binary
99-
checksum: [u8; 32],
98+
/// The checksum of the source binary from which the module was compiled.
99+
checksum: WasmChecksum,
100100
}
101101

102102
pub(crate) struct AllCallFuncPointers {
@@ -875,7 +875,7 @@ impl Component {
875875
reason = "used only for verification with wasmtime `rr` feature \
876876
and requires a lot of unnecessary gating across crates"
877877
)]
878-
pub(crate) fn checksum(&self) -> &[u8; 32] {
878+
pub(crate) fn checksum(&self) -> &WasmChecksum {
879879
&self.inner.checksum
880880
}
881881

0 commit comments

Comments
 (0)