Use floats for wasmtime::component::Val::Float* (#5510)

The definitions of `wasmtime::component::Val::Float{32,64}` mirrored
`wasmtime::Val::F{32,64}` by using integers as their wrapped types,
storing the bit representation of their floating point values.
This was necessary for the core Wasm `f32`/`f64` types because Rust
floats don't have guaranteed NaN bit representations.

The component model `float32`/`float64` types require NaN
canonicalization, so we can use normal Rust `f{32,64}` instead.

Closes #5480
This commit is contained in:
Lann
2023-01-03 15:23:38 -05:00
committed by GitHub
parent 7e94704264
commit 0029ff95ac
4 changed files with 33 additions and 41 deletions

View File

@@ -18,8 +18,8 @@ pub fn val(v: &WastVal<'_>, ty: &Type) -> Result<Val> {
WastVal::S32(b) => Val::S32(*b),
WastVal::U64(b) => Val::U64(*b),
WastVal::S64(b) => Val::S64(*b),
WastVal::Float32(b) => Val::Float32(b.bits),
WastVal::Float64(b) => Val::Float64(b.bits),
WastVal::Float32(b) => Val::Float32(f32::from_bits(b.bits)),
WastVal::Float64(b) => Val::Float64(f64::from_bits(b.bits)),
WastVal::Char(b) => Val::Char(*b),
WastVal::String(s) => Val::String(s.to_string().into()),
WastVal::List(vals) => match ty {
@@ -173,11 +173,11 @@ pub fn match_val(expected: &WastVal<'_>, actual: &Val) -> Result<()> {
_ => mismatch(expected, actual),
},
WastVal::Float32(e) => match actual {
Val::Float32(a) => core::match_f32(*a, &NanPattern::Value(*e)),
Val::Float32(a) => core::match_f32(a.to_bits(), &NanPattern::Value(*e)),
_ => mismatch(expected, actual),
},
WastVal::Float64(e) => match actual {
Val::Float64(a) => core::match_f64(*a, &NanPattern::Value(*e)),
Val::Float64(a) => core::match_f64(a.to_bits(), &NanPattern::Value(*e)),
_ => mismatch(expected, actual),
},
WastVal::Char(e) => match actual {