Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Merge `wasmtime-math` into `wasmtime-core` (#12398)

Alex Crichton9acefdfee0c0
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 9a4c55b76f..3937129593 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -1179,6 +1179,8 @@ jobs:
- crate: "pulley-interpreter --all-features"
- crate: "wasmtime-internal-error"
- crate: "wasmtime-internal-error --all-features"
+ - crate: "wasmtime-internal-core"
+ - crate: "wasmtime-internal-core --all-features"
- script: ./ci/miri-provenance-test.sh
- script: ./ci/miri-wast.sh ./tests/spec_testsuite/table.wast
needs: determine
diff --git a/Cargo.lock b/Cargo.lock
index 345059d465..95504bae1e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -780,7 +780,7 @@ dependencies = [
"smallvec 1.15.1",
"souper-ir",
"target-lexicon",
- "wasmtime-internal-math",
+ "wasmtime-internal-core",
]
[[package]]
@@ -2810,7 +2810,7 @@ dependencies = [
"log",
"pulley-macros",
"termcolor",
- "wasmtime-internal-math",
+ "wasmtime-internal-core",
]
[[package]]
@@ -4543,11 +4543,11 @@ dependencies = [
"wasmtime-internal-cache",
"wasmtime-internal-component-macro",
"wasmtime-internal-component-util",
+ "wasmtime-internal-core",
"wasmtime-internal-cranelift",
"wasmtime-internal-fiber",
"wasmtime-internal-jit-debug",
"wasmtime-internal-jit-icache-coherence",
- "wasmtime-internal-math",
"wasmtime-internal-slab",
"wasmtime-internal-unwinder",
"wasmtime-internal-versioned-export-macros",
@@ -4863,6 +4863,7 @@ version = "42.0.0"
name = "wasmtime-internal-core"
version = "42.0.0"
dependencies = [
+ "libm",
"wasmtime-internal-error",
]
@@ -4886,7 +4887,7 @@ dependencies = [
"thiserror 2.0.17",
"wasmparser 0.244.0",
"wasmtime-environ",
- "wasmtime-internal-math",
+ "wasmtime-internal-core",
"wasmtime-internal-unwinder",
"wasmtime-internal-versioned-export-macros",
]
@@ -4956,13 +4957,6 @@ dependencies = [
"windows-sys 0.61.2",
]
-[[package]]
-name = "wasmtime-internal-math"
-version = "42.0.0"
-dependencies = [
- "libm",
-]
-
[[package]]
name = "wasmtime-internal-slab"
version = "42.0.0"
@@ -5412,8 +5406,8 @@ dependencies = [
"thiserror 2.0.17",
"wasmparser 0.244.0",
"wasmtime-environ",
+ "wasmtime-internal-core",
"wasmtime-internal-cranelift",
- "wasmtime-internal-math",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 387c14ba6e..1ae4258e11 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -280,7 +280,6 @@ wasmtime-versioned-export-macros = { path = "crates/versioned-export-macros", ve
wasmtime-slab = { path = "crates/slab", version = "=42.0.0", package = 'wasmtime-internal-slab' }
wasmtime-jit-icache-coherence = { path = "crates/jit-icache-coherence", version = "=42.0.0", package = 'wasmtime-internal-jit-icache-coherence' }
wasmtime-wit-bindgen = { path = "crates/wit-bindgen", version = "=42.0.0", package = 'wasmtime-internal-wit-bindgen' }
-wasmtime-math = { path = "crates/math", version = "=42.0.0", package = 'wasmtime-internal-math' }
wasmtime-unwinder = { path = "crates/unwinder", version = "=42.0.0", package = 'wasmtime-internal-unwinder' }
wasmtime-debugger = { path = "crates/debugger", version = "=42.0.0", package = "wasmtime-internal-debugger" }
wasmtime-wizer = { path = "crates/wizer", version = "42.0.0" }
diff --git a/cranelift/codegen/Cargo.toml b/cranelift/codegen/Cargo.toml
index e8cbe564d0..41df9ea4b5 100644
--- a/cranelift/codegen/Cargo.toml
+++ b/cranelift/codegen/Cargo.toml
@@ -43,7 +43,7 @@ regalloc2 = { workspace = true, features = ["checker"] }
souper-ir = { version = "2.1.0", optional = true }
sha2 = { version = "0.10.2", optional = true }
rustc-hash = { workspace = true }
-wasmtime-math = { workspace = true }
+wasmtime-core = { workspace = true }
libm = { workspace = true }
# It is a goal of the cranelift-codegen crate to have minimal external dependencies.
# Please don't add any unless they are essential to the task of creating binary
diff --git a/cranelift/codegen/src/isa/riscv64/lower/isle.rs b/cranelift/codegen/src/isa/riscv64/lower/isle.rs
index a2a7d0c196..258b3f248b 100644
--- a/cranelift/codegen/src/isa/riscv64/lower/isle.rs
+++ b/cranelift/codegen/src/isa/riscv64/lower/isle.rs
@@ -24,7 +24,7 @@ use crate::{
use alloc::boxed::Box;
use alloc::vec::Vec;
use regalloc2::PReg;
-use wasmtime_math::{f32_cvt_to_int_bounds, f64_cvt_to_int_bounds};
+use wasmtime_core::math::{f32_cvt_to_int_bounds, f64_cvt_to_int_bounds};
type BoxCallInfo = Box<CallInfo<ExternalName>>;
type BoxCallIndInfo = Box<CallInfo<Reg>>;
diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml
index baf65f36d2..0f941d02e5 100644
--- a/crates/core/Cargo.toml
+++ b/crates/core/Cargo.toml
@@ -11,8 +11,10 @@ version.workspace = true
# This crate should have *very* minimal dependencies! Don't add new ones
# lightly.
wasmtime-error = { workspace = true }
+libm = { workspace = true }
[lints]
workspace = true
[features]
+std = []
diff --git a/crates/core/src/alloc/arc.rs b/crates/core/src/alloc/arc.rs
index 021a487ea2..fcd2d98750 100644
--- a/crates/core/src/alloc/arc.rs
+++ b/crates/core/src/alloc/arc.rs
@@ -26,3 +26,13 @@ impl<T> TryNew for Arc<T> {
return Ok(Arc::new(value));
}
}
+
+#[cfg(test)]
+mod test {
+ use super::{Arc, TryNew};
+
+ #[test]
+ fn try_new() {
+ <Arc<_> as TryNew>::try_new(4).unwrap();
+ }
+}
diff --git a/crates/core/src/alloc/boxed.rs b/crates/core/src/alloc/boxed.rs
index 94f6db6e32..65483f4112 100644
--- a/crates/core/src/alloc/boxed.rs
+++ b/crates/core/src/alloc/boxed.rs
@@ -193,6 +193,11 @@ mod tests {
}
}
+ #[test]
+ fn try_new() {
+ <Box<_> as TryNew>::try_new(4).unwrap();
+ }
+
#[test]
fn new_boxed_slice_from_iter_smoke_test() {
let slice = new_boxed_slice_from_iter(3, [42, 36, 1337]).unwrap();
diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs
index be9b081271..08ad1e8dfa 100644
--- a/crates/core/src/lib.rs
+++ b/crates/core/src/lib.rs
@@ -12,4 +12,8 @@
extern crate alloc as std_alloc;
+#[cfg(feature = "std")]
+extern crate std;
+
pub mod alloc;
+pub mod math;
diff --git a/crates/math/src/lib.rs b/crates/core/src/math.rs
similarity index 98%
rename from crates/math/src/lib.rs
rename to crates/core/src/math.rs
index dee07f6645..abd959701b 100644
--- a/crates/math/src/lib.rs
+++ b/crates/core/src/math.rs
@@ -1,4 +1,4 @@
-//! A minimal helper crate for implementing float-related operations for
+//! A minimal module for implementing float-related operations for
//! WebAssembly in terms of the native platform primitives.
//!
//! > **⚠️ Warning ⚠️**: this crate is an internal-only crate for the Wasmtime
@@ -23,10 +23,7 @@
//! needed so they're implemented only in a single location here rather than
//! multiple.
-#![no_std]
-
-#[cfg(feature = "std")]
-extern crate std;
+#![allow(missing_docs, reason = "self-describing methods")]
/// Returns the bounds for guarding a trapping f32-to-int conversion.
///
diff --git a/crates/cranelift/Cargo.toml b/crates/cranelift/Cargo.toml
index e0a574353e..f8f54cf7fa 100644
--- a/crates/cranelift/Cargo.toml
+++ b/crates/cranelift/Cargo.toml
@@ -32,7 +32,7 @@ cfg-if = { workspace = true }
wasmtime-versioned-export-macros = { workspace = true }
itertools = { workspace = true }
pulley-interpreter = { workspace = true, optional = true }
-wasmtime-math = { workspace = true }
+wasmtime-core = { workspace = true }
wasmtime-unwinder = { workspace = true, features = ["cranelift"] }
[features]
diff --git a/crates/cranelift/src/func_environ.rs b/crates/cranelift/src/func_environ.rs
index eb9581f9e3..601ce017ff 100644
--- a/crates/cranelift/src/func_environ.rs
+++ b/crates/cranelift/src/func_environ.rs
@@ -22,6 +22,7 @@ use cranelift_frontend::{FuncInstBuilder, FunctionBuilder};
use smallvec::{SmallVec, smallvec};
use std::mem;
use wasmparser::{FuncValidator, Operator, WasmFeatures, WasmModuleResources};
+use wasmtime_core::math::f64_cvt_to_int_bounds;
use wasmtime_environ::{
BuiltinFunctionIndex, DataIndex, DefinedFuncIndex, ElemIndex, EngineOrModuleTypeIndex,
FrameStateSlotBuilder, FrameValType, FuncIndex, FuncKey, GlobalIndex, IndexType, Memory,
@@ -31,7 +32,6 @@ use wasmtime_environ::{
WasmValType,
};
use wasmtime_environ::{FUNCREF_INIT_BIT, FUNCREF_MASK};
-use wasmtime_math::f64_cvt_to_int_bounds;
#[derive(Debug)]
pub(crate) enum Extension {
diff --git a/crates/math/Cargo.toml b/crates/math/Cargo.toml
deleted file mode 100644
index 4de0881fcb..0000000000
--- a/crates/math/Cargo.toml
+++ /dev/null
@@ -1,22 +0,0 @@
-[package]
-name = "wasmtime-internal-math"
-version.workspace = true
-authors.workspace = true
-description = "INTERNAL: Low-level math routines used in Wasmtime"
-documentation = "https://docs.rs/wasmtime-math"
-license = "Apache-2.0 WITH LLVM-exception"
-repository = "https://github.com/bytecodealliance/wasmtime"
-edition.workspace = true
-rust-version.workspace = true
-
-[lints]
-workspace = true
-
-[package.metadata.docs.rs]
-all-features = true
-
-[features]
-std = []
-
-[dependencies]
-libm = { workspace = true }
diff --git a/crates/wasmtime/Cargo.toml b/crates/wasmtime/Cargo.toml
index 3150d21822..bc8faefbe7 100644
--- a/crates/wasmtime/Cargo.toml
+++ b/crates/wasmtime/Cargo.toml
@@ -30,7 +30,7 @@ wasmtime-component-util = { workspace = true, optional = true }
wasmtime-slab = { workspace = true, optional = true }
wasmtime-versioned-export-macros = { workspace = true }
wasmtime-wmemcheck = { workspace = true, optional = true }
-wasmtime-math = { workspace = true }
+wasmtime-core = { workspace = true }
pulley-interpreter = { workspace = true }
target-lexicon = { workspace = true }
wasmparser = { workspace = true }
@@ -347,7 +347,7 @@ std = [
'once_cell',
'wasmtime-fiber?/std',
'pulley-interpreter/std',
- 'wasmtime-math/std',
+ 'wasmtime-core/std',
'addr2line?/std',
"dep:rustix",
"wasmtime-jit-icache-coherence",
diff --git a/crates/wasmtime/src/runtime/vm/libcalls.rs b/crates/wasmtime/src/runtime/vm/libcalls.rs
index ac3a6be0a1..6330c9dfa7 100644
--- a/crates/wasmtime/src/runtime/vm/libcalls.rs
+++ b/crates/wasmtime/src/runtime/vm/libcalls.rs
@@ -69,6 +69,7 @@ use core::convert::Infallible;
use core::ptr::NonNull;
#[cfg(feature = "threads")]
use core::time::Duration;
+use wasmtime_core::math::WasmFloat;
use wasmtime_environ::{
DataIndex, DefinedMemoryIndex, DefinedTableIndex, ElemIndex, FuncIndex, MemoryIndex,
TableIndex, Trap,
@@ -1492,35 +1493,35 @@ fn update_mem_size(store: &mut dyn VMStore, instance: InstanceId, num_pages: u32
}
fn floor_f32(_store: &mut dyn VMStore, _instance: InstanceId, val: f32) -> f32 {
- wasmtime_math::WasmFloat::wasm_floor(val)
+ val.wasm_floor()
}
fn floor_f64(_store: &mut dyn VMStore, _instance: InstanceId, val: f64) -> f64 {
- wasmtime_math::WasmFloat::wasm_floor(val)
+ val.wasm_floor()
}
fn ceil_f32(_store: &mut dyn VMStore, _instance: InstanceId, val: f32) -> f32 {
- wasmtime_math::WasmFloat::wasm_ceil(val)
+ val.wasm_ceil()
}
fn ceil_f64(_store: &mut dyn VMStore, _instance: InstanceId, val: f64) -> f64 {
- wasmtime_math::WasmFloat::wasm_ceil(val)
+ val.wasm_ceil()
}
fn trunc_f32(_store: &mut dyn VMStore, _instance: InstanceId, val: f32) -> f32 {
- wasmtime_math::WasmFloat::wasm_trunc(val)
+ val.wasm_trunc()
}
fn trunc_f64(_store: &mut dyn VMStore, _instance: InstanceId, val: f64) -> f64 {
- wasmtime_math::WasmFloat::wasm_trunc(val)
+ val.wasm_trunc()
}
fn nearest_f32(_store: &mut dyn VMStore, _instance: InstanceId, val: f32) -> f32 {
- wasmtime_math::WasmFloat::wasm_nearest(val)
+ val.wasm_nearest()
}
fn nearest_f64(_store: &mut dyn VMStore, _instance: InstanceId, val: f64) -> f64 {
- wasmtime_math::WasmFloat::wasm_nearest(val)
+ val.wasm_nearest()
}
// This intrinsic is only used on x86_64 platforms as an implementation of
@@ -1658,10 +1659,10 @@ fn fma_f32x4(
U {
mem: [
- wasmtime_math::WasmFloat::wasm_mul_add(x[0], y[0], z[0]),
- wasmtime_math::WasmFloat::wasm_mul_add(x[1], y[1], z[1]),
- wasmtime_math::WasmFloat::wasm_mul_add(x[2], y[2], z[2]),
- wasmtime_math::WasmFloat::wasm_mul_add(x[3], y[3], z[3]),
+ x[0].wasm_mul_add(y[0], z[0]),
+ x[1].wasm_mul_add(y[1], z[1]),
+ x[2].wasm_mul_add(y[2], z[2]),
+ x[3].wasm_mul_add(y[3], z[3]),
],
}
.reg
@@ -1686,10 +1687,7 @@ fn fma_f64x2(
let z = U { reg: z }.mem;
U {
- mem: [
- wasmtime_math::WasmFloat::wasm_mul_add(x[0], y[0], z[0]),
- wasmtime_math::WasmFloat::wasm_mul_add(x[1], y[1], z[1]),
- ],
+ mem: [x[0].wasm_mul_add(y[0], z[0]), x[1].wasm_mul_add(y[1], z[1])],
}
.reg
}
diff --git a/pulley/Cargo.toml b/pulley/Cargo.toml
index f1cdb79706..8e4b46c189 100644
--- a/pulley/Cargo.toml
+++ b/pulley/Cargo.toml
@@ -16,7 +16,7 @@ workspace = true
arbitrary = { workspace = true, optional = true }
cranelift-bitset = { workspace = true }
log = { workspace = true }
-wasmtime-math = { workspace = true, optional = true }
+wasmtime-core = { workspace = true, optional = true }
anyhow = { workspace = true, optional = true }
pulley-macros = { workspace = true }
@@ -27,12 +27,12 @@ clap = { workspace = true }
termcolor = { workspace = true }
[features]
-std = ['wasmtime-math?/std']
+std = ['wasmtime-core?/std']
arbitrary = ["dep:arbitrary", "arbitrary/derive", "std", "cranelift-bitset/arbitrary"]
encode = []
decode = []
disas = ["decode"]
-interp = ["decode", "encode", "dep:wasmtime-math"]
+interp = ["decode", "encode", "dep:wasmtime-core"]
profile = ['std', 'dep:anyhow']
[package.metadata.docs.rs]
diff --git a/pulley/src/interp.rs b/pulley/src/interp.rs
index ec076e6422..aac2cbac85 100644
--- a/pulley/src/interp.rs
+++ b/pulley/src/interp.rs
@@ -13,7 +13,7 @@ use core::ops::ControlFlow;
use core::ops::{Index, IndexMut};
use core::ptr::NonNull;
use pulley_macros::interp_disable_if_cfg;
-use wasmtime_math::{WasmFloat, f32_cvt_to_int_bounds, f64_cvt_to_int_bounds};
+use wasmtime_core::math::{WasmFloat, f32_cvt_to_int_bounds, f64_cvt_to_int_bounds};
mod debug;
#[cfg(all(not(pulley_tail_calls), not(pulley_assume_llvm_makes_tail_calls)))]
diff --git a/scripts/publish.rs b/scripts/publish.rs
index 91c94ee21f..965609b79d 100644
--- a/scripts/publish.rs
+++ b/scripts/publish.rs
@@ -21,7 +21,6 @@ const CRATES_TO_PUBLISH: &[&str] = &[
"wasmtime-internal-error",
"wasmtime-internal-core",
"cranelift-bitset",
- "wasmtime-internal-math",
"pulley-macros",
"pulley-interpreter",
// cranelift
diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml
index 4bc1fa8207..73328b52a2 100644
--- a/supply-chain/audits.toml
+++ b/supply-chain/audits.toml
@@ -1006,6 +1006,14 @@ start = "2026-01-07"
end = "2027-01-08"
notes = "The Bytecode Alliance is the author of this crate"
+[[wildcard-audits.wasmtime-internal-core]]
+who = "Alex Crichton <[email protected]>"
+criteria = "safe-to-deploy"
+trusted-publisher = "github:bytecodealliance/wasmtime"
+start = "2026-01-07"
+end = "2027-01-08"
+notes = "The Bytecode Alliance is the author of this crate"
+
[[wildcard-audits.wasmtime-internal-cranelift]]
who = "Alex Crichton <[email protected]>"
criteria = "safe-to-deploy"
@@ -5774,6 +5782,12 @@ criteria = "safe-to-deploy"
delta = "0.243.0 -> 0.244.0"
notes = "The Bytecode Alliance is the author of this crate"
+[[audits.wasmtime-internal-core]]
+who = "Alex Crichton <[email protected]>"
+criteria = "safe-to-deploy"
+version = "0.0.0"
+notes = "Empty crate"
+
[[audits.wasmtime-wasi-tls-openssl]]
who = "Dave Bakker <[email protected]>"
criteria = "safe-to-deploy"
diff --git a/supply-chain/config.toml b/supply-chain/config.toml
index 92a1c51466..ccb2b85ddb 100644
--- a/supply-chain/config.toml
+++ b/supply-chain/config.toml
@@ -139,6 +139,9 @@ audit-as-crates-io = true
[policy.wasmtime-internal-component-util]
audit-as-crates-io = true
+[policy.wasmtime-internal-core]
+audit-as-crates-io = true
+
[policy.wasmtime-internal-cranelift]
audit-as-crates-io = true
@@ -160,9 +163,6 @@ audit-as-crates-io = true
[policy.wasmtime-internal-jit-icache-coherence]
audit-as-crates-io = true
-[policy.wasmtime-internal-math]
-audit-as-crates-io = true
-
[policy.wasmtime-internal-slab]
audit-as-crates-io = true
diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock
index be0ba310a5..0b60d6e173 100644
--- a/supply-chain/imports.lock
+++ b/supply-chain/imports.lock
@@ -125,6 +125,10 @@ audited_as = "40.0.1"
version = "42.0.0"
audited_as = "40.0.1"
+[[unpublished.wasmtime-internal-core]]
+version = "42.0.0"
+audited_as = "0.0.0"
+
[[unpublished.wasmtime-internal-cranelift]]
version = "42.0.0"
audited_as = "40.0.1"
@@ -1334,11 +1338,6 @@ version = "40.0.1"
when = "2026-01-07"
trusted-publisher = "github:bytecodealliance/wasmtime"
-[[publisher.wasmtime-internal-math]]
-version = "40.0.1"
-when = "2026-01-07"
-trusted-publisher = "github:bytecodealliance/wasmtime"
-
[[publisher.wasmtime-internal-slab]]
version = "40.0.1"
when = "2026-01-07"
diff --git a/winch/codegen/Cargo.toml b/winch/codegen/Cargo.toml
index 7925888889..d7672fd724 100644
--- a/winch/codegen/Cargo.toml
+++ b/winch/codegen/Cargo.toml
@@ -26,7 +26,7 @@ gimli = { workspace = true }
wasmtime-environ = { workspace = true }
wasmtime-cranelift = { workspace = true }
thiserror = { workspace = true }
-wasmtime-math = { workspace = true }
+wasmtime-core = { workspace = true }
[features]
x64 = ["cranelift-codegen/x86"]
diff --git a/winch/codegen/src/isa/aarch64/asm.rs b/winch/codegen/src/isa/aarch64/asm.rs
index 3d5b52b183..d64b98e9a1 100644
--- a/winch/codegen/src/isa/aarch64/asm.rs
+++ b/winch/codegen/src/isa/aarch64/asm.rs
@@ -32,7 +32,7 @@ use cranelift_codegen::{
settings,
};
use regalloc2::RegClass;
-use wasmtime_math::{f32_cvt_to_int_bounds, f64_cvt_to_int_bounds};
+use wasmtime_core::math::{f32_cvt_to_int_bounds, f64_cvt_to_int_bounds};
impl From<OperandSize> for inst::OperandSize {
fn from(size: OperandSize) -> Self {