Zilliqa / scilla

Scilla - A Smart Contract Intermediate Level Language
https://scilla-lang.org
GNU General Public License v3.0
240 stars 78 forks source link

Equality comparator tool for Scilla ASTs #1158

Closed anton-trunov closed 2 years ago

anton-trunov commented 2 years ago

Such tool is needed to test source code formatters and can be used to check if some AST passes do not change its shape (given we ignore locations and other such AST annotations).

anton-trunov commented 2 years ago

One way to go about this is to dump deannotated contracts in the format of S-expressions and then compare S-expressions as strings.

anton-trunov commented 2 years ago

Here is a recipe to compare the ASTs of two Scilla contracts:

scilla-fmt -h --sexp --deannot contract1.scilla > contract1.sexp
scilla-fmt -h --sexp --deannot contract2.scilla > contract2.sexp
diff contract1.sexp contract2.sexp

Documented in the Scilla wiki: https://github.com/Zilliqa/scilla/wiki/Scilla-AST-comparison

jubnzv commented 2 years ago

@anton-trunov There are cases, when we want to check AST equality in the Scilla code. For example, if we want to remove duplicate pure library functions when we are merging multiple contracts (#1156), we should check their AST equality first.

So, it will be useful to have two API functions in Formatter that check the equality using Sexp comparison.

Anyway, this is a simple change, and we could implement it later, when we really need it.

anton-trunov commented 2 years ago

@jubnzv I think this should be done using at the level of OCaml AST (basically using [@@ deriving equal]).