summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Zimmerman <alan.zimm@gmail.com>2015-04-07 09:10:18 -0500
committerAustin Seipp <austin@well-typed.com>2015-04-07 09:13:38 -0500
commitf1a4e42ea2e5302147dcb69b9baa6f4aa3af6e37 (patch)
tree2a970c82ca848faa7bb278687dab31e370aa9beb
parentcf1d9751e7ca85e9b3284ad57882958b8dc73d16 (diff)
downloadhaskell-f1a4e42ea2e5302147dcb69b9baa6f4aa3af6e37.tar.gz
The production for `pquals` is incorrect; the specifics are in D803.
Reviewed By: austin Differential Revision: https://phabricator.haskell.org/D803 GHC Trac Issues: #10207
-rw-r--r--compiler/parser/Parser.y2
-rw-r--r--testsuite/tests/ghc-api/annotations/.gitignore1
-rw-r--r--testsuite/tests/ghc-api/annotations/ListComprehensions.hs22
-rw-r--r--testsuite/tests/ghc-api/annotations/Makefile7
-rw-r--r--testsuite/tests/ghc-api/annotations/all.T2
-rw-r--r--testsuite/tests/ghc-api/annotations/listcomps.hs109
-rw-r--r--testsuite/tests/ghc-api/annotations/listcomps.stdout116
-rw-r--r--testsuite/tests/parser/should_fail/readFail038.stderr2
8 files changed, 257 insertions, 4 deletions
diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y
index 67c90d507a..99c5374247 100644
--- a/compiler/parser/Parser.y
+++ b/compiler/parser/Parser.y
@@ -2466,7 +2466,7 @@ flattenedpquals :: { Located [LStmt RdrName (LHsExpr RdrName)] }
pquals :: { Located [[LStmt RdrName (LHsExpr RdrName)]] }
: squals '|' pquals
{% addAnnotation (gl $ last $ unLoc $1) AnnVbar (gl $2) >>
- return (L (getLoc $2) (reverse (unLoc $1) : unLoc $3)) }
+ return (sLL $1 $> (reverse (unLoc $1) : unLoc $3)) }
| squals { L (getLoc $1) [reverse (unLoc $1)] }
squals :: { Located [LStmt RdrName (LHsExpr RdrName)] } -- In reverse order, because the last
diff --git a/testsuite/tests/ghc-api/annotations/.gitignore b/testsuite/tests/ghc-api/annotations/.gitignore
index fe31fad9b9..ba31dbbf59 100644
--- a/testsuite/tests/ghc-api/annotations/.gitignore
+++ b/testsuite/tests/ghc-api/annotations/.gitignore
@@ -2,6 +2,7 @@ annotations
parseTree
comments
exampleTest
+listcomps
*.hi
*.o
*.run.*
diff --git a/testsuite/tests/ghc-api/annotations/ListComprehensions.hs b/testsuite/tests/ghc-api/annotations/ListComprehensions.hs
new file mode 100644
index 0000000000..c61f7ca0b1
--- /dev/null
+++ b/testsuite/tests/ghc-api/annotations/ListComprehensions.hs
@@ -0,0 +1,22 @@
+{-# LANGUAGE ParallelListComp,
+ TransformListComp,
+ RecordWildCards #-}
+-- MonadComprehensions,
+
+module ListComprehensions where
+
+
+
+import GHC.Exts
+import qualified Data.Map as M
+import Data.Ord (comparing)
+import Data.List (sortBy)
+
+-- Let’s look at a simple, normal list comprehension to start:
+
+parallelListComp :: [Int]
+parallelListComp = [ x + y * z
+ | x <- [0..10]
+ | y <- [10..20]
+ | z <- [20..30]
+ ]
diff --git a/testsuite/tests/ghc-api/annotations/Makefile b/testsuite/tests/ghc-api/annotations/Makefile
index f5ef3b4a18..5d10d7fa88 100644
--- a/testsuite/tests/ghc-api/annotations/Makefile
+++ b/testsuite/tests/ghc-api/annotations/Makefile
@@ -26,4 +26,9 @@ exampleTest:
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc exampleTest
./exampleTest "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
-.PHONY: clean annotations parseTree comments exampleTest
+listcomps:
+ rm -f listcomps.o listcomps.hi
+ '$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc listcomps
+ ./listcomps "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
+
+.PHONY: clean annotations parseTree comments exampleTest listcops
diff --git a/testsuite/tests/ghc-api/annotations/all.T b/testsuite/tests/ghc-api/annotations/all.T
index cb075cb185..9dadf7a00a 100644
--- a/testsuite/tests/ghc-api/annotations/all.T
+++ b/testsuite/tests/ghc-api/annotations/all.T
@@ -2,4 +2,4 @@ test('annotations', normal, run_command, ['$MAKE -s --no-print-directory annotat
test('parseTree', normal, run_command, ['$MAKE -s --no-print-directory parseTree'])
test('comments', normal, run_command, ['$MAKE -s --no-print-directory comments'])
test('exampleTest', normal, run_command, ['$MAKE -s --no-print-directory exampleTest'])
-
+test('listcomps', normal, run_command, ['$MAKE -s --no-print-directory listcomps'])
diff --git a/testsuite/tests/ghc-api/annotations/listcomps.hs b/testsuite/tests/ghc-api/annotations/listcomps.hs
new file mode 100644
index 0000000000..dc440e9d65
--- /dev/null
+++ b/testsuite/tests/ghc-api/annotations/listcomps.hs
@@ -0,0 +1,109 @@
+{-# LANGUAGE RankNTypes #-}
+
+-- This program must be called with GHC's libdir as the single command line
+-- argument.
+module Main where
+
+-- import Data.Generics
+import Data.Data
+import Data.List
+import System.IO
+import GHC
+import BasicTypes
+import DynFlags
+import MonadUtils
+import Outputable
+import ApiAnnotation
+import Bag (filterBag,isEmptyBag)
+import System.Directory (removeFile)
+import System.Environment( getArgs )
+import System.Exit
+import qualified Data.Map as Map
+import qualified Data.Set as Set
+import Data.Dynamic ( fromDynamic,Dynamic )
+
+main::IO()
+main = do
+ [libdir] <- getArgs
+ testOneFile libdir "ListComprehensions"
+ exitSuccess
+
+testOneFile libdir fileName = do
+ ((anns,cs),p) <- runGhc (Just libdir) $ do
+ dflags <- getSessionDynFlags
+ setSessionDynFlags dflags
+ let mn =mkModuleName fileName
+ addTarget Target { targetId = TargetModule mn
+ , targetAllowObjCode = True
+ , targetContents = Nothing }
+ load LoadAllTargets
+ modSum <- getModSummary mn
+ p <- parseModule modSum
+ t <- typecheckModule p
+ d <- desugarModule t
+ l <- loadModule d
+ let ts=typecheckedSource l
+ r =renamedSource l
+ return (pm_annotations p,p)
+
+ let spans = Set.fromList $ getAllSrcSpans (pm_parsed_source p)
+
+ putStrLn (pp spans)
+ putStrLn "--------------------------------"
+ putStrLn (intercalate "\n" [showAnns anns])
+
+ where
+ getAnnSrcSpans :: ApiAnns -> [(SrcSpan,(ApiAnnKey,[SrcSpan]))]
+ getAnnSrcSpans (anns,_) = map (\a@((ss,_),_) -> (ss,a)) $ Map.toList anns
+
+ getAllSrcSpans :: (Data t) => t -> [SrcSpan]
+ getAllSrcSpans ast = everything (++) ([] `mkQ` getSrcSpan) ast
+ where
+ getSrcSpan :: SrcSpan -> [SrcSpan]
+ getSrcSpan ss = [ss]
+
+showAnns anns = "[\n" ++ (intercalate "\n"
+ $ map (\((s,k),v)
+ -> ("(AK " ++ pp s ++ " " ++ show k ++" = " ++ pp v ++ ")\n"))
+ $ Map.toList anns)
+ ++ "]\n"
+
+pp a = showPpr unsafeGlobalDynFlags a
+
+
+-- ---------------------------------------------------------------------
+
+-- Copied from syb for the test
+
+
+-- | Generic queries of type \"r\",
+-- i.e., take any \"a\" and return an \"r\"
+--
+type GenericQ r = forall a. Data a => a -> r
+
+
+-- | Make a generic query;
+-- start from a type-specific case;
+-- return a constant otherwise
+--
+mkQ :: ( Typeable a
+ , Typeable b
+ )
+ => r
+ -> (b -> r)
+ -> a
+ -> r
+(r `mkQ` br) a = case cast a of
+ Just b -> br b
+ Nothing -> r
+
+
+
+-- | Summarise all nodes in top-down, left-to-right order
+everything :: (r -> r -> r) -> GenericQ r -> GenericQ r
+
+-- Apply f to x to summarise top-level node;
+-- use gmapQ to recurse into immediate subterms;
+-- use ordinary foldl to reduce list of intermediate results
+
+everything k f x = foldl k (f x) (gmapQ (everything k f) x)
diff --git a/testsuite/tests/ghc-api/annotations/listcomps.stdout b/testsuite/tests/ghc-api/annotations/listcomps.stdout
new file mode 100644
index 0000000000..cf7077290a
--- /dev/null
+++ b/testsuite/tests/ghc-api/annotations/listcomps.stdout
@@ -0,0 +1,116 @@
+{ListComprehensions.hs:1:1, ListComprehensions.hs:6:8-25,
+ ListComprehensions.hs:10:1-15, ListComprehensions.hs:10:8-15,
+ ListComprehensions.hs:11:1-30, ListComprehensions.hs:11:18-25,
+ ListComprehensions.hs:12:1-27, ListComprehensions.hs:12:8-15,
+ ListComprehensions.hs:12:17-27, ListComprehensions.hs:12:18-26,
+ ListComprehensions.hs:13:1-25, ListComprehensions.hs:13:8-16,
+ ListComprehensions.hs:13:18-25, ListComprehensions.hs:13:19-24,
+ ListComprehensions.hs:17:1-16, ListComprehensions.hs:17:1-25,
+ ListComprehensions.hs:17:21-25, ListComprehensions.hs:17:22-24,
+ ListComprehensions.hs:18:1-16,
+ ListComprehensions.hs:(18,1)-(22,20),
+ ListComprehensions.hs:(18,18)-(22,20),
+ ListComprehensions.hs:(18,20)-(22,20), ListComprehensions.hs:18:22,
+ ListComprehensions.hs:18:22-26, ListComprehensions.hs:18:22-30,
+ ListComprehensions.hs:18:24, ListComprehensions.hs:18:26,
+ ListComprehensions.hs:18:28, ListComprehensions.hs:18:30,
+ ListComprehensions.hs:19:22, ListComprehensions.hs:19:22-33,
+ ListComprehensions.hs:(19,22)-(21,34),
+ ListComprehensions.hs:19:27-33, ListComprehensions.hs:19:28,
+ ListComprehensions.hs:19:31-32, ListComprehensions.hs:20:22,
+ ListComprehensions.hs:20:22-34, ListComprehensions.hs:20:27-34,
+ ListComprehensions.hs:20:28-29, ListComprehensions.hs:20:32-33,
+ ListComprehensions.hs:21:22, ListComprehensions.hs:21:22-34,
+ ListComprehensions.hs:21:27-34, ListComprehensions.hs:21:28-29,
+ ListComprehensions.hs:21:32-33, <no location info>}
+--------------------------------
+[
+(AK ListComprehensions.hs:1:1 AnnModule = [ListComprehensions.hs:6:1-6])
+
+(AK ListComprehensions.hs:1:1 AnnWhere = [ListComprehensions.hs:6:27-31])
+
+(AK ListComprehensions.hs:10:1-15 AnnImport = [ListComprehensions.hs:10:1-6])
+
+(AK ListComprehensions.hs:10:1-15 AnnSemi = [ListComprehensions.hs:11:1])
+
+(AK ListComprehensions.hs:11:1-30 AnnAs = [ListComprehensions.hs:11:27-28])
+
+(AK ListComprehensions.hs:11:1-30 AnnImport = [ListComprehensions.hs:11:1-6])
+
+(AK ListComprehensions.hs:11:1-30 AnnQualified = [ListComprehensions.hs:11:8-16])
+
+(AK ListComprehensions.hs:11:1-30 AnnSemi = [ListComprehensions.hs:12:1])
+
+(AK ListComprehensions.hs:11:1-30 AnnVal = [ListComprehensions.hs:11:30])
+
+(AK ListComprehensions.hs:12:1-27 AnnImport = [ListComprehensions.hs:12:1-6])
+
+(AK ListComprehensions.hs:12:1-27 AnnSemi = [ListComprehensions.hs:13:1])
+
+(AK ListComprehensions.hs:12:17-27 AnnCloseP = [ListComprehensions.hs:12:27])
+
+(AK ListComprehensions.hs:12:17-27 AnnOpenP = [ListComprehensions.hs:12:17])
+
+(AK ListComprehensions.hs:13:1-25 AnnImport = [ListComprehensions.hs:13:1-6])
+
+(AK ListComprehensions.hs:13:1-25 AnnSemi = [ListComprehensions.hs:17:1])
+
+(AK ListComprehensions.hs:13:18-25 AnnCloseP = [ListComprehensions.hs:13:25])
+
+(AK ListComprehensions.hs:13:18-25 AnnOpenP = [ListComprehensions.hs:13:18])
+
+(AK ListComprehensions.hs:17:1-25 AnnDcolon = [ListComprehensions.hs:17:18-19])
+
+(AK ListComprehensions.hs:17:1-25 AnnSemi = [ListComprehensions.hs:18:1])
+
+(AK ListComprehensions.hs:17:21-25 AnnCloseS = [ListComprehensions.hs:17:25])
+
+(AK ListComprehensions.hs:17:21-25 AnnOpenS = [ListComprehensions.hs:17:21])
+
+(AK ListComprehensions.hs:(18,1)-(22,20) AnnEqual = [ListComprehensions.hs:18:18])
+
+(AK ListComprehensions.hs:(18,1)-(22,20) AnnFunId = [ListComprehensions.hs:18:1-16])
+
+(AK ListComprehensions.hs:(18,1)-(22,20) AnnSemi = [ListComprehensions.hs:23:1])
+
+(AK ListComprehensions.hs:(18,20)-(22,20) AnnCloseS = [ListComprehensions.hs:22:20])
+
+(AK ListComprehensions.hs:(18,20)-(22,20) AnnOpenS = [ListComprehensions.hs:18:20])
+
+(AK ListComprehensions.hs:(18,20)-(22,20) AnnVbar = [ListComprehensions.hs:19:20])
+
+(AK ListComprehensions.hs:18:22-26 AnnVal = [ListComprehensions.hs:18:24])
+
+(AK ListComprehensions.hs:18:22-30 AnnVal = [ListComprehensions.hs:18:28])
+
+(AK ListComprehensions.hs:19:22-33 AnnLarrow = [ListComprehensions.hs:19:24-25])
+
+(AK ListComprehensions.hs:19:22-33 AnnVbar = [ListComprehensions.hs:20:20])
+
+(AK ListComprehensions.hs:19:27-33 AnnCloseS = [ListComprehensions.hs:19:33])
+
+(AK ListComprehensions.hs:19:27-33 AnnDotdot = [ListComprehensions.hs:19:29-30])
+
+(AK ListComprehensions.hs:19:27-33 AnnOpenS = [ListComprehensions.hs:19:27])
+
+(AK ListComprehensions.hs:20:22-34 AnnLarrow = [ListComprehensions.hs:20:24-25])
+
+(AK ListComprehensions.hs:20:22-34 AnnVbar = [ListComprehensions.hs:21:20])
+
+(AK ListComprehensions.hs:20:27-34 AnnCloseS = [ListComprehensions.hs:20:34])
+
+(AK ListComprehensions.hs:20:27-34 AnnDotdot = [ListComprehensions.hs:20:30-31])
+
+(AK ListComprehensions.hs:20:27-34 AnnOpenS = [ListComprehensions.hs:20:27])
+
+(AK ListComprehensions.hs:21:22-34 AnnLarrow = [ListComprehensions.hs:21:24-25])
+
+(AK ListComprehensions.hs:21:27-34 AnnCloseS = [ListComprehensions.hs:21:34])
+
+(AK ListComprehensions.hs:21:27-34 AnnDotdot = [ListComprehensions.hs:21:30-31])
+
+(AK ListComprehensions.hs:21:27-34 AnnOpenS = [ListComprehensions.hs:21:27])
+
+(AK <no location info> AnnEofPos = [ListComprehensions.hs:23:1])
+]
+
diff --git a/testsuite/tests/parser/should_fail/readFail038.stderr b/testsuite/tests/parser/should_fail/readFail038.stderr
index c1650c6904..f9d4be89f9 100644
--- a/testsuite/tests/parser/should_fail/readFail038.stderr
+++ b/testsuite/tests/parser/should_fail/readFail038.stderr
@@ -1,4 +1,4 @@
-readFail038.hs:6:7:
+readFail038.hs:5:9:
Unexpected parallel statement in a list comprehension
Use ParallelListComp