Commit 3cf12e60 authored by Alan Zimmerman's avatar Alan Zimmerman Committed by Ben Gamari

check-api-annotations checks for annotation preceding its span

For an API annotation to be useful, it must not occur before the span
it is enclosed in.

So, for check-api-annotation output, a line such as

((Test16212.hs:3:22-36,AnnOpenP), [Test16212.hs:3:21]),

should be flagged as an error, as the AnnOpenP location of 3:21
precedes its enclosing span of 3:22-26.

This patch does this.

Closes #16217
parent 5cb071af
......@@ -145,3 +145,7 @@ T13163:
.PHONY: T15303
T15303:
$(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test15303.hs
.PHONY: T16212
T16212:
$(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test16212.hs
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[(AnnVal, Test10269.hs:4:4-6)]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
((Test11018.hs:12:22-31,AnnOpenP), [Test11018.hs:12:21]),
((Test11018.hs:37:23-31,AnnOpenP), [Test11018.hs:37:22])
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
[]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
[
((Test16212.hs:1:1,AnnModule), [Test16212.hs:1:1-6]),
((Test16212.hs:1:1,AnnWhere), [Test16212.hs:1:18-22]),
((Test16212.hs:(3,1)-(4,37),AnnClass), [Test16212.hs:3:1-5]),
((Test16212.hs:(3,1)-(4,37),AnnSemi), [Test16212.hs:6:1]),
((Test16212.hs:(3,1)-(4,37),AnnWhere), [Test16212.hs:3:39-43]),
((Test16212.hs:3:21-37,AnnCloseP), [Test16212.hs:3:37]),
((Test16212.hs:3:21-37,AnnOpenP), [Test16212.hs:3:21]),
((Test16212.hs:3:22-36,AnnCloseP), [Test16212.hs:3:37]),
((Test16212.hs:3:22-36,AnnDcolon), [Test16212.hs:3:28-29]),
((Test16212.hs:3:22-36,AnnOpenP), [Test16212.hs:3:21]),
((Test16212.hs:4:3-37,AnnDcolon), [Test16212.hs:4:9-10]),
((Test16212.hs:4:29-37,AnnCloseP), [Test16212.hs:4:37]),
((Test16212.hs:4:29-37,AnnOpenP), [Test16212.hs:4:29]),
((Test16212.hs:(6,1)-(7,37),AnnClass), [Test16212.hs:6:1-5]),
((Test16212.hs:(6,1)-(7,37),AnnSemi), [Test16212.hs:9:1]),
((Test16212.hs:(6,1)-(7,37),AnnWhere), [Test16212.hs:6:42-46]),
((Test16212.hs:6:22-40,AnnCloseP), [Test16212.hs:6:40]),
((Test16212.hs:6:22-40,AnnOpenP), [Test16212.hs:6:22]),
((Test16212.hs:6:23-39,AnnCloseP), [Test16212.hs:6:39]),
((Test16212.hs:6:23-39,AnnOpenP), [Test16212.hs:6:23]),
((Test16212.hs:6:24-38,AnnCloseP), [Test16212.hs:6:40, Test16212.hs:6:39]),
((Test16212.hs:6:24-38,AnnDcolon), [Test16212.hs:6:30-31]),
((Test16212.hs:6:24-38,AnnOpenP), [Test16212.hs:6:22, Test16212.hs:6:23]),
((Test16212.hs:7:3-37,AnnDcolon), [Test16212.hs:7:9-10]),
((Test16212.hs:7:29-37,AnnCloseP), [Test16212.hs:7:37]),
((Test16212.hs:7:29-37,AnnOpenP), [Test16212.hs:7:29]),
((Test16212.hs:(9,1)-(11,36),AnnData), [Test16212.hs:9:1-4]),
((Test16212.hs:(9,1)-(11,36),AnnSemi), [Test16212.hs:12:1]),
((Test16212.hs:(9,1)-(11,36),AnnWhere), [Test16212.hs:9:25-29]),
((Test16212.hs:9:10-23,AnnCloseP), [Test16212.hs:9:23]),
((Test16212.hs:9:10-23,AnnOpenP), [Test16212.hs:9:10]),
((Test16212.hs:9:11-22,AnnCloseP), [Test16212.hs:9:23]),
((Test16212.hs:9:11-22,AnnDcolon), [Test16212.hs:9:13-14]),
((Test16212.hs:9:11-22,AnnOpenP), [Test16212.hs:9:10]),
((Test16212.hs:10:5-23,AnnDcolon), [Test16212.hs:10:13-14]),
((Test16212.hs:10:5-23,AnnSemi), [Test16212.hs:11:5]),
((Test16212.hs:11:5-36,AnnDcolon), [Test16212.hs:11:13-14]),
((Test16212.hs:11:16-20,AnnRarrow), [Test16212.hs:11:22-23]),
((Test16212.hs:11:16-36,AnnRarrow), [Test16212.hs:11:22-23]),
((Test16212.hs:11:29-36,AnnCloseP), [Test16212.hs:11:36]),
((Test16212.hs:11:29-36,AnnOpenP), [Test16212.hs:11:29]),
((<no location info>,AnnEofPos), [Test16212.hs:12:1])
]
module Test16212 where
class LiftingMonad (trans :: MTrans) where
proof :: Monad m :- Monad (trans m)
class LiftingMonad2 ((trans :: MTrans)) where
proof :: Monad m :- Monad (trans m)
data Nat (t :: NatKind) where
ZeroNat :: Nat Zero
SuccNat :: Nat t -> Nat (Succ t)
......@@ -38,7 +38,8 @@ test('T10399', [extra_files(['Test10399.hs']),
ignore_stderr], run_command, ['$MAKE -s --no-print-directory T10399'])
test('T10313', [extra_files(['Test10313.hs', 'stringSource.hs']),
ignore_stderr], run_command, ['$MAKE -s --no-print-directory T10313'])
test('T11018', [extra_files(['Test11018.hs']),
# Stricter tests from trac #16217 now causes this to fail. Will be fixed for trac #16212
test('T11018', [expect_broken(11018),extra_files(['Test11018.hs']),
ignore_stderr], run_command, ['$MAKE -s --no-print-directory T11018'])
test('bundle-export', [extra_files(['BundleExport.hs']),
ignore_stderr], run_command, ['$MAKE -s --no-print-directory bundle-export'])
......@@ -59,3 +60,6 @@ test('T13163', [extra_files(['Test13163.hs']),
ignore_stderr], run_command, ['$MAKE -s --no-print-directory T13163'])
test('T15303', [extra_files(['Test15303.hs']),
ignore_stderr], run_command, ['$MAKE -s --no-print-directory T15303'])
# Stricter tests from trac #16217 now causes this to fail. Will be fixed for trac #16212
test('T16212', [expect_broken(16212),extra_files(['Test16212.hs']),
ignore_stderr], run_command, ['$MAKE -s --no-print-directory T16212'])
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
---Problems (should be empty list)---
---Unattached Annotation Problems (should be empty list)---
[]
---Ann before enclosing span problem (should be empty list)---
[
]
---Annotations-----------------------
-- SrcSpan the annotation is attached to, AnnKeywordId,
-- list of locations the keyword item appears in
......
......@@ -53,14 +53,24 @@ testOneFile libdir fileName = do
problems'' = filter (\((a,_),_) -> a /= AnnEofPos) problems'
putStrLn "---Problems (should be empty list)---"
-- Check that every annotation location in 'vs' appears after
-- the start of the enclosing span 's'
comesBefore ((s,k),vs) = not $ all ok vs
where
ok v = (k == AnnEofPos) || (srcSpanStart s <= srcSpanStart v)
precedingProblems = filter comesBefore $ Map.toList anns
putStrLn "---Unattached Annotation Problems (should be empty list)---"
putStrLn (intercalate "\n" [pp $ Map.fromList $ map fst problems''])
putStrLn "---Ann before enclosing span problem (should be empty list)---"
putStrLn (showAnnsList precedingProblems)
putStrLn "---Annotations-----------------------"
putStrLn "-- SrcSpan the annotation is attached to, AnnKeywordId,"
putStrLn "-- list of locations the keyword item appears in"
-- putStrLn (intercalate "\n" [showAnns anns])
putStrLn (showAnns anns)
if null problems''
if null problems'' && null precedingProblems
then exitSuccess
else exitFailure
......@@ -73,11 +83,13 @@ testOneFile libdir fileName = do
showAnns :: Map.Map ApiAnnKey [SrcSpan] -> String
showAnns anns = "[\n" ++ (intercalate ",\n"
showAnns anns = showAnnsList $ Map.toList anns
showAnnsList :: [(ApiAnnKey, [SrcSpan])] -> String
showAnnsList annsList = "[\n" ++ (intercalate ",\n"
$ map (\((s,k),v)
-- -> ("(AK " ++ pp s ++ " " ++ show k ++" = " ++ pp v ++ ")\n"))
-> ("((" ++ pp s ++ "," ++ show k ++"), " ++ pp v ++ ")"))
$ Map.toList anns)
annsList)
++ "\n]\n"
pp :: (Outputable a) => a -> String
......
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