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

Revert statement. #11037

Merged
merged 7 commits into from
Mar 30, 2021
Merged

Revert statement. #11037

merged 7 commits into from
Mar 30, 2021

Conversation

chriseth
Copy link
Contributor

@chriseth chriseth commented Mar 3, 2021

No description provided.

@chriseth chriseth force-pushed the revertStatement branch 2 times, most recently from 046f830 to 5dd3058 Compare March 3, 2021 17:58
@chriseth chriseth force-pushed the customErrorDeclaration branch from 4b8159f to b4ba6d1 Compare March 9, 2021 15:47
@chriseth chriseth force-pushed the revertStatement branch 4 times, most recently from 201bfc1 to 4e0438e Compare March 10, 2021 17:46
@chriseth chriseth force-pushed the customErrorDeclaration branch from b4ba6d1 to ae5fa34 Compare March 16, 2021 18:18
@chriseth chriseth force-pushed the revertStatement branch 2 times, most recently from 4174c6a to c621909 Compare March 16, 2021 18:47
Copy link
Contributor

@mijovic mijovic left a comment

Choose a reason for hiding this comment

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

Few small comments and suggestions for first round.

Also this needs to be rebased again, as there are some commits from other PRs

libsolidity/analysis/PostTypeChecker.cpp Outdated Show resolved Hide resolved
libsolidity/ast/AST.h Outdated Show resolved Hide resolved
libsolidity/codegen/ir/IRGeneratorForStatements.cpp Outdated Show resolved Hide resolved
libsolidity/codegen/ir/IRGeneratorForStatements.cpp Outdated Show resolved Hide resolved
libsolidity/codegen/ir/IRGeneratorForStatements.cpp Outdated Show resolved Hide resolved
@chriseth chriseth force-pushed the revertStatement branch 2 times, most recently from 51857d7 to 728bc1b Compare March 18, 2021 12:28
Copy link
Member

@cameel cameel left a comment

Choose a reason for hiding this comment

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

Only minor suggestions. I haven't found anything serious.

libsolidity/analysis/PostTypeContractLevelChecker.cpp Outdated Show resolved Hide resolved
libsolidity/analysis/PostTypeContractLevelChecker.cpp Outdated Show resolved Hide resolved
libsolidity/ast/AST.cpp Outdated Show resolved Hide resolved
libsolidity/codegen/ExpressionCompiler.cpp Show resolved Hide resolved
libsolidity/formal/SMTEncoder.cpp Outdated Show resolved Hide resolved
test/libsolidity/semanticTests/errors/panic_via_import.sol Outdated Show resolved Hide resolved
test/libsolidity/semanticTests/errors/using_structs.sol Outdated Show resolved Hide resolved
@chriseth chriseth force-pushed the customErrorDeclaration branch from ae5fa34 to 1aad33d Compare March 24, 2021 13:10
@chriseth chriseth force-pushed the customErrorDeclaration branch 6 times, most recently from 8184bea to 4438a59 Compare March 25, 2021 10:17
@chriseth chriseth force-pushed the customErrorDeclaration branch from 4438a59 to d0cec87 Compare March 25, 2021 11:00
@chriseth chriseth force-pushed the revertStatement branch 2 times, most recently from 59523fa to 5a033f0 Compare March 29, 2021 13:58
cameel
cameel previously approved these changes Mar 29, 2021
Copy link
Member

@cameel cameel left a comment

Choose a reason for hiding this comment

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

LTGM

@@ -433,6 +434,14 @@ bool CompilerStack::analyze()
noErrors = false;
}

if (noErrors)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

I think brackets are not needed, but not mandatory to change

Copy link
Contributor

@mijovic mijovic left a comment

Choose a reason for hiding this comment

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

Looks good.

@hrkrshnn
Copy link
Member

Can you also add this test:

struct error { uint error; }
contract C {
	uint error = 0;
	error test();
	function f() public {
		revert test();
	}
}
contract D {
	error _struct;
	error test();
}

should succeed (already does) because error is not a keyword.

@chriseth
Copy link
Contributor Author

It actually fails :(

@chriseth
Copy link
Contributor Author

Added the test as error_structs.sol.

mijovic
mijovic previously approved these changes Mar 30, 2021
@@ -125,6 +125,8 @@ bool FunctionCallGraphBuilder::visit(FunctionCall const& _functionCall)
// change at runtime). All we can do is to add an edge to the dispatch which in turn has
// edges to all functions could possibly be called.
add(m_currentNode, CallGraph::SpecialNode::InternalDispatch);
else if (functionType->kind() == FunctionType::Kind::Error)
m_graph.usedErrors.insert(&dynamic_cast<ErrorDefinition const&>(functionType->declaration()));
Copy link
Member

Choose a reason for hiding this comment

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

maybe we should add an assert here?

Copy link
Member

Choose a reason for hiding this comment

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

You mean as else? Not really. There are other case possible here, the graph just skips them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a check and I would say it is highly unlikely for this assert to trigger...

@hrkrshnn
Copy link
Member

hrkrshnn commented Mar 30, 2021

  struct S {uint x;}
  contract C {
	  function f() public {
		revert S(10);
	  }
  }

produces an ICE:

: Internal compiler error during compilation:
: /solidity/libsolidity/codegen/ContractCompiler.cpp(79): Throw in function void {anonymous}::StackHeightChecker::check()
: Dynamic exception type: boost::wrapexcept<solidity::langutil::InternalCompilerError>
: std::exception::what: I sense a disturbance in the stack: 2 vs 1
: [solidity::util::tag_comment*] = I sense a disturbance in the stack: 2 vs 1

But the following works!

  struct S {uint x;}
  contract C {
	  error S(uint y);
	  function f() public {
		revert S(10);
	  }
  }

contract C {
event E();
function f() public pure {
revert E();
Copy link
Member

Choose a reason for hiding this comment

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

I was wondering why pure functions are allowed to revert. I think that should be forbidden.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been discussed a lot in the past. Pure means the result only depends on the arguments, and that is the case here.

@chriseth
Copy link
Contributor Author

@hrkrshnn oh wow! Good that you found this! I could swear the code for that was there before...

@chriseth
Copy link
Contributor Author

@hrkrshnn added the check to TypeChecker and added tests.

@chriseth chriseth force-pushed the customErrorDeclaration branch from d0cec87 to b04b189 Compare March 30, 2021 19:15
Base automatically changed from customErrorDeclaration to develop March 30, 2021 21:03
@chriseth chriseth dismissed stale reviews from mijovic and cameel March 30, 2021 21:03

The base branch was changed.

@chriseth chriseth merged commit 4fd6192 into develop Mar 30, 2021
@chriseth chriseth deleted the revertStatement branch March 30, 2021 21:03
Xanewok added a commit to Xanewok/slang that referenced this pull request Sep 19, 2023
It was introduced alongside the `revert` contextual keyword,
see ethereum/solidity#11037.
Xanewok added a commit to Xanewok/slang that referenced this pull request Sep 21, 2023
The statement was introduced alongside the `revert` contextual keyword,
see ethereum/solidity#11037.
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.

5 participants