Skip to content

Commit 787bf9a

Browse files
chore: undo BlockStack changes
Signed-off-by: Henry <mail@henrygressmann.de>
1 parent af3029b commit 787bf9a

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

crates/tinywasm/src/engine.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ pub const DEFAULT_VALUE_STACK_128_SIZE: usize = 4 * 1024; // 4k slots
5252
pub const DEFAULT_VALUE_STACK_REF_SIZE: usize = 4 * 1024; // 4k slots
5353

5454
/// Default initial size for the block stack (control frames).
55-
pub const DEFAULT_BLOCK_STACK_SIZE: usize = 1024; // 1024 frames
55+
pub const DEFAULT_BLOCK_STACK_SIZE: usize = 2048; // 1024 frames
5656

5757
/// Default initial size for the call stack (function frames).
58-
pub const DEFAULT_CALL_STACK_SIZE: usize = 1024; // 1024 frames
58+
pub const DEFAULT_CALL_STACK_SIZE: usize = 2048; // 1024 frames
5959

6060
/// Configuration for the WebAssembly interpreter
6161
#[derive(Debug, Clone)]
@@ -71,8 +71,9 @@ pub struct Config {
7171
pub stack_ref_size: usize,
7272
/// Initial size of the call stack.
7373
pub call_stack_size: usize,
74-
/// Initial size of the control stack (block stack).
75-
pub block_stack_size: usize,
74+
75+
/// Initial size of the block stack.
76+
pub block_stack_initial_size: usize,
7677
}
7778

7879
impl Config {
@@ -90,7 +91,7 @@ impl Default for Config {
9091
stack_128_size: DEFAULT_VALUE_STACK_128_SIZE,
9192
stack_ref_size: DEFAULT_VALUE_STACK_REF_SIZE,
9293
call_stack_size: DEFAULT_CALL_STACK_SIZE,
93-
block_stack_size: DEFAULT_BLOCK_STACK_SIZE,
94+
block_stack_initial_size: DEFAULT_BLOCK_STACK_SIZE,
9495
}
9596
}
9697
}

crates/tinywasm/src/interpreter/stack/block_stack.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use crate::engine::Config;
22
use alloc::vec::Vec;
33

4+
use crate::Result;
45
use crate::interpreter::values::{StackHeight, StackLocation};
5-
use crate::{Result, Trap};
66

77
#[derive(Debug)]
88
pub(crate) struct BlockStack(Vec<BlockFrame>);
99

1010
impl BlockStack {
1111
pub(crate) fn new(config: &Config) -> Self {
12-
Self(Vec::with_capacity(config.block_stack_size))
12+
Self(Vec::with_capacity(config.block_stack_initial_size))
1313
}
1414

1515
pub(crate) fn clear(&mut self) {
@@ -21,19 +21,15 @@ impl BlockStack {
2121
}
2222

2323
pub(crate) fn push(&mut self, block: BlockFrame) -> Result<()> {
24-
if self.0.len() >= self.0.capacity() {
25-
return Err(Trap::BlockStackOverflow.into());
26-
}
27-
2824
self.0.push(block);
2925
Ok(())
3026
}
3127

3228
/// get the label at the given index, where 0 is the top of the stack
3329
pub(crate) fn get_relative_to(&self, index: u32, offset: u32) -> Option<&BlockFrame> {
34-
let len = (self.0.len() as u32) - offset;
30+
let len = (self.0.len() as u32).checked_sub(offset)?;
3531

36-
// the vast majority of wasm functions don't use break to return
32+
// the vast majority of wasm functions don't use break to return, but it is allowed in the spec
3733
if index >= len {
3834
return None;
3935
}

crates/tinywasm/tests/test-wasm-tail-call.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fn main() -> Result<()> {
88

99
let mut test_suite = TestSuite::new();
1010
test_suite.run_files(proposal(&Proposal::TailCall))?;
11+
test_suite.print_errors();
1112
test_suite.save_csv("./tests/generated/wasm-tail-call.csv", env!("CARGO_PKG_VERSION"))?;
1213
test_suite.report_status()
1314
}

0 commit comments

Comments
 (0)