on master help sign in
Merge Transform.Interface into Canonicalize.Setup, the only usage site
commita8377fc4322753c04e0fb4dd74e6a9fa6e0c9b47 authorEvan Czaplicki <info@elm-lang.org> dateMon 4 May 2015, 09:43 (12 years ago) parenta5ef599
3 files changed+57−63
elm-compiler.cabal−1 src/Canonicalize/Setup.hs+57−2 src/Transform/Interface.hs−60
elm-compiler.cabal−1
@@ -74,7 +74,6 @@ Library
7474 Generate.Cases,
7575 Generate.Substitute,
7676 Transform.AddDefaultImports,
77− Transform.Interface,
7877 Parse.Binop,
7978 Parse.Declaration,
8079 Parse.Expression,
src/Canonicalize/Setup.hs+57−2
@@ -21,7 +21,6 @@ import qualified Reporting.Region as R
2121import qualified Canonicalize.Environment as Env
2222import qualified Canonicalize.Result as Result
2323import qualified Canonicalize.Type as Canonicalize
24−import qualified Transform.Interface as Interface
2524
2625
2726environment
@@ -55,7 +54,7 @@ importPatches
5554 -> A.Located (Module.Name, Module.ImportMethod)
5655 -> Result.ResultErr [Env.Patch]
5756importPatches allInterfaces (A.A region (importName, method)) =
58− case Interface.filterExports <$> Map.lookup importName allInterfaces of
57+ case restrictToPublicApi <$> Map.lookup importName allInterfaces of
5958 Nothing
6059 | Module.nameIsNative importName ->
6160 Result.ok []
@@ -332,3 +331,59 @@ declToPatches moduleName (A.A region decl) =
332331 ( Nothing
333332 , []
334333 )
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))