Skip to content

Commit 1ae8aa8

Browse files
committed
Export wasmer::{BaseTunables, Tunables}
1 parent a69c9b3 commit 1ae8aa8

File tree

5 files changed

+26
-23
lines changed

5 files changed

+26
-23
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- [#1851](https://github.com/wasmerio/wasmer/pull/1851) Improve test suite and documentation of the Wasmer C API
1919
- [#1874](https://github.com/wasmerio/wasmer/pull/1874) Set `CompilerConfig` to be owned (following wasm-c-api)
2020
- [#1880](https://github.com/wasmerio/wasmer/pull/1880) Remove cmake dependency for tests
21+
- [#xxxx](https://github.com/wasmerio/wasmer/pull/xxxx) Rename reference implementation `wasmer::Tunables` to `wasmer::BaseTunables`. Export trait `wasmer_engine::Tunables` as `wasmer::Tunables`.
2122

2223
### Fixed
2324

examples/tunables_limit_memory.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ use std::sync::Arc;
44
use wasmer::{
55
imports,
66
vm::{self, MemoryError, MemoryStyle, TableStyle, VMMemoryDefinition, VMTableDefinition},
7-
wat2wasm, Instance, Memory, MemoryType, Module, Pages, Store, TableType, Target,
8-
Tunables as ReferenceTunables,
7+
wat2wasm, BaseTunables, Instance, Memory, MemoryType, Module, Pages, Store, TableType, Target,
8+
Tunables,
99
};
1010
use wasmer_compiler_cranelift::Cranelift;
11-
use wasmer_engine::Tunables;
1211
use wasmer_engine_jit::JIT;
1312

1413
/// A custom tunables that allows you to set a memory limit.
@@ -147,7 +146,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
147146

148147
// Here is where the fun begins
149148

150-
let base = ReferenceTunables::for_target(&Target::default());
149+
let base = BaseTunables::for_target(&Target::default());
151150
let tunables = LimitingTunables::new(base, Pages(24));
152151

153152
// Create a store, that holds the engine and our custom tunables

lib/api/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ pub use crate::module::Module;
294294
pub use crate::native::NativeFunc;
295295
pub use crate::ptr::{Array, Item, WasmPtr};
296296
pub use crate::store::{Store, StoreObject};
297-
pub use crate::tunables::Tunables;
297+
pub use crate::tunables::BaseTunables;
298298
pub use crate::types::{
299299
ExportType, ExternRef, ExternType, FunctionType, GlobalType, HostInfo, HostRef, ImportType,
300300
MemoryType, Mutability, TableType, Val, ValType,
@@ -311,7 +311,7 @@ pub use wasmer_compiler::{
311311
};
312312
pub use wasmer_engine::{
313313
ChainableNamedResolver, DeserializeError, Engine, Export, FrameInfo, LinkError, NamedResolver,
314-
NamedResolverChain, Resolver, RuntimeError, SerializeError,
314+
NamedResolverChain, Resolver, RuntimeError, SerializeError, Tunables,
315315
};
316316
pub use wasmer_types::{
317317
Atomically, Bytes, ExportIndex, GlobalInit, LocalFunctionIndex, MemoryView, Pages, ValueType,

lib/api/src/store.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use crate::tunables::Tunables;
1+
use crate::tunables::BaseTunables;
22
use std::fmt;
33
use std::sync::Arc;
44
#[cfg(all(feature = "compiler", feature = "engine"))]
55
use wasmer_compiler::CompilerConfig;
6-
use wasmer_engine::Engine;
7-
use wasmer_engine::Tunables as BaseTunables;
6+
use wasmer_engine::{Engine, Tunables};
87

98
/// The store represents all global state that can be manipulated by
109
/// WebAssembly programs. It consists of the runtime representation
@@ -19,7 +18,7 @@ use wasmer_engine::Tunables as BaseTunables;
1918
#[derive(Clone)]
2019
pub struct Store {
2120
engine: Arc<dyn Engine + Send + Sync>,
22-
tunables: Arc<dyn BaseTunables + Send + Sync>,
21+
tunables: Arc<dyn Tunables + Send + Sync>,
2322
}
2423

2524
impl Store {
@@ -30,15 +29,12 @@ impl Store {
3029
{
3130
Self {
3231
engine: engine.cloned(),
33-
tunables: Arc::new(Tunables::for_target(engine.target())),
32+
tunables: Arc::new(BaseTunables::for_target(engine.target())),
3433
}
3534
}
3635

3736
/// Creates a new `Store` with a specific [`Engine`] and [`Tunables`].
38-
pub fn new_with_tunables<E>(
39-
engine: &E,
40-
tunables: impl BaseTunables + Send + Sync + 'static,
41-
) -> Self
37+
pub fn new_with_tunables<E>(engine: &E, tunables: impl Tunables + Send + Sync + 'static) -> Self
4238
where
4339
E: Engine + ?Sized,
4440
{
@@ -49,7 +45,7 @@ impl Store {
4945
}
5046

5147
/// Returns the [`Tunables`].
52-
pub fn tunables(&self) -> &dyn BaseTunables {
48+
pub fn tunables(&self) -> &dyn Tunables {
5349
self.tunables.as_ref()
5450
}
5551

@@ -111,7 +107,7 @@ impl Default for Store {
111107

112108
let config = get_config();
113109
let engine = get_engine(config);
114-
let tunables = Tunables::for_target(engine.target());
110+
let tunables = BaseTunables::for_target(engine.target());
115111
Store {
116112
engine: Arc::new(engine),
117113
tunables: Arc::new(tunables),

lib/api/src/tunables.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@ use std::ptr::NonNull;
44
use std::sync::Arc;
55
use target_lexicon::{OperatingSystem, PointerWidth};
66
use wasmer_compiler::Target;
7-
use wasmer_engine::Tunables as BaseTunables;
7+
use wasmer_engine::Tunables;
88
use wasmer_vm::MemoryError;
99
use wasmer_vm::{
1010
LinearMemory, LinearTable, Memory, MemoryStyle, Table, TableStyle, VMMemoryDefinition,
1111
VMTableDefinition,
1212
};
1313

1414
/// Tunable parameters for WebAssembly compilation.
15+
/// This is the reference implementation of the `Tunables` trait,
16+
/// used by default.
17+
///
18+
/// You can use this as a template for creating a custom Tunables
19+
/// implementation or use composition to wrap your Tunables around
20+
/// this one. The later approach is demonstrated in the
21+
/// tunables-limit-memory example.
1522
#[derive(Clone)]
16-
pub struct Tunables {
23+
pub struct BaseTunables {
1724
/// For static heaps, the size in wasm pages of the heap protected by bounds checking.
1825
pub static_memory_bound: Pages,
1926

@@ -24,8 +31,8 @@ pub struct Tunables {
2431
pub dynamic_memory_offset_guard_size: u64,
2532
}
2633

27-
impl Tunables {
28-
/// Get the `Tunables` for a specific Target
34+
impl BaseTunables {
35+
/// Get the `BaseTunables` for a specific Target
2936
pub fn for_target(target: &Target) -> Self {
3037
let triple = target.triple();
3138
let pointer_width: PointerWidth = triple.pointer_width().unwrap();
@@ -61,7 +68,7 @@ impl Tunables {
6168
}
6269
}
6370

64-
impl BaseTunables for Tunables {
71+
impl Tunables for BaseTunables {
6572
/// Get a `MemoryStyle` for the provided `MemoryType`
6673
fn memory_style(&self, memory: &MemoryType) -> MemoryStyle {
6774
// A heap with a maximum that doesn't exceed the static memory bound specified by the
@@ -148,7 +155,7 @@ mod tests {
148155

149156
#[test]
150157
fn memory_style() {
151-
let tunables = Tunables {
158+
let tunables = BaseTunables {
152159
static_memory_bound: Pages(2048),
153160
static_memory_offset_guard_size: 128,
154161
dynamic_memory_offset_guard_size: 256,

0 commit comments

Comments
 (0)