BRL-CAD is huge. With any large body of code, one inevitably ends up with a mix of good and bad coding practices. On the whole, BRL-CAD is actually better than most but we are constantly working on improving the code. This includes eliminating DEAD code, i.e., code that is not called or used by anything.
References:
- http://en.wikipedia.org/wiki/Dead_code
- http://brlcad.org/wiki/Code_Cleanup
- http://brlcad.org/wiki/Compiling
- http://brlcad.org/wiki/SVN
This task involves reducing BRL-CAD's source code by 100 or more lines of code by eliminating DEAD code. You can use whatever method you like to identify dead code, but beware that there are more than 1 million lines of code in BRL-CAD, so you're not likely going to find this duplication just by browsing. You also cannot eliminate "unused" functions that are declared in our public API headers (i.e., our include/ headers).
We suggest using a dead code detection tool, but beware false-positives. You can eliminate a single chunk of dead code or (more likely) several smaller sections of dead code to get to 100+ lines.
One manual way to find dead code is to convert non-library functions (i.e., functions not in the src/lib* directories and not declared in an include/ header) to static functions. If declared static and not used anywhere, GCC will report it as an unused function during compilation (or throw an error if you're wrong).
Another way to find dead code is through scripting. You can write a script to extract a list of all function definitions, then search for any that have no uses (in any directory). A little more tricky to script it right, but you could easily find thousands of lines this way. We'll create a follow-on task for you to submit your script if you write one this way.
Download our latest Subversion trunk sources and make sure you can compile cleanly first. Then you can do whatever you need to find dead code. Make your edits, then make sure the code still compiles (run "make", "make test", "make regress" and "make benchmark" to test your changes)! This is critical, it must still compile exactly as before. Finally, create and submit a patch file of your changes (see the references, svn will create the patch file for you).
Feel free to join the brlcad-devel mailing list or IRC channel to discuss your changes beforehand.
File name/URL | File size | Date submitted | |
---|---|---|---|
_comb_ | 12.2 KB | December 17 2014 13:43 UTC | |
dead.patch | 14.4 KB | December 29 2014 12:52 UTC |
I would like to work on this task.
This task has been assigned to Adarsh. You have 100 hours to complete this task, good luck!
There are less than 24 hours left until the deadline, please submit your work soon.
Melange has detected that the final deadline has passed and it has reopened the task.
I would like to work on this task.
This task has been assigned to Marc Tannous. You have 96 hours to complete this task, good luck!
1) After running Simian, found duplicate code in g-step/comb.c g-ap214/comb.c
2) Apparently, they were both declaring the same function, and they both included a "Comb.h" used in their own directory.
3) I created a new file, Comb.h that was in both their parent directory ( they were both coming from /src/conv/step so I created it here ) with the entire contents of the old Comb.h + the function they were both using, and included it in the two files.
4) Eliminated the duplicated code, included the newly formed Comb.h, removed the old Comb.h that now served no purpose and created a patch.
Regards,
Marc
The work on this task is ready to be reviewed.
This task is about DEAD but not DUPLICATED code, e.g. nowhere used functions.
One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.
http://www.google-melange.com/gci/task/view/google/gci2014/5893656028381184
Same thing, Sean closed it. Why would Simian be mentioned if I am looking for dead code?
The work on this task is ready to be reviewed.
It was the exact same title, did not read the description, have no idea why they differ. What should I do?
This task has been Reopened.
I would like to work on this task.
This task has been assigned to shardulc. You have 96 hours to complete this task, good luck!
What do I do if I find a file which defines only one function, which is not used anywhere? Do I remove the file and the corresponding entries from CMakeLists.txt and the declaring header file? (I can get a clean build this way.) But this seems a bit counter-intuitive because I could extend the process indefinitely, ending up with nothing at all.
Thanks for your attention!
shardulc,
If you do come across that sort of file, then by all means, remove it from all your above mentioned points.
The work on this task is ready to be reviewed.
I did this task by writing my own dead code detection script. The script is in Python, and uses a little regex to find function declarations and uses. It's probably buggy and gives out a lot of false positives, but it doesn't miss any dead functions (I hope). It could be faster if I used grep instead of Python's re module, which I am working on. But it works! Can I submit it?
The patch I've uploaded contains the changes I made after running my script on the src/conv directory to look for function definitions, and searching for calls to them everywhere in the src/ directory. It is more than 100 lines if deleted files are counted.
Thanks for your attention!
shardulc, that's awesome. You absolutely can submit it.
I'll add another task to create a dead code detection script just for this. The only thing you'll have to be careful of is that you don't eliminate any functions that are declared publicly (in the top-level include/ directory). Even if we don't use that function, external applications might.
I presume you're going to go after all the other dead code elimination tasks too? :)
It's still plenty of work to identify the code, edit the files, test the compilation, run our regression tests, etc.
Congratulations, this task has been completed successfully.
The other open dead code elimination tasks are all beginner tasks, so I can't do them anymore. Also, you don't have to worry about functions in the libraries or public headers because the script can be run on specific directories.
https://www.google-melange.com/gci/task/view/google/gci2014/6455158829481984
Also, all the remaining tasks to eliminate dead code are no longer marked as beginner tasks. Let me know if you need more! :)