@@ -35,24 +35,11 @@ eliminateDeadCode uber@UberModule {..} =
3535 -- trace ("\nadjacencyList:\n" <> shower adjacencyList <> "\n") $
3636 -- trace ("\nreachableIds:\n" <> shower reachableIds <> "\n\n") $
3737 uber
38- { uberModuleForeigns = preservedForeigns
38+ { uberModuleForeigns
3939 , uberModuleBindings = preserveBindings
4040 , uberModuleExports = preservedExports
4141 }
4242 where
43- preservedForeigns ∷ [(ModuleName , FilePath , NonEmpty Name )]
44- preservedForeigns = do
45- (modname, path, foreignNames) ← annotatedForeigns
46- case NE. nonEmpty (preservedNames foreignNames) of
47- Nothing → []
48- Just names → [(modname, path, names)]
49- where
50- preservedNames ∷ [(Id , Name )] → [Name ]
51- preservedNames foreignNames = do
52- (idName, foreignName) ← foreignNames
53- guard $ idName `Set.member` reachableIds
54- pure foreignName
55-
5643 preserveBindings ∷ [Grouping (QName , Exp )]
5744 preserveBindings = do
5845 grouping ← annotatedBindings
@@ -78,15 +65,12 @@ eliminateDeadCode uber@UberModule {..} =
7865
7966 annotatedExports ∷ [(Id , Name , AExp )]
8067 annotatedBindings ∷ [Grouping (Id , QName , AExp )]
81- annotatedForeigns ∷ [(ModuleName , FilePath , [(Id , Name )])]
82- (annotatedExports, annotatedBindings, annotatedForeigns) = runAnnM do
68+ (annotatedExports, annotatedBindings) = runAnnM do
8369 annExports ← forM uberModuleExports \ (name, expr) →
8470 (,name,) <$> nextId <*> annotateExp expr
8571 annBindings ← forM uberModuleBindings $ traverse \ (qname, expr) →
8672 (,qname,) <$> nextId <*> annotateExp expr
87- annForeignNames ← forM uberModuleForeigns \ (modname, path, names) →
88- (modname,path,) <$> forM (toList names) \ name → fmap (,name) nextId
89- pure (annExports, annBindings, annForeignNames)
73+ pure (annExports, annBindings)
9074
9175 dceAnnotatedExp ∷ AExp → Exp
9276 dceAnnotatedExp =
@@ -141,10 +125,7 @@ eliminateDeadCode uber@UberModule {..} =
141125
142126 adjacencyList ∷ [(() , Id , [Id ])]
143127 adjacencyList =
144- DL. toList $
145- adjacencyListFromExports
146- <> adjacencyListFromBindings
147- <> adjacencyListFromForeigns
128+ DL. toList $ adjacencyListFromExports <> adjacencyListFromBindings
148129
149130 adjacencyListFromExports ∷ DList (() , Id , [Id ])
150131 adjacencyListFromExports =
@@ -160,22 +141,13 @@ eliminateDeadCode uber@UberModule {..} =
160141 recBinds & foldMap \ (nodeId, _qname, expr) →
161142 adjacencyListForExpr bindingsInScope (nodeId, expr)
162143
163- adjacencyListFromForeigns ∷ DList (() , Id , [Id ])
164- adjacencyListFromForeigns =
165- annotatedForeigns & foldMap \ (_modname, _path, names) →
166- DL. fromList ((() ,,[] ) . fst <$> names)
167-
168144 bindingsInScope ∷ Map (Qualified Name , Index ) Id
169145 bindingsInScope =
170146 Map. fromList $
171147 [ ((Imported modname name, 0 ), bindId)
172148 | grouping ← annotatedBindings
173149 , (bindId, QName modname name, _boundExpr) ← listGrouping grouping
174150 ]
175- <> [ ((Imported modname name, 0 ), foreignNameId)
176- | (modname, _path, foreignNames) ← annotatedForeigns
177- , (foreignNameId, name) ← foreignNames
178- ]
179151
180152 adjacencyListFromExport ∷ Id → AExp → DList (() , Id , [Id ])
181153 adjacencyListFromExport = curry (adjacencyListForExpr bindingsInScope)
0 commit comments