Skip to content

Reworking iree_status_t/iree::Status and improving error messages across the VM - #2849

Merged
ScottTodd merged 54 commits into
mainfrom
benvanik-status
Aug 17, 2020
Merged

ScottTodd merged 54 commits into
mainfrom
benvanik-status

Conversation

@benvanik

@benvanik benvanik commented Aug 11, 2020 •

Copy link
Copy Markdown
Collaborator

This fixes #265 by implementing the described iree_status_t behavior and changing Status/StatusBuilder/StatusOr to wrap it. By doing this I was able to remove quite a bit of gunk that was required to move between the Google-style C++ Status and the API (such as ToApiStatus/FromApiStatus).

By being able to integrate iree_status_t into the C++ types I was also able to unify all of the macros - so IREE_CHECK_OK and IREE_RETURN_IF_ERROR can take either iree_status_t or Status/etc. Because the behavior is now different we can no longer use the iree/base/google/ versions and as such I've renamed all macros such that there are no collisions with the non-IREE versions.
Now, IREE_CHECK_OK/IREE_RETURN_IF_ERROR when used in C code can take optional printf-style arguments to add annotations to results, for example: IREE_RETURN_IF_ERROR(OtherFunc(...), "with a value: %d", 5);
When used in C++ the macros still accept printf-style arguments but can also use the ostream style: IREE_RETURN_IF_ERROR(OtherFunc(...)) << "with a value: " << 5;. Though it's supported one shouldn't mix them!

The most interesting changes in this branch are in iree/base/api.h + iree/base/api.c and the iree/base/internal/status* files. Other changes are mechanical cleanups required to avoid name conflicts, enable C compilation of core parts (or code to be used both in C and C++), and removing abseil deps from files that are C compatible.

A lot of focus was put on keeping the status usage - even if source location, messages, and stack traces are attached - from increasing codesize or overhead when on the happy success path. https://gcc.godbolt.org/z/xGsPc3

For example, this chain of calls and checks:
image

Ends up as the minimal possible code (while still having any kind of success checks):
image

The error handling cases are moved out of the way and (hopefully) kept out of cache. The handlers are able to hit the tail call optimization happy path and keeps the whole function code size smaller:
image

@benvanik benvanik added enhancement ➕ New feature or request runtime Relating to the IREE runtime library labels Aug 11, 2020
@benvanik benvanik added this to the 2020Q3 Core milestone Aug 11, 2020
@google-cla google-cla Bot added the cla: yes label Aug 11, 2020
@benvanik
benvanik force-pushed the benvanik-status branch 5 times, most recently from 8e9529f to 3c7c7c6 Compare August 12, 2020 03:01
@benvanik
benvanik requested a review from ScottTodd August 12, 2020 15:30
@benvanik
benvanik marked this pull request as ready for review August 12, 2020 15:30

@ScottTodd ScottTodd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First batch of comments. Still looking through.

Comment thread iree/base/internal/status.h Resolved
Comment thread iree/base/BUILD Resolved
Comment thread iree/base/internal/status_builder.h Resolved
Comment thread iree/base/flatbuffer_util.h Resolved
Comment thread iree/base/api.h Resolved
Comment thread iree/base/api.h Resolved
Comment thread iree/base/BUILD Resolved
Comment thread iree/base/api.h Resolved
Comment thread iree/base/api.h Resolved
Comment thread iree/base/flatbuffer_util.h Resolved
Comment thread iree/base/internal/status.h Resolved
Comment thread iree/base/internal/status_builder.h Resolved
@benvanik
benvanik force-pushed the benvanik-status branch 3 times, most recently from 6af80ff to e124913 Compare August 13, 2020 18:15
Comment thread iree/base/api.c Resolved
Comment thread iree/vm/list.c Resolved
Comment thread iree/testing/status_matchers.h Resolved
Comment thread iree/testing/status_matchers.h Resolved
Comment thread iree/hal/vmla/op_kernels_generic.h Resolved
Comment thread iree/hal/cts/cts_test_base.h Resolved
Comment thread iree/base/api.c Resolved

@ScottTodd ScottTodd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wait a bit to merge while we sync the google/main branches and coordinate the Google branch details.

Comment thread iree/hal/vulkan/BUILD Resolved
Comment thread iree/base/internal/status.h Resolved
Comment thread iree/base/internal/BUILD Resolved
Comment thread iree/hal/cts/BUILD Resolved
Comment thread iree/base/api.c Resolved
Comment thread iree/hal/api.cc Resolved
Comment thread iree/hal/api.cc Resolved
Comment thread iree/base/api.c Resolved
Including the C++ file will enable support in the macro for Status.
…2917)

Otherwise the test fails in optimized builds (or other builds which disable annotations).

I used macros instead of helper functions so we get line numbers for failed test checks.
@ScottTodd
ScottTodd merged commit 14257a6 into main Aug 17, 2020
@copybara-service
copybara-service Bot deleted the benvanik-status branch August 18, 2020 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement ➕ New feature or request runtime Relating to the IREE runtime library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iree_status_t/Status reworking

2 participants