Skip to content
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

Default messages in assertion macros #12019

Merged
merged 4 commits into from
Oct 4, 2021

Conversation

cameel
Copy link
Member

@cameel cameel commented Sep 23, 2021

This is an attempt to improve the situation in #12017 a little. It should also be an improvement for external tools because for these our ICEs are often puzzling when they have no message at all (see e.g. trufflesuite/truffle#2849).

  • Now if you use "" in an assertion, it gets replaced with a generic message, like "Solidity assertion failed" or "Unimplemented feature", depending on the assertion type.
  • You can now skip the empty string in solAssert() and other assertions, making them more convenient.

@cameel cameel self-assigned this Sep 23, 2021
@cameel
Copy link
Member Author

cameel commented Sep 23, 2021

Looks like MSVC does not like variadic macros very much...

Comment on lines +74 to +80
/// Assertion that throws an exception containing the given description if it is not met.
/// Use it as assertThrow(1 == 1, ExceptionType, "Mathematics is wrong.");
/// The second parameter must be an exception class (rather than an instance).
#define assertThrow(_condition, _exceptionType, _description) \
assertThrowWithDefaultDescription(_condition, _exceptionType, _description, "Assertion failed")
Copy link
Member Author

Choose a reason for hiding this comment

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

Is assertThrow() really an assertion? In most cases I've seen it's just used as a convenience helper to throw a boost exception.

@cameel cameel force-pushed the default-messages-in-assert-macros branch from ee2ae56 to 07d53b5 Compare September 23, 2021 16:21
@cameel
Copy link
Member Author

cameel commented Sep 23, 2021

Looks like MSVC does not like variadic macros very much...

Looks like it requires extra #ifdefs unfortunately: BOOST_PP_OVERLOAD.

@cameel cameel force-pushed the default-messages-in-assert-macros branch from 07d53b5 to 87a2245 Compare September 23, 2021 16:29
@cameel
Copy link
Member Author

cameel commented Sep 23, 2021

By the way, is this something that should have a changelog entry? This might affect tools that try to detect some specific ICEs in the output and do some workarounds. We might want to at least inform them even if we do not guarantee any backwards-compatibility for these messages.

@cameel cameel force-pushed the default-messages-in-assert-macros branch from 87a2245 to 83ba149 Compare September 23, 2021 16:47
@leonardoalt
Copy link
Member

I don't think we should guarantee backwards compatibility in ICEs

@@ -1217,7 +1217,7 @@ string YulUtilFunctions::extractByteArrayLengthFunction()
std::string YulUtilFunctions::resizeArrayFunction(ArrayType const& _type)
{
solAssert(_type.location() == DataLocation::Storage, "");
solUnimplementedAssert(_type.baseType()->storageBytes() <= 32, "...");
Copy link
Member

Choose a reason for hiding this comment

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

lol

@cameel cameel force-pushed the default-messages-in-assert-macros branch from 83ba149 to 514b9a0 Compare October 1, 2021 11:16
leonardoalt
leonardoalt previously approved these changes Oct 1, 2021
@leonardoalt
Copy link
Member

Needs rebase

@chriseth chriseth enabled auto-merge October 4, 2021 10:07
@chriseth chriseth merged commit a9b99dd into develop Oct 4, 2021
@chriseth chriseth deleted the default-messages-in-assert-macros branch October 4, 2021 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants