Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 64ed1bf

Browse files
feat: pass full wasm 1.0 testsuite
Signed-off-by: Henry Gressmann <[email protected]>
1 parent be0c5aa commit 64ed1bf

File tree

13 files changed

+111
-144
lines changed

13 files changed

+111
-144
lines changed

.github/workflows/test.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ jobs:
2727
- name: Run tests (stable)
2828
run: cargo +stable test --workspace --exclude wasm-testsuite
2929

30+
- name: Run MVP testsuite
31+
run: cargo +stable test-mvp
32+
3033
test-no-std:
3134
name: Test without default features on nightly Rust
3235
runs-on: ubuntu-latest
@@ -43,3 +46,6 @@ jobs:
4346

4447
- name: Run tests (nightly, no default features)
4548
run: cargo +nightly test --workspace --exclude wasm-testsuite --no-default-features
49+
50+
- name: Run MVP testsuite (nightly)
51+
run: cargo +nightly test-mvp

crates/cli/src/args.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,14 @@ impl From<WasmArg> for WasmValue {
1717
impl FromStr for WasmArg {
1818
type Err = String;
1919
fn from_str(s: &str) -> std::prelude::v1::Result<Self, Self::Err> {
20-
let [ty, val]: [&str; 2] = s
21-
.split(':')
22-
.collect::<Vec<_>>()
23-
.try_into()
24-
.map_err(|e| format!("invalid arguments: {:?}", e))?;
20+
let [ty, val]: [&str; 2] =
21+
s.split(':').collect::<Vec<_>>().try_into().map_err(|e| format!("invalid arguments: {:?}", e))?;
2522

2623
let arg: WasmValue = match ty {
27-
"i32" => val
28-
.parse::<i32>()
29-
.map_err(|e| format!("invalid argument value for i32: {e:?}"))?
30-
.into(),
31-
"i64" => val
32-
.parse::<i64>()
33-
.map_err(|e| format!("invalid argument value for i64: {e:?}"))?
34-
.into(),
35-
"f32" => val
36-
.parse::<f32>()
37-
.map_err(|e| format!("invalid argument value for f32: {e:?}"))?
38-
.into(),
39-
"f64" => val
40-
.parse::<f64>()
41-
.map_err(|e| format!("invalid argument value for f64: {e:?}"))?
42-
.into(),
24+
"i32" => val.parse::<i32>().map_err(|e| format!("invalid argument value for i32: {e:?}"))?.into(),
25+
"i64" => val.parse::<i64>().map_err(|e| format!("invalid argument value for i64: {e:?}"))?.into(),
26+
"f32" => val.parse::<f32>().map_err(|e| format!("invalid argument value for f32: {e:?}"))?.into(),
27+
"f64" => val.parse::<f64>().map_err(|e| format!("invalid argument value for f64: {e:?}"))?.into(),
4328
t => return Err(format!("Invalid arg type: {}", t)),
4429
};
4530

crates/cli/src/bin.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,7 @@ fn main() -> Result<()> {
8484
let cwd = std::env::current_dir()?;
8585

8686
match args.nested {
87-
TinyWasmSubcommand::Run(Run {
88-
wasm_file,
89-
engine,
90-
args,
91-
func,
92-
}) => {
87+
TinyWasmSubcommand::Run(Run { wasm_file, engine, args, func }) => {
9388
debug!("args: {:?}", args);
9489

9590
let path = cwd.join(wasm_file.clone());

crates/parser/src/error.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ impl crate::std::error::Error for ParseError {}
4343

4444
impl From<wasmparser::BinaryReaderError> for ParseError {
4545
fn from(value: wasmparser::BinaryReaderError) -> Self {
46-
Self::ParseError {
47-
message: value.message().to_string(),
48-
offset: value.offset(),
49-
}
46+
Self::ParseError { message: value.message().to_string(), offset: value.offset() }
5047
}
5148
}
5249

crates/tinywasm/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ impl LinkingError {
7070
pub(crate) fn incompatible_import_type(import: &tinywasm_types::Import) -> Self {
7171
Self::IncompatibleImportType { module: import.module.to_string(), name: import.name.to_string() }
7272
}
73+
74+
pub(crate) fn unknown_import(import: &tinywasm_types::Import) -> Self {
75+
Self::UnknownImport { module: import.module.to_string(), name: import.name.to_string() }
76+
}
7377
}
7478

7579
#[derive(Debug)]

crates/tinywasm/src/func.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ macro_rules! impl_from_wasm_value_tuple {
168168
#[allow(unused_variables, unused_mut)]
169169
let mut iter = values.into_iter();
170170

171-
log::error!("from_wasm_value_tuple: {:?}", iter);
172-
173171
Ok((
174172
$(
175173
$T::try_from(

crates/tinywasm/src/imports.rs

Lines changed: 19 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,8 @@ impl Extern {
162162
R: IntoWasmValueTuple + ValTypesFromTuple + Debug,
163163
{
164164
let inner_func = move |ctx: FuncContext<'_>, args: &[WasmValue]| -> Result<Vec<WasmValue>> {
165-
log::error!("args: {:?}", args);
166165
let args = P::from_wasm_value_tuple(args.to_vec())?;
167166
let result = func(ctx, args)?;
168-
log::error!("result: {:?}", result);
169167
Ok(result.into_wasm_value_tuple())
170168
};
171169

@@ -290,18 +288,6 @@ impl Imports {
290288
_ => {}
291289
}
292290

293-
// if expected.size_max.is_none() && actual.size_max.is_some() {
294-
// return Err(LinkingError::incompatible_import_type(import).into());
295-
// }
296-
297-
// if expected.size_max.unwrap_or(0) < actual.size_max.unwrap_or(0) {
298-
// return Err(LinkingError::incompatible_import_type(import).into());
299-
// }
300-
301-
log::error!("size_initial: expected: {:?} got: {:?}", expected.size_initial, actual.size_initial);
302-
log::error!("size_max: expected: {:?} got: {:?}", expected.size_max, actual.size_max);
303-
// TODO: check limits
304-
305291
Ok(())
306292
}
307293

@@ -331,11 +317,6 @@ impl Imports {
331317
_ => {}
332318
}
333319

334-
log::error!("size_initial: {:?} {:?}", expected.page_count_initial, actual.page_count_initial);
335-
log::error!("size_max: {:?} {:?}", expected.page_count_max, actual.page_count_max);
336-
337-
// TODO: check limits
338-
339320
Ok(())
340321
}
341322

@@ -348,13 +329,7 @@ impl Imports {
348329
let mut imports = ResolvedImports::new();
349330

350331
for import in module.data.imports.iter() {
351-
let Some(val) = self.take(store, import) else {
352-
return Err(crate::LinkingError::UnknownImport {
353-
module: import.module.to_string(),
354-
name: import.name.to_string(),
355-
}
356-
.into());
357-
};
332+
let val = self.take(store, import).ok_or_else(|| LinkingError::unknown_import(import))?;
358333

359334
match val {
360335
// A link to something that needs to be added to the store
@@ -364,42 +339,31 @@ impl Imports {
364339
imports.globals.push(store.add_global(extern_global.ty, extern_global.val.into(), idx)?);
365340
}
366341
(Extern::Table(extern_table), ImportKind::Table(ty)) => {
367-
Self::compare_table_types(import, &extern_table.ty, &ty)?;
342+
Self::compare_table_types(import, &extern_table.ty, ty)?;
368343
imports.tables.push(store.add_table(extern_table.ty, idx)?);
369344
}
370345
(Extern::Memory(extern_memory), ImportKind::Memory(ty)) => {
371-
Self::compare_memory_types(import, &extern_memory.ty, &ty, None)?;
346+
Self::compare_memory_types(import, &extern_memory.ty, ty, None)?;
372347
imports.memories.push(store.add_mem(extern_memory.ty, idx)?);
373348
}
374349
(Extern::Function(extern_func), ImportKind::Function(ty)) => {
375-
let import_func_type = module.data.func_types.get(*ty as usize).ok_or_else(|| {
376-
crate::LinkingError::IncompatibleImportType {
377-
module: import.module.to_string(),
378-
name: import.name.to_string(),
379-
}
380-
})?;
350+
let import_func_type = module
351+
.data
352+
.func_types
353+
.get(*ty as usize)
354+
.ok_or_else(|| LinkingError::incompatible_import_type(import))?;
381355

382356
Self::compare_types(import, extern_func.ty(), import_func_type)?;
383357
imports.funcs.push(store.add_func(extern_func, *ty, idx)?);
384358
}
385-
_ => {
386-
return Err(crate::LinkingError::IncompatibleImportType {
387-
module: import.module.to_string(),
388-
name: import.name.to_string(),
389-
}
390-
.into());
391-
}
359+
_ => return Err(LinkingError::incompatible_import_type(import).into()),
392360
},
393361

394362
// A link to something already in the store
395363
ResolvedExtern::Store(val) => {
396364
// check if the kind matches
397365
if val.kind() != (&import.kind).into() {
398-
return Err(crate::LinkingError::IncompatibleImportType {
399-
module: import.module.to_string(),
400-
name: import.name.to_string(),
401-
}
402-
.into());
366+
return Err(LinkingError::incompatible_import_type(import).into());
403367
}
404368

405369
match (val, &import.kind) {
@@ -410,37 +374,30 @@ impl Imports {
410374
}
411375
(ExternVal::Table(table_addr), ImportKind::Table(ty)) => {
412376
let table = store.get_table(table_addr as usize)?;
413-
Self::compare_table_types(import, &table.borrow().kind, &ty)?;
377+
Self::compare_table_types(import, &table.borrow().kind, ty)?;
414378
imports.tables.push(table_addr);
415379
}
416380
(ExternVal::Mem(memory_addr), ImportKind::Memory(ty)) => {
417381
let mem = store.get_mem(memory_addr as usize)?;
418382
let (size, kind) = {
419383
let mem = mem.borrow();
420-
(mem.page_count(), mem.kind.clone())
384+
(mem.page_count(), mem.kind)
421385
};
422-
Self::compare_memory_types(import, &kind, &ty, Some(size))?;
386+
Self::compare_memory_types(import, &kind, ty, Some(size))?;
423387
imports.memories.push(memory_addr);
424388
}
425389
(ExternVal::Func(func_addr), ImportKind::Function(ty)) => {
426390
let func = store.get_func(func_addr as usize)?;
427-
let import_func_type = module.data.func_types.get(*ty as usize).ok_or_else(|| {
428-
crate::LinkingError::IncompatibleImportType {
429-
module: import.module.to_string(),
430-
name: import.name.to_string(),
431-
}
432-
})?;
391+
let import_func_type = module
392+
.data
393+
.func_types
394+
.get(*ty as usize)
395+
.ok_or_else(|| LinkingError::incompatible_import_type(import))?;
433396

434397
Self::compare_types(import, func.func.ty(), import_func_type)?;
435398
imports.funcs.push(func_addr);
436399
}
437-
_ => {
438-
return Err(crate::LinkingError::IncompatibleImportType {
439-
module: import.module.to_string(),
440-
name: import.name.to_string(),
441-
}
442-
.into());
443-
}
400+
_ => return Err(LinkingError::incompatible_import_type(import).into()),
444401
}
445402
}
446403
}

crates/tinywasm/src/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl ModuleInstance {
7070
addrs.tables.extend(store.init_tables(data.table_types.into(), idx)?);
7171
addrs.memories.extend(store.init_memories(data.memory_types.into(), idx)?);
7272

73-
let global_addrs = store.init_globals(addrs.globals, data.globals.into(), idx)?;
73+
let global_addrs = store.init_globals(addrs.globals, data.globals.into(), &addrs.funcs, idx)?;
7474
let (elem_addrs, elem_trapped) =
7575
store.init_elements(&addrs.tables, &addrs.funcs, &global_addrs, data.elements.into(), idx)?;
7676
let (data_addrs, data_trapped) = store.init_datas(&addrs.memories, data.data.into(), idx)?;

crates/tinywasm/src/runtime/executor/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ fn exec_one(
139139
}
140140

141141
Call(v) => {
142-
log::info!("start call");
143142
// prepare the call frame
144143
let func_idx = module.resolve_func_addr(*v);
145144
let func_inst = store.get_func(func_idx as usize)?.clone();
@@ -148,19 +147,14 @@ fn exec_one(
148147
crate::Function::Wasm(ref f) => (f.locals.to_vec(), f.ty.clone()),
149148
crate::Function::Host(host_func) => {
150149
let func = host_func.func.clone();
151-
log::info!("Getting params: {:?}", host_func.ty.params);
152150
let params = stack.values.pop_params(&host_func.ty.params)?;
153-
log::error!("Calling host function, params: {:?}", params);
154151
let res = (func)(FuncContext { store, module }, &params)?;
155152
stack.values.extend_from_typed(&res);
156153
return Ok(ExecResult::Ok);
157154
}
158155
};
159156

160157
let params = stack.values.pop_n_rev(ty.params.len())?;
161-
log::info!("call: current fn owner: {:?}", module.id());
162-
log::info!("call: func owner: {:?}", func_inst.owner);
163-
164158
let call_frame = CallFrame::new_raw(func_inst, &params, locals);
165159

166160
// push the call frame

crates/tinywasm/src/runtime/stack/blocks.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ impl LabelArgs {
7272
Ok(match args {
7373
BlockArgs::Empty => LabelArgs { params: 0, results: 0 },
7474
BlockArgs::Type(_) => LabelArgs { params: 0, results: 1 },
75-
BlockArgs::FuncType(t) => LabelArgs {
76-
params: module.func_ty(t).params.len(),
77-
results: module.func_ty(t).results.len(),
78-
},
75+
BlockArgs::FuncType(t) => {
76+
LabelArgs { params: module.func_ty(t).params.len(), results: module.func_ty(t).results.len() }
77+
}
7978
})
8079
}
8180
}

0 commit comments

Comments
 (0)