Skip to content

Commit bfa7d17

Browse files
committed
Deduplicate exported symbols.
1 parent 748769d commit bfa7d17

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

src/Language/Haskell/Names/Exports.hs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ import Language.Haskell.Names.ScopeUtils
1616
import Language.Haskell.Names.SyntaxUtils
1717
import Language.Haskell.Names.ModuleSymbols
1818
import Language.Haskell.Names.GlobalSymbolTable as Global
19-
import Data.List (nub)
19+
import qualified Data.Set as Set (fromList, toList)
2020

2121

2222
-- | Compute the list of symbols the given module exports using the given
2323
-- table of symbols that are in scope in that module.
2424
exportedSymbols :: (Data l, Eq l) => Global.Table -> Module l -> [Symbol]
25-
exportedSymbols globalTable modul = case getExportSpecList modul of
25+
exportedSymbols globalTable modul = nubSymbols (case getExportSpecList modul of
2626
Nothing -> moduleSymbols globalTable modul
2727
Just (ExportSpecList _ exportSpecs) ->
28-
concatMap (exportSpecSymbols globalTable) exportSpecs
28+
concatMap (exportSpecSymbols globalTable) exportSpecs)
2929

3030
exportSpecSymbols :: Global.Table -> ExportSpec l -> [Symbol]
3131
exportSpecSymbols globalTable exportSpec =
@@ -70,7 +70,7 @@ annotateExportSpec globalTable exportSpec =
7070
[] -> scopeError (ENotInScope qn) exportSpec
7171
[symbol] ->
7272
let
73-
subSymbols = nub (do
73+
subSymbols = nubSymbols (do
7474
subSymbol <- concat (Map.elems globalTable)
7575
Just subSymbolParentName <- return $ symbolParent subSymbol
7676
guard (subSymbolParentName == symbolName symbol)
@@ -109,3 +109,11 @@ annotateExportSpec globalTable exportSpec =
109109
(UnQual _ _, symbols) <- Map.toList globalTable
110110
symbols)
111111

112+
113+
nubSymbols :: [Symbol] -> [Symbol]
114+
nubSymbols = loop Set.empty where
115+
loop _ [] = []
116+
loop a (b : c) = if Set.member b a
117+
then loop a c
118+
else b : loop (Set.insert b a) c
119+

tests/exports/DataFamilies.hs.golden

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
, symbolName = Ident () "method1"
1818
, className = Ident () "ListLike"
1919
}
20-
, DataFam
21-
{ symbolModule = ModuleName () "DataFamilies"
22-
, symbolName = Ident () "Vector"
23-
, associate = Nothing
24-
}
2520
, Constructor
2621
{ symbolModule = ModuleName () "DataFamilies"
2722
, symbolName = Ident () "U_Vector"

tests/exports/DuplicateExports.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module DuplicateExports (A(A), A) where
2+
3+
data A = A
4+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[ Data
2+
{ symbolModule = ModuleName () "DuplicateExports"
3+
, symbolName = Ident () "A"
4+
}
5+
, Constructor
6+
{ symbolModule = ModuleName () "DuplicateExports"
7+
, symbolName = Ident () "A"
8+
, typeName = Ident () "A"
9+
}
10+
]

0 commit comments

Comments
 (0)