git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #520 from purescript/dce-fix
dce3cdaPhil Freeman
src/Language/PureScript/DeadCodeElimination.hs+12−6
@@ -39,7 +39,8 @@ eliminateDeadCode entryPoints ms = map go ms
39 entryPointVertices = mapMaybe (vertexFor . fst) . filter (\((mn, _), _) -> mn `elem` entryPoints) $ declarations
39 entryPointVertices = mapMaybe (vertexFor . fst) . filter (\((mn, _), _) -> mn `elem` entryPoints) $ declarations
40
40
41 filterExport :: [Declaration] -> DeclarationRef -> Maybe DeclarationRef
41 filterExport :: [Declaration] -> DeclarationRef -> Maybe DeclarationRef
42− filterExport decls r@(TypeRef name _) | (any $ typeExists name) decls = Just r
42+ filterExport decls r@(TypeRef name _) | (any $ typeOrClassExists name) decls = Just r
43+ filterExport decls r@(TypeClassRef name) | (any $ typeOrClassExists name) decls = Just r
43 filterExport decls r@(ValueRef name) | (any $ valueExists name) decls = Just r
44 filterExport decls r@(ValueRef name) | (any $ valueExists name) decls = Just r
44 filterExport decls r@(TypeInstanceRef name) | (any $ valueExists name) decls = Just r
45 filterExport decls r@(TypeInstanceRef name) | (any $ valueExists name) decls = Just r
45 filterExport _ _ = Nothing
46 filterExport _ _ = Nothing
@@ -51,11 +52,12 @@ eliminateDeadCode entryPoints ms = map go ms
51 valueExists name (PositionedDeclaration _ d) = valueExists name d
52 valueExists name (PositionedDeclaration _ d) = valueExists name d
52 valueExists _ _ = False
53 valueExists _ _ = False
53
54
54− typeExists :: ProperName -> Declaration -> Bool
55+ typeOrClassExists :: ProperName -> Declaration -> Bool
55− typeExists name (DataDeclaration _ name' _ _) = name == name'
56+ typeOrClassExists name (DataDeclaration _ name' _ _) = name == name'
57+ typeOrClassExists name (TypeClassDeclaration name' _ _ _) = name == name'
56− typeExists name (DataBindingGroupDeclaration decls) = any (typeExists name) decls
58+ typeOrClassExists name (DataBindingGroupDeclaration decls) = any (typeOrClassExists name) decls
57− typeExists name (PositionedDeclaration _ d) = typeExists name d
59+ typeOrClassExists name (PositionedDeclaration _ d) = typeOrClassExists name d
58− typeExists _ _ = False
60+ typeOrClassExists _ _ = False
59
61
60type Key = (ModuleName, Either Ident ProperName)
62type Key = (ModuleName, Either Ident ProperName)
61
63
@@ -68,6 +70,7 @@ declarationsByModule (Module moduleName ds _) = concatMap go ds
68 go (ExternDeclaration _ name _ _) = [((moduleName, Left name), [])]
70 go (ExternDeclaration _ name _ _) = [((moduleName, Left name), [])]
69 go d@(BindingGroupDeclaration names') = map (\(name, _, _) -> ((moduleName, Left name), dependencies moduleName d)) names'
71 go d@(BindingGroupDeclaration names') = map (\(name, _, _) -> ((moduleName, Left name), dependencies moduleName d)) names'
70 go (DataBindingGroupDeclaration ds') = concatMap go ds'
72 go (DataBindingGroupDeclaration ds') = concatMap go ds'
73+ go (TypeClassDeclaration name _ _ _) = [((moduleName, Right name), [])]
71 go (PositionedDeclaration _ d) = go d
74 go (PositionedDeclaration _ d) = go d
72 go _ = []
75 go _ = []
73
76
@@ -102,6 +105,9 @@ isUsed moduleName graph vertexFor entryPointVertices (BindingGroupDeclaration ds
102 in any (\v -> path graph v v') entryPointVertices) ds
105 in any (\v -> path graph v v') entryPointVertices) ds
103isUsed moduleName graph vertexFor entryPointVertices (DataBindingGroupDeclaration ds) =
106isUsed moduleName graph vertexFor entryPointVertices (DataBindingGroupDeclaration ds) =
104 any (isUsed moduleName graph vertexFor entryPointVertices) ds
107 any (isUsed moduleName graph vertexFor entryPointVertices) ds
108+isUsed moduleName graph vertexFor entryPointVertices (TypeClassDeclaration name _ _ _) =
109+ let Just v' = vertexFor (moduleName, Right name)
110+ in any (\v -> path graph v v') entryPointVertices
105isUsed moduleName graph vertexFor entryPointVertices (PositionedDeclaration _ d) =
111isUsed moduleName graph vertexFor entryPointVertices (PositionedDeclaration _ d) =
106 isUsed moduleName graph vertexFor entryPointVertices d
112 isUsed moduleName graph vertexFor entryPointVertices d
107isUsed _ _ _ _ _ = True
113isUsed _ _ _ _ _ = True