[Git][ghc/ghc][wip/marge_bot_batch_merge_job] 5 commits: Consolidate imports in getMinimalImports (#18264)

Marge Bot gitlab at gitlab.haskell.org
Fri Aug 28 00:22:38 UTC 2020



 Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC


Commits:
01ff8c89 by Aditya Gupta at 2020-08-27T14:19:26-04:00
Consolidate imports in getMinimalImports (#18264)

- - - - -
bacccb73 by Ryan Scott at 2020-08-27T14:20:01-04:00
Make {hsExpr,hsType,pat}NeedsParens aware of boxed 1-tuples

`hsExprNeedsParens`, `hsTypeNeedsParens`, and `patNeedsParens`
previously assumed that all uses of explicit tuples in the source
syntax never need to be parenthesized. This is true save for one
exception: boxed one-tuples, which use the `Solo` data type from
`GHC.Tuple` instead of special tuple syntax. This patch adds the
necessary logic to the three `*NeedsParens` functions to handle
`Solo` correctly.

Fixes #18612.

- - - - -
2d6d3b0a by Krzysztof Gogolewski at 2020-08-27T20:22:26-04:00
Add missing primop documentation (#18454)

- Add three pseudoops to primops.txt.pp, so that Haddock renders
  the documentation
- Update comments
- Remove special case for "->" - it's no longer exported from GHC.Prim
- Remove reference to Note [Compiling GHC.Prim] - the ad-hoc fix is no
  longer there after updates to levity polymorphism.
- Document GHC.Prim
- Remove the comment that lazy is levity-polymorphic.
  As far as I can tell, it never was: in 80e399639,
  only the unfolding was given an open type variable.
- Remove haddock hack in GHC.Magic - no longer neccessary after
  adding realWorld# to primops.txt.pp.

- - - - -
de672122 by Tamar Christina at 2020-08-27T20:22:28-04:00
Fix use distro toolchian

- - - - -
36098d00 by Tamar Christina at 2020-08-27T20:22:28-04:00
document how build system find toolchains on Windows

- - - - -


29 changed files:

- aclocal.m4
- compiler/GHC/Builtin/Utils.hs
- compiler/GHC/Builtin/primops.txt.pp
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/Hs/Pat.hs
- compiler/GHC/Hs/Type.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/SysTools/BaseDir.hs
- compiler/GHC/Types/Id/Make.hs
- compiler/GHC/Types/Unique/Supply.hs
- configure.ac
- hadrian/cfg/system.config.in
- hadrian/src/Oracles/Flag.hs
- hadrian/src/Oracles/Setting.hs
- hadrian/src/Rules/Generate.hs
- includes/ghc.mk
- libraries/ghc-prim/GHC/Magic.hs
- mk/config.mk.in
- mk/project.mk.in
- testsuite/tests/rename/should_compile/Makefile
- + testsuite/tests/rename/should_compile/T18264.hs
- + testsuite/tests/rename/should_compile/T18264.stdout
- testsuite/tests/rename/should_compile/all.T
- + testsuite/tests/th/T18612.hs
- + testsuite/tests/th/T18612.stderr
- testsuite/tests/th/all.T
- utils/genprimopcode/Main.hs
- utils/genprimopcode/Parser.y


Changes:

=====================================
aclocal.m4
=====================================
@@ -507,6 +507,7 @@ AC_DEFUN([GET_ARM_ISA],
 # FP_SETTINGS
 # ----------------------------------
 # Set the variables used in the settings file
+# See Note [tooldir: How GHC finds mingw on Windows]
 AC_DEFUN([FP_SETTINGS],
 [
     if test "$windows" = YES -a "$EnableDistroToolchain" = "NO"
@@ -583,6 +584,7 @@ AC_DEFUN([FP_SETTINGS],
     SettingsCCompilerLinkFlags="$CONF_GCC_LINKER_OPTS_STAGE2"
     SettingsCCompilerSupportsNoPie="$CONF_GCC_SUPPORTS_NO_PIE"
     SettingsLdFlags="$CONF_LD_LINKER_OPTS_STAGE2"
+    SettingsUseDistroMINGW="$EnableDistroToolchain"
     AC_SUBST(SettingsCCompilerCommand)
     AC_SUBST(SettingsHaskellCPPCommand)
     AC_SUBST(SettingsHaskellCPPFlags)
@@ -601,6 +603,7 @@ AC_DEFUN([FP_SETTINGS],
     AC_SUBST(SettingsClangCommand)
     AC_SUBST(SettingsLlcCommand)
     AC_SUBST(SettingsOptCommand)
+    AC_SUBST(SettingsUseDistroMINGW)
 ])
 
 # Helper for cloning a shell variable's state


=====================================
compiler/GHC/Builtin/Utils.hs
=====================================
@@ -257,9 +257,6 @@ primOpId op = primOpIds ! primOpTag op
             Export lists for pseudo-modules (GHC.Prim)
 *                                                                      *
 ************************************************************************
-
-GHC.Prim "exports" all the primops and primitive types, some
-wired-in Ids.
 -}
 
 ghcPrimExports :: [IfaceExport]


=====================================
compiler/GHC/Builtin/primops.txt.pp
=====================================
@@ -15,14 +15,86 @@
 --
 -- It should first be preprocessed.
 --
+-- Note in particular that Haskell block-style comments are not recognized
+-- here, so stick to '--' (even for Notes spanning multiple lines).
+
+-- Note [GHC.Prim]
+-- ~~~~~~~~~~~~~~~
+-- GHC.Prim is a special module:
+--
+-- * It can be imported by any module (import GHC.Prim).
+--   However, in the future we might change which functions are primitives
+--   and which are defined in Haskell.
+--   Users should import GHC.Exts, which reexports GHC.Prim and is more stable.
+--   In particular, we might move some of the primops to 'foreign import prim'
+--   (see ticket #16929 and Note [When do out-of-line primops go in primops.txt.pp])
+--
+-- * It provides primitives of three sorts:
+--   - primitive types such as Int64#, MutableByteArray#
+--   - primops such as (+#), newTVar#, touch#
+--   - pseudoops such as realWorld#, nullAddr#
+--
+-- * The pseudoops are described in Note [ghcPrimIds (aka pseudoops)]
+--   in GHC.Types.Id.Make.
+--
+-- * The primitives (primtypes, primops, pseudoops) cannot be defined in
+--   source Haskell.
+--   There is no GHC/Prim.hs file with definitions.
+--   Instead, we support importing GHC.Prim by manually defining its
+--   ModIface (see Iface.Load.ghcPrimIface).
+--
+-- * The primitives are listed in this file, primops.txt.pp.
+--   It goes through CPP, which creates primops.txt.
+--   It is then consumed by the utility program genprimopcode, which produces
+--   the following three types of files.
+--
+--   1. The files with extension .hs-incl.
+--      They can be found by grepping for hs-incl.
+--      They are #included in compiler sources.
+--
+--      One of them, primop-data-decl.hs-incl, defines the PrimOp type:
+--        data PrimOp
+--         = IntAddOp
+--         | IntSubOp
+--         | CharGtOp
+--         | CharGeOp
+--         | ...
+--
+--      The remaining files define properties of the primops
+--      by pattern matching, for example:
+--        primOpFixity IntAddOp = Just (Fixity NoSourceText 6 InfixL)
+--        primOpFixity IntSubOp = Just (Fixity NoSourceText 6 InfixL)
+--        ...
+--      This includes fixity, has-side-effects, commutability,
+--      IDs used to generate Uniques etc.
+--
+--      Additionally, we pattern match on PrimOp when generating Cmm in
+--      GHC/StgToCmm/Prim.hs.
+--
+--   2. The dummy Prim.hs file, which is used for Haddock and
+--      contains descriptions taken from primops.txt.pp.
+--      All definitions are replaced by placeholders.
+--      See Note [GHC.Prim Docs] in genprimopcode.
+--
+--   3. The module PrimopWrappers.hs, which wraps every call for GHCi;
+--      see Note [Primop wrappers] in GHC.Builtin.Primops for details.
+--
+-- * This file does not list internal-only equality types
+--   (GHC.Builtin.Types.Prim.unexposedPrimTyCons and coercionToken#
+--   in GHC.Types.Id.Make) which are defined but not exported from GHC.Prim.
+--   Every export of GHC.Prim should be in listed in this file.
+--
+-- * The primitive types should be listed in primTyCons in Builtin.Types.Prim
+--   in addition to primops.txt.pp.
+--   (This task should be delegated to genprimopcode in the future.)
+--
+--
+--
 -- Information on how PrimOps are implemented and the steps necessary to
 -- add a new one can be found in the Commentary:
 --
 --  https://gitlab.haskell.org/ghc/ghc/wikis/commentary/prim-ops
 --
--- Note in particular that Haskell block-style comments are not recognized
--- here, so stick to '--' (even for Notes spanning multiple lines).
-
 -- This file is divided into named sections, each containing or more
 -- primop entries. Section headers have the format:
 --
@@ -76,7 +148,6 @@ defaults
    vector           = []
    deprecated_msg   = {}      -- A non-empty message indicates deprecation
 
-
 -- Note [When do out-of-line primops go in primops.txt.pp]
 -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 --
@@ -189,19 +260,6 @@ section "The word size story."
 #define WORD64 Word#
 #endif
 
--- This type won't be exported directly (since there is no concrete
--- syntax for this sort of export) so we'll have to manually patch
--- export lists in both GHC and Haddock.
-primtype FUN m a b
-  {The builtin function type, written in infix form as {\tt a # m -> b}.
-   Values of this type are functions taking inputs of type {\tt a} and
-   producing outputs of type {\tt b}. The multiplicity of the input is
-   {\tt m}.
-
-   Note that {\tt FUN m a b} permits levity-polymorphism in both {\tt a} and
-   {\tt b}, so that types like {\tt Int\# -> Int\#} can still be well-kinded.
-  }
-
 ------------------------------------------------------------------------
 section "Char#"
         {Operations on 31-bit characters.}
@@ -3377,6 +3435,37 @@ section "Etc"
         {Miscellaneous built-ins}
 ------------------------------------------------------------------------
 
+primtype FUN m a b
+  {The builtin function type, written in infix form as {\tt a # m -> b}.
+   Values of this type are functions taking inputs of type {\tt a} and
+   producing outputs of type {\tt b}. The multiplicity of the input is
+   {\tt m}.
+
+   Note that {\tt FUN m a b} permits levity-polymorphism in both {\tt a} and
+   {\tt b}, so that types like {\tt Int\# -> Int\#} can still be well-kinded.
+  }
+
+pseudoop "realWorld#"
+   State# RealWorld
+   { The token used in the implementation of the IO monad as a state monad.
+     It does not pass any information at runtime.
+     See also {\tt GHC.Magic.runRW\#}. }
+
+pseudoop "void#"
+   (# #)
+   { This is an alias for the unboxed unit tuple constructor.
+     In earlier versions of GHC, {\tt void\#} was a value
+     of the primitive type {\tt Void\#}, which is now defined to be {\tt (\# \#)}.
+   }
+   with deprecated_msg = { Use an unboxed unit tuple instead }
+
+pseudoop "magicDict"
+   a
+   { {\tt magicDict} is a special-purpose placeholder value.
+     It is used internally by modules such as {\tt GHC.TypeNats} to cast a typeclass
+     dictionary with a single method. It is eliminated by a rule during compilation.
+     For the details, see Note [magicDictId magic] in GHC. }
+
 primtype Proxy# a
    { The type constructor {\tt Proxy#} is used to bear witness to some
    type variable. It's used when you want to pass around proxy values


=====================================
compiler/GHC/Hs/Expr.hs
=====================================
@@ -1320,6 +1320,11 @@ hsExprNeedsParens p = go
     go (NegApp{})                     = p > topPrec
     go (SectionL{})                   = True
     go (SectionR{})                   = True
+    -- Special-case unary boxed tuple applications so that they are
+    -- parenthesized as `Identity (Solo x)`, not `Identity Solo x` (#18612)
+    -- See Note [One-tuples] in GHC.Builtin.Types
+    go (ExplicitTuple _ [L _ Present{}] Boxed)
+                                      = p >= appPrec
     go (ExplicitTuple{})              = False
     go (ExplicitSum{})                = False
     go (HsLam{})                      = p > topPrec


=====================================
compiler/GHC/Hs/Pat.hs
=====================================
@@ -857,7 +857,12 @@ patNeedsParens p = go
     go (BangPat {})      = False
     go (ParPat {})       = False
     go (AsPat {})        = False
-    go (TuplePat {})     = False
+    -- Special-case unary boxed tuple applications so that they are
+    -- parenthesized as `Identity (Solo x)`, not `Identity Solo x` (#18612)
+    -- See Note [One-tuples] in GHC.Builtin.Types
+    go (TuplePat _ [_] Boxed)
+                         = p >= appPrec
+    go (TuplePat{})      = False
     go (SumPat {})       = False
     go (ListPat {})      = False
     go (LitPat _ l)      = hsLitNeedsParens p l


=====================================
compiler/GHC/Hs/Type.hs
=====================================
@@ -1979,6 +1979,15 @@ hsTypeNeedsParens p = go_hs_ty
     go_hs_ty (HsRecTy{})              = False
     go_hs_ty (HsTyVar{})              = False
     go_hs_ty (HsFunTy{})              = p >= funPrec
+    -- Special-case unary boxed tuple applications so that they are
+    -- parenthesized as `Identity (Solo x)`, not `Identity Solo x` (#18612)
+    -- See Note [One-tuples] in GHC.Builtin.Types
+    go_hs_ty (HsTupleTy _ con [L _ ty])
+      = case con of
+          HsBoxedTuple               -> p >= appPrec
+          HsBoxedOrConstraintTuple   -> p >= appPrec
+          HsConstraintTuple          -> go_hs_ty ty
+          HsUnboxedTuple             -> False
     go_hs_ty (HsTupleTy{})            = False
     go_hs_ty (HsSumTy{})              = False
     go_hs_ty (HsKindSig{})            = p >= sigPrec
@@ -1986,6 +1995,11 @@ hsTypeNeedsParens p = go_hs_ty
     go_hs_ty (HsIParamTy{})           = p > topPrec
     go_hs_ty (HsSpliceTy{})           = False
     go_hs_ty (HsExplicitListTy{})     = False
+    -- Special-case unary boxed tuple applications so that they are
+    -- parenthesized as `Proxy ('Solo x)`, not `Proxy 'Solo x` (#18612)
+    -- See Note [One-tuples] in GHC.Builtin.Types
+    go_hs_ty (HsExplicitTupleTy _ [_])
+                                      = p >= appPrec
     go_hs_ty (HsExplicitTupleTy{})    = False
     go_hs_ty (HsTyLit{})              = False
     go_hs_ty (HsWildCardTy{})         = False


=====================================
compiler/GHC/Iface/Load.hs
=====================================
@@ -915,6 +915,7 @@ findAndReadIface doc_str mod wanted_mod_with_insts hi_boot_file
                      nest 4 (text "reason:" <+> doc_str)])
 
        -- Check for GHC.Prim, and return its static interface
+       -- See Note [GHC.Prim] in primops.txt.pp.
        -- TODO: make this check a function
        if mod `installedModuleEq` gHC_PRIM
            then do
@@ -1059,6 +1060,7 @@ initExternalPackageState home_unit
 *********************************************************
 -}
 
+-- See Note [GHC.Prim] in primops.txt.pp.
 ghcPrimIface :: ModIface
 ghcPrimIface
   = empty_iface {
@@ -1071,7 +1073,7 @@ ghcPrimIface
   where
     empty_iface = emptyFullModIface gHC_PRIM
 
-    -- The fixities listed here for @`seq`@ or @->@ should match
+    -- The fixity listed here for @`seq`@ should match
     -- those in primops.txt.pp (from which Haddock docs are generated).
     fixities = (getOccName seqId, Fixity NoSourceText 0 InfixR)
              : mapMaybe mkFixity allThePrimOps


=====================================
compiler/GHC/Rename/Names.hs
=====================================
@@ -4,7 +4,7 @@
 Extracting imported and top-level names in scope
 -}
 
-{-# LANGUAGE CPP, NondecreasingIndentation, MultiWayIf, NamedFieldPuns #-}
+{-# LANGUAGE CPP, NondecreasingIndentation #-}
 {-# LANGUAGE FlexibleContexts #-}
 {-# LANGUAGE RankNTypes #-}
 {-# LANGUAGE ScopedTypeVariables #-}
@@ -72,7 +72,7 @@ import Data.Either      ( partitionEithers, isRight, rights )
 import Data.Map         ( Map )
 import qualified Data.Map as Map
 import Data.Ord         ( comparing )
-import Data.List        ( partition, (\\), find, sortBy )
+import Data.List        ( partition, (\\), find, sortBy, groupBy, sortOn )
 import Data.Function    ( on )
 import qualified Data.Set as S
 import System.FilePath  ((</>))
@@ -1570,7 +1570,7 @@ decls, and simply trim their import lists.  NB that
 -}
 
 getMinimalImports :: [ImportDeclUsage] -> RnM [LImportDecl GhcRn]
-getMinimalImports = mapM mk_minimal
+getMinimalImports = fmap combine . mapM mk_minimal
   where
     mk_minimal (L l decl, used_gres, unused)
       | null unused
@@ -1623,6 +1623,25 @@ getMinimalImports = mapM mk_minimal
 
           all_non_overloaded = all (not . flIsOverloaded)
 
+    combine :: [LImportDecl GhcRn] -> [LImportDecl GhcRn]
+    combine = map merge . groupBy ((==) `on` getKey) . sortOn getKey
+
+    getKey :: LImportDecl GhcRn -> (Bool, Maybe ModuleName, ModuleName)
+    getKey decl =
+      ( isImportDeclQualified . ideclQualified $ idecl -- is this qualified? (important that this be first)
+      , unLoc <$> ideclAs idecl -- what is the qualifier (inside Maybe monad)
+      , unLoc . ideclName $ idecl -- Module Name
+      )
+      where
+        idecl :: ImportDecl GhcRn
+        idecl = unLoc decl
+
+    merge :: [LImportDecl GhcRn] -> LImportDecl GhcRn
+    merge []                     = error "getMinimalImports: unexpected empty list"
+    merge decls@((L l decl) : _) = L l (decl { ideclHiding = Just (False, L l lies) })
+      where lies = concatMap (unLoc . snd) $ mapMaybe (ideclHiding . unLoc) decls
+
+
 printMinimalImports :: HscSource -> [ImportDeclUsage] -> RnM ()
 -- See Note [Printing minimal imports]
 printMinimalImports hsc_src imports_w_usage


=====================================
compiler/GHC/SysTools/BaseDir.hs
=====================================
@@ -34,16 +34,6 @@ import System.FilePath
 import System.Directory (doesDirectoryExist)
 #endif
 
-#if defined(mingw32_HOST_OS)
-# if defined(i386_HOST_ARCH)
-#  define WINDOWS_CCONV stdcall
-# elif defined(x86_64_HOST_ARCH)
-#  define WINDOWS_CCONV ccall
-# else
-#  error Unknown mingw32 arch
-# endif
-#endif
-
 {-
 Note [topdir: How GHC finds its files]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -70,16 +60,89 @@ Note [tooldir: How GHC finds mingw on Windows]
 GHC has some custom logic on Windows for finding the mingw
 toolchain and perl. Depending on whether GHC is built
 with the make build system or Hadrian, and on whether we're
-running a bindist, we might find the mingw toolchain and perl
+running a bindist, we might find the mingw toolchain
 either under $topdir/../{mingw, perl}/ or
 $topdir/../../{mingw, perl}/.
 
+This story is long and with lots of twist and turns..  But lets talk about how
+the build system finds and wires through the toolchain information.
+
+1) It all starts in configure.ac which has two modes it operates on:
+   a) The default is where `EnableDistroToolchain` is false.  This indicates
+      that we want to use the in-tree bundled toolchains.  In this mode we will
+      download and unpack some custom toolchains into the `inplace/mingw` folder
+      and everything is pointed to that folder.
+   b) The second path is when `EnableDistroToolchain` is true.  This makes the
+      toolchain behave a lot like Linux, in that  the environment is queried for
+      information on the tools we require.
+
+  From configure.ac we export the standard variables to set the paths to the
+  tools for the build system to use.
+
+2) After we have the path to the tools we have to generate the right paths to
+   store in the settings file for ghc to use.  This is done in aclocal.m4.
+   Again we have two modes of operation:
+   a) If not `EnableDistroToolchain` the paths are rewritten to paths using a
+      variable `$tooldir` as we need an absolute path.  $tooldir is filled in by
+      the `expandToolDir` function in this module at GHC startup.
+   b) When `EnableDistroToolchain` then instead of filling in a absolute path
+      we fill in just the program name.  The assumption here is that at runtime
+      the environment GHC is operating on will be the same as the one configure
+      was run in.  This means we expect `gcc, ld, as` etc to be on the PATH.
+
+  From `aclocal.m4` we export a couple of variables starting with `Settings`
+  which will be used to generate the settings file.
+
+3) The next step is to generate the settings file, this is where things diverge
+   based on the build system.  Both Make and Hadrian handle this differently:
+
+make)
+  Make deals with this rather simply.  As an output of configure.ac
+  `config.mk.in` is processed and `config.mk` generated which has the values we
+  set in `aclocal.m4`. This allows the rest of the build system to have access
+  to these and other values determined by configure.
+
+  Based on this file, `includes/ghc.mk` when ran will produce the settings file
+  by echoing the values into a the final file.  Coincidentally this is also
+  where `ghcplatform.h` and `ghcversion.h` generated which contains information
+  about the build platform and sets CPP for use by the entire build.
+
+hadrian)
+  For hadrian the file `cfg/system.config.in` is preprocessed by configure and
+  the output written to `system.config`.  This serves the same purpose as
+  `config.mk` but it rewrites the values that were exported.  As an example
+  `SettingsCCompilerCommand` is rewritten to `settings-c-compiler-command`.
+
+  Next up is `src/Oracles/Settings.hs` which makes from some Haskell ADT to
+  the settings `keys` in the `system.config`.  As an example,
+  `settings-c-compiler-command` is mapped to
+  `SettingsFileSetting_CCompilerCommand`.
+
+  The last part of this is the `generateSettings` in `src/Rules/Generate.hs`
+  which produces the desired settings file out of Hadrian. This is the
+  equivalent to `includes/ghc.mk`.
+
+--
+
+So why do we have these? On Windows there's no such thing as a platform compiler
+and as such we need to provide GCC and binutils.  The easiest way is to bundle
+these with the compiler and wire them up.  This gives you a relocatable
+binball.  This works fine for most users.  However mingw-w64 have a different
+requirement.  They require all packages in the repo to be compiled using the
+same version of the compiler.  So it means when they are rebuilding the world to
+add support for GCC X, they expect all packages to have been compiled with GCC X
+which is a problem since we ship an older GCC version.
+
+GHC is a package in mingw-w64 because there are Haskell packages in the
+repository which of course requires a Haskell compiler.  To help them we
+provide the override which allows GHC to instead of using an inplace compiler to
+play nice with the system compiler instead.
 -}
 
 -- | Expand occurrences of the @$tooldir@ interpolation in a string
 -- on Windows, leave the string untouched otherwise.
 expandToolDir :: Maybe FilePath -> String -> String
-#if defined(mingw32_HOST_OS)
+#if defined(mingw32_HOST_OS) && !defined(USE_INPLACE_MINGW_TOOLCHAIN)
 expandToolDir (Just tool_dir) s = expandPathVar "tooldir" tool_dir s
 expandToolDir Nothing         _ = panic "Could not determine $tooldir"
 #else
@@ -113,14 +176,15 @@ tryFindTopDir Nothing
              Nothing -> getBaseDir
 
 
--- See Note [tooldir: How GHC finds mingw and perl on Windows]
+-- See Note [tooldir: How GHC finds mingw on Windows]
 -- Returns @Nothing@ when not on Windows.
 -- When called on Windows, it either throws an error when the
 -- tooldir can't be located, or returns @Just tooldirpath at .
+-- If the distro toolchain is being used we treat Windows the same as Linux
 findToolDir
   :: FilePath -- ^ topdir
   -> IO (Maybe FilePath)
-#if defined(mingw32_HOST_OS)
+#if defined(mingw32_HOST_OS) && !defined(USE_INPLACE_MINGW_TOOLCHAIN)
 findToolDir top_dir = go 0 (top_dir </> "..")
   where maxDepth = 3
         go :: Int -> FilePath -> IO (Maybe FilePath)


=====================================
compiler/GHC/Types/Id/Make.hs
=====================================
@@ -118,7 +118,8 @@ Note [ghcPrimIds (aka pseudoops)]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 The ghcPrimIds
 
-  * Are exported from GHC.Prim
+  * Are exported from GHC.Prim (see ghcPrimExports, used in ghcPrimInterface)
+    See Note [GHC.Prim] in primops.txt.pp for the remaining items in GHC.Prim.
 
   * Can't be defined in Haskell, and hence no Haskell binding site,
     but have perfectly reasonable unfoldings in Core
@@ -141,7 +142,17 @@ The magicIds
   * May or may not have a CompulsoryUnfolding.
 
   * But have some special behaviour that can't be done via an
-    unfolding from an interface file
+    unfolding from an interface file.
+
+  * May have IdInfo that differs from what would be imported from GHC.Magic.hi.
+    For example, 'lazy' gets a lazy strictness signature, per Note [lazyId magic].
+
+  The two remaining identifiers in GHC.Magic, runRW# and inline, are not listed
+  in magicIds: they have special behavior but they can be known-key and
+  not wired-in.
+  runRW#: see Note [Simplification of runRW#] in Prep, runRW# code in
+  Simplifier, Note [Linting of runRW#].
+  inline: see Note [inlineId magic]
 -}
 
 wiredInIds :: [Id]
@@ -1402,12 +1413,12 @@ These Ids can't be defined in Haskell.  They could be defined in
 unfoldings in the wired-in GHC.Prim interface file, but we'd have to
 ensure that they were definitely, definitely inlined, because there is
 no curried identifier for them.  That's what mkCompulsoryUnfolding
-does.  If we had a way to get a compulsory unfolding from an interface
-file, we could do that, but we don't right now.
+does. Alternatively, we could add the definitions to mi_decls of ghcPrimIface
+but it's not clear if this would be simpler.
 
-The type variables we use here are "open" type variables: this means
-they can unify with both unlifted and lifted types.  Hence we provide
-another gun with which to shoot yourself in the foot.
+coercionToken# is not listed in ghcPrimIds, since its type uses (~#)
+which is not supposed to be used in expressions (GHC throws an assertion
+failure when trying.)
 -}
 
 nullAddrName, seqName,
@@ -1422,6 +1433,7 @@ magicDictName     = mkWiredInIdName gHC_PRIM  (fsLit "magicDict")      magicDict
 coerceName        = mkWiredInIdName gHC_PRIM  (fsLit "coerce")         coerceKey          coerceId
 proxyName         = mkWiredInIdName gHC_PRIM  (fsLit "proxy#")         proxyHashKey       proxyHashId
 
+-- Names listed in magicIds; see Note [magicIds]
 lazyIdName, oneShotName, noinlineIdName :: Name
 lazyIdName        = mkWiredInIdName gHC_MAGIC (fsLit "lazy")           lazyIdKey          lazyId
 oneShotName       = mkWiredInIdName gHC_MAGIC (fsLit "oneShot")        oneShotKey         oneShotId
@@ -1598,7 +1610,7 @@ See also: Note [User-defined RULES for seq] in GHC.Core.Opt.Simplify.
 
 Note [lazyId magic]
 ~~~~~~~~~~~~~~~~~~~
-lazy :: forall a?. a? -> a?   (i.e. works for unboxed types too)
+lazy :: forall a. a -> a
 
 'lazy' is used to make sure that a sub-expression, and its free variables,
 are truly used call-by-need, with no code motion.  Key examples:
@@ -1616,7 +1628,7 @@ are truly used call-by-need, with no code motion.  Key examples:
 Implementing 'lazy' is a bit tricky:
 
 * It must not have a strictness signature: by being a built-in Id,
-  all the info about lazyId comes from here, not from GHC.Base.hi.
+  all the info about lazyId comes from here, not from GHC.Magic.hi.
   This is important, because the strictness analyser will spot it as
   strict!
 
@@ -1777,7 +1789,7 @@ voidPrimId  = pcMiscPrelId voidPrimIdName unboxedUnitTy
 voidArgId :: Id       -- Local lambda-bound :: Void#
 voidArgId = mkSysLocal (fsLit "void") voidArgIdKey Many unboxedUnitTy
 
-coercionTokenId :: Id         -- :: () ~ ()
+coercionTokenId :: Id         -- :: () ~# ()
 coercionTokenId -- See Note [Coercion tokens] in "GHC.CoreToStg"
   = pcMiscPrelId coercionTokenName
                  (mkTyConApp eqPrimTyCon [liftedTypeKind, liftedTypeKind, unitTy, unitTy])
@@ -1786,8 +1798,3 @@ coercionTokenId -- See Note [Coercion tokens] in "GHC.CoreToStg"
 pcMiscPrelId :: Name -> Type -> IdInfo -> Id
 pcMiscPrelId name ty info
   = mkVanillaGlobalWithInfo name ty info
-    -- We lie and say the thing is imported; otherwise, we get into
-    -- a mess with dependency analysis; e.g., core2stg may heave in
-    -- random calls to GHCbase.unpackPS__.  If GHCbase is the module
-    -- being compiled, then it's just a matter of luck if the definition
-    -- will be in "the right place" to be in scope.


=====================================
compiler/GHC/Types/Unique/Supply.hs
=====================================
@@ -180,7 +180,7 @@ The magic `inline` function does two things
 
 * It helps ensure that 'm' really does inline.
 
-Note that 'inline' evaporates in phase 0.  See Note [inlineIdMagic]
+Note that 'inline' evaporates in phase 0.  See Note [inlineId magic]
 in GHC.Core.Opt.ConstantFold.match_inline.
 
 The INLINE pragma on multiShotIO is very important, else the


=====================================
configure.ac
=====================================
@@ -435,6 +435,7 @@ set_up_tarballs() {
     fi
 }
 
+# See Note [tooldir: How GHC finds mingw on Windows]
 if test "$HostOS" = "mingw32" -a "$EnableDistroToolchain" = "NO"
 then
     test -d inplace || mkdir inplace
@@ -455,6 +456,7 @@ fi
 
 # We don't want to bundle a MinGW-w64 toolchain
 # So we have to find these individual tools.
+# See Note [tooldir: How GHC finds mingw on Windows]
 if test "$EnableDistroToolchain" = "YES"
 then
     # Ideally should use AC_CHECK_TARGET_TOOL but our triples
@@ -462,6 +464,7 @@ then
     # so never tried without the prefix.
     AC_PATH_PROG([CC],[gcc], [clang])
     AC_PATH_PROG([NM],[nm])
+    AC_PATH_PROG([LD],[ld])
     AC_PATH_PROG([AR],[ar])
     AC_PATH_PROG([RANLIB],[ranlib])
     AC_PATH_PROG([OBJDUMP],[objdump])


=====================================
hadrian/cfg/system.config.in
=====================================
@@ -92,6 +92,8 @@ project-patch-level1  = @ProjectPatchLevel1@
 project-patch-level2  = @ProjectPatchLevel2@
 project-git-commit-id = @ProjectGitCommitId@
 
+system-use-distro-mingw  = @SettingsUseDistroMINGW@
+
 # Compilation and linking flags:
 #===============================
 
@@ -127,6 +129,7 @@ conf-merge-objects-args-stage3  = @SettingsMergeObjectsFlags@
 # We are in the process of moving the settings file from being entirely
 # generated by configure, to generated being by the build system. Many of these
 # might become redundant.
+# See Note [tooldir: How GHC finds mingw on Windows]
 
 gcc-extra-via-c-opts = @GccExtraViaCOpts@
 ld-has-no-compact-unwind = @LdHasNoCompactUnwind@


=====================================
hadrian/src/Oracles/Flag.hs
=====================================
@@ -25,6 +25,7 @@ data Flag = ArSupportsAtFile
           | HaveLibMingwEx
           | UseSystemFfi
           | BootstrapThreadedRts
+          | SystemDistroMINGW
 
 -- Note, if a flag is set to empty string we treat it as set to NO. This seems
 -- fragile, but some flags do behave like this.
@@ -45,6 +46,7 @@ flag f = do
             HaveLibMingwEx       -> "have-lib-mingw-ex"
             UseSystemFfi         -> "use-system-ffi"
             BootstrapThreadedRts -> "bootstrap-threaded-rts"
+            SystemDistroMINGW    -> "system-use-distro-mingw"
     value <- lookupValueOrError configFile key
     when (value `notElem` ["YES", "NO", ""]) . error $ "Configuration flag "
         ++ quote (key ++ " = " ++ value) ++ " cannot be parsed."


=====================================
hadrian/src/Oracles/Setting.hs
=====================================
@@ -184,6 +184,7 @@ settingList key = fmap words $ lookupValueOrError configFile $ case key of
 
 -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the
 -- result.
+-- See Note [tooldir: How GHC finds mingw on Windows]
 settingsFileSetting :: SettingsFileSetting -> Action String
 settingsFileSetting key = lookupValueOrError configFile $ case key of
     SettingsFileSetting_CCompilerCommand -> "settings-c-compiler-command"


=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -245,6 +245,7 @@ generateGhcPlatformH = do
     hostOs         <- chooseSetting HostOs        TargetOs
     hostVendor     <- chooseSetting HostVendor    TargetVendor
     ghcUnreg       <- getFlag    GhcUnregisterised
+    inplaceTools   <- getFlag    SystemDistroMINGW
     return . unlines $
         [ "#if !defined(__GHCPLATFORM_H__)"
         , "#define __GHCPLATFORM_H__"
@@ -274,12 +275,15 @@ generateGhcPlatformH = do
         , ""
         ]
         ++
+        [ "#define USE_INPLACE_MINGW_TOOLCHAIN 1" | inplaceTools ]
+        ++
         [ "#define UnregisterisedCompiler 1" | ghcUnreg ]
         ++
         [ ""
         , "#endif /* __GHCPLATFORM_H__ */"
         ]
 
+-- See Note [tooldir: How GHC finds mingw on Windows]
 generateSettings :: Expr String
 generateSettings = do
     ctx <- getContext


=====================================
includes/ghc.mk
=====================================
@@ -186,6 +186,9 @@ $$(includes_$1_H_PLATFORM) : includes/ghc.mk includes/Makefile | $$$$(dir $$$$@)
 	@echo "#define BUILD_VENDOR  \"$(BuildVendor_$1_CPP)\""     >> $$@
 	@echo "#define HOST_VENDOR  \"$(HostVendor_$1_CPP)\""       >> $$@
 	@echo                                                       >> $$@
+ifeq "$$(SettingsUseDistroMINGW)" "YES"
+	@echo "#define USE_INPLACE_MINGW_TOOLCHAIN 1"               >> $$@
+endif
 ifeq "$$(GhcUnregisterised)" "YES"
 	@echo "#define UnregisterisedCompiler 1"                    >> $$@
 endif
@@ -204,6 +207,7 @@ $(eval $(call includesHeaderPlatform,1))
 
 # These settings are read by GHC at runtime, so as to not cause spurious
 # rebuilds.
+# See Note [tooldir: How GHC finds mingw on Windows]
 
 includes_SETTINGS = includes/dist/build/settings
 


=====================================
libraries/ghc-prim/GHC/Magic.hs
=====================================
@@ -1,8 +1,6 @@
-{-# LANGUAGE CPP #-}
 {-# LANGUAGE Trustworthy #-}
 {-# LANGUAGE NoImplicitPrelude #-}
 {-# LANGUAGE MagicHash #-}
-{-# LANGUAGE UnboxedTuples #-}
 {-# LANGUAGE DataKinds #-}
 {-# LANGUAGE PolyKinds #-}
 {-# LANGUAGE ScopedTypeVariables #-}
@@ -32,13 +30,8 @@ module GHC.Magic ( inline, noinline, lazy, oneShot, runRW# ) where
 
 -- Here import TYPE explicitly from GHC.Types and not from GHC.Prim. This is
 -- because TYPE is not exported by the source Haskell module generated by
--- genprimops which Haddock will typecheck.
--- Likewise, realWorld# is not generated by genprimops so we use CPP and only
--- import/use it when not building haddock docs.
-#if !defined(__HADDOCK_VERSION__)
-import GHC.Prim (realWorld#)
-#endif
-import GHC.Prim (State#, RealWorld)
+-- genprimops which Haddock will typecheck (#15935).
+import GHC.Prim (State#, realWorld#, RealWorld)
 import GHC.Types (RuntimeRep, TYPE)
 
 -- | The call @inline f@ arranges that @f@ is inlined, regardless of
@@ -83,8 +76,6 @@ noinline x = x
 --
 -- If 'lazy' were not lazy, 'Control.Parallel.par' would look strict in
 -- @y@ which would defeat the whole purpose of 'Control.Parallel.par'.
---
--- Like 'seq', the argument of 'lazy' can have an unboxed type.
 lazy :: a -> a
 lazy x = x
 -- Implementation note: its strictness and unfolding are over-ridden
@@ -124,8 +115,4 @@ runRW# :: forall (r :: RuntimeRep) (o :: TYPE r).
           (State# RealWorld -> o) -> o
 -- See Note [runRW magic] in GHC.CoreToStg.Prep.
 {-# NOINLINE runRW# #-}  -- runRW# is inlined manually in CorePrep
-#if !defined(__HADDOCK_VERSION__)
 runRW# m = m realWorld#
-#else
-runRW# = runRW#   -- The realWorld# is too much for haddock
-#endif


=====================================
mk/config.mk.in
=====================================
@@ -475,6 +475,7 @@ endif
 # We are in the process of moving the settings file from being entirely
 # generated by configure, to generated being by the build system. Many of these
 # might become redundant.
+# See Note [tooldir: How GHC finds mingw on Windows]
 
 GccExtraViaCOpts = @GccExtraViaCOpts@
 LdHasFilelist = @LdHasFilelist@


=====================================
mk/project.mk.in
=====================================
@@ -20,8 +20,8 @@
 #
 # The ProjectVersionInt is included in interface files, and GHC
 # checks that it's reading interface generated by the same ProjectVersion
-# as itself. It does this even though interface file syntax may not 
-# change between versions.  Rationale: calling conventions or other 
+# as itself. It does this even though interface file syntax may not
+# change between versions.  Rationale: calling conventions or other
 # random .o-file stuff might change even if the .hi syntax doesn't
 
 ProjectName       = @ProjectName@
@@ -127,6 +127,7 @@ BuildVendor_CPP         = @BuildVendor_CPP@
 # Valid options: YES/NO
 #
 LeadingUnderscore=@LeadingUnderscore@
+SettingsUseDistroMINGW=@SettingsUseDistroMINGW@
 
 # Pin a suffix on executables? If so, what (Windows only).
 exeext0=@exeext_host@


=====================================
testsuite/tests/rename/should_compile/Makefile
=====================================
@@ -60,3 +60,8 @@ T7969:
 T18497:
 	'$(TEST_HC)' $(TEST_HC_OPTS) -fno-code T18497_Foo.hs T18497_Bar.hs -ddump-minimal-imports
 	cat T18497_Bar.imports-boot
+
+T18264:
+	$(RM) T18264.hi T18264.o T18264.imports
+	'$(TEST_HC)' $(TEST_HC_OPTS) -ddump-minimal-imports -c T18264.hs
+	cat T18264.imports


=====================================
testsuite/tests/rename/should_compile/T18264.hs
=====================================
@@ -0,0 +1,20 @@
+module T18264 where
+
+import Data.Char (isDigit)
+import Data.Maybe (isJust)
+import Data.Char (isPrint)
+import Data.List (sortOn)
+import Data.Char (isLetter)
+import Data.Maybe hiding (isNothing)
+
+import qualified Data.List as S (sort)
+import qualified Data.Char as C --only isDigit & isLetter used later
+import qualified Data.List as T (nub)
+
+test1 x = isDigit x || isLetter x
+test2a = isJust
+test2b = fromJust
+test3 x = C.isDigit x || C.isLetter x
+test4 xs = S.sort xs
+test5 xs = T.nub xs
+test6 f xs = sortOn f xs


=====================================
testsuite/tests/rename/should_compile/T18264.stdout
=====================================
@@ -0,0 +1,6 @@
+import Data.Char ( isDigit, isLetter )
+import Data.List ( sortOn )
+import Data.Maybe ( fromJust, isJust )
+import qualified Data.Char as C ( isLetter, isDigit )
+import qualified Data.List as S ( sort )
+import qualified Data.List as T ( nub )


=====================================
testsuite/tests/rename/should_compile/all.T
=====================================
@@ -175,3 +175,4 @@ test('T17244C', normal, compile, [''])
 test('T17832', [], multimod_compile, ['T17832M1', 'T17832M2'])
 test('T17837', normal, compile, [''])
 test('T18497', [], makefile_test, ['T18497'])
+test('T18264', [], makefile_test, ['T18264'])


=====================================
testsuite/tests/th/T18612.hs
=====================================
@@ -0,0 +1,14 @@
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE TemplateHaskell #-}
+{-# OPTIONS_GHC -ddump-splices #-}
+module T18612 where
+
+import Data.Functor.Identity
+import Data.Proxy
+import Language.Haskell.TH
+
+f :: $(arrowT `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0)))
+              `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0))))
+f $(conP 'Identity [tupP [tupP []]]) = $(conE 'Identity `appE` tupE [tupE []])
+
+type G = $(conT ''Proxy `appT` (promotedTupleT 1 `appT` (tupleT 0)))


=====================================
testsuite/tests/th/T18612.stderr
=====================================
@@ -0,0 +1,13 @@
+T18612.hs:14:11-68: Splicing type
+    conT ''Proxy `appT` (promotedTupleT 1 `appT` (tupleT 0))
+  ======>
+    Proxy ('Solo ())
+T18612.hs:(10,7)-(11,75): Splicing type
+    arrowT `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0)))
+      `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0)))
+  ======>
+    Identity (Solo ()) -> Identity (Solo ())
+T18612.hs:12:4-36: Splicing pattern
+    conP 'Identity [tupP [tupP []]] ======> Identity (Solo())
+T18612.hs:12:41-78: Splicing expression
+    conE 'Identity `appE` tupE [tupE []] ======> Identity (Solo ())


=====================================
testsuite/tests/th/all.T
=====================================
@@ -513,3 +513,4 @@ test('T18102b', extra_files(['T18102b_aux.hs']), compile_and_run, [''])
 test('T18121', normal, compile, [''])
 test('T18123', normal, compile, [''])
 test('T18388', normal, compile, [''])
+test('T18612', normal, compile, [''])


=====================================
utils/genprimopcode/Main.hs
=====================================
@@ -1,5 +1,7 @@
 ------------------------------------------------------------------
 -- A primop-table mangling program                              --
+--
+-- See Note [GHC.Prim] in primops.txt.pp for details.
 ------------------------------------------------------------------
 
 module Main where
@@ -293,8 +295,6 @@ gen_hs_source (Info defaults entries) =
            hdr (PrimOpSpec { name = n })                         = wrapOp n ++ ","
            hdr (PrimVecOpSpec { name = n })                      = wrapOp n ++ ","
            hdr (PseudoOpSpec { name = n })                       = wrapOp n ++ ","
-           hdr (PrimTypeSpec { ty = TyApp (TyCon "->") _ })      = ""
-                  -- GHC lacks the syntax to explicitly export "->"
            hdr (PrimTypeSpec { ty = TyApp (TyCon n) _ })         = wrapOp n ++ ","
            hdr (PrimTypeSpec {})                                 = error $ "Illegal type spec"
            hdr (PrimVecTypeSpec { ty = TyApp (VecTyCon n _) _ }) = wrapOp n ++ ","
@@ -398,8 +398,6 @@ keep GHC's renamer and typechecker happy enough for what Haddock
 needs.  Our main plan is to say
         foo :: <type>
         foo = foo
-We have to silence GHC's complaints about unboxed-top-level declarations
-with an ad-hoc fix in GHC.Tc.Gen.Bind: see Note [Compiling GHC.Prim] in GHC.Tc.Gen.Bind.
 
 That works for all the primitive functions except tagToEnum#.
 If we generate the binding


=====================================
utils/genprimopcode/Parser.y
=====================================
@@ -163,6 +163,7 @@ paT : pTycon ppTs     { TyApp $1 $2 }
 
 pUnboxedTupleTy :: { Ty }
 pUnboxedTupleTy : '(#' pCommaTypes '#)' { TyUTup $2 }
+                | '(#' '#)' { TyUTup [] }
 
 pCommaTypes :: { [Ty] }
 pCommaTypes : pType ',' pCommaTypes { $1 : $3 }



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e0b3cbdac94de38586d2cbe0654a2ef35e96635f...36098d00f0906efd87bc4ca7d37001c7658904d5

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e0b3cbdac94de38586d2cbe0654a2ef35e96635f...36098d00f0906efd87bc4ca7d37001c7658904d5
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/20200827/5b447f48/attachment-0001.html>


More information about the ghc-commits mailing list