Skip to content

Commit fc3302a

Browse files
authored
Update spec test suite (#10611)
Now that wasm-tools is updated it's possible to run the latest version again. This notably required implementing the `extern.convert_any` and `any.convert_extern` instructions in a const-expression context.
1 parent 3326ff9 commit fc3302a

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

crates/environ/src/types.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,8 @@ pub enum ConstOp {
17421742
array_type_index: TypeIndex,
17431743
array_size: u32,
17441744
},
1745+
ExternConvertAny,
1746+
AnyConvertExtern,
17451747
}
17461748

17471749
impl ConstOp {
@@ -1783,6 +1785,8 @@ impl ConstOp {
17831785
array_type_index: TypeIndex::from_u32(array_type_index),
17841786
array_size,
17851787
},
1788+
O::ExternConvertAny => Self::ExternConvertAny,
1789+
O::AnyConvertExtern => Self::AnyConvertExtern,
17861790
op => {
17871791
return Err(wasm_unsupported!(
17881792
"unsupported opcode in const expression at offset {offset:#x}: {op:?}",

crates/wasmtime/src/runtime/vm/const_expr.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use crate::prelude::*;
44
use crate::runtime::vm::{Instance, VMGcRef, ValRaw, I31};
55
use crate::store::{AutoAssertNoGc, StoreOpaque};
66
#[cfg(feature = "gc")]
7-
use crate::{ArrayRef, ArrayRefPre, ArrayType, StructRef, StructRefPre, StructType, Val};
7+
use crate::{
8+
AnyRef, ArrayRef, ArrayRefPre, ArrayType, ExternRef, StructRef, StructRefPre, StructType, Val,
9+
};
810
use smallvec::SmallVec;
911
use wasmtime_environ::{ConstExpr, ConstOp, FuncIndex, GlobalIndex};
1012
#[cfg(feature = "gc")]
@@ -224,7 +226,9 @@ impl ConstExprEvaluator {
224226
| ConstOp::StructNewDefault { .. }
225227
| ConstOp::ArrayNew { .. }
226228
| ConstOp::ArrayNewDefault { .. }
227-
| ConstOp::ArrayNewFixed { .. } => {
229+
| ConstOp::ArrayNewFixed { .. }
230+
| ConstOp::ExternConvertAny
231+
| ConstOp::AnyConvertExtern => {
228232
bail!(
229233
"const expr evaluation error: struct operations are not \
230234
supported without the `gc` feature"
@@ -334,6 +338,28 @@ impl ConstExprEvaluator {
334338
self.stack
335339
.push(ValRaw::anyref(array.to_anyref()._to_raw(&mut store)?));
336340
}
341+
342+
#[cfg(feature = "gc")]
343+
ConstOp::ExternConvertAny => {
344+
let result = match AnyRef::_from_raw(&mut store, self.pop()?.get_anyref()) {
345+
Some(anyref) => {
346+
ExternRef::_convert_any(&mut store, anyref)?._to_raw(&mut store)?
347+
}
348+
None => 0,
349+
};
350+
self.stack.push(ValRaw::externref(result));
351+
}
352+
353+
#[cfg(feature = "gc")]
354+
ConstOp::AnyConvertExtern => {
355+
let result =
356+
match ExternRef::_from_raw(&mut store, self.pop()?.get_externref()) {
357+
Some(externref) => AnyRef::_convert_extern(&mut store, externref)?
358+
._to_raw(&mut store)?,
359+
None => 0,
360+
};
361+
self.stack.push(ValRaw::anyref(result));
362+
}
337363
}
338364
}
339365

0 commit comments

Comments
 (0)