-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
import ast from JSON #7153
import ast from JSON #7153
Conversation
bug3: address(this) has a wrong "referencedDeclaration" [SOLVED]steps to reproduce
suspected source"referencedDeclaration" is produced from this:
so when there is no annotation, it will just produce a new one... ideas about fixing itAnother thing i think i understood is that the annotations are set in the analyze()-step by the NameAndTypeResolver, which uses resolveImports relies on So possible avenues for solving it could be to mdofify m_sourceJsons so that it can be used to fill m_sourceOrder?? =========== SOLUTION:magic variables such as this, block.x are producing some Pseudo-ASTNodes, some of those apparently during parsing. So from now on those will all have nodeID 0 |
52f178e
to
88373c9
Compare
current list of code-lines that trigger bugs: [SOLVED, see above]throw.sol
leads to wrong referenced declarations in nodeType Identifier import.sol
-> first and last element are switched in AST-Node baseContracts address_payable.soladdress(this) (see bug description above) |
The evm version and the ast should be unrelated. The evm version is a setting for the compiler that can be mixed with any source code and the ast is the representation of the source code only, and not of the compiler switches and settings. |
As far as the testing is concerned: Why do you need to store the .json as a file? Wouldn't a usual test just take the solidity source code, export it to json-ast, and compile. Then clear all internal state, re-import from the ast and check that the result is (almost) the same? |
Yeah, that would be a better way. The testfile grew as I adapted the ASTJSONTest and I stopped refactoring it once it did the job. I'll put that on the todo-list. edit: Done |
4f28394
to
280d936
Compare
libsolidity/ast/AST.h
Outdated
@@ -70,6 +70,8 @@ class ASTNode: private boost::noncopyable | |||
|
|||
/// @returns an identifier of this AST node that is unique for a single compilation run. | |||
size_t id() const { return m_id; } | |||
/// Set the ID manually, used when recreating the AST from a JSON-tree |
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.
Ah, this is tricky. Now I think this might have negative impacts later on, because two AST nodes with the same id are considered equal.
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.
note: we resolved to have the IDDispenser register all given IDs. still a TODO so i'll leave this around
280d936
to
5d12e62
Compare
scripts/ASTImportTest.sh
Outdated
do | ||
# remove everything after the first '/' to delete all | ||
# subdirectories and content | ||
echo $f | cut -d'/' -f-1 | xargs -d"\n" rm -r 2> /dev/null |
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.
Strong objection against this.
We should create a temporary directory at the very beginning and remove that.
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.
That's what we're doing: https://github.com/ethereum/solidity/pull/7153/files#diff-a8a5760144e03e410389fb0afd20e8c8R440
This is only doing cleanup within that temporary directory for the next test.
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.
but we could create another tmp directory so we don't use rm
in such an intransparent and potentially dangerous way.
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.
yes, maybe that would be cleaner
# for solfile in $(find $DEV_DIR -name *.sol) | ||
for solfile in $(find $SYNTAXTESTS_DIR -name *.sol) | ||
do | ||
OUTPUT=$($SPLITSOURCES $solfile) |
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.
Is splitting the sources and creating actual files really the only option? We cannot use standard-json, for example?
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.
hmm I could try using the standard-json interface yes
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.
Keep the current way but do it in a fresh temp dir per run and just delete that, then it's also fine I think.
c51c285
to
aaf9349
Compare
I just noticed a complication @chriseth Exporting the version means the tests have a hard-coded version in the json files, which makes testing different evm versions difficult |
I could use something like |
Whooohoooo!
…On Tue, Jan 14, 2020, 17:56 chriseth ***@***.***> wrote:
Merged #7153 <#7153> into
develop.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#7153?email_source=notifications&email_token=ACLMYXHZPYTC4BSZFQZYCT3Q5XVFRA5CNFSM4IH3FITKYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOV62M3NI#event-2947861941>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACLMYXC6AGDNBD3Z4SMPMZ3Q5XVFRANCNFSM4IH3FITA>
.
|
This introduces a new input format to the compiler: an AST in JSON format, as produced by
--standard-json`` or ```` --combined-json ast,compact-format
. Importing an AST leaves the compiler in the same state as after CompilerStack::parse().Motiviation: This could enable things like mutation testing.
Current status:
--import-ast
option in commandline able to import and compile all kinds of AST-nodesthis assumes that inline assembly is exported to an AST as well, so inline assembly to AST in json export #7537 will have to be merged first.
testuite that verifies
The testsuite runs on all contracts defined in
/test/libsolidity/syntaxTests/
. As some syntaxTestfiles define multiple sources in one file, a script is added that separates those to their own files (creating directories in the process) and removing those after it is done.Other changes introduces by this PR
this, block.x, msg.x
now all have the special nodeID < 0import {C as BC} from ...
. Previously C was only referred to with its ID and the information about the name C was lost, which made it impossible to reconstruct the IdentifierNode.left TODOs
This PR assumes that InlineAssembly is exported to an ast (currently being reviewed in
#7537).
So to make it work and develop the tests I added the changes from there in a second commit.
scripts/AstImportTest.sh
to the testsuite. I tried adding it tocmdlineTests.sh
which worked for me locally, but it broke some tests.echo xxx
from the two files in scripts