-
Notifications
You must be signed in to change notification settings - Fork 10
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
Print error message #110
Print error message #110
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This improves the usage of shell a lot. Some comments though.
src/shell/Shell.cpp
Outdated
fprintf(stderr, "Syntax error"); | ||
if (errors.size() > 1) | ||
fprintf(stderr, "s"); | ||
fprintf(stderr, ":\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fprintf(stderr, "Syntax error(s)\n");
is enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
src/shell/Shell.cpp
Outdated
fprintf(stderr, ":\n"); | ||
int i = 1; | ||
for (auto e : errors) | ||
fprintf(stderr, "%15d.) %s\n", i++, e.message.c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is rare to have many errors, and their index is not improtant, so I think just print the error messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay
src/shell/Shell.cpp
Outdated
auto trapResult = executeWASM(store, filename, buf->data, functionTypes, ®isteredInstanceMap); | ||
if (trapResult.exception) { | ||
std::string& errorMessage = trapResult.exception->message(); | ||
fprintf(stderr, "Semantic error: %s\n", errorMessage.c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Error: "
is enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay
src/shell/Shell.cpp
Outdated
printf(") expect value("); | ||
printConstVector(data->expectedResult); | ||
printf(") (line: %d) : FAILED\n", data->action->loc.line); | ||
abort(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think printing i
, result[i]
, and data->expectedResult[i]
are the key thing here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, printf
is used to print messages but other case, fprintf
is used instead.
For the code consistency, please use just one function for printing messages.
One more, we prefer RELEASE_ASSERT
or ASSERT
to abort
function.
Please change abort
function too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
Thank you!
In this patch, you replaced some |
src/runtime/Module.cpp
Outdated
@@ -282,7 +282,7 @@ Instance* Module::instantiate(ExecutionState& state, const ExternVector& imports | |||
&data); | |||
} | |||
|
|||
if (UNLIKELY(elem->tableIndex() >= numberOfTableTypes() || index >= instance->m_tables[elem->tableIndex()]->size() || index + elem->functionIndex().size() > instance->m_tables[elem->tableIndex()]->size())) { | |||
if (UNLIKELY(elem->tableIndex() >= numberOfTableTypes() || index > instance->m_tables[elem->tableIndex()]->size() || index + elem->functionIndex().size() > instance->m_tables[elem->tableIndex()]->size())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that index >= instance->m_tables[elem->tableIndex()]->size()
can be totally removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe adding an (uint64_t)
casting could be used to avoid overflow situations.
Btw, isn't the wabt validator should be able to catch these issues? We could check it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked this?
It seems that wabt validator cannot check this case in advance.. but what do you think about it?
https://github.com/Samsung/walrus/blob/interp/src/Walrus.h#L266 RELEASE_ASSERT is basically an |
I'm wondering that additionally printing error messages are really necessary for each |
It is a developer friendly patch, since it is hard to tell (for me) the actual error from the error message provided by shell. So this is a QoL change not a functionality change. It only affects the shell, not the engine. |
We could use a macro to make the code simpler if that would help. |
src/shell/Shell.cpp
Outdated
RELEASE_ASSERT(data->fn->functionType()->result().size() == data->expectedResult.size()); | ||
// compare result | ||
for (size_t i = 0; i < result.size(); i++) { | ||
RELEASE_ASSERT(equals(result[i], data->expectedResult[i])); | ||
if (!equals(result[i], data->expectedResult[i])) { | ||
printf("Assert FAILED (line: %d) ", data->action->loc.line); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you going to replace all RELEASE_ASSERT
statements by this approach?
If so, please consider all RELEASE_ASSERT
cases in this patch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
d537e06
to
41207f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close to done
src/shell/Shell.cpp
Outdated
if (!wabt::Succeeded(result)) { | ||
RELEASE_ASSERT_NOT_REACHED(); | ||
return; | ||
if (wabt::Succeeded(result) == false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!wabt::Succeeded(result)
is ok
src/shell/Shell.cpp
Outdated
if (assertReturn->action->type() == wabt::ActionType::Invoke) { | ||
auto action = static_cast<wabt::InvokeAction*>(assertReturn->action.get()); | ||
auto fn = fetchInstance(action->module_var, instanceMap, registeredInstanceMap)->resolveExportFunction(action->name); | ||
executeInvokeAction(action, fn, assertReturn->expected, nullptr); | ||
} else if (assertReturn->action->type() == wabt::ActionType::Get) { | ||
auto action = static_cast<wabt::GetAction*>(assertReturn->action.get()); | ||
auto v = fetchInstance(action->module_var, instanceMap, registeredInstanceMap)->resolveExportGlobal(action->name)->value(); | ||
RELEASE_ASSERT(equals(v, assertReturn->expected[0])) | ||
if (equals(v, assertReturn->expected[0]) == false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!equals
std::vector<uint8_t> buf; | ||
if (tsm) { | ||
buf = readModuleData(&tsm->module)->data; | ||
} else { | ||
buf = dsm->data; | ||
} | ||
auto trapResult = executeWASM(store, filename, buf, functionTypes); | ||
RELEASE_ASSERT(trapResult.exception); | ||
if (trapResult.exception == nullptr) { | ||
printf("Execute WASM returned nullptr (in wabt::CommandType::AssertInvalid case)\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected exception: assertModuleInvalid->text.data()
std::vector<uint8_t> buf; | ||
if (tsm) { | ||
buf = readModuleData(&tsm->module)->data; | ||
} else { | ||
buf = dsm->data; | ||
} | ||
auto trapResult = executeWASM(store, filename, buf, functionTypes); | ||
RELEASE_ASSERT(trapResult.exception); | ||
if (trapResult.exception == nullptr) { | ||
printf("Execute WASM returned nullptr (in wabt::CommandType::AssertUnlinkable case)\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected exception
src/shell/Shell.cpp
Outdated
@@ -427,7 +438,9 @@ static Walrus::Value toWalrusValue(wabt::Const& c) | |||
return Walrus::Value(Walrus::Value::ExternRef, c.ref_bits() + 1, Walrus::Value::Force); | |||
} | |||
default: | |||
RELEASE_ASSERT_NOT_REACHED(); | |||
printf("Error: unknown value type during converting wabt::Const to wabt::Value\n"); | |||
ASSERT_NOT_REACHED(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep RELEASE_ASSERT_NOT_REACHED
src/shell/Shell.cpp
Outdated
} | ||
default: { | ||
printf("Error: unkown wabt::Const type\n"); | ||
ASSERT_NOT_REACHED(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep RELEASE_ASSERT_NOT_REACHED
src/shell/Shell.cpp
Outdated
RELEASE_ASSERT(fn->functionType()->param().size() == action->args.size()); | ||
if (fn->functionType()->param().size() != action->args.size()) { | ||
printf("Error: expected %zu parameter(s) but got %zu.\n", fn->functionType()->param().size(), action->args.size()); | ||
ASSERT_NOT_REACHED(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this assert is weaker than RELEASE_ASSERT_NOT_REACHED, keep the latter everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
- fix 2 typos (uint16_t to Walrus::ByteCodeStackOffset) - fix 1 typo (because of it 3 tests failed, altough it was unnoticable hence the error wasn't caught) - refactor nested if...else to switch...case - print error message before exit - make string() operator for Value class
099a77a
to
71ca82d
Compare
Since this patch is updated now, could we land it? |
May I alter something or is it good? |
Sorry for late 😢 |
fix 2 typo (replace uint16_t with Walrus::ByteCodeStackOffset).
fix another typo. Because of it 3 tests
failed (binary.wast, binary-leb128.wast, elem.wast), but it didn't throw assert failed and the ExecuteWASM() returned with an error that wasn't caught.
For example in elem.wast:174-177 where it tries to write nothing to a 0 sized table: