[Git][ghc/ghc][wip/ghc-9.10] 7 commits: EPA: Fix range for GADT decl with sig only

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Thu May 9 15:49:47 UTC 2024



Ben Gamari pushed to branch wip/ghc-9.10 at Glasgow Haskell Compiler / GHC


Commits:
255f44e7 by Alan Zimmerman at 2024-05-08T20:07:57+01:00
EPA: Fix range for GADT decl with sig only

Closes #24714

(cherry picked from commit d5bea4d6bce785b1d09f1b8faad7451af23b728d)

- - - - -
ea1bca98 by Alan Zimmerman at 2024-05-08T20:36:04+01:00
EPA: Preserve comments for pattern synonym sig

Closes #24749

(cherry picked from commit bf3d4db0894233ec72f092a4a34bce9ed4ff4e21)

- - - - -
2cb0fb44 by Alan Zimmerman at 2024-05-08T20:36:33+01:00
EPA: Widen stmtslist to include last semicolon

Closes #24754

(cherry picked from commit 7eab4e019205cfced90f06242a9afa23dfcaa70b)

- - - - -
776fa6e1 by Alan Zimmerman at 2024-05-08T20:49:33+01:00
EPA: Keep comments in a CaseAlt match

The comments now live in the surrounding location, not inside the
Match. Make sure we keep them.

Closes #24707

(cherry picked from commit e916fc9215e66b15c7e2387cc087a9d1cc57bf77)

- - - - -
c192d254 by Ben Gamari at 2024-05-09T11:49:25-04:00
Revert "ghcup-metadata: Drop output_name field"

This reverts commit 250c5df7875658f172804f511cd7eb325392f347.

- - - - -
923e21bc by Ben Gamari at 2024-05-09T11:49:26-04:00
ghcup-metadata: Drop output_name

This is entirely redundant to the filename of the URL. There is no
compelling reason to name the downloaded file differently from its
source.

- - - - -
78092043 by Ryan Scott at 2024-05-09T11:49:26-04:00
unboxedSum{Type,Data}Name: Use GHC.Types as the module

Unboxed sum constructors are now defined in the `GHC.Types` module, so if you
manually quote an unboxed sum (e.g., `''Sum2#`), you will get a `Name` like:

```hs
GHC.Types.Sum2#
```

The `unboxedSumTypeName` function in `template-haskell`, however, mistakenly
believes that unboxed sum constructors are defined in `GHC.Prim`, so
`unboxedSumTypeName 2` would return an entirely different `Name`:

```hs
GHC.Prim.(#|#)
```

This is a problem for Template Haskell users, as it means that they can't be
sure which `Name` is the correct one. (Similarly for `unboxedSumDataName`.)

This patch fixes the implementations of `unboxedSum{Type,Data}Name` to use
`GHC.Types` as the module. For consistency with `unboxedTupleTypeName`, the
`unboxedSumTypeName` function now uses the non-punned syntax for unboxed sums
(`Sum<N>#`) as the `OccName`.

Fixes #24750.

- - - - -


10 changed files:

- .gitlab/rel_eng/mk-ghcup-metadata/mk_ghcup_metadata.py
- compiler/GHC/Parser.y
- libraries/template-haskell/Language/Haskell/TH/Syntax.hs
- testsuite/tests/parser/should_compile/DumpSemis.stderr
- + testsuite/tests/printer/CaseAltComments.hs
- + testsuite/tests/printer/DataDeclShort.hs
- testsuite/tests/printer/Makefile
- + testsuite/tests/printer/Test24749.hs
- + testsuite/tests/printer/Test24754.hs
- testsuite/tests/printer/all.T


Changes:

=====================================
.gitlab/rel_eng/mk-ghcup-metadata/mk_ghcup_metadata.py
=====================================
@@ -65,6 +65,7 @@ eprint(f"Supported platforms: {job_mapping.keys()}")
 class Artifact(NamedTuple):
     job_name: str
     download_name: str
+    output_name: Optional[str]
     subdir: str
 
 # Platform spec provides a specification which is agnostic to Job
@@ -75,9 +76,11 @@ class PlatformSpec(NamedTuple):
 
 source_artifact = Artifact('source-tarball'
                           , 'ghc-{version}-src.tar.xz'
+                          , None
                           , 'ghc-{version}' )
 test_artifact = Artifact('source-tarball'
                         , 'ghc-{version}-testsuite.tar.xz'
+                        , None
                         , 'ghc-{version}/testsuite' )
 
 def debian(arch, n):
@@ -111,8 +114,7 @@ def linux_platform(arch, opsys):
 
 base_url = 'https://gitlab.haskell.org/api/v4/projects/1/jobs/{job_id}/artifacts/{artifact_name}'
 
-
-hash_cache = {}
+hash_cache = {} # type: Dict[str, str]
 
 # Download a URL and return its hash
 def download_and_hash(url):
@@ -166,12 +168,15 @@ def mk_one_metadata(release_mode, version, job_map, artifact):
 
 # Turns a platform into an Artifact respecting pipeline_type
 # Looks up the right job to use from the .gitlab/jobs-metadata.json file
-def mk_from_platform(pipeline_type, platform):
+def mk_from_platform(release_mode, pipeline_type, platform):
     info = job_mapping[platform.name][pipeline_type]
     eprint(f"From {platform.name} / {pipeline_type} selecting {info['name']}")
+    output_name = None
+    if not release_mode:
+        output_name = "ghc-{version}-{pn}.tar.xz".format(version="{version}", pn=platform.name)
     return Artifact(info['name']
                    , f"{info['jobInfo']['bindistName']}.tar.xz"
-                   , "ghc-{version}-{pn}.tar.xz".format(version="{version}", pn=platform.name)
+                   , output_name
                    , platform.subdir)
 
 
@@ -179,7 +184,7 @@ def mk_from_platform(pipeline_type, platform):
 def mk_new_yaml(release_mode, version, date, pipeline_type, job_map):
     def mk(platform):
         eprint("\n=== " + platform.name + " " + ('=' * (75 - len(platform.name))))
-        return mk_one_metadata(release_mode, version, job_map, mk_from_platform(pipeline_type, platform))
+        return mk_one_metadata(release_mode, version, job_map, mk_from_platform(release_mode, pipeline_type, platform))
 
     ubuntu1804 = mk(ubuntu("18_04"))
     ubuntu2004 = mk(ubuntu("20_04"))


=====================================
compiler/GHC/Parser.y
=====================================
@@ -1303,7 +1303,7 @@ ty_decl :: { LTyClDecl GhcPs }
         | type_data_or_newtype capi_ctype tycl_hdr opt_kind_sig
                  gadt_constrlist
                  maybe_derivings
-            {% mkTyData (comb4 $1 $3 $5 $6) (sndOf3 $ unLoc $1) (thdOf3 $ unLoc $1) $2 $3
+            {% mkTyData (comb5 $1 $3 $4 $5 $6) (sndOf3 $ unLoc $1) (thdOf3 $ unLoc $1) $2 $3
                             (snd $ unLoc $4) (snd $ unLoc $5)
                             (fmap reverse $6)
                             ((fstOf3 $ unLoc $1)++(fst $ unLoc $4)++(fst $ unLoc $5)) }
@@ -2652,7 +2652,7 @@ sigdecl :: { LHsDecl GhcPs }
                                     (Fixity fixText fixPrec (unLoc $1)))))
                    }}
 
-        | pattern_synonym_sig   { sL1a $1 . SigD noExtField . unLoc $ $1 }
+        | pattern_synonym_sig   { L (getLoc $1) . SigD noExtField . unLoc $ $1 }
 
         | '{-# COMPLETE' qcon_list opt_tyconsig  '#-}'
                 {% let (dcolon, tc) = $3
@@ -3341,7 +3341,7 @@ alts1(PATS) :: { forall b. DisambECP b => PV (Located ([AddEpAnn],[LMatch GhcPs
 
 alt(PATS) :: { forall b. DisambECP b => PV (LMatch GhcPs (LocatedA b)) }
         : PATS alt_rhs { $2 >>= \ $2 ->
-                         acsA (sLLAsl $1 $> ()) (\loc cs -> L (locA loc)
+                         amsA' (sLLAsl $1 $>
                                          (Match { m_ext = []
                                                 , m_ctxt = CaseAlt -- for \case and \cases, this will be changed during post-processing
                                                 , m_pats = $1
@@ -3443,7 +3443,7 @@ stmts :: { forall b. DisambECP b => PV (Located (OrdList AddEpAnn,[LStmt GhcPs (
                              [] -> return (sLZ $1 $> ((fst $ unLoc $1) `snocOL` (mj AnnSemi $2),snd $ unLoc $1))
                              (h:t) -> do
                                { h' <- addTrailingSemiA h (gl $2)
-                               ; return $ sL1 $1 (fst $ unLoc $1,h':t) }}
+                               ; return $ sLZ $1 $> (fst $ unLoc $1,h':t) }}
         | stmt                   { $1 >>= \ $1 ->
                                    return $ sL1 $1 (nilOL,[$1]) }
         | {- empty -}            { return $ noLoc (nilOL,[]) }


=====================================
libraries/template-haskell/Language/Haskell/TH/Syntax.hs
=====================================
@@ -1951,7 +1951,7 @@ unboxedSumDataName alt arity
 
   | otherwise
   = Name (mkOccName sum_occ)
-         (NameG DataName (mkPkgName "ghc-prim") (mkModName "GHC.Prim"))
+         (NameG DataName (mkPkgName "ghc-prim") (mkModName "GHC.Types"))
 
   where
     prefix     = "unboxedSumDataName: "
@@ -1970,11 +1970,11 @@ unboxedSumTypeName arity
 
   | otherwise
   = Name (mkOccName sum_occ)
-         (NameG TcClsName (mkPkgName "ghc-prim") (mkModName "GHC.Prim"))
+         (NameG TcClsName (mkPkgName "ghc-prim") (mkModName "GHC.Types"))
 
   where
     -- Synced with the definition of mkSumTyConOcc in GHC.Builtin.Types
-    sum_occ = '(' : '#' : replicate (arity - 1) '|' ++ "#)"
+    sum_occ = "Sum" ++ show arity ++ "#"
 
 -----------------------------------------------------
 --              Locations


=====================================
testsuite/tests/parser/should_compile/DumpSemis.stderr
=====================================
@@ -856,7 +856,7 @@
                    (EpaSpan { DumpSemis.hs:22:10-30 })
                    (AnnList
                     (Just
-                     (EpaSpan { DumpSemis.hs:22:12-25 }))
+                     (EpaSpan { DumpSemis.hs:22:12-28 }))
                     (Just
                      (AddEpAnn AnnOpenC (EpaSpan { DumpSemis.hs:22:10 })))
                     (Just


=====================================
testsuite/tests/printer/CaseAltComments.hs
=====================================
@@ -0,0 +1,7 @@
+{-# LANGUAGE PatternGuards #-}
+module CaseAltComments where
+
+nfCom = case expr of
+      x :*: y  -- comment
+         | x' <= y'  -> x' :*: y'
+      _ -> blah


=====================================
testsuite/tests/printer/DataDeclShort.hs
=====================================
@@ -0,0 +1,8 @@
+module DataDeclShort where
+
+data GenericOptions
+  :: fieldLabelModifier
+  -> tagSingleConstructors
+  -> Type
+
+x = 1


=====================================
testsuite/tests/printer/Makefile
=====================================
@@ -856,3 +856,18 @@ Test24753:
 Test24771:
 	$(CHECK_PPR)   $(LIBDIR) Test24771.hs
 	$(CHECK_EXACT) $(LIBDIR) Test24771.hs
+
+.PHONY: DataDeclShort
+DataDeclShort:
+	$(CHECK_PPR)   $(LIBDIR) DataDeclShort.hs
+	$(CHECK_EXACT) $(LIBDIR) DataDeclShort.hs
+
+.PHONY: Test24749
+Test24749:
+	$(CHECK_PPR)   $(LIBDIR) Test24749.hs
+	$(CHECK_EXACT) $(LIBDIR) Test24749.hs
+
+.PHONY: Test24754
+Test24754:
+	$(CHECK_PPR)   $(LIBDIR) Test24754.hs
+	$(CHECK_EXACT) $(LIBDIR) Test24754.hs


=====================================
testsuite/tests/printer/Test24749.hs
=====================================
@@ -0,0 +1,11 @@
+{-# LANGUAGE PatternSynonyms #-}
+module Test24749 where
+
+-- c0
+pattern (:|) ::
+  -- c1
+  a ->
+  -- c2
+  a ->
+  -- c3
+  Domino a


=====================================
testsuite/tests/printer/Test24754.hs
=====================================
@@ -0,0 +1,4 @@
+module Test24754 where
+
+eh1  =  try (do return r;) <|> (do
+                return r)


=====================================
testsuite/tests/printer/all.T
=====================================
@@ -203,3 +203,7 @@ test('Test24748', [ignore_stderr, req_ppr_deps], makefile_test, ['Test24748'])
 test('Test24755', [ignore_stderr, req_ppr_deps], makefile_test, ['Test24755'])
 test('Test24753', [ignore_stderr, req_ppr_deps], makefile_test, ['Test24753'])
 test('Test24771', [ignore_stderr, req_ppr_deps], makefile_test, ['Test24771'])
+test('DataDeclShort', [ignore_stderr, req_ppr_deps], makefile_test, ['DataDeclShort'])
+test('Test24749', [ignore_stderr, req_ppr_deps], makefile_test, ['Test24749'])
+test('Test24754', [ignore_stderr, req_ppr_deps], makefile_test, ['Test24754'])
+test('CaseAltComments', [ignore_stderr, req_ppr_deps], makefile_test, ['CaseAltComments'])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/41019e5c90cc08c8cab7f03a3c61f63dc42dc3ea...78092043c8406a2f3ada950d56f15af39e3de00b

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/41019e5c90cc08c8cab7f03a3c61f63dc42dc3ea...78092043c8406a2f3ada950d56f15af39e3de00b
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240509/5327c80d/attachment-0001.html>


More information about the ghc-commits mailing list