From 55af054b6b0b6d30fca7da43ac1c4522ff812e67 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 24 Mar 2021 16:40:00 -0700 Subject: Validator: Pass the module along when printing errors, so type names are used (#3727) For example, on this invalid wat: (module (type $vec (struct (field i64))) (func $test (drop (struct.new_with_rtt $vec (i32.const 1) (rtt.canon $vec)) ) ) ) We used to print: [wasm-validator error in function test] struct.new operand must have proper type, on (struct.new_with_rtt ${i64} (i32.const 1) (rtt.canon ${i64}) ) We will now print: [wasm-validator error in function test] struct.new operand must have proper type, on (struct.new_with_rtt $vec (i32.const 1) (rtt.canon $vec) ) Note that $vec is used. In real-world examples the autogenerated structural name can be huge, which this avoids. --- src/wasm/wasm-validator.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/wasm/wasm-validator.cpp') diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index b49b4bb0f..14955ecae 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -35,22 +35,25 @@ template::type>::value>::type* = nullptr> -inline std::ostream& printModuleComponent(T curr, std::ostream& stream) { +inline std::ostream& +printModuleComponent(T curr, std::ostream& stream, Module& wasm) { stream << curr << std::endl; return stream; } // Extra overload for Expressions, to print their contents. -inline std::ostream& printModuleComponent(Expression* curr, - std::ostream& stream) { +inline std::ostream& +printModuleComponent(Expression* curr, std::ostream& stream, Module& wasm) { if (curr) { - stream << *curr << '\n'; + stream << ModuleExpression(wasm, curr) << '\n'; } return stream; } // For parallel validation, we have a helper struct for coordination struct ValidationInfo { + Module& wasm; + bool validateWeb; bool validateGlobally; bool quiet; @@ -63,7 +66,7 @@ struct ValidationInfo { std::mutex mutex; std::unordered_map> outputs; - ValidationInfo() { valid.store(true); } + ValidationInfo(Module& wasm) : wasm(wasm) { valid.store(true); } std::ostringstream& getStream(Function* func) { std::unique_lock lock(mutex); @@ -86,7 +89,7 @@ struct ValidationInfo { } auto& ret = printFailureHeader(func); ret << text << ", on \n"; - return printModuleComponent(curr, ret); + return printModuleComponent(curr, ret, wasm); } std::ostream& printFailureHeader(Function* func) { @@ -2919,7 +2922,7 @@ static void validateFeatures(Module& module, ValidationInfo& info) { // then Using PassRunner::getPassDebug causes a circular dependence. We should // fix that, perhaps by moving some of the pass infrastructure into libsupport. bool WasmValidator::validate(Module& module, Flags flags) { - ValidationInfo info; + ValidationInfo info(module); info.validateWeb = (flags & Web) != 0; info.validateGlobally = (flags & Globally) != 0; info.quiet = (flags & Quiet) != 0; -- cgit v1.2.3