Changes between Version 6 and Version 7 of Commentary/Compiler/UnusedImports


Ignore:
Timestamp:
Jul 1, 2009 12:36:37 PM (6 years ago)
Author:
igloo
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/UnusedImports

    v6 v7  
    153153                             [ImportInfo] -- Child import infos
    154154}}}
    155 Here are how some example imports map to trees of `ImportInfo`, assuming `Foo` exports `a`, `b`, `D(c1, c2)`. Only the `SDoc` and `[RdrName]` fields are given, as that's the interesting bit.
    156 {{{
    157 import Foo
    158 ->
    159 ImportInfo "Foo" ["a", "b", "D", "c1", "c2", "Foo.a", "Foo.b", "Foo.D", "Foo.c1", "Foo.c2"]
    160 
    161 import qualified Foo as Bar
    162 ->
    163 ImportInfo "Foo" ["Bar.a", "Bar.b", "Bar.D", "Bar.c1", "Bar.c2"]
    164 
    165 import qualified Foo (a, D)
    166 ->
    167 ImportInfo "Foo" []
    168     ImportInfo "a" ["Foo.a"]
    169     ImportInfo "D" ["Foo.D"]
    170 
    171 import qualified Foo hiding (a, D(..))
    172 ->
    173 ImportInfo "Foo" ["Foo.b"]
    174 
    175 import Foo (D(c1, c2))
    176 ->
    177 ImportInfo "Foo" []
    178     ImportInfo "D" ["D", "Foo.D"]
    179         ImportInfo "c1" ["c1", "Foo.c1"]
    180         ImportInfo "c2" ["c2", "Foo.c2"]
    181 
    182 import qualified Foo (D(..))
    183 ->
    184 ImportInfo "Foo" []
    185     ImportInfo "D(..)" ["Foo.D", "Foo.c1", "Foo.c2"]
    186 }}}
    187 
    188 If a node in the tree is marked as used, then so are all nodes above it. For example, given the tree
     155
     156We convert import declarations into trees of `ImportInfo`s, e.g.
     157{{{
     158import Foo (a, D(c1, c2))
     159}}}
     160becomes (only the `SDoc` and `[RdrName]` fields are given, as that's the interesting bit)
    189161{{{
    190162ImportInfo "Foo" []
     
    194166        ImportInfo "c2" ["c2", "Foo.c2"]
    195167}}}
     168If a node in the tree is marked as used, then so are all nodes above it. For example, given the tree
    196169a use of `"D"` marks both the first and third lines as used.
     170
     171Here are how some example imports map to trees of `ImportInfo`, assuming `Foo` exports `a`, `b`, `D(c1, c2)`.
     172{{{
     173import Foo
     174->
     175ImportInfo "Foo" ["a", "b", "D", "c1", "c2", "Foo.a", "Foo.b", "Foo.D", "Foo.c1", "Foo.c2"]
     176
     177import qualified Foo as Bar
     178->
     179ImportInfo "Foo" ["Bar.a", "Bar.b", "Bar.D", "Bar.c1", "Bar.c2"]
     180
     181import qualified Foo (a, D)
     182->
     183ImportInfo "Foo" []
     184    ImportInfo "a" ["Foo.a"]
     185    ImportInfo "D" ["Foo.D"]
     186
     187import qualified Foo hiding (a, D(..))
     188->
     189ImportInfo "Foo" ["Foo.b"]
     190
     191import Foo (D(c1, c2))
     192->
     193ImportInfo "Foo" []
     194    ImportInfo "D" ["D", "Foo.D"]
     195        ImportInfo "c1" ["c1", "Foo.c1"]
     196        ImportInfo "c2" ["c2", "Foo.c2"]
     197
     198import qualified Foo (D(..))
     199->
     200ImportInfo "Foo" []
     201    ImportInfo "D(..)" ["Foo.D", "Foo.c1", "Foo.c2"]
     202}}}
    197203
    198204When we come to giving warnings, if a node is unused then we warn about it, and do not descend into the rest of that subtree, as the node we warn about subsumes its children. If the node is marked as used then we descend, looking to see if any of its children are unused.