warp
warp copied to clipboard
Add debug documentation
To make it easier to quick start contributing to warp we need to add the documentation for warp debugging. Let's discuss it here and add conclusions from this discussion to the documentation. Please add your suggestions on how to debug warp in comments.
I'll start:
- Using visual studio code debugger you can put the breakpoint e.g. here to analyze the AST pass by pass
- Using
--print-treescommand line argument. For example:npx ts-node src/ transpile erc.sol --print-trees | less - Tests may be debugged using vs code javascript integrated terminal in combination with
FILTERenvironment variable:FILTER=functions/functionOverriding yarn test:behaviour
Also using transform command allows you to check the changes applied in the code. Usually it is used together with the option --until <pass_letters> so you can stop transpilation after the selected pass. For example, having this simple contract:
pragma solidity ^0.8.10;
//SPDX-License-Identifier: MIT
contract WARP {
function test(bool x, bool y) public pure returns (bool) {
return x && y;
}
}
you can use bin/warp transform a.sol --until "Sc". This will show the transformations made to the code until ShortCircuitToConditional (Sc) pass. The output looks like the following:
contract WARP {
function test_7442b287(bool __warp_0_x, bool __warp_1_y) external pure returns (bool __warp_2) {
return __warp_0_x ? __warp_1_y : false;
}
constructor() {
return;
}
}
It is usually a good idea to store the output of using --print-trees flag in a file because it can get really long. Something like warp transpile file.sol --print-trees > output.txt
@AlejandroLabourdette you don't have to store it in a file. You can use less as in the example I provided above
@AlejandroLabourdette you don't have to store it in a file. You can use less as in the example I provided above
Ye, that's a good option too. I've found myself looking for differences between the ast of two different approach over the same pass so I stored them into 2 different files. But you can do the same using less with 2 terminals, so it's kind of similar