Skip to content

Commit bc82e7a

Browse files
authored
Add skeleton copying collector (#13093)
This commit adds the skeleton of a new copying collector, guarded behind a new "gc-copying" cargo feature. It compiles and implements the various `Gc*` traits to interface with the runtime and compiler, but is not yet actually functional. The copying collector is intentionally excluded from the fuzzing config generator, as it isn't ready to be fuzzed yet.
1 parent d4ce35c commit bc82e7a

23 files changed

Lines changed: 266 additions & 19 deletions

File tree

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ jobs:
360360
-p wasmtime --no-default-features --features gc-null
361361
-p wasmtime --no-default-features --features runtime,gc-null
362362
-p wasmtime --no-default-features --features cranelift,gc-null
363+
-p wasmtime --no-default-features --features gc-copying
364+
-p wasmtime --no-default-features --features runtime,gc-copying
365+
-p wasmtime --no-default-features --features cranelift,gc-copying
363366
-p wasmtime --no-default-features --features runtime
364367
-p wasmtime --no-default-features --features threads
365368
-p wasmtime --no-default-features --features runtime,threads

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ threads = ["wasmtime-cli-flags/threads"]
583583
gc = ["wasmtime-cli-flags/gc", "wasmtime/gc"]
584584
gc-drc = ["gc", "wasmtime/gc-drc", "wasmtime-cli-flags/gc-drc"]
585585
gc-null = ["gc", "wasmtime/gc-null", "wasmtime-cli-flags/gc-null"]
586+
gc-copying = ["gc", "wasmtime/gc-copying", "wasmtime-cli-flags/gc-copying"]
586587
pulley = ["wasmtime-cli-flags/pulley"]
587588
stack-switching = ["wasmtime/stack-switching", "wasmtime-cli-flags/stack-switching"]
588589
debug = ["wasmtime-cli-flags/debug", "wasmtime/debug", "component-model"]

crates/c-api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ threads = ["wasmtime/threads"]
5858
gc = ["wasmtime/gc"]
5959
gc-drc = ["wasmtime/gc-drc"]
6060
gc-null = ["wasmtime/gc-null"]
61+
gc-copying = ["wasmtime/gc-copying"]
6162
cranelift = ['wasmtime/cranelift']
6263
winch = ['wasmtime/winch']
6364
debug-builtins = ['wasmtime/debug-builtins']

crates/c-api/artifact/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ threads = ["wasmtime-c-api/threads"]
6464
gc = ["wasmtime-c-api/gc"]
6565
gc-drc = ["wasmtime-c-api/gc-drc"]
6666
gc-null = ["wasmtime-c-api/gc-null"]
67+
gc-copying = ["wasmtime-c-api/gc-copying"]
6768
cranelift = ["wasmtime-c-api/cranelift"]
6869
winch = ["wasmtime-c-api/winch"]
6970
debug-builtins = ["wasmtime-c-api/debug-builtins"]

crates/cli-flags/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ coredump = ["wasmtime/coredump"]
3535
gc = ["wasmtime/gc"]
3636
gc-drc = ["gc", "wasmtime/gc-drc"]
3737
gc-null = ["gc", "wasmtime/gc-null"]
38+
gc-copying = ["gc", "wasmtime/gc-copying"]
3839
threads = ["wasmtime/threads"]
3940
memory-protection-keys = ["wasmtime/memory-protection-keys"]
4041
pulley = ["wasmtime/pulley"]

crates/cli-flags/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,15 @@ wasmtime_option_group! {
234234
#[serde(default)]
235235
#[serde(deserialize_with = "crate::opt::cli_parse_wrapper")]
236236
pub compiler: Option<wasmtime::Strategy>,
237-
/// Which garbage collector to use: `drc` or `null`.
237+
/// Which garbage collector to use: `drc`, `null`, or `copying`.
238238
///
239239
/// `drc` is the deferred reference-counting collector.
240240
///
241241
/// `null` is the null garbage collector, which does not collect any
242242
/// garbage.
243243
///
244+
/// `copying` is the copying garbage collector (not yet implemented).
245+
///
244246
/// Note that not all builds of Wasmtime will have support for garbage
245247
/// collection included.
246248
#[serde(default)]
@@ -1325,6 +1327,7 @@ mod tests {
13251327
Some(wasmtime::Collector::DeferredReferenceCounting),
13261328
),
13271329
("\"null\"", Some(wasmtime::Collector::Null)),
1330+
("\"copying\"", Some(wasmtime::Collector::Copying)),
13281331
("\"hello\"", None), // should fail
13291332
("5", None), // should fail
13301333
("true", None), // should fail

crates/cli-flags/src/opt.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,19 +548,23 @@ impl WasmtimeOptionValue for wasmtime::Strategy {
548548
}
549549

550550
impl WasmtimeOptionValue for wasmtime::Collector {
551-
const VAL_HELP: &'static str = "=drc|null";
551+
const VAL_HELP: &'static str = "=drc|null|copying";
552552
fn parse(val: Option<&str>) -> Result<Self> {
553553
match String::parse(val)?.as_str() {
554554
"drc" => Ok(wasmtime::Collector::DeferredReferenceCounting),
555555
"null" => Ok(wasmtime::Collector::Null),
556-
other => bail!("unknown collector `{other}` only `drc` and `null` accepted",),
556+
"copying" => Ok(wasmtime::Collector::Copying),
557+
other => {
558+
bail!("unknown collector `{other}` only `drc`, `null`, and `copying` accepted",)
559+
}
557560
}
558561
}
559562

560563
fn display(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
561564
match *self {
562565
wasmtime::Collector::DeferredReferenceCounting => f.write_str("drc"),
563566
wasmtime::Collector::Null => f.write_str("null"),
567+
wasmtime::Collector::Copying => f.write_str("copying"),
564568
_ => unreachable!(),
565569
}
566570
}

crates/cranelift/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ wmemcheck = ["wasmtime-environ/wmemcheck"]
4646
gc = ["wasmtime-environ/gc"]
4747
gc-drc = ["gc", "wasmtime-environ/gc-drc"]
4848
gc-null = ["gc", "wasmtime-environ/gc-null"]
49+
gc-copying = ["gc", "wasmtime-environ/gc-copying"]
4950
stack-switching = []
5051
threads = ["wasmtime-environ/threads"]

crates/cranelift/src/func_environ/gc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ pub use imp::*;
2626

2727
/// How to initialize a newly-allocated array's elements.
2828
#[derive(Clone, Copy)]
29-
#[cfg_attr(not(feature = "gc"), expect(dead_code))]
29+
#[cfg_attr(
30+
not(any(feature = "gc-drc", feature = "gc-null")),
31+
allow(dead_code, reason = "easier to define")
32+
)]
3033
pub enum ArrayInit<'a> {
3134
/// Initialize the array's elements with the given values.
3235
Elems(&'a [ir::Value]),

crates/cranelift/src/func_environ/gc/enabled.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ mod drc;
2424
#[cfg(feature = "gc-null")]
2525
mod null;
2626

27+
#[cfg(feature = "gc-copying")]
28+
mod copying;
29+
2730
/// Get the default GC compiler.
2831
pub fn gc_compiler(func_env: &mut FuncEnvironment<'_>) -> WasmResult<Box<dyn GcCompiler>> {
2932
// If this function requires a GC compiler, that is not too bad of an
@@ -47,11 +50,19 @@ pub fn gc_compiler(func_env: &mut FuncEnvironment<'_>) -> WasmResult<Box<dyn GcC
4750
was disabled at compile time",
4851
)),
4952

50-
#[cfg(any(feature = "gc-drc", feature = "gc-null"))]
53+
#[cfg(feature = "gc-copying")]
54+
Some(Collector::Copying) => Ok(Box::new(copying::CopyingCompiler::default())),
55+
#[cfg(not(feature = "gc-copying"))]
56+
Some(Collector::Copying) => Err(wasm_unsupported!(
57+
"the copying collector is unavailable because the `gc-copying` feature \
58+
was disabled at compile time",
59+
)),
60+
61+
#[cfg(any(feature = "gc-drc", feature = "gc-null", feature = "gc-copying"))]
5162
None => Err(wasm_unsupported!(
5263
"support for GC types disabled at configuration time"
5364
)),
54-
#[cfg(not(any(feature = "gc-drc", feature = "gc-null")))]
65+
#[cfg(not(any(feature = "gc-drc", feature = "gc-null", feature = "gc-copying")))]
5566
None => Err(wasm_unsupported!(
5667
"support for GC types disabled because no collector implementation \
5768
was selected at compile time; enable one of the `gc-drc` or \

0 commit comments

Comments
 (0)