summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorAlan Zimmerman <alan.zimm@gmail.com>2015-05-11 14:19:14 +0200
committerAlan Zimmerman <alan.zimm@gmail.com>2015-05-11 14:19:14 +0200
commit24707d72d6137cb970878ef243c090a6bf6601e0 (patch)
tree3a4b540709b187a9b2aee23c0d0bf9e3a23eb9db /testsuite
parent9736c042f4292b4fb94ca9faca6a010372a0f92f (diff)
downloadhaskell-24707d72d6137cb970878ef243c090a6bf6601e0.tar.gz
ApiAnnotations : BooleanFormula construction discards original
Summary: The MINIMAL pragma is captured in the parser using a BooleanFormula. The constructors (mkBool,mkAnd,mkOr) are smart and try to minimise the boolean formula as it is constructed. This discards the original information, making round tripping impossible. Note: there is another version which provides a more API Annotations friendly version of the MINIMAL pragma, but this requires changes to haddock, which will cause problems for 7.10.2. See https://github.com/alanz/ghc/tree/wip/10287 Test Plan: ./validate Reviewers: hvr, austin Reviewed By: austin Subscribers: bgamari, Fuuzetsu, thomie, mpickering Differential Revision: https://phabricator.haskell.org/D837 GHC Trac Issues: #10287
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/ghc-api/annotations/.gitignore1
-rw-r--r--testsuite/tests/ghc-api/annotations/Makefile8
-rw-r--r--testsuite/tests/ghc-api/annotations/TestBoolFormula.hs26
-rw-r--r--testsuite/tests/ghc-api/annotations/all.T1
-rw-r--r--testsuite/tests/ghc-api/annotations/boolFormula.hs107
-rw-r--r--testsuite/tests/ghc-api/annotations/boolFormula.stderr17
-rw-r--r--testsuite/tests/ghc-api/annotations/boolFormula.stdout163
7 files changed, 323 insertions, 0 deletions
diff --git a/testsuite/tests/ghc-api/annotations/.gitignore b/testsuite/tests/ghc-api/annotations/.gitignore
index 8ff93b44f8..79e26095de 100644
--- a/testsuite/tests/ghc-api/annotations/.gitignore
+++ b/testsuite/tests/ghc-api/annotations/.gitignore
@@ -10,6 +10,7 @@ t10269
t10280
t10312
t10307
+boolFormula
*.hi
*.o
*.run.*
diff --git a/testsuite/tests/ghc-api/annotations/Makefile b/testsuite/tests/ghc-api/annotations/Makefile
index c7aa1e5cb8..c181ef09a0 100644
--- a/testsuite/tests/ghc-api/annotations/Makefile
+++ b/testsuite/tests/ghc-api/annotations/Makefile
@@ -9,6 +9,7 @@ clean:
rm -f t10255 t10312
rm -f t1037
rm -f t10309
+ rm -f listcomps boolFormula
annotations:
rm -f annotations.o annotations.hi
@@ -81,3 +82,10 @@ t10309:
./t10309 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: t10309
+
+boolFormula:
+ rm -f boolFormula.o boolFormula.hi
+ '$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc boolFormula
+ ./boolFormula "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
+
+.PHONY: clean annotations parseTree comments exampleTest listcomps boolFormula
diff --git a/testsuite/tests/ghc-api/annotations/TestBoolFormula.hs b/testsuite/tests/ghc-api/annotations/TestBoolFormula.hs
new file mode 100644
index 0000000000..e945318b8a
--- /dev/null
+++ b/testsuite/tests/ghc-api/annotations/TestBoolFormula.hs
@@ -0,0 +1,26 @@
+module TestBoolFormula where
+
+class ManyOps a where
+ aOp :: a -> a -> Bool
+ bOp :: a -> a -> Bool
+ cOp :: a -> a -> Bool
+ dOp :: a -> a -> Bool
+ eOp :: a -> a -> Bool
+ fOp :: a -> a -> Bool
+ {-# MINIMAL ( aOp)
+ | ( bOp , cOp)
+ | ((dOp | eOp) , fOp)
+ #-}
+
+class Foo a where
+ bar :: a -> a -> Bool
+ foo :: a -> a -> Bool
+ baq :: a -> a -> Bool
+ baz :: a -> a -> Bool
+ quux :: a -> a -> Bool
+ {-# MINIMAL bar, (foo, baq | foo, quux) #-}
+
+instance Foo Int where
+ bar = undefined
+ baz = undefined
+ quux = undefined
diff --git a/testsuite/tests/ghc-api/annotations/all.T b/testsuite/tests/ghc-api/annotations/all.T
index 81aec52b60..4709c2a2f5 100644
--- a/testsuite/tests/ghc-api/annotations/all.T
+++ b/testsuite/tests/ghc-api/annotations/all.T
@@ -10,3 +10,4 @@ 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'])
test('T10309', normal, run_command, ['$MAKE -s --no-print-directory t10309'])
+test('boolFormula', normal, run_command, ['$MAKE -s --no-print-directory boolFormula'])
diff --git a/testsuite/tests/ghc-api/annotations/boolFormula.hs b/testsuite/tests/ghc-api/annotations/boolFormula.hs
new file mode 100644
index 0000000000..be23f8b152
--- /dev/null
+++ b/testsuite/tests/ghc-api/annotations/boolFormula.hs
@@ -0,0 +1,107 @@
+{-# 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 "TestBoolFormula"
+
+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)
+
+ -- putStrLn (pp spans)
+ 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)
diff --git a/testsuite/tests/ghc-api/annotations/boolFormula.stderr b/testsuite/tests/ghc-api/annotations/boolFormula.stderr
new file mode 100644
index 0000000000..65cbf267af
--- /dev/null
+++ b/testsuite/tests/ghc-api/annotations/boolFormula.stderr
@@ -0,0 +1,17 @@
+
+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’
diff --git a/testsuite/tests/ghc-api/annotations/boolFormula.stdout b/testsuite/tests/ghc-api/annotations/boolFormula.stdout
new file mode 100644
index 0000000000..1c7a9431b3
--- /dev/null
+++ b/testsuite/tests/ghc-api/annotations/boolFormula.stdout
@@ -0,0 +1,163 @@
+---Problems---------------------
+[
+]
+
+--------------------------------
+[
+(AK TestBoolFormula.hs:1:1 AnnModule = [TestBoolFormula.hs:1:1-6])
+
+(AK TestBoolFormula.hs:1:1 AnnWhere = [TestBoolFormula.hs:1:24-28])
+
+(AK TestBoolFormula.hs:(3,1)-(13,9) AnnClass = [TestBoolFormula.hs:3:1-5])
+
+(AK TestBoolFormula.hs:(3,1)-(13,9) AnnSemi = [TestBoolFormula.hs:15:1])
+
+(AK TestBoolFormula.hs:(3,1)-(13,9) AnnWhere = [TestBoolFormula.hs:3:17-21])
+
+(AK TestBoolFormula.hs:4:5-25 AnnDcolon = [TestBoolFormula.hs:4:9-10])
+
+(AK TestBoolFormula.hs:4:5-25 AnnSemi = [TestBoolFormula.hs:5:5])
+
+(AK TestBoolFormula.hs:4:12-25 AnnRarrow = [TestBoolFormula.hs:4:14-15])
+
+(AK TestBoolFormula.hs:4:17-25 AnnRarrow = [TestBoolFormula.hs:4:19-20])
+
+(AK TestBoolFormula.hs:5:5-25 AnnDcolon = [TestBoolFormula.hs:5:9-10])
+
+(AK TestBoolFormula.hs:5:5-25 AnnSemi = [TestBoolFormula.hs:6:5])
+
+(AK TestBoolFormula.hs:5:12-25 AnnRarrow = [TestBoolFormula.hs:5:14-15])
+
+(AK TestBoolFormula.hs:5:17-25 AnnRarrow = [TestBoolFormula.hs:5:19-20])
+
+(AK TestBoolFormula.hs:6:5-25 AnnDcolon = [TestBoolFormula.hs:6:9-10])
+
+(AK TestBoolFormula.hs:6:5-25 AnnSemi = [TestBoolFormula.hs:7:5])
+
+(AK TestBoolFormula.hs:6:12-25 AnnRarrow = [TestBoolFormula.hs:6:14-15])
+
+(AK TestBoolFormula.hs:6:17-25 AnnRarrow = [TestBoolFormula.hs:6:19-20])
+
+(AK TestBoolFormula.hs:7:5-25 AnnDcolon = [TestBoolFormula.hs:7:9-10])
+
+(AK TestBoolFormula.hs:7:5-25 AnnSemi = [TestBoolFormula.hs:8:5])
+
+(AK TestBoolFormula.hs:7:12-25 AnnRarrow = [TestBoolFormula.hs:7:14-15])
+
+(AK TestBoolFormula.hs:7:17-25 AnnRarrow = [TestBoolFormula.hs:7:19-20])
+
+(AK TestBoolFormula.hs:8:5-25 AnnDcolon = [TestBoolFormula.hs:8:9-10])
+
+(AK TestBoolFormula.hs:8:5-25 AnnSemi = [TestBoolFormula.hs:9:5])
+
+(AK TestBoolFormula.hs:8:12-25 AnnRarrow = [TestBoolFormula.hs:8:14-15])
+
+(AK TestBoolFormula.hs:8:17-25 AnnRarrow = [TestBoolFormula.hs:8:19-20])
+
+(AK TestBoolFormula.hs:9:5-25 AnnDcolon = [TestBoolFormula.hs:9:9-10])
+
+(AK TestBoolFormula.hs:9:5-25 AnnSemi = [TestBoolFormula.hs:10:5])
+
+(AK TestBoolFormula.hs:9:12-25 AnnRarrow = [TestBoolFormula.hs:9:14-15])
+
+(AK TestBoolFormula.hs:9:17-25 AnnRarrow = [TestBoolFormula.hs:9:19-20])
+
+(AK TestBoolFormula.hs:(10,5)-(13,9) AnnClose = [TestBoolFormula.hs:13:7-9])
+
+(AK TestBoolFormula.hs:(10,5)-(13,9) AnnCloseP = [TestBoolFormula.hs:10:23, TestBoolFormula.hs:11:31,
+ TestBoolFormula.hs:12:38, TestBoolFormula.hs:12:31])
+
+(AK TestBoolFormula.hs:(10,5)-(13,9) AnnComma = [TestBoolFormula.hs:11:26, TestBoolFormula.hs:12:33])
+
+(AK TestBoolFormula.hs:(10,5)-(13,9) AnnOpen = [TestBoolFormula.hs:10:5-15])
+
+(AK TestBoolFormula.hs:(10,5)-(13,9) AnnOpenP = [TestBoolFormula.hs:10:18, TestBoolFormula.hs:11:18,
+ TestBoolFormula.hs:12:18, TestBoolFormula.hs:12:19])
+
+(AK TestBoolFormula.hs:(10,5)-(13,9) AnnVbar = [TestBoolFormula.hs:11:16, TestBoolFormula.hs:12:16,
+ TestBoolFormula.hs:12:25])
+
+(AK TestBoolFormula.hs:(15,1)-(21,47) AnnClass = [TestBoolFormula.hs:15:1-5])
+
+(AK TestBoolFormula.hs:(15,1)-(21,47) AnnSemi = [TestBoolFormula.hs:23:1])
+
+(AK TestBoolFormula.hs:(15,1)-(21,47) AnnWhere = [TestBoolFormula.hs:15:13-17])
+
+(AK TestBoolFormula.hs:16:5-25 AnnDcolon = [TestBoolFormula.hs:16:9-10])
+
+(AK TestBoolFormula.hs:16:5-25 AnnSemi = [TestBoolFormula.hs:17:5])
+
+(AK TestBoolFormula.hs:16:12-25 AnnRarrow = [TestBoolFormula.hs:16:14-15])
+
+(AK TestBoolFormula.hs:16:17-25 AnnRarrow = [TestBoolFormula.hs:16:19-20])
+
+(AK TestBoolFormula.hs:17:5-25 AnnDcolon = [TestBoolFormula.hs:17:9-10])
+
+(AK TestBoolFormula.hs:17:5-25 AnnSemi = [TestBoolFormula.hs:18:5])
+
+(AK TestBoolFormula.hs:17:12-25 AnnRarrow = [TestBoolFormula.hs:17:14-15])
+
+(AK TestBoolFormula.hs:17:17-25 AnnRarrow = [TestBoolFormula.hs:17:19-20])
+
+(AK TestBoolFormula.hs:18:5-25 AnnDcolon = [TestBoolFormula.hs:18:9-10])
+
+(AK TestBoolFormula.hs:18:5-25 AnnSemi = [TestBoolFormula.hs:19:5])
+
+(AK TestBoolFormula.hs:18:12-25 AnnRarrow = [TestBoolFormula.hs:18:14-15])
+
+(AK TestBoolFormula.hs:18:17-25 AnnRarrow = [TestBoolFormula.hs:18:19-20])
+
+(AK TestBoolFormula.hs:19:5-25 AnnDcolon = [TestBoolFormula.hs:19:9-10])
+
+(AK TestBoolFormula.hs:19:5-25 AnnSemi = [TestBoolFormula.hs:20:5])
+
+(AK TestBoolFormula.hs:19:12-25 AnnRarrow = [TestBoolFormula.hs:19:14-15])
+
+(AK TestBoolFormula.hs:19:17-25 AnnRarrow = [TestBoolFormula.hs:19:19-20])
+
+(AK TestBoolFormula.hs:20:5-26 AnnDcolon = [TestBoolFormula.hs:20:10-11])
+
+(AK TestBoolFormula.hs:20:5-26 AnnSemi = [TestBoolFormula.hs:21:5])
+
+(AK TestBoolFormula.hs:20:13-26 AnnRarrow = [TestBoolFormula.hs:20:15-16])
+
+(AK TestBoolFormula.hs:20:18-26 AnnRarrow = [TestBoolFormula.hs:20:20-21])
+
+(AK TestBoolFormula.hs:21:5-47 AnnClose = [TestBoolFormula.hs:21:45-47])
+
+(AK TestBoolFormula.hs:21:5-47 AnnCloseP = [TestBoolFormula.hs:21:43])
+
+(AK TestBoolFormula.hs:21:5-47 AnnComma = [TestBoolFormula.hs:21:20, TestBoolFormula.hs:21:26,
+ TestBoolFormula.hs:21:37])
+
+(AK TestBoolFormula.hs:21:5-47 AnnOpen = [TestBoolFormula.hs:21:5-15])
+
+(AK TestBoolFormula.hs:21:5-47 AnnOpenP = [TestBoolFormula.hs:21:22])
+
+(AK TestBoolFormula.hs:21:5-47 AnnVbar = [TestBoolFormula.hs:21:32])
+
+(AK TestBoolFormula.hs:(23,1)-(26,20) AnnInstance = [TestBoolFormula.hs:23:1-8])
+
+(AK TestBoolFormula.hs:(23,1)-(26,20) AnnSemi = [TestBoolFormula.hs:27:1])
+
+(AK TestBoolFormula.hs:(23,1)-(26,20) AnnWhere = [TestBoolFormula.hs:23:18-22])
+
+(AK TestBoolFormula.hs:24:5-19 AnnEqual = [TestBoolFormula.hs:24:9])
+
+(AK TestBoolFormula.hs:24:5-19 AnnFunId = [TestBoolFormula.hs:24:5-7])
+
+(AK TestBoolFormula.hs:24:5-19 AnnSemi = [TestBoolFormula.hs:25:5])
+
+(AK TestBoolFormula.hs:25:5-19 AnnEqual = [TestBoolFormula.hs:25:9])
+
+(AK TestBoolFormula.hs:25:5-19 AnnFunId = [TestBoolFormula.hs:25:5-7])
+
+(AK TestBoolFormula.hs:25:5-19 AnnSemi = [TestBoolFormula.hs:26:5])
+
+(AK TestBoolFormula.hs:26:5-20 AnnEqual = [TestBoolFormula.hs:26:10])
+
+(AK TestBoolFormula.hs:26:5-20 AnnFunId = [TestBoolFormula.hs:26:5-8])
+
+(AK <no location info> AnnEofPos = [TestBoolFormula.hs:27:1])
+]
+