Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honor ModuleVersionStrategy in Engine::precompile_compatibility_hash #6457

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/wasmtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ impl Default for ModuleVersionStrategy {
}
}

impl std::hash::Hash for ModuleVersionStrategy {
fn hash<H: std::hash::Hasher>(&self, hasher: &mut H) {
match self {
Self::WasmtimeVersion => env!("CARGO_PKG_VERSION").hash(hasher),
Self::Custom(s) => s.hash(hasher),
Self::None => {}
};
}
}

/// Global configuration options used to create an [`Engine`](crate::Engine)
/// and customize its behavior.
///
Expand Down
29 changes: 28 additions & 1 deletion crates/wasmtime/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ mod tests {
hash::{Hash, Hasher},
};

use crate::{Config, Engine, Module, OptLevel};
use crate::{Config, Engine, Module, ModuleVersionStrategy, OptLevel};

use anyhow::Result;
use tempfile::TempDir;
Expand Down Expand Up @@ -727,4 +727,31 @@ mod tests {
let opt_speed_hash = hash_for_config(&cfg);
assert_ne!(opt_none_hash, opt_speed_hash)
}

#[test]
fn precompile_compatibility_key_accounts_for_module_version_strategy() -> Result<()> {
fn hash_for_config(cfg: &Config) -> u64 {
let engine = Engine::new(cfg).expect("Config should be valid");
let mut hasher = DefaultHasher::new();
engine.precompile_compatibility_hash().hash(&mut hasher);
hasher.finish()
}
let mut cfg_custom_version = Config::new();
cfg_custom_version.module_version(ModuleVersionStrategy::Custom("1.0.1111".to_string()))?;
let custom_version_hash = hash_for_config(&cfg_custom_version);

let mut cfg_default_version = Config::new();
cfg_default_version.module_version(ModuleVersionStrategy::WasmtimeVersion)?;
let default_version_hash = hash_for_config(&cfg_default_version);

let mut cfg_none_version = Config::new();
cfg_none_version.module_version(ModuleVersionStrategy::None)?;
let none_version_hash = hash_for_config(&cfg_none_version);

assert_ne!(custom_version_hash, default_version_hash);
assert_ne!(custom_version_hash, none_version_hash);
assert_ne!(default_version_hash, none_version_hash);

Ok(())
}
}
2 changes: 1 addition & 1 deletion crates/wasmtime/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ impl std::hash::Hash for HashedEngineCompileEnv<'_> {
config.features.hash(hasher);

// Catch accidental bugs of reusing across crate versions.
env!("CARGO_PKG_VERSION").hash(hasher);
config.module_version.hash(hasher);
}
}

Expand Down