Commit ecc3d6be authored by Alan Zimmerman's avatar Alan Zimmerman

ApiAnnotations : PatBind gives wrong SrcSpan for the pattern.

Summary:
The production for decl_no_th starts

    decl_no_th :: { Located (OrdList (LHsDecl RdrName)) }
            : sigdecl               { $1 }

            | '!' aexp rhs  {% do { let { e = sLL $1 $> (SectionR (sL1 $1 (HsVar bang_RDR)) $2) };
                                    pat <- checkPattern empty e;
    ...

The e value should be just the pattern, excluding the rhs, but the span
created includes the rhs.

Test Plan: ./validate

Reviewers: hvr, austin

Reviewed By: austin

Subscribers: bgamari, thomie, mpickering

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

GHC Trac Issues: #10358
parent fe38195e
......@@ -1986,10 +1986,10 @@ docdecld :: { LDocDecl }
decl_no_th :: { Located (OrdList (LHsDecl RdrName)) }
: sigdecl { $1 }
| '!' aexp rhs {% do { let { e = sLL $1 $> (SectionR (sL1 $1 (HsVar bang_RDR)) $2) };
| '!' aexp rhs {% do { let { e = sLL $1 $2 (SectionR (sL1 $1 (HsVar bang_RDR)) $2) };
pat <- checkPattern empty e;
_ <- ams (sLL $1 $> ())
(mj AnnBang $1:(fst $ unLoc $3));
(fst $ unLoc $3);
return $ sLL $1 $> $ unitOL $ sLL $1 $> $ ValD $
PatBind pat (snd $ unLoc $3)
placeHolderType
......
......@@ -5,6 +5,7 @@ exampleTest
listcomps
t10309
t10357
t10358
t10255
t10268
t10269
......
......@@ -37,6 +37,13 @@ listcomps:
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc listcomps
./listcomps "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
t10358:
rm -f t10358.o t10358.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10358
./t10358 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: t10358
t10255:
rm -f t10255.o t10255.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10255
......
Test10358.hs:5:14: error: Not in scope: ‘x’
Test10358.hs:5:16: error: Not in scope: ‘x’
Test10358.hs:6:12: error: Not in scope: ‘v’
Test10358.hs:6:14: error: Not in scope: ‘v’
Test10358.hs:6:16: error: Not in scope: ‘v’
Test10358.hs:7:12: error: Not in scope: ‘d’
---Problems---------------------
[
(AK <no location info> AnnEofPos = [Test10358.hs:9:1])
]
---Problems'--------------------
[(AnnEofPos, Test10358.hs:9:1)]
--------------------------------
[
(AK Test10358.hs:1:1 AnnModule = [Test10358.hs:2:1-6])
(AK Test10358.hs:1:1 AnnWhere = [Test10358.hs:2:18-22])
(AK Test10358.hs:(4,1)-(8,6) AnnEqual = [Test10358.hs:4:13])
(AK Test10358.hs:(4,1)-(8,6) AnnFunId = [Test10358.hs:4:1-7])
(AK Test10358.hs:(4,1)-(8,6) AnnSemi = [Test10358.hs:9:1])
(AK Test10358.hs:(5,3)-(8,6) AnnIn = [Test10358.hs:8:3-4])
(AK Test10358.hs:(5,3)-(8,6) AnnLet = [Test10358.hs:5:3-5])
(AK Test10358.hs:5:7-10 AnnBang = [Test10358.hs:5:7])
(AK Test10358.hs:5:7-16 AnnEqual = [Test10358.hs:5:12])
(AK Test10358.hs:5:7-16 AnnSemi = [Test10358.hs:5:17])
(AK Test10358.hs:5:14-16 AnnVal = [Test10358.hs:5:15])
(AK Test10358.hs:5:19-22 AnnBang = [Test10358.hs:5:19])
(AK Test10358.hs:5:19-32 AnnEqual = [Test10358.hs:5:24])
(AK Test10358.hs:5:19-32 AnnSemi = [Test10358.hs:6:7])
(AK Test10358.hs:5:26-32 AnnVal = [Test10358.hs:5:29])
(AK Test10358.hs:6:7-16 AnnEqual = [Test10358.hs:6:10])
(AK Test10358.hs:6:7-16 AnnFunId = [Test10358.hs:6:7-8])
(AK Test10358.hs:6:7-16 AnnSemi = [Test10358.hs:7:7])
(AK Test10358.hs:6:12-14 AnnVal = [Test10358.hs:6:13])
(AK Test10358.hs:6:12-16 AnnVal = [Test10358.hs:6:15])
(AK Test10358.hs:7:7-17 AnnEqual = [Test10358.hs:7:10])
(AK Test10358.hs:7:7-17 AnnFunId = [Test10358.hs:7:7-8])
(AK Test10358.hs:7:12-17 AnnVal = [Test10358.hs:7:14])
(AK <no location info> AnnEofPos = [Test10358.hs:9:1])
]
{-# LANGUAGE BangPatterns #-}
module Test10358 where
mtGamma a b =
let !x_2 = x*x; !x_4 = x_2*x_2
v3 = v*v*v
dv = d * v3
in 5
......@@ -12,3 +12,4 @@ 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'])
test('T10358', normal, run_command, ['$MAKE -s --no-print-directory t10358'])
TestBoolFormula.hs:3:1: Warning:
The MINIMAL pragma does not require:
‘aOp’, ‘bOp’, ‘cOp’, ‘dOp’, ‘eOp’, and ‘fOp’
but there is no default implementation.
In the class declaration for ‘ManyOps’
TestBoolFormula.hs:15:1: Warning:
The MINIMAL pragma does not require:
‘baq’, ‘baz’, and ‘quux’
but there is no default implementation.
In the class declaration for ‘Foo’
TestBoolFormula.hs:23:10: Warning:
No explicit implementation for
either (‘foo’ and ‘baq’) or ‘foo’
In the instance declaration for ‘Foo Int’
{-# 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 "Test10358"
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