Skip to content

Commit 200c24a

Browse files
committed
address review feedback
1 parent 3f2ec37 commit 200c24a

File tree

9 files changed

+95
-162
lines changed

9 files changed

+95
-162
lines changed

crates/environ/src/component/translate/adapt.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,7 @@ impl<'data> Translator<'_, 'data> {
208208
// the module using standard core wasm translation, and then fills out
209209
// the dfg metadata for each adapter.
210210
for (module_id, adapter_module) in state.adapter_modules.iter() {
211-
let mut module = fact::Module::new(
212-
self.types.types(),
213-
self.tunables.debug_adapter_modules,
214-
self.tunables.component_model_concurrency,
215-
);
211+
let mut module = fact::Module::new(self.types.types(), self.tunables);
216212
let mut names = Vec::with_capacity(adapter_module.adapters.len());
217213
for adapter in adapter_module.adapters.iter() {
218214
let name = format!("adapter{}", adapter.as_u32());

crates/environ/src/fact.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::component::{
2424
RuntimeComponentInstanceIndex, StringEncoding, Transcode, TypeFuncIndex,
2525
};
2626
use crate::fact::transcode::Transcoder;
27-
use crate::{EntityRef, FuncIndex, GlobalIndex, MemoryIndex, PrimaryMap};
27+
use crate::{EntityRef, FuncIndex, GlobalIndex, MemoryIndex, PrimaryMap, Tunables};
2828
use crate::{ModuleInternedTypeIndex, prelude::*};
2929
use std::collections::HashMap;
3030
use wasm_encoder::*;
@@ -52,10 +52,8 @@ pub static PREPARE_CALL_FIXED_PARAMS: &[ValType] = &[
5252

5353
/// Representation of an adapter module.
5454
pub struct Module<'a> {
55-
/// Whether or not debug code is inserted into the adapters themselves.
56-
debug: bool,
57-
/// Whether the `component-model-async` feature is enabled
58-
enable_async: bool,
55+
/// Compilation configuration
56+
tunables: &'a Tunables,
5957
/// Type information from the creator of this `Module`
6058
types: &'a ComponentTypesBuilder,
6159

@@ -246,10 +244,9 @@ enum HelperLocation {
246244

247245
impl<'a> Module<'a> {
248246
/// Creates an empty module.
249-
pub fn new(types: &'a ComponentTypesBuilder, debug: bool, enable_async: bool) -> Module<'a> {
247+
pub fn new(types: &'a ComponentTypesBuilder, tunables: &'a Tunables) -> Module<'a> {
250248
Module {
251-
debug,
252-
enable_async,
249+
tunables,
253250
types,
254251
core_types: Default::default(),
255252
core_imports: Default::default(),

crates/environ/src/fact/trampoline.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub(super) fn compile(module: &mut Module<'_>, adapter: &AdapterData) {
180180
compiler.compile_sync_to_sync_adapter(adapter, &lower_sig, &lift_sig)
181181
}
182182
(true, true) => {
183-
assert!(module.enable_async);
183+
assert!(module.tunables.component_model_concurrency);
184184

185185
// In the async->async case, we must compile a couple of helper functions:
186186
//
@@ -209,7 +209,7 @@ pub(super) fn compile(module: &mut Module<'_>, adapter: &AdapterData) {
209209
);
210210
}
211211
(false, true) => {
212-
assert!(module.enable_async);
212+
assert!(module.tunables.component_model_concurrency);
213213

214214
// Like the async->async case above, for the sync->async case we
215215
// also need `async-start` and `async-return` helper functions to
@@ -235,7 +235,7 @@ pub(super) fn compile(module: &mut Module<'_>, adapter: &AdapterData) {
235235
);
236236
}
237237
(true, false) => {
238-
assert!(module.enable_async);
238+
assert!(module.tunables.component_model_concurrency);
239239

240240
// As with the async->async and sync->async cases above, for the
241241
// async->sync case we use `async-start` and `async-return` helper
@@ -759,7 +759,7 @@ impl<'a, 'b> Compiler<'a, 'b> {
759759
Trap::CannotLeaveComponent,
760760
);
761761

762-
let old_task_may_block = if self.module.enable_async {
762+
let old_task_may_block = if self.module.tunables.component_model_concurrency {
763763
// Save, clear, and later restore the `may_block` field.
764764
let task_may_block = self.module.import_task_may_block();
765765
let old_task_may_block = if self.types[adapter.lift.ty].async_ {
@@ -871,7 +871,7 @@ impl<'a, 'b> Compiler<'a, 'b> {
871871
self.instruction(Call(exit.as_u32()));
872872
}
873873

874-
if self.module.enable_async {
874+
if self.module.tunables.component_model_concurrency {
875875
// Pop the task we pushed earlier off of the current task stack.
876876
//
877877
// FIXME: Apply the optimizations described in #12311.
@@ -1993,7 +1993,7 @@ impl<'a, 'b> Compiler<'a, 'b> {
19931993

19941994
// In debug mode verify the first result consumed the entire string,
19951995
// otherwise simply discard it.
1996-
if self.module.debug {
1996+
if self.module.tunables.debug_adapter_modules {
19971997
self.instruction(LocalGet(src.len.idx));
19981998
self.instruction(LocalGet(src_len_tmp.idx));
19991999
self.ptr_sub(src_mem_opts);
@@ -2020,7 +2020,7 @@ impl<'a, 'b> Compiler<'a, 'b> {
20202020

20212021
// If the first transcode was enough then assert that the returned
20222022
// amount of destination items written equals the byte size.
2023-
if self.module.debug {
2023+
if self.module.tunables.debug_adapter_modules {
20242024
self.instruction(Else);
20252025

20262026
self.instruction(LocalGet(dst.len.idx));
@@ -2191,7 +2191,7 @@ impl<'a, 'b> Compiler<'a, 'b> {
21912191

21922192
// Assert that the untagged code unit length is the same as the
21932193
// source code unit length.
2194-
if self.module.debug {
2194+
if self.module.tunables.debug_adapter_modules {
21952195
self.instruction(LocalGet(dst.len.idx));
21962196
self.ptr_uconst(dst_mem_opts, !UTF16_TAG);
21972197
self.ptr_and(dst_mem_opts);
@@ -3464,7 +3464,7 @@ impl<'a, 'b> Compiler<'a, 'b> {
34643464

34653465
fn assert_aligned(&mut self, ty: &InterfaceType, mem: &Memory) {
34663466
let mem_opts = mem.mem_opts();
3467-
if !self.module.debug {
3467+
if !self.module.tunables.debug_adapter_modules {
34683468
return;
34693469
}
34703470
let align = self.types.align(mem_opts, ty);
@@ -3654,7 +3654,7 @@ impl<'a, 'b> Compiler<'a, 'b> {
36543654
}
36553655

36563656
fn assert_i64_upper_bits_not_set(&mut self, local: u32) {
3657-
if !self.module.debug {
3657+
if !self.module.tunables.debug_adapter_modules {
36583658
return;
36593659
}
36603660
self.instruction(LocalGet(local));

crates/wasmtime/src/config.rs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub struct Config {
125125
#[cfg(feature = "gc")]
126126
collector: Collector,
127127
profiling_strategy: ProfilingStrategy,
128-
pub(crate) tunables: ConfigTunables,
128+
tunables: ConfigTunables,
129129

130130
#[cfg(feature = "cache")]
131131
pub(crate) cache: Option<Cache>,
@@ -294,20 +294,6 @@ impl Config {
294294
)
295295
}
296296

297-
pub(crate) fn enable_component_model_concurrency(&self) -> bool {
298-
self.enabled_features.contains(WasmFeatures::CM_ASYNC)
299-
|| self
300-
.enabled_features
301-
.contains(WasmFeatures::CM_ASYNC_BUILTINS)
302-
|| self
303-
.enabled_features
304-
.contains(WasmFeatures::CM_ASYNC_STACKFUL)
305-
|| self.enabled_features.contains(WasmFeatures::CM_THREADING)
306-
|| self
307-
.enabled_features
308-
.contains(WasmFeatures::CM_ERROR_CONTEXT)
309-
}
310-
311297
/// Configure whether Wasm compilation is enabled.
312298
///
313299
/// Disabling Wasm compilation will allow you to load and run
@@ -2536,7 +2522,10 @@ impl Config {
25362522
);
25372523
}
25382524

2539-
tunables.component_model_concurrency = self.enable_component_model_concurrency();
2525+
#[cfg(feature = "component-model")]
2526+
{
2527+
tunables.component_model_concurrency = self.cm_concurrency_enabled();
2528+
}
25402529

25412530
Ok((tunables, features))
25422531
}
@@ -3030,17 +3019,13 @@ impl Config {
30303019
#[inline]
30313020
pub(crate) fn cm_concurrency_enabled(&self) -> bool {
30323021
cfg!(feature = "component-model-async")
3033-
&& (self.enabled_features.contains(WasmFeatures::CM_ASYNC)
3034-
|| self
3035-
.enabled_features
3036-
.contains(WasmFeatures::CM_ASYNC_BUILTINS)
3037-
|| self
3038-
.enabled_features
3039-
.contains(WasmFeatures::CM_ASYNC_STACKFUL)
3040-
|| self.enabled_features.contains(WasmFeatures::CM_THREADING)
3041-
|| self
3042-
.enabled_features
3043-
.contains(WasmFeatures::CM_ERROR_CONTEXT))
3022+
&& self.enabled_features.intersects(
3023+
WasmFeatures::CM_ASYNC
3024+
| WasmFeatures::CM_ASYNC_BUILTINS
3025+
| WasmFeatures::CM_ASYNC_STACKFUL
3026+
| WasmFeatures::CM_THREADING
3027+
| WasmFeatures::CM_ERROR_CONTEXT,
3028+
)
30443029
}
30453030
}
30463031

0 commit comments

Comments
 (0)