Closed anton-trunov closed 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.
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
@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.
@jubnzv I think this should be done using at the level of OCaml AST (basically using [@@ deriving equal]
).
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).