Skip to content

Commit 58ce6b8

Browse files
authored
Remove unnecessary memory_tys param from vm::Instance::new (#12414)
We already have this information in the `InstanceAllocationRequest`, and by avoiding a parameter we can never accidentally pass the wrong memory types.
1 parent 1d13b98 commit 58ce6b8

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,25 @@ impl Instance {
161161
req: InstanceAllocationRequest,
162162
memories: PrimaryMap<DefinedMemoryIndex, (MemoryAllocationIndex, Memory)>,
163163
tables: PrimaryMap<DefinedTableIndex, (TableAllocationIndex, Table)>,
164-
memory_tys: &PrimaryMap<MemoryIndex, wasmtime_environ::Memory>,
165164
) -> InstanceHandle {
166165
let module = req.runtime_info.env_module();
166+
let memory_tys = &module.memories;
167167
let dropped_elements = EntitySet::with_capacity(module.passive_elements.len());
168168
let dropped_data = EntitySet::with_capacity(module.passive_data_map.len());
169169

170+
#[cfg(feature = "wmemcheck")]
171+
let wmemcheck_state = if req.store.engine().config().wmemcheck {
172+
let size = memory_tys
173+
.iter()
174+
.next()
175+
.map(|memory| memory.1.limits.min)
176+
.unwrap_or(0)
177+
* 64
178+
* 1024;
179+
Some(Wmemcheck::new(size.try_into().unwrap()))
180+
} else {
181+
None
182+
};
170183
#[cfg(not(feature = "wmemcheck"))]
171184
let _ = memory_tys;
172185

@@ -178,20 +191,7 @@ impl Instance {
178191
dropped_elements,
179192
dropped_data,
180193
#[cfg(feature = "wmemcheck")]
181-
wmemcheck_state: {
182-
if req.store.engine().config().wmemcheck {
183-
let size = memory_tys
184-
.iter()
185-
.next()
186-
.map(|memory| memory.1.limits.min)
187-
.unwrap_or(0)
188-
* 64
189-
* 1024;
190-
Some(Wmemcheck::new(size.try_into().unwrap()))
191-
} else {
192-
None
193-
}
194-
},
194+
wmemcheck_state,
195195
store: None,
196196
vmctx: OwnedVMContext::new(),
197197
});

crates/wasmtime/src/runtime/vm/instance/allocator.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ impl dyn InstanceAllocator + '_ {
344344
request,
345345
mem::take(&mut guard.memories),
346346
mem::take(&mut guard.tables),
347-
&module.memories,
348347
))
349348
};
350349

0 commit comments

Comments
 (0)