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

Commits:

24 changed files:

Changes:

  • .gitlab/ci.sh
    ... ... @@ -628,20 +628,6 @@ function install_bindist() {
    628 628
         *)
    
    629 629
           read -r -a args <<< "${INSTALL_CONFIGURE_ARGS:-}"
    
    630 630
     
    
    631
    -      if [[ "${CROSS_TARGET:-no_cross_target}" =~ "mingw" ]]; then
    
    632
    -          # We suppose that host target = build target.
    
    633
    -          # By the fact above it is clearly turning out which host value is
    
    634
    -          # for currently built compiler.
    
    635
    -          # The fix for #21970 will probably remove this if-branch.
    
    636
    -          local -r CROSS_HOST_GUESS=$($SHELL ./config.guess)
    
    637
    -          args+=( "--target=$CROSS_TARGET" "--host=$CROSS_HOST_GUESS" )
    
    638
    -
    
    639
    -      # FIXME: The bindist configure script shouldn't need to be reminded of
    
    640
    -      # the target platform. See #21970.
    
    641
    -      elif [ -n "${CROSS_TARGET:-}" ]; then
    
    642
    -          args+=( "--target=$CROSS_TARGET" "--host=$CROSS_TARGET" )
    
    643
    -      fi
    
    644
    -
    
    645 631
           run ${CONFIGURE_WRAPPER:-} ./configure \
    
    646 632
               --prefix="$instdir" \
    
    647 633
               "${args[@]+"${args[@]}"}" || fail "bindist configure failed"
    

  • .gitlab/generate-ci/gen_ci.hs
    ... ... @@ -1316,6 +1316,13 @@ cross_jobs = [
    1316 1316
               -- unexpected triple.
    
    1317 1317
             . setVariable "CFLAGS" cflags
    
    1318 1318
             . setVariable "CONF_CC_OPTS_STAGE2" cflags
    
    1319
    +          -- For bindists `$USER_CONF_CC_OPTS_STAGE2` is not automatically set
    
    1320
    +          -- to `$CONF_CC_OPTS_STAGE2`. But, we still have to deal with the hack
    
    1321
    +          -- mentioned in the previous comment.
    
    1322
    +          --
    
    1323
    +          -- TODO: It would be nice to get rid of this hack. This would probably
    
    1324
    +          -- involve setting the toolchain up in a different way.
    
    1325
    +        . setVariable "USER_CONF_CC_OPTS_STAGE2" cflags
    
    1319 1326
             ) where
    
    1320 1327
                 llvm_prefix = "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-"
    
    1321 1328
                 cflags = "-fuse-ld=" ++ llvm_prefix ++ "ld --rtlib=compiler-rt"
    

  • .gitlab/jobs.yaml
    ... ... @@ -331,6 +331,7 @@
    331 331
           "STRINGS": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-strings",
    
    332 332
           "STRIP": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-strip",
    
    333 333
           "TEST_ENV": "aarch64-linux-deb12-wine-int_native-cross_aarch64-unknown-mingw32-validate",
    
    334
    +      "USER_CONF_CC_OPTS_STAGE2": "-fuse-ld=/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-ld --rtlib=compiler-rt",
    
    334 335
           "WindresCmd": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-windres"
    
    335 336
         }
    
    336 337
       },
    
    ... ... @@ -412,6 +413,7 @@
    412 413
           "STRINGS": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-strings",
    
    413 414
           "STRIP": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-strip",
    
    414 415
           "TEST_ENV": "aarch64-linux-deb12-wine-int_native-cross_aarch64-unknown-mingw32-validate+llvm",
    
    416
    +      "USER_CONF_CC_OPTS_STAGE2": "-fuse-ld=/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-ld --rtlib=compiler-rt",
    
    415 417
           "WindresCmd": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-windres"
    
    416 418
         }
    
    417 419
       },
    
    ... ... @@ -1123,6 +1125,7 @@
    1123 1125
           "STRINGS": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-strings",
    
    1124 1126
           "STRIP": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-strip",
    
    1125 1127
           "TEST_ENV": "aarch64-linux-deb12-wine-int_native-cross_aarch64-unknown-mingw32-validate",
    
    1128
    +      "USER_CONF_CC_OPTS_STAGE2": "-fuse-ld=/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-ld --rtlib=compiler-rt",
    
    1126 1129
           "WindresCmd": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-windres",
    
    1127 1130
           "XZ_OPT": "-9"
    
    1128 1131
         }
    
    ... ... @@ -1205,6 +1208,7 @@
    1205 1208
           "STRINGS": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-strings",
    
    1206 1209
           "STRIP": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-strip",
    
    1207 1210
           "TEST_ENV": "aarch64-linux-deb12-wine-int_native-cross_aarch64-unknown-mingw32-validate+llvm",
    
    1211
    +      "USER_CONF_CC_OPTS_STAGE2": "-fuse-ld=/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-ld --rtlib=compiler-rt",
    
    1208 1212
           "WindresCmd": "/opt/llvm-mingw-linux/bin/aarch64-w64-mingw32-windres",
    
    1209 1213
           "XZ_OPT": "-9"
    
    1210 1214
         }
    

  • compiler/GHC/ByteCode/Breakpoints.hs
    ... ... @@ -37,6 +37,7 @@ import GHC.Prelude
    37 37
     import GHC.Types.SrcLoc
    
    38 38
     import GHC.Types.Name.Occurrence
    
    39 39
     import Control.DeepSeq
    
    40
    +import qualified Data.ByteString.Short as SBS
    
    40 41
     import Data.IntMap.Strict (IntMap)
    
    41 42
     import qualified Data.IntMap.Strict as IM
    
    42 43
     
    
    ... ... @@ -235,8 +236,8 @@ getBreakVars = getBreakXXX modBreaks_vars
    235 236
     getBreakDecls :: (Module -> IO ModBreaks) -> InternalBreakpointId -> InternalModBreaks -> IO [String]
    
    236 237
     getBreakDecls = getBreakXXX modBreaks_decls
    
    237 238
     
    
    238
    --- | Get the decls for this breakpoint
    
    239
    -getBreakCCS :: (Module -> IO ModBreaks) -> InternalBreakpointId -> InternalModBreaks -> IO ((String, String))
    
    239
    +-- | Get the cost centre info for this breakpoint
    
    240
    +getBreakCCS :: (Module -> IO ModBreaks) -> InternalBreakpointId -> InternalModBreaks -> IO (SBS.ShortByteString, SBS.ShortByteString)
    
    240 241
     getBreakCCS = getBreakXXX modBreaks_ccs
    
    241 242
     
    
    242 243
     -- | Internal utility to access a ModBreaks field at a particular breakpoint index
    

  • compiler/GHC/Driver/Plugins.hs
    ... ... @@ -405,7 +405,7 @@ loadExternalPlugins ps = do
    405 405
             symbol
    
    406 406
               | null unit = ztmp
    
    407 407
               | otherwise = zEncodeString unit ++ "_" ++ ztmp
    
    408
    -    plugin <- lookupSymbol symbol >>= \case
    
    408
    +    plugin <- lookupSymbol (utf8EncodeShortByteString symbol) >>= \case
    
    409 409
           Nothing -> pprPanic "loadExternalPlugins"
    
    410 410
                       (vcat [ text "Symbol not found"
    
    411 411
                             , text "  Library path: " <> text path
    

  • compiler/GHC/HsToCore/Breakpoints.hs
    ... ... @@ -23,6 +23,7 @@ module GHC.HsToCore.Breakpoints
    23 23
     
    
    24 24
     import GHC.Prelude
    
    25 25
     import Data.Array
    
    26
    +import qualified Data.ByteString.Short as SBS
    
    26 27
     
    
    27 28
     import GHC.HsToCore.Ticks (Tick (..))
    
    28 29
     import GHC.Data.SizedSeq
    
    ... ... @@ -31,6 +32,7 @@ import GHC.Types.Name (OccName)
    31 32
     import GHC.Types.Tickish (BreakTickIndex, BreakpointId(..))
    
    32 33
     import GHC.Unit.Module (Module)
    
    33 34
     import GHC.Utils.Binary
    
    35
    +import GHC.Utils.Encoding (utf8EncodeShortByteString)
    
    34 36
     import GHC.Utils.Outputable
    
    35 37
     import Data.List (intersperse)
    
    36 38
     import Data.Coerce
    
    ... ... @@ -59,7 +61,7 @@ data ModBreaks
    59 61
        , modBreaks_decls  :: !(Array BreakTickIndex [String])
    
    60 62
             -- ^ An array giving the names of the declarations enclosing each breakpoint.
    
    61 63
             -- See Note [Field modBreaks_decls]
    
    62
    -   , modBreaks_ccs    :: !(Array BreakTickIndex (String, String))
    
    64
    +   , modBreaks_ccs    :: !(Array BreakTickIndex (SBS.ShortByteString, SBS.ShortByteString))
    
    63 65
             -- ^ Array pointing to cost centre info for each breakpoint;
    
    64 66
             -- actual 'CostCentre' allocation is done at link-time.
    
    65 67
        , modBreaks_module :: !Module
    
    ... ... @@ -89,8 +91,8 @@ mkModBreaks interpreterProfiled modl extendedMixEntries
    89 91
               | interpreterProfiled =
    
    90 92
                   listArray
    
    91 93
                     (0, count - 1)
    
    92
    -                [ ( concat $ intersperse "." $ tick_path t,
    
    93
    -                    renderWithContext defaultSDocContext $ ppr $ tick_loc t
    
    94
    +                [ ( utf8EncodeShortByteString $ concat $ intersperse "." $ tick_path t,
    
    95
    +                    utf8EncodeShortByteString $ renderWithContext defaultSDocContext $ ppr $ tick_loc t
    
    94 96
                       )
    
    95 97
                     | t <- entries
    
    96 98
                     ]
    

  • compiler/GHC/Linker/Loader.hs
    ... ... @@ -1846,7 +1846,7 @@ allocateCCS interp ce mbss
    1846 1846
                 ccs <- {- one ccs ptr per tick index -}
    
    1847 1847
                   mkCostCentres
    
    1848 1848
                     interp
    
    1849
    -                (moduleNameString $ moduleName modBreaks_module)
    
    1849
    +                (moduleNameFS $ moduleName modBreaks_module)
    
    1850 1850
                     (elems modBreaks_ccs)
    
    1851 1851
                 return $ M.fromList $
    
    1852 1852
                   zipWith (\el ix -> (BreakpointId modBreaks_module ix, el)) ccs [0..]
    

  • compiler/GHC/Runtime/Interpreter.hs
    ... ... @@ -107,6 +107,7 @@ import Control.Monad.IO.Class
    107 107
     import Control.Monad.Catch as MC (mask)
    
    108 108
     import Data.Binary
    
    109 109
     import Data.ByteString (ByteString)
    
    110
    +import qualified Data.ByteString.Short as SBS
    
    110 111
     import Foreign hiding (void)
    
    111 112
     import qualified GHC.Exts.Heap as Heap
    
    112 113
     import GHC.Stack.CCS (CostCentre,CostCentreStack)
    
    ... ... @@ -352,9 +353,15 @@ evalStringToIOString interp fhv str =
    352 353
     mallocData :: Interp -> ByteString -> IO (RemotePtr ())
    
    353 354
     mallocData interp bs = interpCmd interp (MallocData bs)
    
    354 355
     
    
    355
    -mkCostCentres :: Interp -> String -> [(String,String)] -> IO [RemotePtr CostCentre]
    
    356
    -mkCostCentres interp mod ccs =
    
    357
    -  interpCmd interp (MkCostCentres mod ccs)
    
    356
    +mkCostCentres :: Interp -> FastString -> [(SBS.ShortByteString, SBS.ShortByteString)] -> IO [RemotePtr CostCentre]
    
    357
    +mkCostCentres interp mod ccs = do
    
    358
    +  rp <- modifyMVar (interpStringCache interp) $ \fs_env ->
    
    359
    +    case lookupFsEnv fs_env mod of
    
    360
    +      Just rp -> pure (fs_env, rp)
    
    361
    +      Nothing -> do
    
    362
    +        rp <- fmap head $ interpCmd interp $ MallocStrings [bytesFS mod]
    
    363
    +        pure (extendFsEnv fs_env mod rp, rp)
    
    364
    +  interpCmd interp $ MkCostCentres rp ccs
    
    358 365
     
    
    359 366
     -- | Create a set of BCOs that may be mutually recursive.
    
    360 367
     createBCOs :: Interp -> [ResolvedBCO] -> IO [HValueRef]
    
    ... ... @@ -413,7 +420,7 @@ evalBreakpointToId :: EvalBreakpoint -> InternalBreakpointId
    413 420
     evalBreakpointToId eval_break =
    
    414 421
       let
    
    415 422
         mkUnitId u = fsToUnit $ mkFastStringShortByteString u
    
    416
    -    toModule u n = mkModule (mkUnitId u) (mkModuleName n)
    
    423
    +    toModule u n = mkModule (mkUnitId u) (mkModuleNameFS (mkFastStringShortByteString n))
    
    417 424
       in
    
    418 425
         InternalBreakpointId
    
    419 426
           { ibi_info_mod   = toModule (eb_info_mod_unit eval_break) (eb_info_mod eval_break)
    
    ... ... @@ -465,27 +472,27 @@ lookupSymbol :: Interp -> InterpSymbol s -> IO (Maybe (Ptr ()))
    465 472
     lookupSymbol interp str = withSymbolCache interp str $
    
    466 473
       case interpInstance interp of
    
    467 474
     #if defined(HAVE_INTERNAL_INTERPRETER)
    
    468
    -    InternalInterp -> fmap fromRemotePtr <$> run (LookupSymbol (unpackFS (interpSymbolToCLabel str)))
    
    475
    +    InternalInterp -> fmap fromRemotePtr <$> run (LookupSymbol (fastStringToShortByteString (interpSymbolToCLabel str)))
    
    469 476
     #endif
    
    470 477
         ExternalInterp ext -> case ext of
    
    471 478
           ExtIServ i -> withIServ i $ \inst -> fmap fromRemotePtr <$> do
    
    472 479
             uninterruptibleMask_ $
    
    473
    -          sendMessage inst (LookupSymbol (unpackFS (interpSymbolToCLabel str)))
    
    480
    +          sendMessage inst (LookupSymbol (fastStringToShortByteString (interpSymbolToCLabel str)))
    
    474 481
           ExtJS {} -> pprPanic "lookupSymbol not supported by the JS interpreter" (ppr str)
    
    475 482
           ExtWasm i -> withWasmInterp i $ \inst -> fmap fromRemotePtr <$> do
    
    476 483
             uninterruptibleMask_ $
    
    477
    -          sendMessage inst (LookupSymbol (unpackFS (interpSymbolToCLabel str)))
    
    484
    +          sendMessage inst (LookupSymbol (fastStringToShortByteString (interpSymbolToCLabel str)))
    
    478 485
     
    
    479 486
     lookupSymbolInDLL :: Interp -> RemotePtr LoadedDLL -> InterpSymbol s -> IO (Maybe (Ptr ()))
    
    480 487
     lookupSymbolInDLL interp dll str = withSymbolCache interp str $
    
    481 488
       case interpInstance interp of
    
    482 489
     #if defined(HAVE_INTERNAL_INTERPRETER)
    
    483
    -    InternalInterp -> fmap fromRemotePtr <$> run (LookupSymbolInDLL dll (unpackFS (interpSymbolToCLabel str)))
    
    490
    +    InternalInterp -> fmap fromRemotePtr <$> run (LookupSymbolInDLL dll (fastStringToShortByteString (interpSymbolToCLabel str)))
    
    484 491
     #endif
    
    485 492
         ExternalInterp ext -> case ext of
    
    486 493
           ExtIServ i -> withIServ i $ \inst -> fmap fromRemotePtr <$> do
    
    487 494
             uninterruptibleMask_ $
    
    488
    -          sendMessage inst (LookupSymbolInDLL dll (unpackFS (interpSymbolToCLabel str)))
    
    495
    +          sendMessage inst (LookupSymbolInDLL dll (fastStringToShortByteString (interpSymbolToCLabel str)))
    
    489 496
           ExtJS {} -> pprPanic "lookupSymbol not supported by the JS interpreter" (ppr str)
    
    490 497
           -- wasm dyld doesn't track which symbol comes from which .so
    
    491 498
           ExtWasm {} -> lookupSymbol interp str
    
    ... ... @@ -519,7 +526,7 @@ interpSymbolToCLabel s = eliminateInterpSymbol s interpretedInterpSymbol $ \is -
    519 526
     
    
    520 527
     lookupClosure :: Interp -> InterpSymbol s -> IO (Maybe HValueRef)
    
    521 528
     lookupClosure interp str =
    
    522
    -  interpCmd interp (LookupClosure (unpackFS (interpSymbolToCLabel str)))
    
    529
    +  interpCmd interp (LookupClosure (fastStringToShortByteString (interpSymbolToCLabel str)))
    
    523 530
     
    
    524 531
     -- | 'withSymbolCache' tries to find a symbol in the 'interpLookupSymbolCache'
    
    525 532
     -- which maps symbols to the address where they are loaded.
    

  • compiler/GHC/Utils/Binary.hs
    ... ... @@ -142,6 +142,7 @@ import Control.DeepSeq
    142 142
     import Control.Monad            ( when, (<$!>), unless, forM_, void )
    
    143 143
     import Foreign hiding (bit, setBit, clearBit, shiftL, shiftR, void)
    
    144 144
     import Data.Array
    
    145
    +import Data.Array.Base (traverseArray_, unsafeFreezeIOArray)
    
    145 146
     import Data.Array.IO
    
    146 147
     import Data.Array.Unsafe
    
    147 148
     import qualified Data.Binary as Binary
    
    ... ... @@ -970,11 +971,12 @@ instance Binary a => Binary (NonEmpty a) where
    970 971
     instance (Ix a, Binary a, Binary b) => Binary (Array a b) where
    
    971 972
         put_ bh arr = do
    
    972 973
             put_ bh $ bounds arr
    
    973
    -        put_ bh $ elems arr
    
    974
    +        traverseArray_ (put_ bh) arr
    
    975
    +
    
    974 976
         get bh = do
    
    975
    -        bounds <- get bh
    
    976
    -        xs <- get bh
    
    977
    -        return $ listArray bounds xs
    
    977
    +        (l, u) <- get bh
    
    978
    +        marr <- newGenArray (l, u) $ \_ -> get bh
    
    979
    +        unsafeFreezeIOArray marr
    
    978 980
     
    
    979 981
     instance Binary a => Binary (SmallArray a) where
    
    980 982
         put_ bh sa = do
    

  • configure.ac
    ... ... @@ -255,6 +255,7 @@ if test "${WithGhc}" != ""
    255 255
     then
    
    256 256
             bootstrap_host=`"${WithGhc}" --info | grep '^ ,("Host platform"' | sed -e 's/.*,"//' -e 's/")//' | tr -d '\r'`
    
    257 257
             bootstrap_target=`"${WithGhc}" --info | grep '^ ,("Target platform"' | sed -e 's/.*,"//' -e 's/")//' | tr -d '\r'`
    
    258
    +	      bootstrap_build="$bootstrap_host"
    
    258 259
             if test "$bootstrap_host" != "$bootstrap_target"
    
    259 260
             then
    
    260 261
                     echo "Bootstrapping GHC is a cross compiler. This probably isn't going to work"
    
    ... ... @@ -394,8 +395,33 @@ then
    394 395
     else
    
    395 396
       TargetPlatformFull="${target_alias}"
    
    396 397
     fi
    
    398
    +
    
    399
    +if test -z "${build_alias}"
    
    400
    +then
    
    401
    +  # --target wasn't given; use result from AC_CANONICAL_TARGET
    
    402
    +  BuildPlatformFull="${build}"
    
    403
    +else
    
    404
    +  BuildPlatformFull="${build_alias}"
    
    405
    +fi
    
    406
    +if test -z "${host_alias}"
    
    407
    +then
    
    408
    +  # --target wasn't given; use result from AC_CANONICAL_TARGET
    
    409
    +  HostPlatformFull="${host}"
    
    410
    +else
    
    411
    +  HostPlatformFull="${host_alias}"
    
    412
    +fi
    
    413
    +if test "$CrossCompiling" = "YES"
    
    414
    +then
    
    415
    +  # Use value passed by user from --target=
    
    416
    +  CrossCompilePrefix="${TargetPlatformFull}-"
    
    417
    +else
    
    418
    +  CrossCompilePrefix=""
    
    419
    +fi
    
    420
    +
    
    397 421
     AC_SUBST(CrossCompiling)
    
    398 422
     AC_SUBST(TargetPlatformFull)
    
    423
    +AC_SUBST(BuildPlatformFull)
    
    424
    +AC_SUBST(HostPlatformFull)
    
    399 425
     
    
    400 426
     dnl ** Which gcc to use?
    
    401 427
     dnl --------------------------------------------------------------
    

  • distrib/configure.ac.in
    ... ... @@ -15,7 +15,18 @@ dnl--------------------------------------------------------------------
    15 15
     dnl * Deal with arguments telling us gmp is somewhere odd
    
    16 16
     dnl--------------------------------------------------------------------
    
    17 17
     
    
    18
    +build_alias=@BuildPlatformFull@
    
    19
    +host_alias=@HostPlatformFull@
    
    20
    +target_alias=@TargetPlatformFull@
    
    21
    +
    
    22
    +dnl this makes sure `./configure --target=<cross-compile-target>`
    
    23
    +dnl works as expected, since we're slightly modifying how Autoconf
    
    24
    +dnl interprets build/host/target and how this interacts with $CC tests
    
    25
    +test -n "$target_alias" && ac_tool_prefix=$target_alias-
    
    26
    +
    
    18 27
     dnl Various things from the source distribution configure
    
    28
    +bootstrap_build=@BuildPlatform@
    
    29
    +bootstrap_host=@HostPlatform@
    
    19 30
     bootstrap_target=@TargetPlatform@
    
    20 31
     
    
    21 32
     bootstrap_llvm_target=@LlvmTarget@
    

  • hadrian/cfg/system.config.in
    ... ... @@ -50,6 +50,9 @@ use-ghc-toolchain = @EnableGhcToolchain@
    50 50
     #     And we can reconstruct the platform info using targetPlatformTriple
    
    51 51
     # Q: What is TargetPlatformFull?
    
    52 52
     target-platform-full  = @TargetPlatformFull@
    
    53
    +build-platform-full   = @BuildPlatformFull@
    
    54
    +host-platform-full    = @HostPlatformFull@
    
    55
    +
    
    53 56
     
    
    54 57
     cross-compiling       = @CrossCompiling@
    
    55 58
     
    

  • hadrian/src/Oracles/Setting.hs
    ... ... @@ -69,6 +69,8 @@ data Setting = CursesIncludeDir
    69 69
                  | ProjectPatchLevel2
    
    70 70
                  | SystemGhc
    
    71 71
                  | TargetPlatformFull
    
    72
    +             | BuildPlatformFull
    
    73
    +             | HostPlatformFull
    
    72 74
                  | BourneShell
    
    73 75
                  | EmsdkVersion
    
    74 76
     
    
    ... ... @@ -107,6 +109,8 @@ setting key = lookupSystemConfig $ case key of
    107 109
         ProjectPatchLevel2 -> "project-patch-level2"
    
    108 110
         SystemGhc          -> "system-ghc"
    
    109 111
         TargetPlatformFull -> "target-platform-full"
    
    112
    +    BuildPlatformFull  -> "build-platform-full"
    
    113
    +    HostPlatformFull   -> "host-platform-full"
    
    110 114
         BourneShell        -> "bourne-shell"
    
    111 115
         EmsdkVersion       -> "emsdk-version"
    
    112 116
     
    

  • hadrian/src/Rules/Generate.hs
    ... ... @@ -424,6 +424,8 @@ bindistRules = do
    424 424
         , interpolateVar "TablesNextToCode" $ yesNo <$> getTarget tgtTablesNextToCode
    
    425 425
         , interpolateVar "TargetHasLibm" $ yesNo <$> getTarget tgtHasLibm
    
    426 426
         , interpolateVar "TargetPlatform" $ getTarget targetPlatformTriple
    
    427
    +    , interpolateVar "BuildPlatform"  $ interp $ queryBuild targetPlatformTriple
    
    428
    +    , interpolateVar "HostPlatform"   $ interp $ queryHost targetPlatformTriple
    
    427 429
         , interpolateVar "TargetWordBigEndian" $ getTarget isBigEndian
    
    428 430
         , interpolateVar "TargetWordSize" $ getTarget wordSize
    
    429 431
         , interpolateVar "Unregisterised" $ yesNo <$> getTarget tgtUnregisterised
    
    ... ... @@ -431,6 +433,9 @@ bindistRules = do
    431 433
         , interpolateVar "UseLibffiForAdjustors" $ yesNo <$> getTarget tgtUseLibffiForAdjustors
    
    432 434
         , interpolateVar "GhcWithSMP" $ yesNo <$> targetSupportsSMP
    
    433 435
         , interpolateVar "BaseUnitId" $ pkgUnitId Stage1 base
    
    436
    +    , interpolateVar "TargetPlatformFull" (setting TargetPlatformFull)
    
    437
    +    , interpolateVar "BuildPlatformFull" (setting BuildPlatformFull)
    
    438
    +    , interpolateVar "HostPlatformFull"  (setting HostPlatformFull)
    
    434 439
         ]
    
    435 440
       where
    
    436 441
         interp = interpretInContext (semiEmptyTarget Stage2)
    

  • hadrian/src/Settings/Default.hs
    ... ... @@ -122,7 +122,11 @@ stage0Packages = do
    122 122
               -- for upper stages. As we only use stage0 to build upper stages,
    
    123 123
               -- this should be fine.
    
    124 124
               ++ [ terminfo | not windowsHost, not cross ]
    
    125
    -          ++ [ timeout  | windowsHost                                ]
    
    125
    +          ++ [ timeout  | windowsHost ]
    
    126
    +          -- Due to some weird logic, we need ghcToolchainBin in Stage0 and
    
    127
    +          -- Stage1 packages if we're cross compiling. "Stage2 cross-compilers"
    
    128
    +          -- will solve this.
    
    129
    +          ++ [ ghcToolchainBin | cross ]
    
    126 130
     
    
    127 131
     -- | Packages built in 'Stage1' by default. You can change this in "UserSettings".
    
    128 132
     stage1Packages :: Action [Package]
    
    ... ... @@ -181,12 +185,12 @@ stage1Packages = do
    181 185
             , transformers
    
    182 186
             , unlit
    
    183 187
             , xhtml
    
    188
    +        , ghcToolchainBin
    
    184 189
             , if winTarget then win32 else unix
    
    185 190
             ]
    
    186 191
           , when (not cross)
    
    187 192
             [ hpcBin
    
    188 193
             , runGhc
    
    189
    -        , ghcToolchainBin
    
    190 194
             ]
    
    191 195
           , when (winTarget && not cross)
    
    192 196
             [ -- See Note [Hadrian's ghci-wrapper package]
    

  • libraries/ghci/GHCi/Message.hs
    ... ... @@ -86,9 +86,9 @@ data Message a where
    86 86
     
    
    87 87
       -- These all invoke the corresponding functions in the RTS Linker API.
    
    88 88
       InitLinker :: Message ()
    
    89
    -  LookupSymbol :: String -> Message (Maybe (RemotePtr ()))
    
    90
    -  LookupSymbolInDLL :: RemotePtr LoadedDLL -> String -> Message (Maybe (RemotePtr ()))
    
    91
    -  LookupClosure :: String -> Message (Maybe HValueRef)
    
    89
    +  LookupSymbol :: !BS.ShortByteString -> Message (Maybe (RemotePtr ()))
    
    90
    +  LookupSymbolInDLL :: !(RemotePtr LoadedDLL) -> !BS.ShortByteString -> Message (Maybe (RemotePtr ()))
    
    91
    +  LookupClosure :: !BS.ShortByteString -> Message (Maybe HValueRef)
    
    92 92
       LoadDLLs :: [String] -> Message (Either String [RemotePtr LoadedDLL])
    
    93 93
       LoadArchive :: String -> Message () -- error?
    
    94 94
       LoadObj :: String -> Message () -- error?
    
    ... ... @@ -162,8 +162,8 @@ data Message a where
    162 162
     
    
    163 163
       -- | Create a set of CostCentres with the same module name
    
    164 164
       MkCostCentres
    
    165
    -   :: String     -- module, RemotePtr so it can be shared
    
    166
    -   -> [(String,String)] -- (name, SrcSpan)
    
    165
    +   :: !(RemotePtr ())                             -- ModuleName
    
    166
    +   -> ![(BS.ShortByteString, BS.ShortByteString)] -- (name, SrcSpan)
    
    167 167
        -> Message [RemotePtr CostCentre]
    
    168 168
     
    
    169 169
       -- | Show a 'CostCentreStack' as a @[String]@
    
    ... ... @@ -430,7 +430,7 @@ data EvalStatus_ a b
    430 430
     instance Binary a => Binary (EvalStatus_ a b)
    
    431 431
     
    
    432 432
     data EvalBreakpoint = EvalBreakpoint
    
    433
    -  { eb_info_mod      :: String -- ^ Breakpoint info module
    
    433
    +  { eb_info_mod      :: !BS.ShortByteString -- ^ Breakpoint info module
    
    434 434
       , eb_info_mod_unit :: BS.ShortByteString -- ^ Breakpoint tick module unit id
    
    435 435
       , eb_info_index    :: Int    -- ^ Breakpoint info index
    
    436 436
       }
    

  • libraries/ghci/GHCi/ObjLink.hs
    ... ... @@ -31,6 +31,8 @@ import GHCi.RemoteTypes
    31 31
     import GHCi.Message (LoadedDLL)
    
    32 32
     import Control.Exception (throwIO, ErrorCall(..))
    
    33 33
     import Control.Monad    ( when )
    
    34
    +import qualified Data.ByteString.Short as BS
    
    35
    +import Data.Char (ord)
    
    34 36
     import Data.Foldable
    
    35 37
     import Foreign.C
    
    36 38
     import Foreign.Marshal.Alloc ( alloca, free )
    
    ... ... @@ -104,15 +106,15 @@ unloadObj f = throwIO $ ErrorCall $ "unloadObj: unsupported on wasm for " <> f
    104 106
     purgeObj :: String -> IO ()
    
    105 107
     purgeObj f = throwIO $ ErrorCall $ "purgeObj: unsupported on wasm for " <> f
    
    106 108
     
    
    107
    -lookupSymbol :: String -> IO (Maybe (Ptr a))
    
    108
    -lookupSymbol sym = do
    
    109
    -  r <- js_lookupSymbol $ toJSString sym
    
    109
    +lookupSymbol :: BS.ShortByteString -> IO (Maybe (Ptr a))
    
    110
    +lookupSymbol sym@(BS.SBS ba#) = do
    
    111
    +  r <- js_lookupSymbolPtr ba# (BS.length sym)
    
    110 112
       evaluate $ if r == nullPtr then Nothing else Just r
    
    111 113
     
    
    112
    -foreign import javascript unsafe "__ghc_wasm_jsffi_dyld.lookupSymbol($1)"
    
    113
    -  js_lookupSymbol :: JSString -> IO (Ptr a)
    
    114
    +foreign import javascript unsafe "__ghc_wasm_jsffi_dyld.lookupSymbolPtr($1,$2)"
    
    115
    +  js_lookupSymbolPtr :: ByteArray# -> Int -> IO (Ptr a)
    
    114 116
     
    
    115
    -lookupSymbolInDLL :: Ptr LoadedDLL -> String -> IO (Maybe (Ptr a))
    
    117
    +lookupSymbolInDLL :: Ptr LoadedDLL -> BS.ShortByteString -> IO (Maybe (Ptr a))
    
    116 118
     lookupSymbolInDLL _ _ = pure Nothing
    
    117 119
     
    
    118 120
     resolveObjs :: IO Bool
    
    ... ... @@ -149,27 +151,27 @@ initObjLinker :: ShouldRetainCAFs -> IO ()
    149 151
     initObjLinker RetainCAFs = c_initLinker_ 1
    
    150 152
     initObjLinker _ = c_initLinker_ 0
    
    151 153
     
    
    152
    -lookupSymbol :: String -> IO (Maybe (Ptr a))
    
    154
    +lookupSymbol :: BS.ShortByteString -> IO (Maybe (Ptr a))
    
    153 155
     lookupSymbol str_in = do
    
    154 156
        let str = prefixUnderscore str_in
    
    155
    -   withCAString str $ \c_str -> do
    
    157
    +   BS.useAsCString str $ \c_str -> do
    
    156 158
          addr <- c_lookupSymbol c_str
    
    157 159
          if addr == nullPtr
    
    158 160
             then return Nothing
    
    159 161
             else return (Just addr)
    
    160 162
     
    
    161
    -lookupSymbolInDLL :: Ptr LoadedDLL -> String -> IO (Maybe (Ptr a))
    
    163
    +lookupSymbolInDLL :: Ptr LoadedDLL -> BS.ShortByteString -> IO (Maybe (Ptr a))
    
    162 164
     lookupSymbolInDLL dll str_in = do
    
    163 165
        let str = prefixUnderscore str_in
    
    164
    -   withCAString str $ \c_str -> do
    
    166
    +   BS.useAsCString str $ \c_str -> do
    
    165 167
          addr <- c_lookupSymbolInNativeObj dll c_str
    
    166 168
          if addr == nullPtr
    
    167 169
            then return Nothing
    
    168 170
            else return (Just addr)
    
    169 171
     
    
    170
    -prefixUnderscore :: String -> String
    
    172
    +prefixUnderscore :: BS.ShortByteString -> BS.ShortByteString
    
    171 173
     prefixUnderscore
    
    172
    - | cLeadingUnderscore = ('_':)
    
    174
    + | cLeadingUnderscore = BS.cons (fromIntegral (ord '_'))
    
    173 175
      | otherwise          = id
    
    174 176
     
    
    175 177
     -- | loadDLL loads a dynamic library using the OS's native linker
    
    ... ... @@ -298,7 +300,7 @@ isWindowsHost = False
    298 300
     
    
    299 301
     #endif
    
    300 302
     
    
    301
    -lookupClosure :: String -> IO (Maybe HValueRef)
    
    303
    +lookupClosure :: BS.ShortByteString -> IO (Maybe HValueRef)
    
    302 304
     lookupClosure str = do
    
    303 305
       m <- lookupSymbol str
    
    304 306
       case m of
    

  • libraries/ghci/GHCi/Run.hs
    ... ... @@ -34,7 +34,7 @@ import Control.DeepSeq
    34 34
     import Control.Exception
    
    35 35
     import Control.Monad
    
    36 36
     import Data.ByteString (ByteString)
    
    37
    -import qualified Data.ByteString.Short as BS
    
    37
    +import qualified Data.ByteString.Short.Internal as BS
    
    38 38
     import qualified Data.ByteString.Unsafe as B
    
    39 39
     import GHC.Exts
    
    40 40
     import qualified GHC.Exts.Heap as Heap
    
    ... ... @@ -135,12 +135,12 @@ foreign import javascript "((ptr,off) => globalThis.h$loadJS(h$decodeUtf8z(ptr,o
    135 135
     
    
    136 136
     foreign import javascript "((ptr,off) => globalThis.h$lookupClosure(h$decodeUtf8z(ptr,off)))" lookupJSClosure# :: CString -> State# RealWorld -> (# State# RealWorld, Int# #)
    
    137 137
     
    
    138
    -lookupJSClosure' :: String -> IO Int
    
    139
    -lookupJSClosure' str = withCString str $ \cstr -> IO (\s ->
    
    138
    +lookupJSClosure' :: BS.ShortByteString -> IO Int
    
    139
    +lookupJSClosure' str = BS.useAsCString str $ \cstr -> IO (\s ->
    
    140 140
       case lookupJSClosure# cstr s of
    
    141 141
         (# s', r #) -> (# s', I# r #))
    
    142 142
     
    
    143
    -lookupJSClosure :: String -> IO (Maybe HValueRef)
    
    143
    +lookupJSClosure :: BS.ShortByteString -> IO (Maybe HValueRef)
    
    144 144
     lookupJSClosure str = lookupJSClosure' str >>= \case
    
    145 145
       0 -> pure Nothing
    
    146 146
       r -> pure (Just (RemoteRef (RemotePtr (fromIntegral r))))
    
    ... ... @@ -359,7 +359,7 @@ withBreakAction opts breakMVar statusMVar mtid act
    359 359
            if is_exception
    
    360 360
            then pure Nothing
    
    361 361
            else do
    
    362
    -         info_mod <- peekCString (Ptr info_mod#)
    
    362
    +         info_mod <- BS.packCString (Ptr info_mod#)
    
    363 363
              info_mod_uid <- BS.packCString (Ptr info_mod_uid#)
    
    364 364
              pure (Just (EvalBreakpoint info_mod info_mod_uid (I# infox#)))
    
    365 365
          putMVar statusMVar $ EvalBreak apStack_r breakpoint resume_r ccs
    
    ... ... @@ -434,17 +434,24 @@ mkString0 bs = B.unsafeUseAsCStringLen bs $ \(cstr,len) -> do
    434 434
       pokeElemOff (ptr :: Ptr CChar) len 0
    
    435 435
       return (castRemotePtr (toRemotePtr ptr))
    
    436 436
     
    
    437
    -mkCostCentres :: String -> [(String,String)] -> IO [RemotePtr CostCentre]
    
    437
    +mkCostCentres :: RemotePtr () -> [(BS.ShortByteString, BS.ShortByteString)] -> IO [RemotePtr CostCentre]
    
    438 438
     #if defined(PROFILING)
    
    439 439
     mkCostCentres mod ccs = do
    
    440
    -  c_module <- newCString mod
    
    440
    +  let c_module = fromRemotePtr $ castRemotePtr mod
    
    441 441
       mapM (mk_one c_module) ccs
    
    442 442
      where
    
    443 443
       mk_one c_module (decl_path,srcspan) = do
    
    444
    -    c_name <- newCString decl_path
    
    445
    -    c_srcspan <- newCString srcspan
    
    444
    +    c_name <- newCStringFromSBS decl_path
    
    445
    +    c_srcspan <- newCStringFromSBS srcspan
    
    446 446
         toRemotePtr <$> c_mkCostCentre c_name c_module c_srcspan
    
    447 447
     
    
    448
    +  newCStringFromSBS sbs = do
    
    449
    +    let len = BS.length sbs
    
    450
    +    buf <- mallocBytes $ len + 1
    
    451
    +    BS.copyToPtr sbs 0 buf (fromIntegral len)
    
    452
    +    pokeByteOff buf len (0 :: Word8)
    
    453
    +    pure buf
    
    454
    +
    
    448 455
     foreign import ccall unsafe "mkCostCentre"
    
    449 456
       c_mkCostCentre :: Ptr CChar -> Ptr CChar -> Ptr CChar -> IO (Ptr CostCentre)
    
    450 457
     #else
    

  • m4/fptools_set_platform_vars.m4
    ... ... @@ -77,9 +77,9 @@ dnl fi
    77 77
     # compiler's target platform.
    
    78 78
     AC_DEFUN([FPTOOLS_OVERRIDE_PLATFORM_FROM_BOOTSTRAP],
    
    79 79
     [
    
    80
    -    if test "$bootstrap_target" != ""
    
    80
    +    if test "$bootstrap_$1" != ""
    
    81 81
         then
    
    82
    -        $1=$bootstrap_target
    
    82
    +        $1=$bootstrap_$1
    
    83 83
             echo "$1 platform inferred as: [$]$1"
    
    84 84
         else
    
    85 85
             echo "Can't work out $1 platform"
    

  • m4/ghc_toolchain.m4
    ... ... @@ -136,8 +136,10 @@ dnl and that we must compile ghc-toolchain before invoking it
    136 136
     AC_DEFUN([FIND_GHC_TOOLCHAIN_BIN],[
    
    137 137
         case "$1" in
    
    138 138
             YES)
    
    139
    -            # We're configuring the bindist, and the binary is already available
    
    140
    -            GHC_TOOLCHAIN_BIN="bin/ghc-toolchain-bin"
    
    139
    +            # We're configuring the bindist, and the binary is already available.
    
    140
    +            # For cross-compilation bindists, Hadrian names the binary with the
    
    141
    +            # cross-compile prefix (e.g. riscv64-linux-gnu-ghc-toolchain-bin).
    
    142
    +            GHC_TOOLCHAIN_BIN="bin/${CrossCompilePrefix}ghc-toolchain-bin"
    
    141 143
                 ;;
    
    142 144
             NO)
    
    143 145
                 # We're in the source tree, so compile ghc-toolchain
    

  • testsuite/tests/driver/linkwhole/Main.hs
    1
    +{-# LANGUAGE OverloadedStrings #-}
    
    1 2
     {-# LANGUAGE RecordWildCards #-}
    
    2 3
     
    
    3 4
     module Main (main) where
    
    4 5
     
    
    5 6
     import Control.Exception
    
    6 7
     import Control.Monad
    
    8
    +import Data.ByteString.Short (ShortByteString)
    
    7 9
     
    
    8 10
     import Foreign
    
    9 11
     
    
    ... ... @@ -15,7 +17,7 @@ import GHCi.ObjLink
    15 17
     
    
    16 18
     rotateSO
    
    17 19
       :: (FunPtr (IO (StablePtr a)) -> (IO (StablePtr a)))
    
    18
    -  -> String
    
    20
    +  -> ShortByteString
    
    19 21
       -> (Maybe FilePath, FilePath)
    
    20 22
       -> IO a
    
    21 23
     rotateSO dynamicCall symName (old, newDLL) = do
    

  • testsuite/tests/ghci/should_run/T18064.script
    1
    +:set -XOverloadedStrings
    
    1 2
     import GHCi.ObjLink
    
    2 3
     lookupClosure "blah"

  • testsuite/tests/rts/KeepCafsMain.hs
    1
    +{-# LANGUAGE OverloadedStrings #-}
    
    2
    +
    
    1 3
     module Main (main) where
    
    2 4
     
    
    3 5
     import Foreign
    

  • utils/jsffi/dyld.mjs
    ... ... @@ -1334,6 +1334,13 @@ class DyLD {
    1334 1334
         }
    
    1335 1335
         return 0;
    
    1336 1336
       }
    
    1337
    +
    
    1338
    +  lookupSymbolPtr(symPtr, symLen) {
    
    1339
    +    const sym = new TextDecoder("utf-8", { fatal: true }).decode(
    
    1340
    +      new Uint8Array(this.#memory.buffer, symPtr, symLen)
    
    1341
    +    );
    
    1342
    +    return this.lookupSymbol(sym);
    
    1343
    +  }
    
    1337 1344
     }
    
    1338 1345
     
    
    1339 1346
     // The main entry point of dyld that may be run on node/browser, and