foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.28k stars 1.75k forks source link

bug: `forge inspect <contract> ir` hangs as it compiles all contracts #4765

Closed clabby closed 1 month ago

clabby commented 1 year ago

Component

Forge

Have you ensured that all of these are up to date?

What version of Foundry are you on?

da2392e & head at time of writing (8d0099be497922b53cded74b77a3e0b3c1079336)

What command(s) is the bug in?

forge inspect

Operating System

Linux

Describe the bug

When running forge inspect L1CrossDomainMessenger ir in contracts-bedrock, the process seems to perpetually hang. I've had it running for nearly an hour on my Desktop, and the process has not exited.

Note This could be due to long compilation times via the IR pipeline, contracts-bedrock is a large project - it is possible this is not foundry's fault.

clabby commented 1 year ago

Update: After an hour and a half, the command exited: Screenshot from 2023-04-18 13-33-51

mattsse commented 1 year ago

hmm, this looks like a solc issue because this is a solc error message

maurelian commented 1 year ago

hmm, this looks like a solc issue because this is a solc error message

That is odd. I'm able to generate the IR (in the same repo and dir as @clabby's screenshot) by running solc directly with this command:

solc --ir "@openzeppelin/=./node_modules/@openzeppelin/" "@rari-capital=./node_modules/@rari-capital" contracts/L1/L1CrossDomainMessenger.sol

Perhaps forge is invoking the compiler incorrectly?

daltyboy11 commented 1 year ago

I have experienced the same issue, and you can reproduce it with a very simple contract.

forge inspect Foo ir will hang, yet solc --ir Foo.sol will work. Forge version is forge 0.2.0 (59f026f 2023-05-23T17:21:42.593814000Z)

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.19;

contract Foo {
  function increment(uint x) external pure returns (uint) {
    return x + 1;
  }
}
mattsse commented 1 year ago

can't reproduce this @daltyboy11

forge init
# add Foo.sol with contract Foo
forge inspect Foo it
mattsse commented 1 year ago

it could just be that the solc input args for inspect are causing this, perhaps this is set for the entire input, which leads to long compile times on large repos

mds1 commented 1 year ago

@mattsse yea I'm pretty sure the issue is that forge inspect compiles the full project. I often just do mv test testt; forge inspect <contract> irOpt; mv testt test and it's significantly faster. Even with that it's still compiling unnecessary src contracts, and ideally it should just compile the minimum set based on the <contract> specified

mattsse commented 1 year ago

we could improve this with some additional effort, but the issue is that inspect accepts a contract name but we don't really now where this contract exists, so we simply set inspect to all: *.

we could try to find the contract and its file before calling solc though.

grandizzy commented 1 month ago

I cannot reproduce this with latest version, time forge inspect L1CrossDomainMessenger ir output

real    0m0.832s
user    0m1.459s
sys 0m0.140s

@clabby @mds1 could you please recheck and see if it can be closed? thank you!

mds1 commented 1 month ago

Confirmed I got similar performance, thank you!