on master help sign in
Merge Transform.Interface into Canonicalize.Setup, the only usage site
a8377fcEvan Czaplicki
elm-compiler.cabal−1
@@ -74,7 +74,6 @@ Library
74 Generate.Cases,
74 Generate.Cases,
75 Generate.Substitute,
75 Generate.Substitute,
76 Transform.AddDefaultImports,
76 Transform.AddDefaultImports,
77− Transform.Interface,
78 Parse.Binop,
77 Parse.Binop,
79 Parse.Declaration,
78 Parse.Declaration,
80 Parse.Expression,
79 Parse.Expression,
src/Canonicalize/Setup.hs+57−2
@@ -21,7 +21,6 @@ import qualified Reporting.Region as R
21import qualified Canonicalize.Environment as Env
21import qualified Canonicalize.Environment as Env
22import qualified Canonicalize.Result as Result
22import qualified Canonicalize.Result as Result
23import qualified Canonicalize.Type as Canonicalize
23import qualified Canonicalize.Type as Canonicalize
24−import qualified Transform.Interface as Interface
25
24
26
25
27environment
26environment
@@ -55,7 +54,7 @@ importPatches
55 -> A.Located (Module.Name, Module.ImportMethod)
54 -> A.Located (Module.Name, Module.ImportMethod)
56 -> Result.ResultErr [Env.Patch]
55 -> Result.ResultErr [Env.Patch]
57importPatches allInterfaces (A.A region (importName, method)) =
56importPatches allInterfaces (A.A region (importName, method)) =
58− case Interface.filterExports <$> Map.lookup importName allInterfaces of
57+ case restrictToPublicApi <$> Map.lookup importName allInterfaces of
59 Nothing
58 Nothing
60 | Module.nameIsNative importName ->
59 | Module.nameIsNative importName ->
61 Result.ok []
60 Result.ok []
@@ -332,3 +331,59 @@ declToPatches moduleName (A.A region decl) =
332 ( Nothing
331 ( Nothing
333 , []
332 , []
334 )
333 )
334+
335+
336+-- RESTRICT VISIBLE API OF INTERFACES
337+
338+restrictToPublicApi :: Module.Interface -> Module.Interface
339+restrictToPublicApi interface =
340+ interface
341+ { Module.iTypes =
342+ Map.fromList $
343+ Maybe.mapMaybe
344+ (get (Module.iTypes interface))
345+ (Var.getValues exports ++ ctors)
346+
347+ , Module.iAliases =
348+ Map.fromList $
349+ Maybe.mapMaybe
350+ (get (Module.iAliases interface))
351+ (Var.getAliases exports)
352+
353+ , Module.iAdts =
354+ Map.fromList
355+ (Maybe.mapMaybe (trimUnions interface) unions)
356+ }
357+ where
358+ exports :: [Var.Value]
359+ exports =
360+ Module.iExports interface
361+
362+ unions :: [(String, Var.Listing String)]
363+ unions =
364+ Var.getUnions exports
365+
366+ ctors :: [String]
367+ ctors =
368+ concatMap (\(_, Var.Listing ctorList _) -> ctorList) unions
369+
370+
371+get :: Map.Map String a -> String -> Maybe (String, a)
372+get dict key =
373+ case Map.lookup key dict of
374+ Nothing -> Nothing
375+ Just value -> Just (key, value)
376+
377+
378+trimUnions
379+ :: Module.Interface
380+ -> (String, Var.Listing String)
381+ -> Maybe (String, Module.AdtInfo String)
382+trimUnions interface (name, Var.Listing exportedCtors _) =
383+ case Map.lookup name (Module.iAdts interface) of
384+ Nothing -> Nothing
385+ Just (tvars, ctors) ->
386+ let isExported (ctor, _) =
387+ ctor `elem` exportedCtors
388+ in
389+ Just (name, (tvars, filter isExported ctors))
src/Transform/Interface.hsdeleted−60
@@ -1,60 +0,0 @@
1−module Transform.Interface (filterExports) where
2−
3−import qualified Data.Map as Map
4−import qualified Data.Maybe as Maybe
5−import qualified AST.Module as Module
6−import qualified AST.Variable as Var
7−
8−
9−filterExports :: Module.Interface -> Module.Interface
10−filterExports interface =
11− interface
12− { Module.iTypes =
13− Map.fromList $
14− Maybe.mapMaybe
15− (get (Module.iTypes interface))
16− (Var.getValues exports ++ ctors)
17−
18− , Module.iAliases =
19− Map.fromList $
20− Maybe.mapMaybe
21− (get (Module.iAliases interface))
22− (Var.getAliases exports)
23−
24− , Module.iAdts =
25− Map.fromList
26− (Maybe.mapMaybe (trimUnions interface) unions)
27− }
28− where
29− exports :: [Var.Value]
30− exports =
31− Module.iExports interface
32−
33− unions :: [(String, Var.Listing String)]
34− unions =
35− Var.getUnions exports
36−
37− ctors :: [String]
38− ctors =
39− concatMap (\(_, Var.Listing ctorList _) -> ctorList) unions
40−
41−
42−get :: Map.Map String a -> String -> Maybe (String, a)
43−get dict key =
44− case Map.lookup key dict of
45− Nothing -> Nothing
46− Just value -> Just (key, value)
47−
48−
49−trimUnions
50− :: Module.Interface
51− -> (String, Var.Listing String)
52− -> Maybe (String, Module.AdtInfo String)
53−trimUnions interface (name, Var.Listing exportedCtors _) =
54− case Map.lookup name (Module.iAdts interface) of
55− Nothing -> Nothing
56− Just (tvars, ctors) ->
57− let isExported (ctor, _) =
58− ctor `elem` exportedCtors
59− in
60− Just (name, (tvars, filter isExported ctors))