Skip to content
This repository was archived by the owner on Oct 3, 2025. It is now read-only.

Commit 4425733

Browse files
chore: Memory and Data Instances are no longer reference counted
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
1 parent 9c85fa9 commit 4425733

File tree

13 files changed

+266
-145
lines changed

13 files changed

+266
-145
lines changed

.cargo/config.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,3 @@ test-mvp="test --package tinywasm --test test-mvp --release -- --enable "
55
test-2="test --package tinywasm --test test-two --release -- --enable "
66
test-wast="test --package tinywasm --test test-wast -- --enable "
77
test-wast-release="test --package tinywasm --test test-wast --release -- --enable "
8-
9-
# enable for linux perf
10-
[target.x86_64-unknown-linux-gnu]
11-
linker="/usr/bin/clang"
12-
rustflags=["-Clink-arg=-fuse-ld=lld", "-Clink-arg=-Wl,--no-rosegment"]

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Use a seperate stack and locals for 32, 64 and 128 bit values and references (#21)
1515
- Updated to latest `wasmparser` version
1616
- Removed benchmarks comparing TinyWasm to other WebAssembly runtimes to reduce build dependencies
17+
- Memory and Data Instances are no longer reference counted
1718

1819
## [0.7.0] - 2024-05-15
1920

crates/tinywasm/benches/fibonacci.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn criterion_benchmark(c: &mut Criterion) {
4343
c.bench_function("fibonacci_to_twasm", |b| b.iter(|| fibonacci_to_twasm(module.clone())));
4444
c.bench_function("fibonacci_from_twasm", |b| b.iter(|| fibonacci_from_twasm(twasm.clone())));
4545
c.bench_function("fibonacci_iterative_60", |b| b.iter(|| fibonacci_run(module.clone(), false, 60)));
46-
c.bench_function("fibonacci_recursive_60", |b| b.iter(|| fibonacci_run(module.clone(), true, 60)));
46+
c.bench_function("fibonacci_recursive_26", |b| b.iter(|| fibonacci_run(module.clone(), true, 26)));
4747
}
4848

4949
criterion_group!(benches, criterion_benchmark);

crates/tinywasm/src/imports.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use alloc::vec::Vec;
66
use core::fmt::Debug;
77

88
use crate::func::{FromWasmValueTuple, IntoWasmValueTuple, ValTypesFromTuple};
9-
use crate::{log, LinkingError, Result};
9+
use crate::{log, LinkingError, MemoryRef, MemoryRefMut, Result};
1010
use tinywasm_types::*;
1111

1212
/// The internal representation of a function
@@ -72,12 +72,12 @@ impl FuncContext<'_> {
7272
}
7373

7474
/// Get a reference to an exported memory
75-
pub fn exported_memory(&mut self, name: &str) -> Result<crate::MemoryRef<'_>> {
75+
pub fn exported_memory(&mut self, name: &str) -> Result<MemoryRef<'_>> {
7676
self.module().exported_memory(self.store, name)
7777
}
7878

7979
/// Get a reference to an exported memory
80-
pub fn exported_memory_mut(&mut self, name: &str) -> Result<crate::MemoryRefMut<'_>> {
80+
pub fn exported_memory_mut(&mut self, name: &str) -> Result<MemoryRefMut<'_>> {
8181
self.module().exported_memory_mut(self.store, name)
8282
}
8383
}
@@ -394,15 +394,12 @@ impl Imports {
394394
}
395395
(ExternVal::Table(table_addr), ImportKind::Table(ty)) => {
396396
let table = store.get_table(table_addr)?;
397-
Self::compare_table_types(import, &table.borrow().kind, ty)?;
397+
Self::compare_table_types(import, &table.kind, ty)?;
398398
imports.tables.push(table_addr);
399399
}
400400
(ExternVal::Memory(memory_addr), ImportKind::Memory(ty)) => {
401401
let mem = store.get_mem(memory_addr)?;
402-
let (size, kind) = {
403-
let mem = mem.borrow();
404-
(mem.page_count(), mem.kind)
405-
};
402+
let (size, kind) = { (mem.page_count(), mem.kind) };
406403
Self::compare_memory_types(import, &kind, ty, Some(size))?;
407404
imports.memories.push(memory_addr);
408405
}

crates/tinywasm/src/instance.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,37 +133,37 @@ impl ModuleInstance {
133133
}
134134

135135
// resolve a function address to the global store address
136-
#[inline(always)]
136+
#[inline]
137137
pub(crate) fn resolve_func_addr(&self, addr: FuncAddr) -> Result<FuncAddr> {
138138
self.0.func_addrs.get(addr as usize).ok_or_else(|| Self::not_found_error("function")).copied()
139139
}
140140

141141
// resolve a table address to the global store address
142-
#[inline(always)]
142+
#[inline]
143143
pub(crate) fn resolve_table_addr(&self, addr: TableAddr) -> Result<TableAddr> {
144144
self.0.table_addrs.get(addr as usize).ok_or_else(|| Self::not_found_error("table")).copied()
145145
}
146146

147147
// resolve a memory address to the global store address
148-
#[inline(always)]
148+
#[inline]
149149
pub(crate) fn resolve_mem_addr(&self, addr: MemAddr) -> Result<MemAddr> {
150150
self.0.mem_addrs.get(addr as usize).ok_or_else(|| Self::not_found_error("mem")).copied()
151151
}
152152

153153
// resolve a data address to the global store address
154-
#[inline(always)]
154+
#[inline]
155155
pub(crate) fn resolve_data_addr(&self, addr: DataAddr) -> Result<DataAddr> {
156156
self.0.data_addrs.get(addr as usize).ok_or_else(|| Self::not_found_error("data")).copied()
157157
}
158158

159159
// resolve a memory address to the global store address
160-
#[inline(always)]
160+
#[inline]
161161
pub(crate) fn resolve_elem_addr(&self, addr: ElemAddr) -> Result<ElemAddr> {
162162
self.0.elem_addrs.get(addr as usize).ok_or_else(|| Self::not_found_error("elem")).copied()
163163
}
164164

165165
// resolve a global address to the global store address
166-
#[inline(always)]
166+
#[inline]
167167
pub(crate) fn resolve_global_addr(&self, addr: GlobalAddr) -> Result<GlobalAddr> {
168168
self.0.global_addrs.get(addr as usize).ok_or_else(|| Self::not_found_error("global")).copied()
169169
}
@@ -216,15 +216,15 @@ impl ModuleInstance {
216216
}
217217

218218
/// Get a memory by address
219-
pub fn memory<'a>(&self, store: &'a mut Store, addr: MemAddr) -> Result<MemoryRef<'a>> {
219+
pub fn memory<'a>(&self, store: &'a Store, addr: MemAddr) -> Result<MemoryRef<'a>> {
220220
let mem = store.get_mem(self.resolve_mem_addr(addr)?)?;
221-
Ok(MemoryRef(mem.borrow()))
221+
Ok(MemoryRef(mem))
222222
}
223223

224224
/// Get a memory by address (mutable)
225225
pub fn memory_mut<'a>(&self, store: &'a mut Store, addr: MemAddr) -> Result<MemoryRefMut<'a>> {
226-
let mem = store.get_mem(self.resolve_mem_addr(addr)?)?;
227-
Ok(MemoryRefMut(mem.borrow_mut()))
226+
let mem = store.get_mem_mut(self.resolve_mem_addr(addr)?)?;
227+
Ok(MemoryRefMut(mem))
228228
}
229229

230230
/// Get the start function of the module

0 commit comments

Comments
 (0)