Commit fe38195e authored by Alan Zimmerman's avatar Alan Zimmerman

ApiAnnotations : pquals production adds AnnVbar in the wrong place

Summary:
The Parser.y production for pquals is

    pquals :: { Located [[LStmt RdrName (LHsExpr RdrName)]] }
        : squals '|' pquals
                         {% addAnnotation (gl $ last $ unLoc $1) AnnVbar (gl $2) >>
                            return (sLL $1 $> (reverse (unLoc $1) : unLoc $3)) }
        | squals         { L (getLoc $1) [reverse (unLoc $1)] }

The squals are returned in reverse order, so the AnnVbar should be
attached to the head of the list, not the last.

Test Plan: ./validate

Reviewers: hvr, austin

Reviewed By: austin

Subscribers: thomie, mpickering

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

GHC Trac Issues: #10357
parent f35d621d
......@@ -2470,7 +2470,7 @@ flattenedpquals :: { Located [LStmt RdrName (LHsExpr RdrName)] }
pquals :: { Located [[LStmt RdrName (LHsExpr RdrName)]] }
: squals '|' pquals
{% addAnnotation (gl $ last $ unLoc $1) AnnVbar (gl $2) >>
{% addAnnotation (gl $ head $ unLoc $1) AnnVbar (gl $2) >>
return (sLL $1 $> (reverse (unLoc $1) : unLoc $3)) }
| squals { L (getLoc $1) [reverse (unLoc $1)] }
......
......@@ -4,6 +4,7 @@ comments
exampleTest
listcomps
t10309
t10357
t10255
t10268
t10269
......
......@@ -10,6 +10,7 @@ clean:
rm -f t1037
rm -f t10309
rm -f listcomps boolFormula
rm -f t10357
annotations:
rm -f annotations.o annotations.hi
......@@ -41,6 +42,13 @@ t10255:
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10255
./t10255 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
t10357:
rm -f t10357.o t10357.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10357
./t10357 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: t10357
.PHONY: clean annotations parseTree comments exampleTest listcomps t10255
T10268:
......
Test10357.hs:4:13: error: Not in scope: ‘one’
Test10357.hs:4:19: error: Not in scope: ‘x’
Test10357.hs:5:7: error: Not in scope: ‘multPoly’
Test10357.hs:6:10: error: Not in scope: ‘poly’
Test10357.hs:6:15: error:
Not in scope: data constructor ‘LE’
Perhaps you meant ‘LT’ (imported from Prelude)
Test10357.hs:7:10: error: Not in scope: ‘addPoly’
Test10357.hs:7:19: error: Not in scope: ‘poly’
Test10357.hs:7:24: error:
Not in scope: data constructor ‘LE’
Perhaps you meant ‘LT’ (imported from Prelude)
Test10357.hs:7:43: error: Not in scope: ‘multPoly’
Test10357.hs:8:19: error: Not in scope: ‘poly’
Test10357.hs:8:24: error:
Not in scope: data constructor ‘LE’
Perhaps you meant ‘LT’ (imported from Prelude)
Test10357.hs:8:43: error: Not in scope: ‘multPoly’
---Problems---------------------
[
(AK <no location info> AnnEofPos = [Test10357.hs:14:1])
]
---Problems'--------------------
[(AnnEofPos, Test10357.hs:14:1)]
--------------------------------
[
(AK Test10357.hs:1:1 AnnModule = [Test10357.hs:2:1-6])
(AK Test10357.hs:1:1 AnnWhere = [Test10357.hs:2:18-22])
(AK Test10357.hs:(4,1)-(13,5) AnnEqual = [Test10357.hs:4:11])
(AK Test10357.hs:(4,1)-(13,5) AnnFunId = [Test10357.hs:4:1-9])
(AK Test10357.hs:(4,1)-(13,5) AnnSemi = [Test10357.hs:14:1])
(AK Test10357.hs:4:13-19 AnnVal = [Test10357.hs:4:17])
(AK Test10357.hs:(4,13)-(13,5) AnnVal = [Test10357.hs:4:21])
(AK Test10357.hs:(5,5)-(13,5) AnnCloseS = [Test10357.hs:13:5])
(AK Test10357.hs:(5,5)-(13,5) AnnOpenS = [Test10357.hs:5:5])
(AK Test10357.hs:(5,5)-(13,5) AnnVbar = [Test10357.hs:10:5])
(AK Test10357.hs:6:9-34 AnnCloseP = [Test10357.hs:6:34])
(AK Test10357.hs:6:9-34 AnnOpenP = [Test10357.hs:6:9])
(AK Test10357.hs:6:18-33 AnnCloseS = [Test10357.hs:6:33])
(AK Test10357.hs:6:18-33 AnnOpenS = [Test10357.hs:6:18])
(AK Test10357.hs:6:25-32 AnnCloseP = [Test10357.hs:6:32])
(AK Test10357.hs:6:25-32 AnnOpenP = [Test10357.hs:6:25])
(AK Test10357.hs:6:26-31 AnnVal = [Test10357.hs:6:29])
(AK Test10357.hs:(7,9)-(9,9) AnnCloseP = [Test10357.hs:9:9])
(AK Test10357.hs:(7,9)-(9,9) AnnOpenP = [Test10357.hs:7:9])
(AK Test10357.hs:7:18-57 AnnCloseP = [Test10357.hs:7:57])
(AK Test10357.hs:7:18-57 AnnOpenP = [Test10357.hs:7:18])
(AK Test10357.hs:7:19-56 AnnVal = [Test10357.hs:7:43-52])
(AK Test10357.hs:7:27-41 AnnCloseS = [Test10357.hs:7:41])
(AK Test10357.hs:7:27-41 AnnOpenS = [Test10357.hs:7:27])
(AK Test10357.hs:7:28 AnnComma = [Test10357.hs:7:29])
(AK Test10357.hs:7:31-36 AnnVal = [Test10357.hs:7:33])
(AK Test10357.hs:7:31-40 AnnVal = [Test10357.hs:7:38])
(AK Test10357.hs:7:43-52 AnnBackquote = [Test10357.hs:7:43, Test10357.hs:7:52])
(AK Test10357.hs:7:43-52 AnnVal = [Test10357.hs:7:44-51])
(AK Test10357.hs:8:18-59 AnnCloseP = [Test10357.hs:8:59])
(AK Test10357.hs:8:18-59 AnnOpenP = [Test10357.hs:8:18])
(AK Test10357.hs:8:19-58 AnnVal = [Test10357.hs:8:43-52])
(AK Test10357.hs:8:37-41 AnnCloseS = [Test10357.hs:8:41])
(AK Test10357.hs:8:37-41 AnnOpenS = [Test10357.hs:8:37])
(AK Test10357.hs:8:38-40 AnnMinus = [Test10357.hs:8:38])
(AK Test10357.hs:8:43-52 AnnBackquote = [Test10357.hs:8:43, Test10357.hs:8:52])
(AK Test10357.hs:8:43-52 AnnVal = [Test10357.hs:8:44-51])
(AK Test10357.hs:10:7-20 AnnComma = [Test10357.hs:10:21])
(AK Test10357.hs:10:7-20 AnnLarrow = [Test10357.hs:10:13-14])
(AK Test10357.hs:10:16-20 AnnCloseS = [Test10357.hs:10:20])
(AK Test10357.hs:10:16-20 AnnDotdot = [Test10357.hs:10:18-19])
(AK Test10357.hs:10:16-20 AnnOpenS = [Test10357.hs:10:16])
(AK Test10357.hs:10:23-44 AnnLet = [Test10357.hs:10:23-25])
(AK Test10357.hs:10:23-44 AnnVbar = [Test10357.hs:11:5])
(AK Test10357.hs:10:27-44 AnnEqual = [Test10357.hs:10:30])
(AK Test10357.hs:10:27-44 AnnFunId = [Test10357.hs:10:27-28])
(AK Test10357.hs:11:7-29 AnnLarrow = [Test10357.hs:11:13-14])
(AK Test10357.hs:11:7-29 AnnVbar = [Test10357.hs:12:5])
(AK Test10357.hs:12:7-24 AnnLarrow = [Test10357.hs:12:13-14])
(AK <no location info> AnnEofPos = [Test10357.hs:14:1])
]
{-# LANGUAGE ParallelListComp #-}
module Test10357 where
legendres = one : x :
[ multPoly
(poly LE [recip (n' + 1)])
(addPoly (poly LE [0, 2 * n' + 1] `multPoly` p_n)
(poly LE [-n'] `multPoly` p_nm1)
)
| n <- [1..], let n' = fromInteger n
| p_n <- tail legendres
| p_nm1 <- legendres
]
......@@ -11,3 +11,4 @@ test('T10312', normal, run_command, ['$MAKE -s --no-print-directory t10312'
test('T10307', normal, run_command, ['$MAKE -s --no-print-directory t10307'])
test('T10309', normal, run_command, ['$MAKE -s --no-print-directory t10309'])
test('boolFormula', normal, run_command, ['$MAKE -s --no-print-directory boolFormula'])
test('T10357', normal, run_command, ['$MAKE -s --no-print-directory t10357'])
{-# 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 qualified Data.Map as Map
import qualified Data.Set as Set
import Data.Dynamic ( fromDynamic,Dynamic )
main::IO()
main = do
[libdir] <- getArgs
testOneFile libdir "Test10357"
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
return (pm_annotations p,p)
let spans = Set.fromList $ getAllSrcSpans (pm_parsed_source p)
problems = filter (\(s,a) -> not (Set.member s spans))
$ getAnnSrcSpans (anns,cs)
exploded = [((kw,ss),[anchor])
| ((anchor,kw),sss) <- Map.toList anns,ss <- sss]
exploded' = Map.toList $ Map.fromListWith (++) exploded
problems' = filter (\(_,anchors)
-> not (any (\a -> Set.member a spans) anchors))
exploded'
putStrLn "---Problems---------------------"
putStrLn (intercalate "\n" [showAnns $ Map.fromList $ map snd problems])
putStrLn "---Problems'--------------------"
putStrLn (intercalate "\n" [pp $ Map.fromList $ map fst problems'])
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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment