NethermindEth / warp

Warp - Bringing Solidity to Starknet at warp speed. Warp is a Solidity to Cairo Compiler, this allows teams to write/migrate Solidity to Cairo for easy onboarding into the StarkNet ecosystem.
https://nethermind.io/warp/
Apache License 2.0
751 stars 69 forks source link

Add debug documentation #875

Open piwonskp opened 1 year ago

piwonskp commented 1 year ago

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:

cicr99 commented 1 year ago

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;
    }
}
AlejandroLabourdette commented 1 year ago

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

piwonskp commented 1 year ago

@AlejandroLabourdette you don't have to store it in a file. You can use less as in the example I provided above

AlejandroLabourdette commented 1 year ago

@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