Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertUninstantiable ParseError #51

Open
bjfish opened this issue Aug 5, 2019 · 1 comment
Open

AssertUninstantiable ParseError #51

bjfish opened this issue Aug 5, 2019 · 1 comment

Comments

@bjfish
Copy link

bjfish commented Aug 5, 2019

I unexpectedly saw AssertUninstantiable while parsing wast files that do not contain assert_uninstantiable.

Expected:

$ cargo run
in AssertTrap

Actual:

$ cargo run
in AssertUninstantiable

Example:

use wabt::script::{Action, Command, CommandKind, Error, ScriptParser, Value};

fn main() -> Result<(), wabt::script::Error> {
    let wast = r#"
(assert_trap
  (module (func $main (unreachable)) (start $main))
  "unreachable"
)
"#;

    let mut parser: ScriptParser = ScriptParser::from_str(wast)?;
    while let Some(Command { kind, .. }) = parser.next()? {
        match kind {
            CommandKind::Module { module, name } => {
                println!("in Module");
            },
            CommandKind::AssertReturn { action, expected } => {
                println!("in AssertReturn");
            },
            CommandKind::AssertTrap { action, message: _ } => {
                println!("in AssertTrap");
            },
            CommandKind::AssertUninstantiable {module: _, message: _,} => {
                 println!("in AssertUninstantiable");
            },
            _ => panic!("there are no other commands apart from that defined above"),
        }
    }
    Ok(())
}

@nlewycky
Copy link
Contributor

nlewycky commented Oct 1, 2019

This is coming in from wabt, outside wabt-rs:

$ cat unin.wast
(assert_trap
  (module (func $main (unreachable)) (start $main))
  "unreachable"
)
$ wabt/build/wast2json unin.wast -o unin.json
$ cat unin.json
{"source_filename": "unin.wast",
 "commands": [
  {"type": "assert_uninstantiable", "line": 2, "filename": "unin.0.wasm", "text": "unreachable", "module_type": "binary"}]}

It appears to be deliberate. Whenever there is an assert_trap, it checks whether you're about to declare a module, and if so creates an assert_uninstantiable instead. Code from wabt:

Result WastParser::ParseAssertTrapCommand(CommandPtr* out_command) {
  WABT_TRACE(ParseAssertTrapCommand);
  EXPECT(Lpar);
  EXPECT(AssertTrap);
  if (PeekMatchLpar(TokenType::Module)) {
    auto command = MakeUnique<AssertUninstantiableCommand>();
    CHECK_RESULT(ParseScriptModule(&command->module));
    CHECK_RESULT(ParseQuotedText(&command->text));
    *out_command = std::move(command);
  } else {
    auto command = MakeUnique<AssertTrapCommand>();
    CHECK_RESULT(ParseAction(&command->action));
    CHECK_RESULT(ParseQuotedText(&command->text));
    *out_command = std::move(command);
  }
  EXPECT(Rpar);
  return Result::Ok;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants