The production for `pquals` is incorrect; the specifics are in D803.
authorAlan Zimmerman <alan.zimm@gmail.com>
Tue, 7 Apr 2015 14:10:18 +0000 (09:10 -0500)
committerAustin Seipp <austin@well-typed.com>
Tue, 7 Apr 2015 14:13:38 +0000 (09:13 -0500)
Reviewed By: austin

Differential Revision: https://phabricator.haskell.org/D803

GHC Trac Issues: #10207

compiler/parser/Parser.y
testsuite/tests/ghc-api/annotations/.gitignore
testsuite/tests/ghc-api/annotations/ListComprehensions.hs [new file with mode: 0644]
testsuite/tests/ghc-api/annotations/Makefile
testsuite/tests/ghc-api/annotations/all.T
testsuite/tests/ghc-api/annotations/listcomps.hs [new file with mode: 0644]
testsuite/tests/ghc-api/annotations/listcomps.stdout [new file with mode: 0644]
testsuite/tests/parser/should_fail/readFail038.stderr

index 67c90d5..99c5374 100644 (file)
@@ -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
index fe31fad..ba31dbb 100644 (file)
@@ -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 (file)
index 0000000..c61f7ca
--- /dev/null
@@ -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]
+                   ]
index f5ef3b4..5d10d7f 100644 (file)
@@ -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
index cb075cb..9dadf7a 100644 (file)
@@ -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 (file)
index 0000000..dc440e9
--- /dev/null
@@ -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 (file)
index 0000000..cf70772
--- /dev/null
@@ -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])
+]
+
index c1650c6..f9d4be8 100644 (file)
@@ -1,4 +1,4 @@
 
-readFail038.hs:6:7:
+readFail038.hs:5:9:
     Unexpected parallel statement in a list comprehension
     Use ParallelListComp