diff options
author | Alan Zimmerman <alan.zimm@gmail.com> | 2015-05-11 09:34:27 +0200 |
---|---|---|
committer | Alan Zimmerman <alan.zimm@gmail.com> | 2015-05-11 09:34:27 +0200 |
commit | 811b72adedcd12149783eac19ebccff1dd72bc1c (patch) | |
tree | 2c9a959649ff7d927ea5602384ccdef6f325d21c /testsuite | |
parent | 5c459eefcb17ff97beebdc08ccfca21bd8fa5201 (diff) | |
download | haskell-811b72adedcd12149783eac19ebccff1dd72bc1c.tar.gz |
Api Annotations: RdrHsSyn.mkAtDefault causes annotations to be disconnected.
Summary:
The code for mkAtDefault is as follows.
mkATDefault (L loc (TyFamInstDecl { tfid_eqn = L _ e }))
| TyFamEqn { tfe_tycon = tc, tfe_pats = pats, tfe_rhs = rhs } <- e
= do { tvs <- checkTyVars (ptext (sLit "default")) equalsDots tc (hswb_cts pats)
; return (L loc (TyFamEqn { tfe_tycon = tc
, tfe_pats = tvs
, tfe_rhs = rhs })) }
An associated type in a class of the form
type FoldableConstraint t x = ()
has an AnnEqual attached to the location in tfid_eqn. Since the location
is discarded, this annotation is then disconnected from the AST.
Test Plan: ./validate
Reviewers: hvr, austin
Reviewed By: austin
Subscribers: bgamari, thomie, mpickering
Differential Revision: https://phabricator.haskell.org/D842
GHC Trac Issues: #10307
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/tests/ghc-api/annotations/.gitignore | 1 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/annotations/Makefile | 8 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/annotations/T10307.stdout | 36 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/annotations/Test10307.hs | 6 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/annotations/all.T | 1 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/annotations/t10307.hs | 106 |
6 files changed, 158 insertions, 0 deletions
diff --git a/testsuite/tests/ghc-api/annotations/.gitignore b/testsuite/tests/ghc-api/annotations/.gitignore index 41b32acb65..8b7f082773 100644 --- a/testsuite/tests/ghc-api/annotations/.gitignore +++ b/testsuite/tests/ghc-api/annotations/.gitignore @@ -8,6 +8,7 @@ t10268 t10269 t10280 t10312 +t10307 *.hi *.o *.run.* diff --git a/testsuite/tests/ghc-api/annotations/Makefile b/testsuite/tests/ghc-api/annotations/Makefile index 1f03afc5ea..15c3bc4237 100644 --- a/testsuite/tests/ghc-api/annotations/Makefile +++ b/testsuite/tests/ghc-api/annotations/Makefile @@ -7,6 +7,7 @@ clean: rm -f annotations comments parseTree exampleTest rm -f t10269 rm -f t10255 t10312 + rm -f t1037 annotations: rm -f annotations.o annotations.hi @@ -65,3 +66,10 @@ t10312: ./t10312 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" .PHONY: clean annotations parseTree comments exampleTest listcomps t10255 t10312 + +t10307: + rm -f t10307.o t10307.hi + '$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10307 + ./t10307 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" + +.PHONY: t10307 diff --git a/testsuite/tests/ghc-api/annotations/T10307.stdout b/testsuite/tests/ghc-api/annotations/T10307.stdout new file mode 100644 index 0000000000..66cc8aa59b --- /dev/null +++ b/testsuite/tests/ghc-api/annotations/T10307.stdout @@ -0,0 +1,36 @@ +---Problems--------------------- +[ +(AK Test10307.hs:6:8-34 AnnEqual = [Test10307.hs:6:31]) +] + +-------------------------------- +[ +(AK Test10307.hs:1:1 AnnModule = [Test10307.hs:2:1-6]) + +(AK Test10307.hs:1:1 AnnWhere = [Test10307.hs:2:18-22]) + +(AK Test10307.hs:(4,1)-(6,34) AnnClass = [Test10307.hs:4:1-5]) + +(AK Test10307.hs:(4,1)-(6,34) AnnSemi = [Test10307.hs:7:1]) + +(AK Test10307.hs:(4,1)-(6,34) AnnWhere = [Test10307.hs:4:18-22]) + +(AK Test10307.hs:5:3-34 AnnDcolon = [Test10307.hs:5:31-32]) + +(AK Test10307.hs:5:3-34 AnnSemi = [Test10307.hs:6:3]) + +(AK Test10307.hs:5:3-34 AnnType = [Test10307.hs:5:3-6]) + +(AK Test10307.hs:6:3-34 AnnEqual = [Test10307.hs:6:31]) + +(AK Test10307.hs:6:3-34 AnnType = [Test10307.hs:6:3-6]) + +(AK Test10307.hs:6:8-34 AnnEqual = [Test10307.hs:6:31]) + +(AK Test10307.hs:6:33-34 AnnCloseP = [Test10307.hs:6:34]) + +(AK Test10307.hs:6:33-34 AnnOpenP = [Test10307.hs:6:33]) + +(AK <no location info> AnnEofPos = [Test10307.hs:7:1]) +] + diff --git a/testsuite/tests/ghc-api/annotations/Test10307.hs b/testsuite/tests/ghc-api/annotations/Test10307.hs new file mode 100644 index 0000000000..938801a8d6 --- /dev/null +++ b/testsuite/tests/ghc-api/annotations/Test10307.hs @@ -0,0 +1,6 @@ +{-# LANGUAGE TypeFamilies #-} +module Test10307 where + +class Foldable t where + type FoldableConstraint t x :: * + type FoldableConstraint t x = () diff --git a/testsuite/tests/ghc-api/annotations/all.T b/testsuite/tests/ghc-api/annotations/all.T index b537bcd617..3e145b946b 100644 --- a/testsuite/tests/ghc-api/annotations/all.T +++ b/testsuite/tests/ghc-api/annotations/all.T @@ -8,3 +8,4 @@ test('T10268', normal, run_command, ['$MAKE -s --no-print-directory T10268' test('T10269', normal, run_command, ['$MAKE -s --no-print-directory T10269']) test('T10280', normal, run_command, ['$MAKE -s --no-print-directory T10280']) test('T10312', normal, run_command, ['$MAKE -s --no-print-directory t10312']) +test('T10307', normal, run_command, ['$MAKE -s --no-print-directory t10307']) diff --git a/testsuite/tests/ghc-api/annotations/t10307.hs b/testsuite/tests/ghc-api/annotations/t10307.hs new file mode 100644 index 0000000000..5c6f233f02 --- /dev/null +++ b/testsuite/tests/ghc-api/annotations/t10307.hs @@ -0,0 +1,106 @@ +{-# 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 "Test10307" + +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) + putStrLn "---Problems---------------------" + putStrLn (intercalate "\n" [showAnns $ Map.fromList $ map snd 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) |