git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix #306. Had to move ref(In)Eq back to Prelude to avoid circular dependency between Prelude and Data.Eq.Unsafe
53e8af8Phil Freeman
prelude/prelude.purs+22−32
@@ -146,17 +146,31 @@ module Prelude where
146 (==) :: a -> a -> Boolean
146 (==) :: a -> a -> Boolean
147 (/=) :: a -> a -> Boolean
147 (/=) :: a -> a -> Boolean
148
148
149+ foreign import refEq
150+ "function refEq(r1) {\
151+ \ return function(r2) {\
152+ \ return r1 === r2;\
153+ \ };\
154+ \}" :: forall a. a -> a -> Boolean
155+
156+ foreign import refIneq
157+ "function refIneq(r1) {\
158+ \ return function(r2) {\
159+ \ return r1 !== r2;\
160+ \ };\
161+ \}" :: forall a. a -> a -> Boolean
162+
149 instance eqString :: Eq String where
163 instance eqString :: Eq String where
150− (==) = Data.Eq.Unsafe.refEq
164+ (==) = refEq
151− (/=) = Data.Eq.Unsafe.refIneq
165+ (/=) = refIneq
152
166
153 instance eqNumber :: Eq Number where
167 instance eqNumber :: Eq Number where
154− (==) = Data.Eq.Unsafe.refEq
168+ (==) = refEq
155− (/=) = Data.Eq.Unsafe.refIneq
169+ (/=) = refIneq
156
170
157 instance eqBoolean :: Eq Boolean where
171 instance eqBoolean :: Eq Boolean where
158− (==) = Data.Eq.Unsafe.refEq
172+ (==) = refEq
159− (/=) = Data.Eq.Unsafe.refIneq
173+ (/=) = refIneq
160
174
161 instance eqArray :: (Eq a) => Eq [a] where
175 instance eqArray :: (Eq a) => Eq [a] where
162 (==) [] [] = true
176 (==) [] [] = true
@@ -321,39 +335,15 @@ module Prelude where
321
335
322module Data.Eq where
336module Data.Eq where
323
337
324− import qualified Data.Eq.Unsafe as Unsafe
325−
326 data Ref a = Ref a
338 data Ref a = Ref a
327
339
328 liftRef :: forall a b. (a -> a -> b) -> Ref a -> Ref a -> b
340 liftRef :: forall a b. (a -> a -> b) -> Ref a -> Ref a -> b
329 liftRef f (Ref x) (Ref y) = f x y
341 liftRef f (Ref x) (Ref y) = f x y
330
342
331− refEq :: forall a. Ref a -> Ref a -> Boolean
332− refEq = liftRef Unsafe.refEq
333−
334− refIneq :: forall a. Ref a -> Ref a -> Boolean
335− refIneq = liftRef Unsafe.refIneq
336−
337 instance eqRef :: Eq (Ref a) where
343 instance eqRef :: Eq (Ref a) where
338− (==) = refEq
344+ (==) = liftRef refEq
339− (/=) = refIneq
345+ (/=) = liftRef refIneq
340
346
341−module Data.Eq.Unsafe where
342−
343− foreign import refEq
344− "function refEq(r1) {\
345− \ return function(r2) {\
346− \ return r1 === r2;\
347− \ };\
348− \}" :: forall a. a -> a -> Boolean
349−
350− foreign import refIneq
351− "function refIneq(r1) {\
352− \ return function(r2) {\
353− \ return r1 !== r2;\
354− \ };\
355− \}" :: forall a. a -> a -> Boolean
356−
357module Control.Monad.Eff where
347module Control.Monad.Eff where
358
348
359 foreign import data Eff :: # ! -> * -> *
349 foreign import data Eff :: # ! -> * -> *
src/Language/PureScript.hs+16−2
@@ -68,7 +68,7 @@ compile = compile' initEnvironment
68
68
69compile' :: Environment -> Options -> [Module] -> Either String (String, String, Environment)
69compile' :: Environment -> Options -> [Module] -> Either String (String, String, Environment)
70compile' env opts ms = do
70compile' env opts ms = do
71− (sorted, _) <- sortModules ms
71+ (sorted, _) <- sortModules (map importPrelude ms)
72 desugared <- desugar sorted
72 desugared <- desugar sorted
73 (elaborated, env') <- runCheck' env $ forM desugared $ \(Module moduleName' decls exps) -> do
73 (elaborated, env') <- runCheck' env $ forM desugared $ \(Module moduleName' decls exps) -> do
74 modify (\s -> s { checkCurrentModule = Just moduleName' })
74 modify (\s -> s { checkCurrentModule = Just moduleName' })
@@ -129,7 +129,7 @@ make :: (Functor m, Monad m, MonadMake m) => Options -> [(FilePath, Module)] ->
129make opts ms = do
129make opts ms = do
130 let filePathMap = M.fromList (map (\(fp, (Module mn _ _)) -> (mn, fp)) ms)
130 let filePathMap = M.fromList (map (\(fp, (Module mn _ _)) -> (mn, fp)) ms)
131
131
132− (sorted, graph) <- liftError $ sortModules (map snd ms)
132+ (sorted, graph) <- liftError $ sortModules (map (importPrelude . snd) ms)
133
133
134 toRebuild <- foldM (\s (Module moduleName' _ _) -> do
134 toRebuild <- foldM (\s (Module moduleName' _ _) -> do
135 let filePath = toFileName moduleName'
135 let filePath = toFileName moduleName'
@@ -204,3 +204,17 @@ reverseDependencies g = combine [ (dep, mn) | (mn, deps) <- g, dep <- deps ]
204 where
204 where
205 combine :: (Ord a) => [(a, b)] -> M.Map a [b]
205 combine :: (Ord a) => [(a, b)] -> M.Map a [b]
206 combine = M.fromList . map ((fst . head) &&& map snd) . groupBy ((==) `on` fst) . sortBy (compare `on` fst)
206 combine = M.fromList . map ((fst . head) &&& map snd) . groupBy ((==) `on` fst) . sortBy (compare `on` fst)
207+
208+-- |
209+-- Add an import declaration for the Prelude to a module if it does not already explicitly import
210+-- it.
211+--
212+importPrelude :: Module -> Module
213+importPrelude m@(Module mn decls exps) =
214+ if isPreludeImport `any` decls || mn == prelude then m
215+ else Module mn (preludeImport : decls) exps
216+ where
217+ prelude = ModuleName [ProperName C.prelude]
218+ isPreludeImport (ImportDeclaration (ModuleName [ProperName mn']) _ _) | mn' == C.prelude = True
219+ isPreludeImport _ = False
220+ preludeImport = ImportDeclaration prelude Nothing Nothing
src/Language/PureScript/ModuleDependencies.hs+1−1
@@ -67,4 +67,4 @@ getModuleName (Module mn _ _) = mn
67toModule :: SCC Module -> Either String Module
67toModule :: SCC Module -> Either String Module
68toModule (AcyclicSCC m) = return m
68toModule (AcyclicSCC m) = return m
69toModule (CyclicSCC [m]) = return m
69toModule (CyclicSCC [m]) = return m
70−toModule (CyclicSCC _) = Left "Cycle in module dependencies"
70+toModule (CyclicSCC ms) = Left $ "Cycle in module dependencies: " ++ show (map getModuleName ms)
src/Language/PureScript/Sugar/Names.hs+3−17
@@ -134,10 +134,9 @@ addExport exports name =
134--
134--
135desugarImports :: [Module] -> Either String [Module]
135desugarImports :: [Module] -> Either String [Module]
136desugarImports modules = do
136desugarImports modules = do
137− let modules' = importPrelude `map` modules
138− unfilteredExports <- findExports modules'
137+ unfilteredExports <- findExports modules
139− exports <- foldM filterModuleExports unfilteredExports modules'
138+ exports <- foldM filterModuleExports unfilteredExports modules
140− mapM (renameInModule' unfilteredExports exports) modules'
139+ mapM (renameInModule' unfilteredExports exports) modules
141 where
140 where
142
141
143 -- Filters the exports for a module in the global exports environment so that only explicitly
142 -- Filters the exports for a module in the global exports environment so that only explicitly
@@ -156,19 +155,6 @@ desugarImports modules = do
156 imports <- resolveImports env m
155 imports <- resolveImports env m
157 renameInModule imports env (elaborateExports exps m)
156 renameInModule imports env (elaborateExports exps m)
158
157
159−-- |
160−-- Add an import declaration for the Prelude to a module if it does not already explicitly import
161−-- it.
162−--
163−importPrelude :: Module -> Module
164−importPrelude m@(Module mn decls exps) =
165− if isPreludeImport `any` decls then m
166− else Module mn (preludeImport : decls) exps
167− where
168− isPreludeImport (ImportDeclaration (ModuleName [ProperName "Prelude"]) _ _) = True
169− isPreludeImport _ = False
170− preludeImport = ImportDeclaration (ModuleName [ProperName "Prelude"]) Nothing Nothing
171−
172-- |
158-- |
173-- Rethrow an error with the name of the current module in the case of a failure
159-- Rethrow an error with the name of the current module in the case of a failure
174--
160--