Skip to content

Commit 75ac484

Browse files
committed
Implement feedback
1 parent ba53a43 commit 75ac484

13 files changed

Lines changed: 211 additions & 344 deletions

File tree

crates/c-api/include/wasmtime/config.hh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,15 @@ class Config {
303303
wasmtime_config_wasm_tail_call_set(ptr.get(), enable);
304304
}
305305

306+
#ifdef WASMTIME_FEATURE_GC
306307
/// \brief Configures whether the WebAssembly reference types proposal is
307308
/// enabled
308309
///
309310
/// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.wasm_reference_types
310311
void wasm_reference_types(bool enable) {
311312
wasmtime_config_wasm_reference_types_set(ptr.get(), enable);
312313
}
314+
#endif // WASMTIME_FEATURE_GC
313315

314316
/// \brief Configures whether the WebAssembly simd proposal is enabled
315317
///
@@ -361,11 +363,13 @@ class Config {
361363
wasmtime_config_wasm_memory64_set(ptr.get(), enable);
362364
}
363365

366+
#ifdef WASMTIME_FEATURE_GC
364367
/// \brief Configures whether the WebAssembly Garbage Collection proposal will
365368
/// be enabled
366369
///
367370
/// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.wasm_gc
368371
void wasm_gc(bool enable) { wasmtime_config_wasm_gc_set(ptr.get(), enable); }
372+
#endif // WASMTIME_FEATURE_GC
369373

370374
/// \brief Configures whether the WebAssembly function references proposal
371375
/// will be enabled
@@ -383,13 +387,15 @@ class Config {
383387
wasmtime_config_wasm_wide_arithmetic_set(ptr.get(), enable);
384388
}
385389

390+
#ifdef WASMTIME_FEATURE_GC
386391
/// \brief Configures whether the WebAssembly exceptions proposal will be
387392
/// enabled
388393
///
389394
/// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.wasm_exceptions
390395
void wasm_exceptions(bool enable) {
391396
wasmtime_config_wasm_exceptions_set(ptr.get(), enable);
392397
}
398+
#endif // WASMTIME_FEATURE_GC
393399

394400
/// \brief Configures whether the WebAssembly custom-page-sizes proposal will
395401
/// be enabled

crates/c-api/include/wasmtime/func.hh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,18 @@ template <> struct WasmType<std::optional<ExternRef>> {
102102
p->externref = 0;
103103
}
104104
}
105+
106+
#ifdef WASMTIME_FEATURE_GC
105107
static std::optional<ExternRef> load(Store::Context cx,
106-
wasmtime_val_raw_t *p) {
108+
wasmtime_val_raw_t *p) {
107109
if (p->externref == 0) {
108110
return std::nullopt;
109111
}
110112
wasmtime_externref_t val;
111113
wasmtime_externref_from_raw(cx.capi(), p->externref, &val);
112114
return ExternRef(val);
113115
}
116+
#endif // WASMTIME_FEATURE_GC
114117
};
115118

116119
/// Type information for the `V128` host value used as a wasm value.

crates/c-api/include/wasmtime/store.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ WASM_API_EXTERN void wasmtime_context_set_data(wasmtime_context_t *context,
144144
*
145145
* The `context` argument must not be NULL.
146146
*/
147+
#ifdef WASMTIME_FEATURE_GC
147148
WASM_API_EXTERN wasmtime_error_t *
148149
wasmtime_context_gc(wasmtime_context_t *context);
150+
#endif
149151

150152
/**
151153
* \brief Set fuel to this context's store for wasm to consume while executing.

crates/c-api/include/wasmtime/store.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public:
8989
/// Creates a context referencing the provided `Caller`.
9090
Context(Caller *caller);
9191

92+
#ifdef WASMTIME_FEATURE_GC
9293
/// Runs a garbage collection pass in the referenced store to collect loose
9394
/// `externref` values, if any are available.
9495
Result<std::monostate> gc() {
@@ -98,6 +99,7 @@ public:
9899
}
99100
return std::monostate();
100101
}
102+
#endif
101103

102104
/// Injects fuel to be consumed within this store.
103105
///
@@ -231,9 +233,11 @@ public:
231233
/// Explicit function to acquire a `Context` from this store.
232234
Context context() { return this; }
233235

236+
#ifdef WASMTIME_FEATURE_GC
234237
/// Runs a garbage collection pass in the referenced store to collect loose
235238
/// GC-managed objects, if any are available.
236239
Result<std::monostate> gc() { return context().gc(); }
240+
#endif
237241

238242
private:
239243
template <typename F>

crates/c-api/include/wasmtime/val.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ WASM_API_EXTERN void wasmtime_anyref_clone(const wasmtime_anyref_t *anyref,
9292
*/
9393
WASM_API_EXTERN void wasmtime_anyref_unroot(wasmtime_anyref_t *ref);
9494

95+
#ifdef WASMTIME_FEATURE_GC
9596
/**
9697
* \brief Converts a raw `anyref` value coming from #wasmtime_val_raw_t into
9798
* a #wasmtime_anyref_t.
@@ -102,7 +103,9 @@ WASM_API_EXTERN void wasmtime_anyref_unroot(wasmtime_anyref_t *ref);
102103
WASM_API_EXTERN void wasmtime_anyref_from_raw(wasmtime_context_t *context,
103104
uint32_t raw,
104105
wasmtime_anyref_t *out);
106+
#endif // WASMTIME_FEATURE_GC
105107

108+
#ifdef WASMTIME_FEATURE_GC
106109
/**
107110
* \brief Converts a #wasmtime_anyref_t to a raw value suitable for storing
108111
* into a #wasmtime_val_raw_t.
@@ -115,7 +118,9 @@ WASM_API_EXTERN void wasmtime_anyref_from_raw(wasmtime_context_t *context,
115118
*/
116119
WASM_API_EXTERN uint32_t wasmtime_anyref_to_raw(wasmtime_context_t *context,
117120
const wasmtime_anyref_t *ref);
121+
#endif // WASMTIME_FEATURE_GC
118122

123+
#ifdef WASMTIME_FEATURE_GC
119124
/**
120125
* \brief Create a new `i31ref` value.
121126
*
@@ -127,7 +132,10 @@ WASM_API_EXTERN uint32_t wasmtime_anyref_to_raw(wasmtime_context_t *context,
127132
WASM_API_EXTERN void wasmtime_anyref_from_i31(wasmtime_context_t *context,
128133
uint32_t i31val,
129134
wasmtime_anyref_t *out);
135+
#endif // WASMTIME_FEATURE_GC
130136

137+
138+
#ifdef WASMTIME_FEATURE_GC
131139
/**
132140
* \brief Get the `anyref`'s underlying `i31ref` value, zero extended, if any.
133141
*
@@ -140,7 +148,9 @@ WASM_API_EXTERN void wasmtime_anyref_from_i31(wasmtime_context_t *context,
140148
WASM_API_EXTERN bool wasmtime_anyref_i31_get_u(wasmtime_context_t *context,
141149
const wasmtime_anyref_t *anyref,
142150
uint32_t *dst);
151+
#endif // WASMTIME_FEATURE_GC
143152

153+
#ifdef WASMTIME_FEATURE_GC
144154
/**
145155
* \brief Get the `anyref`'s underlying `i31ref` value, sign extended, if any.
146156
*
@@ -153,6 +163,7 @@ WASM_API_EXTERN bool wasmtime_anyref_i31_get_u(wasmtime_context_t *context,
153163
WASM_API_EXTERN bool wasmtime_anyref_i31_get_s(wasmtime_context_t *context,
154164
const wasmtime_anyref_t *anyref,
155165
int32_t *dst);
166+
#endif // WASMTIME_FEATURE_GC
156167

157168
/**
158169
* \typedef wasmtime_externref_t
@@ -202,6 +213,7 @@ static inline bool wasmtime_externref_is_null(const wasmtime_externref_t *ref) {
202213
return ref->store_id == 0;
203214
}
204215

216+
#ifdef WASMTIME_FEATURE_GC
205217
/**
206218
* \brief Create a new `externref` value.
207219
*
@@ -229,7 +241,10 @@ WASM_API_EXTERN bool wasmtime_externref_new(wasmtime_context_t *context,
229241
void *data,
230242
void (*finalizer)(void *),
231243
wasmtime_externref_t *out);
244+
#endif // WASMTIME_FEATURE_GC
245+
232246

247+
#ifdef WASMTIME_FEATURE_GC
233248
/**
234249
* \brief Get an `externref`'s wrapped data
235250
*
@@ -238,6 +253,7 @@ WASM_API_EXTERN bool wasmtime_externref_new(wasmtime_context_t *context,
238253
*/
239254
WASM_API_EXTERN void *wasmtime_externref_data(wasmtime_context_t *context,
240255
const wasmtime_externref_t *data);
256+
#endif // WASMTIME_FEATURE_GC
241257

242258
/**
243259
* \brief Creates a new reference pointing to the same data that `ref` points
@@ -264,6 +280,7 @@ WASM_API_EXTERN void wasmtime_externref_clone(const wasmtime_externref_t *ref,
264280
*/
265281
WASM_API_EXTERN void wasmtime_externref_unroot(wasmtime_externref_t *ref);
266282

283+
#ifdef WASMTIME_FEATURE_GC
267284
/**
268285
* \brief Converts a raw `externref` value coming from #wasmtime_val_raw_t into
269286
* a #wasmtime_externref_t.
@@ -274,7 +291,9 @@ WASM_API_EXTERN void wasmtime_externref_unroot(wasmtime_externref_t *ref);
274291
WASM_API_EXTERN void wasmtime_externref_from_raw(wasmtime_context_t *context,
275292
uint32_t raw,
276293
wasmtime_externref_t *out);
294+
#endif // WASMTIME_FEATURE_GC
277295

296+
#ifdef WASMTIME_FEATURE_GC
278297
/**
279298
* \brief Converts a #wasmtime_externref_t to a raw value suitable for storing
280299
* into a #wasmtime_val_raw_t.
@@ -287,6 +306,7 @@ WASM_API_EXTERN void wasmtime_externref_from_raw(wasmtime_context_t *context,
287306
*/
288307
WASM_API_EXTERN uint32_t wasmtime_externref_to_raw(
289308
wasmtime_context_t *context, const wasmtime_externref_t *ref);
309+
#endif // WASMTIME_FEATURE_GC
290310

291311
/// \brief Discriminant stored in #wasmtime_val::kind
292312
typedef uint8_t wasmtime_valkind_t;

crates/c-api/include/wasmtime/val.hh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public:
6666

6767
~ExternRef() { wasmtime_externref_unroot(&val); }
6868

69+
#ifdef WASMTIME_FEATURE_GC
6970
/// Creates a new `externref` value from the provided argument.
7071
///
7172
/// Note that `val` should be safe to send across threads and should own any
@@ -79,24 +80,31 @@ public:
7980
abort();
8081
}
8182
}
83+
#endif // WASMTIME_FEATURE_GC
8284

85+
#ifdef WASMTIME_FEATURE_GC
8386
/// Returns the underlying host data associated with this `ExternRef`.
8487
std::any &data(Store::Context cx) {
8588
return *static_cast<std::any *>(wasmtime_externref_data(cx.ptr, &val));
8689
}
90+
#endif // WASMTIME_FEATURE_GC
8791

92+
#ifdef WASMTIME_FEATURE_GC
8893
/// Consumes ownership of the underlying `wasmtime_externref_t` and returns
8994
/// the result of `wasmtime_externref_to_raw`.
9095
uint32_t take_raw(Store::Context cx) {
9196
uint32_t ret = wasmtime_externref_to_raw(cx.capi(), &val);
9297
wasmtime_externref_set_null(&val);
9398
return ret;
9499
}
100+
#endif // WASMTIME_FEATURE_GC
95101

102+
#ifdef WASMTIME_FEATURE_GC
96103
/// Returns `wasmtime_externref_to_raw`.
97104
uint32_t borrow_raw(Store::Context cx) const {
98105
return wasmtime_externref_to_raw(cx.capi(), &val);
99106
}
107+
#endif // WASMTIME_FEATURE_GC
100108
};
101109

102110
/**
@@ -166,13 +174,15 @@ public:
166174
return std::nullopt;
167175
}
168176

177+
#ifdef WASMTIME_FEATURE_GC
169178
/// \brief If this is an `i31`, get the value sign-extended.
170179
std::optional<int32_t> i31(Store::Context cx) const {
171180
int32_t ret = 0;
172181
if (wasmtime_anyref_i31_get_s(cx.ptr, &val, &ret))
173182
return ret;
174183
return std::nullopt;
175184
}
185+
#endif // WASMTIME_FEATURE_GC
176186
};
177187

178188
/// \brief Container for the `v128` WebAssembly type.

crates/c-api/src/config.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,33 +90,24 @@ pub extern "C" fn wasmtime_config_wasm_tail_call_set(c: &mut wasm_config_t, enab
9090
}
9191

9292
#[unsafe(no_mangle)]
93+
#[cfg(feature = "gc")]
9394
pub extern "C" fn wasmtime_config_wasm_reference_types_set(c: &mut wasm_config_t, enable: bool) {
94-
#[cfg(feature = "gc")]
9595
c.config.wasm_reference_types(enable);
96-
97-
#[cfg(not(feature = "gc"))]
98-
let _ = (c, enable);
9996
}
10097

10198
#[unsafe(no_mangle)]
99+
#[cfg(feature = "gc")]
102100
pub extern "C" fn wasmtime_config_wasm_function_references_set(
103101
c: &mut wasm_config_t,
104102
enable: bool,
105103
) {
106-
#[cfg(feature = "gc")]
107104
c.config.wasm_function_references(enable);
108-
109-
#[cfg(not(feature = "gc"))]
110-
let _ = (c, enable);
111105
}
112106

113107
#[unsafe(no_mangle)]
108+
#[cfg(feature = "gc")]
114109
pub extern "C" fn wasmtime_config_wasm_gc_set(c: &mut wasm_config_t, enable: bool) {
115-
#[cfg(feature = "gc")]
116110
c.config.wasm_gc(enable);
117-
118-
#[cfg(not(feature = "gc"))]
119-
let _ = (c, enable);
120111
}
121112

122113
#[unsafe(no_mangle)]
@@ -488,12 +479,9 @@ pub extern "C" fn wasmtime_config_wasm_wide_arithmetic_set(c: &mut wasm_config_t
488479
}
489480

490481
#[unsafe(no_mangle)]
482+
#[cfg(feature = "gc")]
491483
pub extern "C" fn wasmtime_config_wasm_exceptions_set(c: &mut wasm_config_t, enable: bool) {
492-
#[cfg(feature = "gc")]
493484
c.config.wasm_exceptions(enable);
494-
495-
#[cfg(not(feature = "gc"))]
496-
let _ = (c, enable);
497485
}
498486

499487
#[unsafe(no_mangle)]

0 commit comments

Comments
 (0)