solidity icon indicating copy to clipboard operation
solidity copied to clipboard

Remove unneeded includes in files

Open axic opened this issue 5 years ago • 8 comments

It seems there is a very large number of includes which are imported without any reason. Most of these are remnants of old code.

Removing them could allow for nicer separation of concerns, but could also speed up compilation.

Is there a simple tool which could show includes whose declarations are not really used in a given file?

axic avatar Nov 12 '20 01:11 axic

i am a beginner how can i contribute on this??

KishkinJ10 avatar Mar 29 '21 12:03 KishkinJ10

@KishkinJ10

Probably the easiest way to proceed is to find a tool that would automatically do this. Googling lead me to https://stackoverflow.com/questions/1301850/tools-to-find-included-headers-which-are-unused. You could also do some research into it, since the stack overflow answer might be outdated.

So try to pick one such tool and then run it on the repo, then try compiling to see if it works.

Might be useful: https://docs.soliditylang.org/en/v0.8.3/installing-solidity.html#building-from-source

Feel free to ask questions if you are stuck. Please make sure you understand the problem before working on this. There is no pressure to actually do it, so please take your time.

hrkrshnn avatar Mar 29 '21 13:03 hrkrshnn

@chriseth I can work on this if it still needs to be done

TerranCivilian avatar Jun 01 '21 21:06 TerranCivilian

Letting the CLion inspector run now. I'm having it analyze header files as well, not sure if that matters.

TerranCivilian avatar Jun 02 '21 13:06 TerranCivilian

Do we consider it done after #11491 or do we want to have it automated?

cameel avatar Jun 25 '21 10:06 cameel

I can take a crack at automating it. @cameel do you have anything in mind for that?

TerranCivilian avatar Jun 26 '21 22:06 TerranCivilian

@TerranCivilian If it's like CLion then there will be some false-positives and I think we won't want to hook that up into the CI. A script that we can run manually from time to time might still be useful though.

Here are tools I suggested the last time:

cppclean seems unmaintained so I'd try include-what-you-use if you want to take this further.

But overall, maybe you'd like a task where you'd get a chance to work more with C++ than Bash? If so, take a look at these two easy ones: #11553, #11583. The first one is extremely simple. The second is still simple and also adds a nice small feature so should be pretty satisfying to implement :)

Import removal is nice to have but also very low priority. I actually expected many more of them to be removed so either the problem is smaller than we thought or the tools for finding them are just not good enough.

cameel avatar Jun 26 '21 23:06 cameel

I had a deeper investigation on include what you use tool. The result I got is not as good as I expected. It generates a lot of useful points. However, I got also points that are absolutely wrong e.g.

  • in Exceptions.cpp tool suggests to add #include <iosfwd> for std
  • in CommonIO.cpp it suggest to add #include <bits/termios-c_cc.h> which leads to error "Never include <bits/termios_c_cc.h> directly; use <termios.h> instead."

Generally, after applying fix from the tool I end up with tons of compilation errors.

wechman avatar Mar 09 '22 11:03 wechman