www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10437] New: Warnings for unused private imports

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10437

           Summary: Warnings for unused private imports
           Product: D
           Version: future
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: qznc web.de



The compiler should output warnings, if the source code contains imports, which
are not used and can be removed.

Example: For debugging the following private imports were used, but now the
module does not contain any writeln or text call anymore, but parse is used.

private import std.stdio;
private import std.conv: text, parse;

The compiler should print warnings like:

foo.d(3): Warning: unused private import std.stdio; should be deleted
foo.d(4): Warning: unused private import std.conv: text; should be deleted

This has been discussed together with other unused stuff,
but there seems to be no conclusion in the thread.

http://forum.dlang.org/thread/i4luk9$2rdg$1 digitalmars.com

This enhancement helps to keep a code base clean. Less imports might reduce
compile times.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 21 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10437




What will occur with template function?

import std.conv : to;

T convert(T, S)(S src)
{
    return to!T(src);
}

void main() {}
// template function convert is not instantiated.

In this case, imported std.conv is unused then compiler might warn it. Is this
right?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 21 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10437


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



06:16:52 PDT ---
This warning should at best be a separate switch (or we should add
customization to the -w switch like we have with -transition). I dislike chatty
compilers which complain about every single little nuisance.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 21 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10437





 What will occur with template function?
 
 import std.conv : to;
 
 T convert(T, S)(S src)
 {
     return to!T(src);
 }
 
 void main() {}
 // template function convert is not instantiated.
 
 In this case, imported std.conv is unused then compiler might warn it. Is this
 right?
I think the question is misleading. The actual question is how clever the analysis is. Call-graph information provides a similar scenario: import std.stdio; void foo() { writeln("foo"); } void main () {} // foo is never called In such scenarios, deleting a statement might declare a whole chain (actually DAG) of (template or normal) functions unused. It is a question of taste, if the user should be flooded with warnings in this case. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 21 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10437





 I think the question is misleading. The actual question is how clever the
 analysis is. Call-graph information provides a similar scenario:
 
 import std.stdio;
 
 void foo() {
     writeln("foo");
 }
 
 void main () {}
 // foo is never called
 
 In such scenarios, deleting a statement might declare a whole chain (actually
 DAG) of (template or normal) functions unused. It is a question of taste, if
 the user should be flooded with warnings in this case.
It's impossible to do that strictly with templates. Let's try to show more suitable case. import std.conv; import std.stdio; auto call(string name, A...)(A args) { return mixin(name~"(args)"); } Until 'call' template function is instantiated, compiler cannot determine which import declaration is actually unused. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 21 2013