Skip to content

Commit

Permalink
Move conditional default initialization to its own method
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottt committed May 3, 2024
1 parent 68bc800 commit 15838b4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
34 changes: 14 additions & 20 deletions crates/wasmtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1728,30 +1728,24 @@ impl Config {
self
}

pub(crate) fn validate(mut self) -> Result<(Self, Tunables)> {
pub(crate) fn conditionally_enable_defaults(&mut self) {
// Enable tail calls by default when cranelift is going to be used as the compilation
// strategy, and we're not targeting s390x, which currently lacks tail-call support.
match self.tunables.tail_callable {
None => {
#[cfg(feature = "cranelift")]
let default_tail_calls = self.compiler_config.strategy == Strategy::Cranelift
&& self.compiler_config.target.as_ref().map_or_else(
|| target_lexicon::Triple::host().architecture,
|triple| triple.architecture,
) != Architecture::S390x;
#[cfg(not(feature = "cranelift"))]
let default_tail_calls = false;

self.features
.set(WasmFeatures::TAIL_CALL, default_tail_calls);
self.tunables.tail_callable = Some(default_tail_calls);
}
if self.tunables.tail_callable.is_none() {
#[cfg(feature = "cranelift")]
let default_tail_calls = self.compiler_config.strategy == Strategy::Cranelift
&& self.compiler_config.target.as_ref().map_or_else(
|| target_lexicon::Triple::host().architecture,
|triple| triple.architecture,
) != Architecture::S390x;
#[cfg(not(feature = "cranelift"))]
let default_tail_calls = false;

Some(val) => {
self.features.set(WasmFeatures::TAIL_CALL, val);
}
self.wasm_tail_call(default_tail_calls);
}
}

pub(crate) fn validate(&self) -> Result<Tunables> {
if self.features.contains(WasmFeatures::REFERENCE_TYPES)
&& !self.features.contains(WasmFeatures::BULK_MEMORY)
{
Expand Down Expand Up @@ -1843,7 +1837,7 @@ impl Config {
bail!("static memory guard size cannot be smaller than dynamic memory guard size");
}

Ok((self, tunables))
Ok(tunables)
}

#[cfg(feature = "runtime")]
Expand Down
8 changes: 7 additions & 1 deletion crates/wasmtime/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ impl Engine {
crate::runtime::vm::debug_builtins::ensure_exported();
}

let (config, tunables) = config.clone().validate()?;
let config = {
let mut config = config.clone();
config.conditionally_enable_defaults();
config
};

let tunables = config.clone().validate()?;

#[cfg(any(feature = "cranelift", feature = "winch"))]
let (config, compiler) = config.build_compiler(&tunables)?;
Expand Down

0 comments on commit 15838b4

Please sign in to comment.