Skip to content

Commit 83b22a2

Browse files
committed
stack-switching: add stub Val::ContRef
This type is not fully complete until continuation/gc integration is revisited (#10248) but without these changes, test cases are now failing on panics as we need some representation of continuation references in the runtime Val enumeration. Runtime errors with TODO notes are added for the stubbed code paths to revisit later.
1 parent e1c704c commit 83b22a2

File tree

9 files changed

+73
-7
lines changed

9 files changed

+73
-7
lines changed

crates/environ/src/gc.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,10 @@ pub const VM_GC_HEADER_TYPE_INDEX_OFFSET: u32 = 4;
4040
/// Get the byte size of the given Wasm type when it is stored inside the GC
4141
/// heap.
4242
pub fn byte_size_of_wasm_ty_in_gc_heap(ty: &WasmStorageType) -> u32 {
43-
use crate::{WasmHeapType::*, WasmRefType};
4443
match ty {
4544
WasmStorageType::I8 => 1,
4645
WasmStorageType::I16 => 2,
4746
WasmStorageType::Val(ty) => match ty {
48-
WasmValType::Ref(WasmRefType {
49-
nullable: _,
50-
heap_type: ConcreteCont(_) | Cont,
51-
}) => unimplemented!("Stack switching feature not compatbile with GC, yet"),
5247
WasmValType::I32 | WasmValType::F32 | WasmValType::Ref(_) => 4,
5348
WasmValType::I64 | WasmValType::F64 => 8,
5449
WasmValType::V128 => 16,

crates/wasmtime/src/runtime/coredump.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ impl WasmCoreDump {
210210
ty: wasm_encoder::AbstractHeapType::Exn,
211211
})
212212
}
213+
Val::ContRef(_) => {
214+
wasm_encoder::ConstExpr::ref_null(wasm_encoder::HeapType::Abstract {
215+
shared: false,
216+
ty: wasm_encoder::AbstractHeapType::Cont,
217+
})
218+
}
213219
};
214220
globals.global(
215221
wasm_encoder::GlobalType {

crates/wasmtime/src/runtime/externals/global.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@ impl Global {
274274
let new = new.as_ref();
275275
definition.write_gc_ref(&mut store, new);
276276
}
277+
Val::ContRef(None) => {
278+
// Allow null continuation references for globals - these are just placeholders
279+
// Non-null references are not supported yet
280+
}
281+
Val::ContRef(Some(_)) => {
282+
// TODO(#10248): Implement non-null global continuation reference handling
283+
return Err(anyhow::anyhow!("setting non-null continuation references in globals not yet supported"));
284+
}
277285
}
278286
}
279287
Ok(())

crates/wasmtime/src/runtime/trampoline/global.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ pub fn generate_global_export(
7070
let new = new.as_ref();
7171
global.write_gc_ref(&mut store, new);
7272
}
73+
Val::ContRef(None) => {
74+
// Allow null continuation references for trampoline globals - these are just placeholders
75+
// Non-null references are not supported yet
76+
}
77+
Val::ContRef(Some(_)) => {
78+
// TODO(#10248): Implement non-null trampoline continuation reference handling
79+
return Err(anyhow::anyhow!("non-null continuation references in trampoline globals not yet supported"));
80+
}
7381
}
7482
}
7583

crates/wasmtime/src/runtime/values.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ use wasmtime_environ::WasmHeapTopType;
88

99
pub use crate::runtime::vm::ValRaw;
1010

11+
/// A stub implementation for continuation references.
12+
///
13+
/// This is a placeholder until continuation objects are fully integrated
14+
/// with the GC system (see #10248).
15+
#[derive(Debug, Clone, Copy)]
16+
pub struct ContRef;
17+
1118
/// Possible runtime values that a WebAssembly module can either consume or
1219
/// produce.
1320
///
@@ -50,6 +57,12 @@ pub enum Val {
5057

5158
/// An exception reference.
5259
ExnRef(Option<Rooted<ExnRef>>),
60+
61+
/// A continuation reference.
62+
///
63+
/// Note: This is currently a stub implementation as continuation objects
64+
/// are not yet fully integrated with the GC system. See #10248.
65+
ContRef(Option<ContRef>),
5366
}
5467

5568
macro_rules! accessors {
@@ -118,7 +131,7 @@ impl Val {
118131
WasmHeapTopType::Extern => Val::ExternRef(None),
119132
WasmHeapTopType::Any => Val::AnyRef(None),
120133
WasmHeapTopType::Exn => Val::ExnRef(None),
121-
WasmHeapTopType::Cont => todo!(), // FIXME(#10248)
134+
WasmHeapTopType::Cont => Val::ContRef(None),
122135
}
123136
}
124137

@@ -177,6 +190,12 @@ impl Val {
177190
Val::AnyRef(Some(a)) => ValType::Ref(RefType::new(false, a._ty(store)?)),
178191
Val::ExnRef(None) => ValType::NULLEXNREF,
179192
Val::ExnRef(Some(e)) => ValType::Ref(RefType::new(false, e._ty(store)?.into())),
193+
Val::ContRef(_) => {
194+
// TODO(#10248): Return proper continuation reference type when available
195+
return Err(anyhow::anyhow!(
196+
"continuation references not yet supported in embedder API"
197+
));
198+
}
180199
})
181200
}
182201

@@ -216,7 +235,8 @@ impl Val {
216235
| (Val::FuncRef(_), _)
217236
| (Val::ExternRef(_), _)
218237
| (Val::AnyRef(_), _)
219-
| (Val::ExnRef(_), _) => false,
238+
| (Val::ExnRef(_), _)
239+
| (Val::ContRef(_), _) => false,
220240
})
221241
}
222242

@@ -268,6 +288,12 @@ impl Val {
268288
Some(f) => f.to_raw(store),
269289
None => ptr::null_mut(),
270290
})),
291+
Val::ContRef(_) => {
292+
// TODO(#10248): Implement proper continuation reference to_raw conversion
293+
Err(anyhow::anyhow!(
294+
"continuation references not yet supported in to_raw conversion"
295+
))
296+
}
271297
}
272298
}
273299

@@ -363,6 +389,7 @@ impl Val {
363389
Val::AnyRef(a) => Some(Ref::Any(a)),
364390
Val::ExnRef(e) => Some(Ref::Exn(e)),
365391
Val::I32(_) | Val::I64(_) | Val::F32(_) | Val::F64(_) | Val::V128(_) => None,
392+
Val::ContRef(_) => None, // TODO(#10248): Return proper Ref::Cont when available
366393
}
367394
}
368395

@@ -509,6 +536,9 @@ impl Val {
509536
// particular store, so they're always considered as "yes I came
510537
// from that store",
511538
Val::I32(_) | Val::I64(_) | Val::F32(_) | Val::F64(_) | Val::V128(_) => true,
539+
540+
// Continuation references are not yet associated with stores
541+
Val::ContRef(_) => true, // TODO(#10248): Proper store association when implemented
512542
}
513543
}
514544
}

crates/wasmtime/src/runtime/vm/gc/enabled/arrayref.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ impl VMArrayRef {
276276
.gc_object_data(self.as_gc_ref())
277277
.write_u32(offset, id.into_raw());
278278
}
279+
Val::ContRef(_) => {
280+
// TODO(#10248): Implement array continuation reference element handling
281+
return Err(anyhow::anyhow!("setting continuation references in array elements not yet supported"));
282+
}
279283
}
280284
Ok(())
281285
}
@@ -383,6 +387,10 @@ impl VMArrayRef {
383387
.gc_object_data(self.as_gc_ref())
384388
.write_u32(offset, id.into_raw());
385389
}
390+
Val::ContRef(_) => {
391+
// TODO(#10248): Implement array continuation reference init handling
392+
return Err(anyhow::anyhow!("initializing continuation references in array elements not yet supported"));
393+
}
386394
}
387395
Ok(())
388396
}

crates/wasmtime/src/runtime/vm/gc/enabled/structref.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ impl VMStructRef {
233233
.gc_object_data(self.as_gc_ref())
234234
.write_u32(offset, id.into_raw());
235235
}
236+
Val::ContRef(_) => {
237+
// TODO(#10248): Implement struct continuation reference field handling
238+
return Err(anyhow::anyhow!("setting continuation references in struct fields not yet supported"));
239+
}
236240
}
237241
Ok(())
238242
}
@@ -386,6 +390,10 @@ pub(crate) fn initialize_field_impl(
386390
.gc_object_data(gc_ref)
387391
.write_u32(offset, id.into_raw());
388392
}
393+
Val::ContRef(_) => {
394+
// TODO(#10248): Implement struct continuation reference field init handling
395+
return Err(anyhow::anyhow!("initializing continuation references in struct fields not yet supported"));
396+
}
389397
}
390398
Ok(())
391399
}

crates/wasmtime/src/runtime/wave/core.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ impl WasmValue for crate::Val {
4040
Self::ExternRef(_) => WasmTypeKind::Unsupported,
4141
Self::AnyRef(_) => WasmTypeKind::Unsupported,
4242
Self::ExnRef(_) => WasmTypeKind::Unsupported,
43+
Self::ContRef(_) => WasmTypeKind::Unsupported,
4344
}
4445
}
4546

src/commands/run.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ impl RunCommand {
746746
Val::AnyRef(Some(_)) => println!("<anyref>"),
747747
Val::ExnRef(None) => println!("<null exnref>"),
748748
Val::ExnRef(Some(_)) => println!("<exnref>"),
749+
Val::ContRef(None) => println!("<null contref>"),
750+
Val::ContRef(Some(_)) => println!("<contref>"),
749751
}
750752
}
751753

0 commit comments

Comments
 (0)