Skip to content

Commit

Permalink
Merge branch '0.9' into 2070
Browse files Browse the repository at this point in the history
  • Loading branch information
paf31 committed May 22, 2016
2 parents 18c3993 + ca98825 commit 8703a73
Show file tree
Hide file tree
Showing 43 changed files with 645 additions and 441 deletions.
30 changes: 30 additions & 0 deletions examples/warning/DuplicateExportRef.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- @shouldWarnWith DuplicateExportRef
-- @shouldWarnWith DuplicateExportRef
-- @shouldWarnWith DuplicateExportRef
-- @shouldWarnWith DuplicateExportRef
-- @shouldWarnWith DuplicateExportRef
-- @shouldWarnWith DuplicateExportRef
-- @shouldWarnWith DuplicateExportRef
module Main
( X(X, X), X
, fn, fn
, (!), (!)
, class Y, class Y
, Natural, type (~>), type (~>)
, module Prelude, module Prelude
) where

import Prelude (Unit)

data X = X

fn :: X -> X -> X
fn _ _ = X

infix 2 fn as !

class Y a

type Natural f g = forall a. f a -> g a

infixl 1 type Natural as ~>
10 changes: 10 additions & 0 deletions examples/warning/DuplicateImport.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- @shouldWarnWith DuplicateImport
module Main where

import Prelude (Unit, unit, pure)
import Prelude (Unit, unit, pure)

import Control.Monad.Eff (Eff)

main :: Eff () Unit
main = pure unit
18 changes: 18 additions & 0 deletions examples/warning/DuplicateImportRef.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- @shouldWarnWith DuplicateImportRef
-- @shouldWarnWith DuplicateImportRef
-- @shouldWarnWith DuplicateImportRef
-- @shouldWarnWith DuplicateImportRef
module Main where

import Prelude
( Unit, Unit
, unit, unit
, class Functor, class Functor
, (<>), (<>)
)

u :: Unit
u = unit <> unit

fid :: forall f a. Functor f => f a -> f a
fid fa = fa
10 changes: 10 additions & 0 deletions examples/warning/DuplicateSelectiveImport.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- @shouldWarnWith DuplicateSelectiveImport
module Main where

import Prelude (Unit, unit)
import Prelude (pure)

import Control.Monad.Eff (Eff)

main :: Eff () Unit
main = pure unit
9 changes: 9 additions & 0 deletions examples/warning/HidingImport.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- @shouldWarnWith HidingImport
-- @shouldWarnWith HidingImport
module Main where

import Prelude hiding (one)
import Control.Monad.Eff hiding (runPure)

main :: Eff () Unit
main = pure unit
9 changes: 9 additions & 0 deletions examples/warning/ImplicitImport.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- @shouldWarnWith ImplicitImport
-- @shouldWarnWith ImplicitImport
module Main where

import Prelude
import Control.Monad.Eff

main :: Eff () Unit
main = pure unit
11 changes: 11 additions & 0 deletions examples/warning/ImplicitQualifiedImport.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- @shouldWarnWith ImplicitQualifiedImport
-- @shouldWarnWith ImplicitQualifiedImport
module Main where

import Data.Unit

import Control.Monad.Eff as E
import Control.Monad.Eff.Console as E

main :: E.Eff (console :: E.CONSOLE) Unit
main = E.log "test"
4 changes: 4 additions & 0 deletions examples/warning/MissingTypeDeclaration.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- @shouldWarnWith MissingTypeDeclaration
module Main where

x = 0
17 changes: 17 additions & 0 deletions examples/warning/OverlappingInstances.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- @shouldWarnWith OverlappingInstances
module Main where

class Test a where
test :: a -> a

instance testRefl :: Test a where
test x = x

instance testInt :: Test Int where
test _ = 0

-- The OverlappingInstances instances warning only arises when there are two
-- choices for a dictionary, not when the instances are defined. So without
-- `value` this module would not raise a warning.
value :: Int
value = test 1
15 changes: 15 additions & 0 deletions examples/warning/OverlappingPattern.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- @shouldWarnWith OverlappingPattern
-- @shouldWarnWith OverlappingPattern
module Main where

data X = A | B

pat1 :: X -> Boolean
pat1 A = true
pat1 A = true
pat1 B = false

pat2 :: X -> Boolean
pat2 A = true
pat2 _ = false
pat2 B = false
13 changes: 13 additions & 0 deletions examples/warning/ScopeShadowing.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- @shouldWarnWith ScopeShadowing
module Main where

import Prelude

-- No warning at the definition, only when the name is later resolved
data Unit = Unit

-- This is only a warning as the `Prelude` import is implicit. If `Unit` was
-- named explicitly in an import list, then this refernce to `Unit`
-- would be a `ScopeConflict` error instead.
test :: Unit
test = const Unit unit
5 changes: 5 additions & 0 deletions examples/warning/ShadowedTypeVar.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- @shouldWarnWith ShadowedTypeVar
module Main where

f :: forall a. (forall a. a -> a) -> a -> a
f g x = g x
1 change: 1 addition & 0 deletions examples/warning/UnnecessaryFFIModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.out = null;
5 changes: 5 additions & 0 deletions examples/warning/UnnecessaryFFIModule.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- @shouldWarnWith UnnecessaryFFIModule
module Main where

t :: Boolean
t = true
8 changes: 8 additions & 0 deletions examples/warning/UnusedDctorExplicitImport.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- @shouldWarnWith UnusedDctorExplicitImport
module Main where

import Data.Ordering (Ordering(EQ, LT))

f :: Ordering -> Ordering
f EQ = EQ
f x = x
7 changes: 7 additions & 0 deletions examples/warning/UnusedDctorImportAll.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- @shouldWarnWith UnusedDctorImport
module Main where

import Data.Ordering (Ordering(..))

f :: Ordering -> Ordering
f x = x
7 changes: 7 additions & 0 deletions examples/warning/UnusedDctorImportExplicit.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- @shouldWarnWith UnusedDctorImport
module Main where

import Data.Ordering (Ordering(EQ))

f :: Ordering -> Ordering
f x = x
8 changes: 8 additions & 0 deletions examples/warning/UnusedExplicitImport.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- @shouldWarnWith UnusedExplicitImport
module Main where

import Prelude (Unit, unit, pure, bind)
import Control.Monad.Eff (Eff)

main :: Eff () Unit
main = pure unit
2 changes: 2 additions & 0 deletions examples/warning/UnusedFFIImplementations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exports.yes = true;
exports.no = false;
4 changes: 4 additions & 0 deletions examples/warning/UnusedFFIImplementations.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- @shouldWarnWith UnusedFFIImplementations
module Main where

foreign import yes :: Boolean
14 changes: 14 additions & 0 deletions examples/warning/UnusedImport.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- @shouldWarnWith UnusedImport
-- @shouldWarnWith UnusedImport
-- @shouldWarnWith UnusedImport
module Main where

import Data.Unit (Unit, unit)

-- All of the below are unused
import Control.Monad.Eff
import Control.Monad.Eff.Console as Console
import Test.Assert ()

main :: Unit
main = unit
5 changes: 5 additions & 0 deletions examples/warning/UnusedTypeVar.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- @shouldWarnWith UnusedTypeVar
module Main where

f :: forall a b. a -> a
f x = x
23 changes: 23 additions & 0 deletions examples/warning/WildcardInferredType.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- @shouldWarnWith WildcardInferredType
-- @shouldWarnWith WildcardInferredType
-- @shouldWarnWith WildcardInferredType
-- @shouldWarnWith WildcardInferredType
module Main where

x :: Int
x = 0 :: _

y :: _
y = 0

z :: Int
z =
let n :: _
n = 0
in n

w :: Int
w = n
where
n :: _
n = 0
65 changes: 21 additions & 44 deletions psc/Main.hs
Original file line number Diff line number Diff line change
@@ -1,48 +1,42 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

module Main where

import Control.Applicative
import Control.Monad
import Control.Monad.Error.Class (MonadError(..))
import Control.Monad.Writer.Strict
import Control.Applicative
import Control.Monad
import Control.Monad.Writer.Strict

import Data.List (isSuffixOf, partition)
import Data.Version (showVersion)
import qualified Data.Map as M
import qualified Data.Aeson as A
import qualified Data.ByteString.Lazy as B
import qualified Data.ByteString.UTF8 as BU8
import qualified Data.Map as M
import Data.Version (showVersion)

import Options.Applicative as Opts
import qualified Language.PureScript as P
import Language.PureScript.Errors.JSON
import Language.PureScript.Make

import System.Exit (exitSuccess, exitFailure)
import System.IO (hSetEncoding, hPutStrLn, stdout, stderr, utf8)
import System.IO.UTF8
import System.FilePath.Glob (glob)
import Options.Applicative as Opts

import qualified Language.PureScript as P
import qualified Paths_purescript as Paths

import Language.PureScript.Make
import Language.PureScript.Errors.JSON
import System.Exit (exitSuccess, exitFailure)
import System.FilePath.Glob (glob)
import System.IO (hSetEncoding, hPutStrLn, stdout, stderr, utf8)
import System.IO.UTF8

data PSCMakeOptions = PSCMakeOptions
{ pscmInput :: [FilePath]
, pscmForeignInput :: [FilePath]
, pscmOutputDir :: FilePath
, pscmOpts :: P.Options
, pscmUsePrefix :: Bool
, pscmJSONErrors :: Bool
}

data InputOptions = InputOptions
{ ioInputFiles :: [FilePath]
}

-- | Argumnets: verbose, use JSON, warnings, errors
printWarningsAndErrors :: Bool -> Bool -> P.MultipleErrors -> Either P.MultipleErrors a -> IO ()
printWarningsAndErrors verbose False warnings errors = do
Expand All @@ -65,14 +59,12 @@ compile PSCMakeOptions{..} = do
when (null input && not pscmJSONErrors) $ do
hPutStrLn stderr "psc: No input files."
exitFailure
let (jsFiles, pursFiles) = partition (isSuffixOf ".js") input
moduleFiles <- readInput (InputOptions pursFiles)
inputForeign <- globWarningOnMisses (unless pscmJSONErrors . warnFileTypeNotFound) pscmForeignInput
foreignFiles <- forM (inputForeign ++ jsFiles) (\inFile -> (inFile,) <$> readUTF8File inFile)
moduleFiles <- readInput input
(makeErrors, makeWarnings) <- runMake pscmOpts $ do
(ms, foreigns) <- parseInputs moduleFiles foreignFiles
let filePathMap = M.fromList $ map (\(fp, P.Module _ _ mn _ _) -> (mn, fp)) ms
makeActions = buildMakeActions pscmOutputDir filePathMap foreigns pscmUsePrefix
ms <- P.parseModulesFromFiles id moduleFiles
let filePathMap = M.fromList $ map (\(fp, P.Module _ _ mn _ _) -> (mn, Right fp)) ms
foreigns <- inferForeignModules filePathMap
let makeActions = buildMakeActions pscmOutputDir filePathMap foreigns pscmUsePrefix
P.make makeActions (map snd ms)
printWarningsAndErrors (P.optionsVerboseErrors pscmOpts) pscmJSONErrors makeWarnings makeErrors
exitSuccess
Expand All @@ -89,28 +81,14 @@ globWarningOnMisses warn = concatMapM globWithWarning
return paths
concatMapM f = liftM concat . mapM f

readInput :: InputOptions -> IO [(Either P.RebuildPolicy FilePath, String)]
readInput InputOptions{..} = forM ioInputFiles $ \inFile -> (Right inFile, ) <$> readUTF8File inFile

parseInputs :: (MonadError P.MultipleErrors m, MonadWriter P.MultipleErrors m)
=> [(Either P.RebuildPolicy FilePath, String)]
-> [(FilePath, P.ForeignJS)]
-> m ([(Either P.RebuildPolicy FilePath, P.Module)], M.Map P.ModuleName FilePath)
parseInputs modules foreigns =
(,) <$> P.parseModulesFromFiles (either (const "") id) modules
<*> P.parseForeignModulesFromFiles foreigns
readInput :: [FilePath] -> IO [(FilePath, String)]
readInput inputFiles = forM inputFiles $ \inFile -> (inFile, ) <$> readUTF8File inFile

inputFile :: Parser FilePath
inputFile = strArgument $
metavar "FILE"
<> help "The input .purs file(s)"

inputForeignFile :: Parser FilePath
inputForeignFile = strOption $
short 'f'
<> long "ffi"
<> help "The input .js file(s) providing foreign import implementations"

outputDirectory :: Parser FilePath
outputDirectory = strOption $
short 'o'
Expand Down Expand Up @@ -173,7 +151,6 @@ options = P.Options <$> noTco

pscMakeOptions :: Parser PSCMakeOptions
pscMakeOptions = PSCMakeOptions <$> many inputFile
<*> many inputForeignFile
<*> outputDirectory
<*> options
<*> (not <$> noPrefix)
Expand Down

0 comments on commit 8703a73

Please sign in to comment.