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
[Proposal] Add exception handling proposal on interpreter mode #2459
[Proposal] Add exception handling proposal on interpreter mode #2459
Conversation
Hello, I am a code review bot on flows.network. Here are my reviews of code commits in this PR. The GitHub Pull Request by Harry Chiang is an expansive update aiming at integrating and enhancing exception handling in the interpreter mode of the software. This proposal involves structural changes to the exception handling process, as well as the addition of a number of new classes, methods, and configurations related to this objective. A principal concern is the significant increase in complexity introduced to the Instruction class, coupled with the coupling of TagTypes to FunctionTypes. Changes have been made to constructors and destructors to account for new fields like the JumpCatchList, making the memory management more intricate. The absence of a significant number of tests in areas of considerable modification presents risks, especially regarding exception scenarios, memory management and handling of edge cases, which can allow critical issues manifest undetected. The changes in instructions handling, especially with JumpCatchList and removal of Tag, might impact other code sections, and thorough evaluation of the interdependency impact is required. The addition of new configuration options raises concerns about code repetition and handling unaccounted cases, which might negatively affect maintainability. Certain changes lack documentation or clear rationale, like the rationale behind renaming to This PR is part of a broader set of changes, analysis in isolation might miss certain potential problems. Hence, it might be beneficial to review this change in the context of a broader system. It is highly recommended to increase the code test coverage, improve the documentation, and reduce complexity where possible. Additionally, the pull request could benefit from improved error messaging and memory management review, amongst others. All these steps would contribute towards a more robust and maintainable code. DetailsCommit a794a5194e8bd6ee053af9385e289856e378c0d3Summary: Identified Potential Problems:
Commit 8f182b1a4ab9feb7188bf7452142ead82cc86379Based on the affected files and code, the patch primarily adds exception handling to the interpreter mode of the software. Notable changes include:
This is a considerable change, making core additions to the script's interpretation process. While the pull request doesn't contain any apparent syntactical errors, there are several areas where problems may arise:
Commit 97eb69f979ae87cea6b62af50b4c26d9d13e7620Summary of the key changes:
Potential problems and concerns:
Commit bf8e5a160d15f5851d04a664f8e86c09d5a45609Summary of the changes:
Potential problems:
Recommendations:
Commit 28dba5d0b68b53017b7a8485dd3384d610aab22cSummary of changes: Harry Chiang has made various changes to the file
Potential problems:
Overall, this commit seems to be a part of a broader set of changes, so analyzing it in isolation might not cover all of the potential problems. Further code review would be beneficial to examine the impact on the system as a whole. Commit 4177263b849332a471d8f48c35673b23078fd3a9This is a code formatting patch. The following are the key changes:
There doesn't appear to be much potential for breaking functionality in this patch as it only does reformatting, so there are no logical changes. Nevertheless, developers need to ensure that consistent formatting rules and style guides are used project-wide to avoid such piecemeal formatting adjustments, which might disrupt the development flow and lead to clutter in version history. All commits should be tested for compilation and functionality just to be sure, even if they are expected not to affect the functionality. Commit 322621757d593d91e91c3a542b2ba57847c818b9The pull request titled "[Proposal] Add exception handling proposal on interpreter mode" is proposing the removal of a Data Tag in the Instruction class and changing code logic to match this modification. The key information is:
The most important change is in the instruction header file, where the struct named Potential issues might include:
Commit c9228b05e8d6cf1c9a0d098dc51feccceb01fd3cSummary of Key Changes:
Potential Problems:
Suggestions:
Commit e5aa96ae0804615c34d4e6ccdab30d7938bd4e76The patch by developer 'Harry Chiang' introduces changes in Key Changes:
Potential Problems:
Please make sure the tests are written and all scenarios are considered. Also, handle all the possible error conditions. Commit 9c7a6cf0172b6172a38c428a16064ff3fb3112f4Changes:
Potential problems:
Commit 09a7829097e616fd73ebf1065fd97c68b9a203cbKey Changes:
Potential Problems:
Suggestion: It would be best to integrate clang-format or any other formatters as part of the CI/CD pipeline so that the codebase follows the same style guide and avoids such massive reformatting PRs. Commit 97efe019f1336700f24ca7a1adfc2603b82f1d34This patch from Harry Chiang includes some changes to the comments and function names on an interface in the file The changes mainly revolve around three functions that act as getters and setters for flag states of instructions in a code interpreter. The changes are as follows:
These changes imply the introduction of exception handling for Potential problems:
Commit a1236e7a16e9f897f3008c490c5a54f8915682b8The Pull Request is a patch on the test/spec/spectest.cpp file. The developer, Harry Chiang, is suggesting modifications on the "exception-handling" section of the TestsuiteProposals array. Key Changes:
Potential Problems:
Recommendation: It would be helpful if the developer could provide more context on this change in the comments. Information about the purpose of this change and any necessary testing that has been conducted is useful. It would also help to know how this change impacts the rest of the project and if dependencies have been taken into account. Commit ade6e5916af4e2ba701dc05ad7398818b9c74e4aThe pull request introduces exception handling to the interpreter mode. Here are the key changes:
Potential problems that may arise include:
This pull request needs some changes in exception testing and properly handling the outlined potential problems before it could be accepted. Commit d86639f0e8b19be9e6dfe75d6f4380f8cd0fc6deChanges: Potential Problems:
Important Notes: Commit dcf092273bdcc6b55274d0dd92e220553aa84f71Summary: Changes:
Potential Problems:
In conclusion, it is advised to take buffer access and potential size growth into consideration when making changes related to exception handling. These areas introduce potential risks that could lead to bugs or performance issues. Commit 630fa6f2998daa0aebff9b101d1c43d314664b57The main changes proposed in this commit titled "[PATCH 17/28] Resolve windows CI issue" revolve around modifying the existing data types from • ast/instruction.h More specifically, the changes are aimed at typecasting the Possible problem areas:
Lastly, since the commit modifies central files within the codebase, comprehensive unit and integration testing should be carried out to understand the impact of changes. If this hasn't been done, it could be a potential area of concern. Commit 7ec47a766742c35dbc4fa6f738e5fdfb39945fb5Title: [Proposal] Add exception handling proposal on interpreter mode The contributor, Harry Chiang, primarily made changes to the The primary changes involved fixing type casting issues. There are situations where the Three changes in the
This pull request seems like an attempt to fix CI issues related to type conversion on a Windows build system. However, an additional validation could be added to ensure that Commit 378fd143c0c7bc973b1ebdefc3969932ef1537e9Summary of Changes: Potential Problems:
Commit f3d1452869b6b24077e95739249cbdc44eefead4The main changes in this patch are as follows:
Potential problems and considerations:
Commit 9f3e630d89beab2be8790ca825db31a68e6ede28This patch from Harry Chiang is titled "Resolve Windows CI issue" and it involves the modification of a single file: 'lib/executor/instantiate/export.cpp'. Key Change:
Potential Issues:
Overall, more context around this change is needed from the developer before proceeding with the merge. Commit 0e44fd58fefd0c7c917b38262d6a7160c5b1f3a9This patch by Harry Chiang focuses on correcting a spelling error in the file formchecker.cpp, which is part of lib/validator in the software. Specifically, the nomeclature of the iteration variable in a for loop has been changed from 'it' to 'It', for maintaining code consistency and better readability. Summary of changes:
Potential problems:
As this is only a simple renaming of a variable, and this does not cause any side effects throughout the rest of the code, no other potential problems significantly stand out in this patch. However, regression testing to ensure no functionality is unexpectedly altered due to this change would still be a good practice. Commit 90f826d3b906674181ca67bb2b104931fa9e0b70The provided patch mainly comprises of two key changes.
{"exception-handling"sv,
{Proposal::ExceptionHandling, Proposal::TailCall},
WasmEdge::SpecTest::TestMode::Interpreter},
// Before
const auto V = reinterpret_cast<const uint32x4_t&>(V64);
// After
const auto V = reinterpret_cast<const uint32x4_t &>(V64); Potential Problem:
For a comprehensive review, a thorough investigation of the referenced variables is necessary, their scope, lifespan, and whether they are being modified elsewhere, especially in multithreading context. The existing code testing and error handling should be reconfirmed to handle this change. Additionally, more tests should be added to validate the new test mode Commit d626285b034b53eada8b5f7e4cf54f5f78306a1eThe patch includes changes made to the
There is no addition or deletion of any functionality, and only the function perimeters for the method are changed. The purpose of the change is likely to fix a type mismatch warning on windows. Potential problems to be aware of:
Commit b28ab89f1daaabd8b001a23d3af0e0da60f27412Summary of Changes:
Potential Problems:
Suggestions: Commit 03d8066e6ef700b5d1d03163ff259fc44f7404bcSummary of Changes: Potential Issues:
In conclusion, while the code should still work as expected, additional tests under different conditions or platforms could help ensure the change does not introduce unexpected side effects. Commit 8ddd4490306e85460ab098ad7c10951704e7475fThis patch is primarily concerned with the handling of exceptions within the interpreter mode. More specifically, it modifies the class StackManager in the header file stackmgr.h. The changes predominantly change the order of operations within the stack size calculations in methods emplace_back of HandlerStack and pushHandler. Key modifications include:
Potential problems and considerations:
|
26c01aa
to
aae5ccf
Compare
ede7226
to
01dea61
Compare
// TODO: Check expected exception type | ||
if (ActType == "invoke"sv) { | ||
ExceptionInvoke(Action, LineNumber); | ||
return; | ||
} | ||
EXPECT_TRUE(false); | ||
return; |
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.
According to the spec test json file, there's an "expected" section to check the type of uncaught exception. However, it would be quite unclean to deal with it under the current code structure if we want to get the type of the uncaught exception. Therefore, I think it's enough for us to check whether there's an uncaught exception.
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.
Sounds acceptable? Does the expected
section require by the Spec?
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'm not sure whether this is require by the spec.
Below is the example json config for spec test. If I understand correctly, "type" inside "expected" is the type of the value associated with the exception. Our implementation to handle "expected" actually suppose there should be a "value" after "type" just like the below "assert_return". Furthermore, "assert_trap" also have the "expected" section, but it seems that our spectest.cpp doesn't deal with it either. So, I believe it's acceptable to not deal with the "expected" section with "assert_exception".
{"type": "assert_trap", "line": 160, "action": {"type": "invoke", "field": "trap-in-callee", "args": [{"type": "i32", "value": "1"}, {"type": "i32", "value": "0"}]}, "text": "integer divide by zero", "expected": [{"type": "i32"}]},
{"type": "assert_return", "line": 162, "action": {"type": "invoke", "field": "catch-complex-1", "args": [{"type": "i32", "value": "0"}]}, "expected": [{"type": "i32", "value": "3"}]},
{"type": "assert_return", "line": 163, "action": {"type": "invoke", "field": "catch-complex-1", "args": [{"type": "i32", "value": "1"}]}, "expected": [{"type": "i32", "value": "4"}]},
{"type": "assert_exception", "line": 164, "action": {"type": "invoke", "field": "catch-complex-1", "args": [{"type": "i32", "value": "2"}]}, "expected": [{"type": "i32"}]},
{"type": "assert_return", "line": 166, "action": {"type": "invoke", "field": "catch-complex-2", "args": [{"type": "i32", "value": "0"}]}, "expected": [{"type": "i32", "value": "3"}]},
{"type": "assert_return", "line": 167, "action": {"type": "invoke", "field": "catch-complex-2", "args": [{"type": "i32", "value": "1"}]}, "expected": [{"type": "i32", "value": "4"}]},
{"type": "assert_exception", "line": 168, "action": {"type": "invoke", "field": "catch-complex-2", "args": [{"type": "i32", "value": "2"}]}, "expected": [{"type": "i32"}]},
: CatchCaluse(), EndIt(E), VPos(V), FPos(F), HPos(H), CPos(C) {} | ||
// nullptr stands for catch all clause | ||
std::vector< | ||
std::pair<Runtime::Instance::TagInstance *, AST::InstrView::iterator>> |
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'm not sure whether it's a proper way to distinguish the tag by the address. The current implementation may compare two tag address to indicate whether they are the same tag.
The current implementation may pass the exception handling spec test. But, it may failed on the following test right now:
For the AOT test, I believe it's reasonable since I hasn't implemented AOT yet. For the rest of the tests, they all failed on the same part:
It seems that it's because the binary format has changed, the malformed part may be distinguished as another type of error. I hasn't come up with a good work around. Do yo have any idea? |
Another question, do I have to add several tag related function to WasmEdge C API? For example: |
01dea61
to
3ab345f
Compare
If we are going to implement the AOT part, then we should have this PR as a standalone branch until all tests are green.
Does the binary format change during this proposal? |
Yes. |
Yes, so this would be merged into WasmEdge:proposal/exception-handling The below issue has been resolved.
To be more specific, some wasm may be parsed successfully after enabling exception handling while they are malformed before. The current problem is that our implementation may generate a different error message compare to the spec test. I believe it's because part of the malformed part become valid after enabling exception handling proposal, but it's still malformed. And I believe the error message generated by the current implementation is reasonable. We can check the failed binary.139.wasm and binary.140.wasm by wasm2wat. It has the different error message 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.
Suggestion of the tag section:
- TagSection: vector of TagType
- TagType: 0x00 (uint8_t in current), TypeIndex (uint32_t), FunctionType*
- At the end of the module loading, find the pointer of function types and set into the content of tag section.
- TagInstanance: TagType
72e8f93
to
461f4b7
Compare
Signed-off-by: Harry Chiang <harry900831@gmail.com>
e461a5f
to
2f5e914
Compare
Signed-off-by: Harry Chiang <harry900831@gmail.com>
2f5e914
to
90f826d
Compare
Codecov Report
@@ Coverage Diff @@
## proposal/exception-handling #2459 +/- ##
===============================================================
- Coverage 80.99% 80.85% -0.15%
===============================================================
Files 150 152 +2
Lines 21596 22138 +542
Branches 4338 4477 +139
===============================================================
+ Hits 17492 17900 +408
- Misses 2944 3042 +98
- Partials 1160 1196 +36
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Signed-off-by: Harry Chiang <harry900831@gmail.com>
Signed-off-by: Harry Chiang <harry900831@gmail.com>
@q82419 |
You can use |
Signed-off-by: Harry Chiang <harry900831@gmail.com>
Signed-off-by: Harry Chiang <harry900831@gmail.com>
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. @q82419 PTAL.
ce9685d
into
WasmEdge:proposal/exception-handling
Signed-off-by: Harry Chiang <harry900831@gmail.com>
Signed-off-by: Harry Chiang <harry900831@gmail.com>
Signed-off-by: Harry Chiang <harry900831@gmail.com>
Signed-off-by: Harry Chiang <harry900831@gmail.com>
Signed-off-by: Harry Chiang <harry900831@gmail.com>
Signed-off-by: Harry Chiang <harry900831@gmail.com>
Signed-off-by: Harry Chiang <harry900831@gmail.com>
Signed-off-by: Harry Chiang <harry900831@gmail.com>
Signed-off-by: Harry Chiang <harry900831@gmail.com>
Signed-off-by: Harry Chiang <harry900831@gmail.com>
Signed-off-by: Harry Chiang <harry900831@gmail.com>
Signed-off-by: Harry Chiang <harry900831@gmail.com>
Signed-off-by: Harry Chiang <harry900831@gmail.com>
#2335
Note
We may now generated the wasm with exception handling by
emcc -O1 -fwasm-exceptions a.cpp -o a.wasm
and test it on the interpreter mode.Example
Output:
However, if I replace printf by cout, the execution may crash. It seems that cout may contain several complicated exception handling block. I think we can merge this first and solve this issue in the future.
References