Skip to content

Create glow::Error and glow::Expected #3515

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

Closed
wants to merge 1 commit into from

Conversation

jackm321
Copy link
Contributor

@jackm321 jackm321 commented Sep 16, 2019

Note for review: Most real changes are in Error.h, Error.cpp, and ErrorTest.cpp and the rest is mostly codemod to switch from llvm::Error/Expected to glow::Error/Expected.

Summary:
Removes dependency on llvm::Error and ensures Errors are don't go unchecked by verifying this in debug build.

glow::Error/Expected are mostly drop-in replacements for llvm::Error/Expected but exclude some features not used in Glow such as multiple error value types, reference types contained in Expected, etc. They also have a couple of different features like Error::empty() which creates "pre-checked" Errors.

Documentation:
doxygen
fixes: #2737, #3505

Test Plan:
added ErrorTest unit tests
ninja check

@jackm321 jackm321 force-pushed the glow_error branch 3 times, most recently from c89e06b to 45c422c Compare September 16, 2019 17:23
Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@jackm321 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@jackm321 jackm321 marked this pull request as ready for review September 16, 2019 17:28
Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@jackm321 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@opti-mix opti-mix left a comment

Choose a reason for hiding this comment

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

@jackm321 This is a huge PR! :-)

The good thing is that it fixes all those bugs we recently discover. The bad thing is that you needed to copy & mod LLVM's types.

Overall, LGTM!

return ss.str();
}

// static
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you plan to remove this static?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove it

#include <glog/logging.h>

/// NOTE: please only use code and macros that resides outside of the detail
Copy link
Contributor

Choose a reason for hiding this comment

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

Are most of the changes in this file "inspired" by LLVM's Error.h, i.e. is it pretty-much a copy of the LLVM's code with minor changes? Is there any possibility to change LLVM's behavior without literally re-defining all these types? Probably not. But it is annoying to have so much boilerplate code ;-(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@opti-mix yeah it is overall pretty similar to LLVM's Error and Expected with a changes like abstracting out the state checking. The thing that it does is pretty dead simple so there isn't a lot of room for creative implementations.

As I mentioned in person, I would actually like to design this a bit differently, have only Expected and model the Error use case with a template specialization for Expected so we only have a single type everywhere. However for the sake of sanity, I think we should switch to a near drop-in replacement first and then consider later whether we want to go in a different direction like this instead of attempting to do everything at once.

Because llvm::Error's checking is disabled at compile time I don't think there is a clean and easy way to turn this back on by wrapping it externally and removing our dependency on llvm::Errors allows us the freedom to change things later as mentioned above.

@jackm321
Copy link
Contributor Author

@opti-mix Thank you for reviewing this monster, really appreciate it!

namespace detail {
/// enableCheckingErrors is used to enable assertions that every Error and
/// Expected has its status checked before it is destroyed. This should be
/// enabled in debug builds but turned off otherwise.
Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, a quick question: What if this could be controlled by a command-line flag instead? It would be disabled by default in release builds, but one could enable it via such a command-line option if needed? Would it bring any value?

Copy link
Contributor Author

@jackm321 jackm321 Sep 17, 2019

Choose a reason for hiding this comment

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

That would be worse because when it is disabled at build time

  1. Error and Expected use less space because no need to store CheckState:: checked_
  2. The code could be slightly faster because the code to do the checking is completely non-existent so no need even to check a flag to see if the state should be checked.

Also this is really a debugging mechanism so I think it makes sense to enable it in only debug mode. My view on it is that ideally, ensuring that Errors are always checked would be done statically but this isn't Rust so having some debug assertions is probably the next best thing, but we shouldn't be putting that check into Release. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, makes sense. Thanks for the explanation!

@jackm321 jackm321 force-pushed the glow_error branch 2 times, most recently from 4cd6a85 to 73df2f1 Compare September 17, 2019 15:55
Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@jackm321 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Summary:
_Note for review: Most real changes are in `Error.h`, `Error.cpp`, and `ErrorTest.cpp` and the rest is mostly codemod to switch from `llvm::Error/Expected` to `glow::Error/Expected`._
Removes dependency on `llvm::Error` and ensures Errors are don't go unchecked by verifying this in debug build.

`glow::Error/Expected` are mostly drop-in replacements for `llvm::Error/Expected` but exclude some features not used in Glow such as multiple error value types, reference types contained in Expected, etc. They also have a couple of different features like `Error::empty()` which creates "pre-checked" `Error`s.

Documentation:
doxygen
fixes: pytorch#2737, pytorch#3505
Pull Request resolved: pytorch#3515

Test Plan:
added `ErrorTest` unit tests
ninja check

Differential Revision: D17399297

fbshipit-source-id: 4b0a524e2c1ba2cf4adc766a0e8196ee94e062f0
@facebook-github-bot
Copy link

@jackm321 merged this pull request in cca5793.

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

Successfully merging this pull request may close these issues.

Enable LLVM and Glow assertions in Release mode
3 participants