Changes between Version 1 and Version 2 of Commentary/Compiler/UnusedImports


Ignore:
Timestamp:
Jun 17, 2009 8:56:13 AM (6 years ago)
Author:
simonpj
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/UnusedImports

    v1 v2  
    44flags, including #1148, #2267, #1074, #2436.
    55This page describes a new design.
    6 
    7 The idea is that for each use of an imported name, we will attribute
    8 that use to one or more import decls. Then, any import decls with no
    9 uses attributed to them are unused, and are warned about.
    106
    117== The current story ==
     
    7167 * It's not worth trying to be too subtle.  The 90% case is very simple.
    7268
    73 Here is an attempt at a specification:
    74  1.  Say that an ''import-item'' is either an entire import-all decl (eg `import Foo`),
    75  or a particular item in an import list (eg `import Foo( ..., x, ...)`). 
    76  2.  For every `RdrName` in the program text, choose one of the import-items
    77  that brought it into scope, the "chosen import-item",
    78  and mark it "used". 
     69Say that an ''import-item'' is either an entire import-all decl (eg `import Foo`),
     70or a particular item in an import list (eg `import Foo( ..., x, ...)`). 
     71The general idea is that for each use of an imported name, we will attribute
     72that use to one (or possibly more) import-items. Then, any import items with no
     73uses attributed to them are unused, and are warned about.
     74More precisely:
     75
     76 1.  For every `RdrName` in the program text, find all the import-items that brought it     into scope.  The lookup mechanism on `RdrNames` already takes account of whether the `RdrName` was qualified, and which imports have the right qualification etc, so this step is very easy.
     77
     78 2. Choose one of these, the "chosen import-item", and mark it "used". 
     79
    7980 3.  Now bleat about any import-items that are unused.  For a decl
    8081 `import Foo(x,y)`, if both the `x` and `y` items are unused, it'd be better
    8182 to bleant about the entire decl rather than the individual items.
    82 
    83 In step 2, the lookup mechanism on `RdrNames` already takes account of whether
    84 the `RdrName` was qualified, and which imports have the right qualification etc.
    8583
    8684The import-item choosing step 2 implies that there is a total order on
     
    9189 * Otherwise choose the textually first one.
    9290
    93 Note that this algorithm chooses exactly one import-item in step 2.  It would
    94 also be sound to choose more than one if there was a tie, but then completely-duplicate
    95 imports might not be reported.
     91Other notes:
     92 * The algorithm chooses exactly one import-item in step 2.  It would
     93 also be sound to choose more than one if there was a tie, but then completely-duplicate
     94 imports might not be reported.
    9695
    97 Note that if we have an import item `import Foo (Bar(bar))`, then
    98 it's marked as used if either `Bar` or `bar` are used.  We could have yet finer
    99 resolution and report even unused sub-items.
     96 * Note that if we have an import item `import Foo (Bar(bar))`, then
     97 it's marked as used if either `Bar` or `bar` are used.  We could have yet finer
     98 resolution and report even unused sub-items.
     99
     100 * We should retain the special case of not warning about `import Foo ()`, which implies "instance declarations only".
    100101
    101102-------------------------------