API Annotations: make all ModuleName Located
authorAlan Zimmerman <alan.zimm@gmail.com>
Thu, 3 Nov 2016 12:40:12 +0000 (14:40 +0200)
committerAlan Zimmerman <alan.zimm@gmail.com>
Thu, 3 Nov 2016 18:45:05 +0000 (20:45 +0200)
Summary:
This also changes the backpack Renaming type to use a Maybe for the
renameTo field, to more accurately reflect the parsed source.

Updates haddock submodule to match AST changes

Test Plan: ./validate

Reviewers: ezyang, bgamari, austin

Reviewed By: bgamari

Subscribers: thomie, mpickering

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

12 files changed:
compiler/backpack/BkpSyn.hs
compiler/backpack/DriverBkp.hs
compiler/hsSyn/HsImpExp.hs
compiler/parser/Parser.y
compiler/rename/RnNames.hs
ghc/GHCi/UI.hs
testsuite/tests/ghc-api/annotations/T10312.stdout
testsuite/tests/ghc-api/annotations/annotations.stdout
testsuite/tests/ghc-api/annotations/exampleTest.stdout
testsuite/tests/ghc-api/annotations/listcomps.stdout
testsuite/tests/ghc-api/annotations/parseTree.stdout
utils/haddock

index ae03324..e019d03 100644 (file)
@@ -73,5 +73,6 @@ data IncludeDecl n = IncludeDecl {
 
 -- | Rename a module from one name to another.  The identity renaming
 -- means that the module should be brought into scope.
-data Renaming = Renaming { renameFrom :: ModuleName, renameTo :: ModuleName }
+data Renaming = Renaming { renameFrom :: Located ModuleName
+                         , renameTo :: Maybe (Located ModuleName) }
 type LRenaming = Located Renaming
index ccf74c8..cdbe06d 100644 (file)
@@ -213,9 +213,12 @@ hsunitDeps :: HsUnit HsComponentId -> [(UnitId, ModRenaming)]
 hsunitDeps unit = concatMap get_dep (hsunitBody unit)
   where
     get_dep (L _ (IncludeD (IncludeDecl (L _ hsuid) mb_lrn))) = [(convertHsUnitId hsuid, go mb_lrn)]
-      where go Nothing = ModRenaming True []
-            go (Just lrns) = ModRenaming False (map convRn lrns)
-              where convRn (L _ (Renaming from to)) = (from, to)
+      where
+        go Nothing = ModRenaming True []
+        go (Just lrns) = ModRenaming False (map convRn lrns)
+          where
+            convRn (L _ (Renaming (L _ from) Nothing))         = (from, from)
+            convRn (L _ (Renaming (L _ from) (Just (L _ to)))) = (from, to)
     get_dep _ = []
 
 buildUnit :: SessionType -> ComponentId -> [(ModuleName, Module)] -> LHsUnit HsComponentId -> BkpM ()
index 6d709cc..011a80a 100644 (file)
@@ -53,7 +53,7 @@ data ImportDecl name
       ideclSafe      :: Bool,          -- ^ True => safe import
       ideclQualified :: Bool,          -- ^ True => qualified
       ideclImplicit  :: Bool,          -- ^ True => implicit import (of Prelude)
-      ideclAs        :: Maybe ModuleName,  -- ^ as Module
+      ideclAs        :: Maybe (Located ModuleName),  -- ^ as Module
       ideclHiding    :: Maybe (Bool, Located [LIE name])
                                        -- ^ (True => hiding, names)
     }
index d72aabd..2c90086 100644 (file)
@@ -575,8 +575,8 @@ rns :: { OrdList LRenaming }
         | rn         { unitOL $1 }
 
 rn :: { LRenaming }
-        : modid 'as' modid { sLL $1 $> $ Renaming (unLoc $1) (unLoc $3) }
-        | modid            { sL1 $1    $ Renaming (unLoc $1) (unLoc $1) }
+        : modid 'as' modid { sLL $1 $> $ Renaming $1 (Just $3) }
+        | modid            { sL1 $1    $ Renaming $1 Nothing }
 
 unitbody :: { OrdList (LHsUnitDecl PackageName) }
         : '{'     unitdecls '}'   { $2 }
@@ -847,9 +847,9 @@ optqualified :: { ([AddAnn],Bool) }
         : 'qualified'                           { ([mj AnnQualified $1],True)  }
         | {- empty -}                           { ([],False) }
 
-maybeas :: { ([AddAnn],Located (Maybe ModuleName)) }
-        : 'as' modid                           { ([mj AnnAs $1,mj AnnVal $2]
-                                                 ,sLL $1 $> (Just (unLoc $2))) }
+maybeas :: { ([AddAnn],Located (Maybe (Located ModuleName))) }
+        : 'as' modid                           { ([mj AnnAs $1]
+                                                 ,sLL $1 $> (Just $2)) }
         | {- empty -}                          { ([],noLoc Nothing) }
 
 maybeimpspec :: { Located (Maybe (Bool, Located [LIE RdrName])) }
index 549bccb..8da11be 100644 (file)
@@ -266,7 +266,7 @@ rnImportDecl this_mod
                                    ++ "Safe, Trustworthy or Unsafe"))
 
     let
-        qual_mod_name = as_mod `orElse` imp_mod_name
+        qual_mod_name = fmap unLoc as_mod `orElse` imp_mod_name
         imp_spec  = ImpDeclSpec { is_mod = imp_mod_name, is_qual = qual_only,
                                   is_dloc = loc, is_as = qual_mod_name }
 
index a3cb955..3fe42d2 100644 (file)
@@ -749,7 +749,7 @@ getInfoForPrompt = do
 
         rev_imports = reverse imports -- rightmost are the most recent
 
-        myIdeclName d | Just m <- ideclAs d = m
+        myIdeclName d | Just m <- ideclAs d = unLoc m
                       | otherwise           = unLoc (ideclName d)
 
         modules_names =
index 00f2544..c8dff60 100644 (file)
@@ -12,7 +12,6 @@
 ((Test10312.hs:9:1-30,AnnImport), [Test10312.hs:9:1-6]),
 ((Test10312.hs:9:1-30,AnnQualified), [Test10312.hs:9:8-16]),
 ((Test10312.hs:9:1-30,AnnSemi), [Test10312.hs:10:1]),
-((Test10312.hs:9:1-30,AnnVal), [Test10312.hs:9:30]),
 ((Test10312.hs:10:1-27,AnnImport), [Test10312.hs:10:1-6]),
 ((Test10312.hs:10:1-27,AnnSemi), [Test10312.hs:11:1]),
 ((Test10312.hs:10:17-27,AnnCloseP), [Test10312.hs:10:27]),
index e465403..f034805 100644 (file)
@@ -19,8 +19,6 @@
 
 (AK AnnotationLet.hs:5:1-32 AnnSemi = [AnnotationLet.hs:6:1])
 
-(AK AnnotationLet.hs:5:1-32 AnnVal = [AnnotationLet.hs:5:31-32])
-
 (AK AnnotationLet.hs:(7,1)-(11,12) AnnEqual = [AnnotationLet.hs:7:5])
 
 (AK AnnotationLet.hs:(7,1)-(11,12) AnnFunId = [AnnotationLet.hs:7:1-3])
index a884f56..2cdef95 100644 (file)
@@ -14,7 +14,6 @@
 ((AnnotationTuple.hs:6:1-32,AnnImport), [AnnotationTuple.hs:6:1-6]),
 ((AnnotationTuple.hs:6:1-32,AnnQualified), [AnnotationTuple.hs:6:8-16]),
 ((AnnotationTuple.hs:6:1-32,AnnSemi), [AnnotationTuple.hs:7:1]),
-((AnnotationTuple.hs:6:1-32,AnnVal), [AnnotationTuple.hs:6:31-32]),
 ((AnnotationTuple.hs:(8,1)-(11,14),AnnEqual), [AnnotationTuple.hs:8:5]),
 ((AnnotationTuple.hs:(8,1)-(11,14),AnnFunId), [AnnotationTuple.hs:8:1-3]),
 ((AnnotationTuple.hs:(8,1)-(11,14),AnnSemi), [AnnotationTuple.hs:13:1]),
index 1c0b8e5..3965257 100644 (file)
@@ -1,13 +1,13 @@
 {ListComprehensions.hs:1:1, ListComprehensions.hs:6:8-25,
  ListComprehensions.hs:10:1-15, ListComprehensions.hs:10:8-15,
  ListComprehensions.hs:11:1-30, ListComprehensions.hs:11:18-25,
- ListComprehensions.hs:12:1-27, ListComprehensions.hs:12:8-15,
- ListComprehensions.hs:12:17-27, ListComprehensions.hs:12:18-26,
- ListComprehensions.hs:13:1-25, ListComprehensions.hs:13:8-16,
- ListComprehensions.hs:13:18-25, ListComprehensions.hs:13:19-24,
- ListComprehensions.hs:17:1-16, ListComprehensions.hs:17:1-25,
- ListComprehensions.hs:17:21-25, ListComprehensions.hs:17:22-24,
- ListComprehensions.hs:18:1-16,
+ ListComprehensions.hs:11:30, ListComprehensions.hs:12:1-27,
+ ListComprehensions.hs:12:8-15, ListComprehensions.hs:12:17-27,
+ ListComprehensions.hs:12:18-26, ListComprehensions.hs:13:1-25,
+ ListComprehensions.hs:13:8-16, ListComprehensions.hs:13:18-25,
+ ListComprehensions.hs:13:19-24, ListComprehensions.hs:17:1-16,
+ ListComprehensions.hs:17:1-25, ListComprehensions.hs:17:21-25,
+ ListComprehensions.hs:17:22-24, ListComprehensions.hs:18:1-16,
  ListComprehensions.hs:(18,1)-(22,20),
  ListComprehensions.hs:(18,18)-(22,20),
  ListComprehensions.hs:(18,20)-(22,20), ListComprehensions.hs:18:22,
@@ -55,8 +55,6 @@
 
 (AK ListComprehensions.hs:11:1-30 AnnSemi = [ListComprehensions.hs:12:1])
 
-(AK ListComprehensions.hs:11:1-30 AnnVal = [ListComprehensions.hs:11:30])
-
 (AK ListComprehensions.hs:12:1-27 AnnImport = [ListComprehensions.hs:12:1-6])
 
 (AK ListComprehensions.hs:12:1-27 AnnSemi = [ListComprehensions.hs:13:1])
index 46b1c4f..092ba97 100644 (file)
@@ -30,8 +30,6 @@
 
 (AK AnnotationTuple.hs:6:1-32 AnnSemi = [AnnotationTuple.hs:7:1])
 
-(AK AnnotationTuple.hs:6:1-32 AnnVal = [AnnotationTuple.hs:6:31-32])
-
 (AK AnnotationTuple.hs:(8,1)-(11,14) AnnEqual = [AnnotationTuple.hs:8:5])
 
 (AK AnnotationTuple.hs:(8,1)-(11,14) AnnFunId = [AnnotationTuple.hs:8:1-3])
index a5a51f9..f4e355f 160000 (submodule)
@@ -1 +1 @@
-Subproject commit a5a51f99f42c7ee5e3bb4aeddf601b5f20a88134
+Subproject commit f4e355f7023057924161160ce75aeaaa3a8d9914