Cheng Shao pushed to branch wip/fix-darwin-toolchain-cruft at Glasgow Haskell Compiler / GHC

Commits:

17 changed files:

Changes:

  • .gitlab/darwin/nix/sources.json
    1 1
     {
    
    2
    -    "niv": {
    
    3
    -        "branch": "master",
    
    4
    -        "description": "Easy dependency management for Nix projects",
    
    5
    -        "homepage": "https://github.com/nmattia/niv",
    
    6
    -        "owner": "nmattia",
    
    7
    -        "repo": "niv",
    
    8
    -        "rev": "e0ca65c81a2d7a4d82a189f1e23a48d59ad42070",
    
    9
    -        "sha256": "1pq9nh1d8nn3xvbdny8fafzw87mj7gsmp6pxkdl65w2g18rmcmzx",
    
    10
    -        "type": "tarball",
    
    11
    -        "url": "https://github.com/nmattia/niv/archive/e0ca65c81a2d7a4d82a189f1e23a48d59ad42070.tar.gz",
    
    12
    -        "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
    
    13
    -    },
    
    14 2
         "nixpkgs": {
    
    15
    -        "branch": "nixos-unstable",
    
    3
    +        "branch": "nixpkgs-25.05-darwin",
    
    16 4
             "description": "Nix Packages collection",
    
    17 5
             "homepage": "",
    
    18 6
             "owner": "nixos",
    
    19 7
             "repo": "nixpkgs",
    
    20
    -        "rev": "2893f56de08021cffd9b6b6dfc70fd9ccd51eb60",
    
    21
    -        "sha256": "1anwxmjpm21msnnlrjdz19w31bxnbpn4kgf93sn3npihi7wf4a8h",
    
    8
    +        "rev": "ac62194c3917d5f474c1a844b6fd6da2db95077d",
    
    9
    +        "sha256": "0v6bd1xk8a2aal83karlvc853x44dg1n4nk08jg3dajqyy0s98np",
    
    22 10
             "type": "tarball",
    
    23
    -        "url": "https://github.com/nixos/nixpkgs/archive/2893f56de08021cffd9b6b6dfc70fd9ccd51eb60.tar.gz",
    
    11
    +        "url": "https://github.com/nixos/nixpkgs/archive/ac62194c3917d5f474c1a844b6fd6da2db95077d.tar.gz",
    
    24 12
             "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
    
    25 13
         }
    
    26 14
     }

  • .gitlab/darwin/nix/sources.nix
    ... ... @@ -10,29 +10,50 @@ let
    10 10
         let
    
    11 11
           name' = sanitizeName name + "-src";
    
    12 12
         in
    
    13
    -      if spec.builtin or true then
    
    14
    -        builtins_fetchurl { inherit (spec) url sha256; name = name'; }
    
    15
    -      else
    
    16
    -        pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
    
    13
    +    if spec.builtin or true then
    
    14
    +      builtins_fetchurl { inherit (spec) url sha256; name = name'; }
    
    15
    +    else
    
    16
    +      pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
    
    17 17
     
    
    18 18
       fetch_tarball = pkgs: name: spec:
    
    19 19
         let
    
    20 20
           name' = sanitizeName name + "-src";
    
    21 21
         in
    
    22
    -      if spec.builtin or true then
    
    23
    -        builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
    
    24
    -      else
    
    25
    -        pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
    
    22
    +    if spec.builtin or true then
    
    23
    +      builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
    
    24
    +    else
    
    25
    +      pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
    
    26 26
     
    
    27 27
       fetch_git = name: spec:
    
    28 28
         let
    
    29 29
           ref =
    
    30
    -        if spec ? ref then spec.ref else
    
    30
    +        spec.ref or (
    
    31 31
               if spec ? branch then "refs/heads/${spec.branch}" else
    
    32
    -            if spec ? tag then "refs/tags/${spec.tag}" else
    
    33
    -              abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
    
    32
    +          if spec ? tag then "refs/tags/${spec.tag}" else
    
    33
    +          abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"
    
    34
    +        );
    
    35
    +      submodules = spec.submodules or false;
    
    36
    +      submoduleArg =
    
    37
    +        let
    
    38
    +          nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0;
    
    39
    +          emptyArgWithWarning =
    
    40
    +            if submodules
    
    41
    +            then
    
    42
    +              builtins.trace
    
    43
    +                (
    
    44
    +                  "The niv input \"${name}\" uses submodules "
    
    45
    +                  + "but your nix's (${builtins.nixVersion}) builtins.fetchGit "
    
    46
    +                  + "does not support them"
    
    47
    +                )
    
    48
    +                { }
    
    49
    +            else { };
    
    50
    +        in
    
    51
    +        if nixSupportsSubmodules
    
    52
    +        then { inherit submodules; }
    
    53
    +        else emptyArgWithWarning;
    
    34 54
         in
    
    35
    -      builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; };
    
    55
    +    builtins.fetchGit
    
    56
    +      ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg);
    
    36 57
     
    
    37 58
       fetch_local = spec: spec.path;
    
    38 59
     
    
    ... ... @@ -66,16 +87,16 @@ let
    66 87
           hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
    
    67 88
           hasThisAsNixpkgsPath = <nixpkgs> == ./.;
    
    68 89
         in
    
    69
    -      if builtins.hasAttr "nixpkgs" sources
    
    70
    -      then sourcesNixpkgs
    
    71
    -      else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
    
    72
    -        import <nixpkgs> {}
    
    73
    -      else
    
    74
    -        abort
    
    75
    -          ''
    
    76
    -            Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
    
    77
    -            add a package called "nixpkgs" to your sources.json.
    
    78
    -          '';
    
    90
    +    if builtins.hasAttr "nixpkgs" sources
    
    91
    +    then sourcesNixpkgs
    
    92
    +    else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
    
    93
    +      import <nixpkgs> { }
    
    94
    +    else
    
    95
    +      abort
    
    96
    +        ''
    
    97
    +          Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
    
    98
    +          add a package called "nixpkgs" to your sources.json.
    
    99
    +        '';
    
    79 100
     
    
    80 101
       # The actual fetching function.
    
    81 102
       fetch = pkgs: name: spec:
    
    ... ... @@ -95,13 +116,13 @@ let
    95 116
       # the path directly as opposed to the fetched source.
    
    96 117
       replace = name: drv:
    
    97 118
         let
    
    98
    -      saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
    
    119
    +      saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name;
    
    99 120
           ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
    
    100 121
         in
    
    101
    -      if ersatz == "" then drv else
    
    102
    -        # this turns the string into an actual Nix path (for both absolute and
    
    103
    -        # relative paths)
    
    104
    -        if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
    
    122
    +    if ersatz == "" then drv else
    
    123
    +      # this turns the string into an actual Nix path (for both absolute and
    
    124
    +      # relative paths)
    
    125
    +    if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
    
    105 126
     
    
    106 127
       # Ports of functions for older nix versions
    
    107 128
     
    
    ... ... @@ -112,7 +133,7 @@ let
    112 133
       );
    
    113 134
     
    
    114 135
       # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
    
    115
    -  range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1);
    
    136
    +  range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1);
    
    116 137
     
    
    117 138
       # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
    
    118 139
       stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
    
    ... ... @@ -123,43 +144,46 @@ let
    123 144
       concatStrings = builtins.concatStringsSep "";
    
    124 145
     
    
    125 146
       # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
    
    126
    -  optionalAttrs = cond: as: if cond then as else {};
    
    147
    +  optionalAttrs = cond: as: if cond then as else { };
    
    127 148
     
    
    128 149
       # fetchTarball version that is compatible between all the versions of Nix
    
    129 150
       builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
    
    130 151
         let
    
    131 152
           inherit (builtins) lessThan nixVersion fetchTarball;
    
    132 153
         in
    
    133
    -      if lessThan nixVersion "1.12" then
    
    134
    -        fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
    
    135
    -      else
    
    136
    -        fetchTarball attrs;
    
    154
    +    if lessThan nixVersion "1.12" then
    
    155
    +      fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; }))
    
    156
    +    else
    
    157
    +      fetchTarball attrs;
    
    137 158
     
    
    138 159
       # fetchurl version that is compatible between all the versions of Nix
    
    139 160
       builtins_fetchurl = { url, name ? null, sha256 }@attrs:
    
    140 161
         let
    
    141 162
           inherit (builtins) lessThan nixVersion fetchurl;
    
    142 163
         in
    
    143
    -      if lessThan nixVersion "1.12" then
    
    144
    -        fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
    
    145
    -      else
    
    146
    -        fetchurl attrs;
    
    164
    +    if lessThan nixVersion "1.12" then
    
    165
    +      fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; }))
    
    166
    +    else
    
    167
    +      fetchurl attrs;
    
    147 168
     
    
    148 169
       # Create the final "sources" from the config
    
    149 170
       mkSources = config:
    
    150
    -    mapAttrs (
    
    151
    -      name: spec:
    
    152
    -        if builtins.hasAttr "outPath" spec
    
    153
    -        then abort
    
    154
    -          "The values in sources.json should not have an 'outPath' attribute"
    
    155
    -        else
    
    156
    -          spec // { outPath = replace name (fetch config.pkgs name spec); }
    
    157
    -    ) config.sources;
    
    171
    +    mapAttrs
    
    172
    +      (
    
    173
    +        name: spec:
    
    174
    +          if builtins.hasAttr "outPath" spec
    
    175
    +          then
    
    176
    +            abort
    
    177
    +              "The values in sources.json should not have an 'outPath' attribute"
    
    178
    +          else
    
    179
    +            spec // { outPath = replace name (fetch config.pkgs name spec); }
    
    180
    +      )
    
    181
    +      config.sources;
    
    158 182
     
    
    159 183
       # The "config" used by the fetchers
    
    160 184
       mkConfig =
    
    161 185
         { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
    
    162
    -    , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)
    
    186
    +    , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile)
    
    163 187
         , system ? builtins.currentSystem
    
    164 188
         , pkgs ? mkPkgs sources system
    
    165 189
         }: rec {
    
    ... ... @@ -171,4 +195,4 @@ let
    171 195
         };
    
    172 196
     
    
    173 197
     in
    
    174
    -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
    198
    +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); }

  • .gitlab/darwin/toolchain.nix
    ... ... @@ -11,69 +11,67 @@ let
    11 11
       hsPkgs = pkgs.haskellPackages;
    
    12 12
       alex = hsPkgs.alex;
    
    13 13
       happy = hsPkgs.happy;
    
    14
    -  targetTriple = pkgs.stdenv.targetPlatform.config;
    
    14
    +  targetTriple = pkgs.stdenvNoCC.targetPlatform.config;
    
    15 15
     
    
    16 16
       ghcBindists = let version = ghc.version; in {
    
    17
    -    aarch64-darwin = hostPkgs.fetchurl {
    
    17
    +    aarch64-darwin = hostPkgs.fetchzip {
    
    18 18
           url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-aarch64-apple-darwin.tar.xz";
    
    19
    -      sha256 = "sha256-/6+DtdeossBJIMbjkJwL4h3eJ7rzgNCV+ifoQKOi6AQ=";
    
    19
    +      hash = "sha512-xUlt7zc/OT3a1SR0BxmFFgrabPkWUENATdw4NbQwEi5+nH5yPau+HSrGI5UUoKdO4gdpgZlPaxtI7eSk0fx1+g==";
    
    20 20
         };
    
    21
    -    x86_64-darwin = hostPkgs.fetchurl {
    
    21
    +    x86_64-darwin = hostPkgs.fetchzip {
    
    22 22
           url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-x86_64-apple-darwin.tar.xz";
    
    23
    -      sha256 = "sha256-jPIhiJMOENesUnDUJeIaPatgavc6ZVSTY5NFIAxlC+k=";
    
    23
    +      hash = "sha512-4/INeJwPPGbOj9MepwnIvIg2lvFkqS8w/3U/I8f6gCsoNlgwPr78iyY9vd6vfMONR1GxNQU3L/lxE07F3P0Qag==";
    
    24 24
         };
    
    25
    -
    
    26 25
       };
    
    27 26
     
    
    28
    -  ghc = pkgs.stdenv.mkDerivation rec {
    
    29
    -    version = "9.10.1";
    
    27
    +  ghc = pkgs.stdenvNoCC.mkDerivation rec {
    
    28
    +    version = "9.10.3";
    
    30 29
         name = "ghc";
    
    31
    -    src = ghcBindists.${pkgs.stdenv.hostPlatform.system};
    
    30
    +    src = ghcBindists.${pkgs.stdenvNoCC.hostPlatform.system};
    
    31
    +
    
    32
    +    dontUpdateAutotoolsGnuConfigScripts = true;
    
    33
    +
    
    32 34
         configureFlags = [
    
    33
    -      "CC=/usr/bin/clang"
    
    34
    -      "CLANG=/usr/bin/clang"
    
    35 35
           "AR=/usr/bin/ar"
    
    36
    -      "LLC=${llvm}/bin/llc"
    
    37
    -      "OPT=${llvm}/bin/opt"
    
    38
    -      "LLVMAS=${llvm_clang}/bin/clang"
    
    39
    -      "CONF_CC_OPTS_STAGE2=--target=${targetTriple}"
    
    40
    -      "CONF_CXX_OPTS_STAGE2=--target=${targetTriple}"
    
    41
    -      "CONF_GCC_LINKER_OPTS_STAGE2=--target=${targetTriple}"
    
    36
    +      "CC=/usr/bin/clang"
    
    37
    +      "CXX=/usr/bin/clang++"
    
    38
    +      "INSTALL=/usr/bin/install"
    
    39
    +      "INSTALL_NAME_TOOL=/usr/bin/install_name_tool"
    
    40
    +      "MergeObjsCmd=/usr/bin/ld"
    
    41
    +      "NM=/usr/bin/nm"
    
    42
    +      "OTOOL=/usr/bin/otool"
    
    43
    +      "RANLIB=/usr/bin/ranlib"
    
    42 44
         ];
    
    43
    -    buildPhase = "true";
    
    44
    -
    
    45
    -    # This is a horrible hack because the configure script invokes /usr/bin/clang
    
    46
    -    # without a `--target` flag. Then depending on whether the `nix` binary itself is
    
    47
    -    # a native x86 or arm64 binary means that /usr/bin/clang thinks it needs to run in
    
    48
    -    # x86 or arm64 mode.
    
    49
    -
    
    50
    -    # The correct answer for the check in question is the first one we try, so by replacing
    
    51
    -    # the condition to true; we select the right C++ standard library still.
    
    52
    -    preConfigure = ''
    
    53
    -      sed "s/\"\$CC\" -o actest actest.o \''${1} 2>\/dev\/null/true/i" configure > configure.new
    
    54
    -      mv configure.new configure
    
    55
    -      chmod +x configure
    
    56
    -      cat configure
    
    57 45
     
    
    46
    +    # Use the arch command to explicitly specify architecture, so that
    
    47
    +    # configure and its subprocesses would pick up the architecture we
    
    48
    +    # choose via the system argument.
    
    49
    +    preConfigure = pkgs.lib.optionalString (system == "aarch64-darwin") ''
    
    50
    +      substituteInPlace configure \
    
    51
    +        --replace-fail "#! /bin/sh" "#!/usr/bin/env -S /usr/bin/arch -arm64 /bin/sh"
    
    52
    +    '' + pkgs.lib.optionalString (system == "x86_64-darwin") ''
    
    53
    +      substituteInPlace configure \
    
    54
    +        --replace-fail "#! /bin/sh" "#!/usr/bin/env -S /usr/bin/arch -x86_64 /bin/sh"
    
    55
    +    '' + ''
    
    56
    +      unset DEVELOPER_DIR SDKROOT
    
    57
    +      export DEVELOPER_DIR="$(/usr/bin/xcode-select --print-path)"
    
    58
    +      export SDKROOT="$(/usr/bin/xcrun --sdk macosx --show-sdk-path)"
    
    58 59
         '';
    
    59 60
     
    
    61
    +    dontPatchShebangsInConfigure = true;
    
    62
    +
    
    60 63
         # N.B. Work around #20253.
    
    61 64
         nativeBuildInputs = [ pkgs.gnused ];
    
    62
    -    postInstallPhase = ''
    
    63
    -      settings="$out/lib/ghc-${version}/settings"
    
    64
    -      sed -i -e "s%\"llc\"%\"${llvm}/bin/llc\"%" $settings
    
    65
    -      sed -i -e "s%\"opt\"%\"${llvm}/bin/opt\"%" $settings
    
    66
    -      sed -i -e "s%\"clang\"%\"/usr/bin/clang\"%" $settings
    
    67
    -      sed -i -e 's%("C compiler command", "")%("C compiler command", "/usr/bin/clang")%' $settings
    
    68
    -      sed -i -e 's%("C compiler flags", "")%("C compiler flags", "--target=${targetTriple}")%' $settings
    
    69
    -      sed -i -e 's%("C++ compiler flags", "")%("C++ compiler flags", "--target=${targetTriple}")%' $settings
    
    70
    -      sed -i -e 's%("C compiler link flags", "")%("C compiler link flags", "--target=${targetTriple}")%' $settings
    
    71
    -    '';
    
    65
    +
    
    66
    +    dontBuild = true;
    
    67
    +
    
    68
    +    enableParallelInstalling = true;
    
    69
    +
    
    70
    +    dontFixup = true;
    
    72 71
     
    
    73 72
         # Sanity check: verify that we can compile hello world.
    
    74 73
         doInstallCheck = true;
    
    75 74
         installCheckPhase = ''
    
    76
    -      unset DYLD_LIBRARY_PATH
    
    77 75
           $out/bin/ghc --info
    
    78 76
           cd $TMP
    
    79 77
           mkdir test-ghc; cd test-ghc
    
    ... ... @@ -91,13 +89,13 @@ let
    91 89
       ourtexlive = with pkgs;
    
    92 90
         texlive.combine {
    
    93 91
           inherit (texlive)
    
    94
    -        scheme-medium collection-xetex fncychap titlesec tabulary varwidth
    
    92
    +        scheme-small collection-xetex fncychap tex-gyre titlesec tabulary varwidth
    
    95 93
             framed capt-of wrapfig needspace dejavu-otf helvetic upquote;
    
    96 94
         };
    
    97 95
       fonts = with pkgs; makeFontsConf { fontDirectories = [ dejavu_fonts ]; };
    
    98 96
     
    
    99
    -  llvm = pkgs.llvm_15;
    
    100
    -  llvm_clang = pkgs.llvmPackages_15.clang-unwrapped;
    
    97
    +  llvm = pkgs.llvm_21;
    
    98
    +  llvm_clang = pkgs.llvmPackages_21.clang-unwrapped;
    
    101 99
     in
    
    102 100
     pkgs.writeTextFile {
    
    103 101
       name = "toolchain";
    

  • .gitlab/generate-ci/gen_ci.hs
    ... ... @@ -1250,7 +1250,7 @@ alpine_x86 =
    1250 1250
       , fullyStaticBrokenTests (disableValidate (allowFailureGroup (standardBuildsWithConfig Amd64 (Linux Alpine312) staticNativeInt)))
    
    1251 1251
         -- Dynamically linked build, suitable for building your own static executables on alpine
    
    1252 1252
       , disableValidate (standardBuildsWithConfig Amd64 (Linux Alpine323) (splitSectionsBroken vanilla))
    
    1253
    -  , allowFailureGroup (standardBuildsWithConfig I386 (Linux Alpine323) (splitSectionsBroken vanilla))
    
    1253
    +  , standardBuildsWithConfig I386 (Linux Alpine323) (splitSectionsBroken vanilla)
    
    1254 1254
       ]
    
    1255 1255
       where
    
    1256 1256
         -- ghcilink002 broken due to #17869
    

  • .gitlab/jobs.yaml
    ... ... @@ -484,7 +484,7 @@
    484 484
           ".gitlab/ci.sh clean",
    
    485 485
           "cat ci_timings.txt"
    
    486 486
         ],
    
    487
    -    "allow_failure": true,
    
    487
    +    "allow_failure": false,
    
    488 488
         "artifacts": {
    
    489 489
           "expire_in": "2 weeks",
    
    490 490
           "paths": [
    
    ... ... @@ -1155,7 +1155,7 @@
    1155 1155
           ".gitlab/ci.sh clean",
    
    1156 1156
           "cat ci_timings.txt"
    
    1157 1157
         ],
    
    1158
    -    "allow_failure": true,
    
    1158
    +    "allow_failure": false,
    
    1159 1159
         "artifacts": {
    
    1160 1160
           "expire_in": "8 weeks",
    
    1161 1161
           "paths": [
    
    ... ... @@ -4034,7 +4034,7 @@
    4034 4034
           ".gitlab/ci.sh clean",
    
    4035 4035
           "cat ci_timings.txt"
    
    4036 4036
         ],
    
    4037
    -    "allow_failure": true,
    
    4037
    +    "allow_failure": false,
    
    4038 4038
         "artifacts": {
    
    4039 4039
           "expire_in": "1 year",
    
    4040 4040
           "paths": [
    

  • compiler/GHC.hs
    ... ... @@ -719,7 +719,7 @@ setTopSessionDynFlags dflags = do
    719 719
                           { interpCreateProcess = createIservProcessHook (hsc_hooks hsc_env)
    
    720 720
                           }
    
    721 721
     
    
    722
    -  interp <- liftIO $ initInterpreter tmpfs logger platform finder_cache unit_env interp_opts
    
    722
    +  interp <- liftIO $ initInterpreter dflags tmpfs logger platform finder_cache unit_env interp_opts
    
    723 723
     
    
    724 724
       modifySession $ \h -> hscSetFlags dflags
    
    725 725
                             h{ hsc_IC = (hsc_IC h){ ic_dflags = dflags }
    

  • compiler/GHC/CmmToLlvm/CodeGen.hs
    ... ... @@ -248,6 +248,14 @@ Since x86 PDep/PExt instructions only exist for 32/64 bit widths
    248 248
     we use the 32bit variant to compute the 8/16bit primops.
    
    249 249
     To do so we extend/truncate the argument/result around the
    
    250 250
     call.
    
    251
    +
    
    252
    +Note that the 64-bit intrinsics (`llvm.x86.bmi.pdep.64` and
    
    253
    +`llvm.x86.bmi.pext.64`) are only legal on 64-bit x86 targets, not on
    
    254
    +i386. Therefore on i386 we must fall back to the runtime helper
    
    255
    +(`hs_pdep64`/`hs_pext64`) for the 64-bit primops.
    
    256
    +
    
    257
    +See https://github.com/llvm/llvm-project/issues/172857 for upstream
    
    258
    +discussion about portable pdep/pext intrinsics.
    
    251 259
     -}
    
    252 260
     genCall (PrimTarget op@(MO_Pdep w)) [dst] args = do
    
    253 261
         cfg <- getConfig
    
    ... ... @@ -970,36 +978,34 @@ cmmPrimOpFunctions mop = do
    970 978
               W8   -> fsLit "llvm.x86.bmi.pdep.32"
    
    971 979
               W16  -> fsLit "llvm.x86.bmi.pdep.32"
    
    972 980
               W32  -> fsLit "llvm.x86.bmi.pdep.32"
    
    973
    -          W64  -> fsLit "llvm.x86.bmi.pdep.64"
    
    974
    -          W128 -> fsLit "llvm.x86.bmi.pdep.128"
    
    975
    -          W256 -> fsLit "llvm.x86.bmi.pdep.256"
    
    976
    -          W512 -> fsLit "llvm.x86.bmi.pdep.512"
    
    981
    +          W64
    
    982
    +            | is32bit   -> fsLit "hs_pdep64"
    
    983
    +            | otherwise -> fsLit "llvm.x86.bmi.pdep.64"
    
    984
    +          -- LLVM only provides x86 PDep/PExt intrinsics for 32/64 bits
    
    985
    +          _ -> unsupported
    
    977 986
           | otherwise -> case w of
    
    978 987
               W8   -> fsLit "hs_pdep8"
    
    979 988
               W16  -> fsLit "hs_pdep16"
    
    980 989
               W32  -> fsLit "hs_pdep32"
    
    981 990
               W64  -> fsLit "hs_pdep64"
    
    982
    -          W128 -> fsLit "hs_pdep128"
    
    983
    -          W256 -> fsLit "hs_pdep256"
    
    984
    -          W512 -> fsLit "hs_pdep512"
    
    991
    +          _ -> unsupported
    
    985 992
         MO_Pext w
    
    986 993
           | isBmi2Enabled -> case w of
    
    987 994
               -- See Note [LLVM PDep/PExt intrinsics]
    
    988 995
               W8   -> fsLit "llvm.x86.bmi.pext.32"
    
    989 996
               W16  -> fsLit "llvm.x86.bmi.pext.32"
    
    990 997
               W32  -> fsLit "llvm.x86.bmi.pext.32"
    
    991
    -          W64  -> fsLit "llvm.x86.bmi.pext.64"
    
    992
    -          W128 -> fsLit "llvm.x86.bmi.pext.128"
    
    993
    -          W256 -> fsLit "llvm.x86.bmi.pext.256"
    
    994
    -          W512 -> fsLit "llvm.x86.bmi.pext.512"
    
    998
    +          W64
    
    999
    +            | is32bit   -> fsLit "hs_pext64"
    
    1000
    +            | otherwise -> fsLit "llvm.x86.bmi.pext.64"
    
    1001
    +          -- LLVM only provides x86 PDep/PExt intrinsics for 32/64 bits
    
    1002
    +          _ -> unsupported
    
    995 1003
           | otherwise -> case w of
    
    996 1004
               W8   -> fsLit "hs_pext8"
    
    997 1005
               W16  -> fsLit "hs_pext16"
    
    998 1006
               W32  -> fsLit "hs_pext32"
    
    999 1007
               W64  -> fsLit "hs_pext64"
    
    1000
    -          W128 -> fsLit "hs_pext128"
    
    1001
    -          W256 -> fsLit "hs_pext256"
    
    1002
    -          W512 -> fsLit "hs_pext512"
    
    1008
    +          _ -> unsupported
    
    1003 1009
     
    
    1004 1010
         MO_AddIntC w    -> case w of
    
    1005 1011
           W8   -> fsLit "llvm.sadd.with.overflow.i8"
    

  • compiler/GHC/Driver/Session.hs
    ... ... @@ -197,6 +197,8 @@ module GHC.Driver.Session (
    197 197
             -- * Compiler configuration suitable for display to the user
    
    198 198
             compilerInfo,
    
    199 199
     
    
    200
    +        targetHasRTSWays,
    
    201
    +
    
    200 202
             wordAlignment,
    
    201 203
     
    
    202 204
             setUnsafeGlobalDynFlags,
    
    ... ... @@ -3635,6 +3637,15 @@ compilerInfo dflags
    3635 3637
         queryCmdMaybe p f = expandDirectories (query (maybe "" (prgPath . p) . f))
    
    3636 3638
         queryFlagsMaybe p f = query (maybe "" (unwords . map escapeArg . prgFlags . p) . f)
    
    3637 3639
     
    
    3640
    +-- | Query if the target RTS has the given 'Ways'. It's computed from
    
    3641
    +-- the @"RTS ways"@ field in the settings file.
    
    3642
    +targetHasRTSWays :: DynFlags -> Ways -> Bool
    
    3643
    +targetHasRTSWays dflags ways
    
    3644
    +  | Just ws <- lookup "RTS ways" $ compilerInfo dflags =
    
    3645
    +      waysTag ways
    
    3646
    +        `elem` words ws
    
    3647
    +  | otherwise = panic "RTS ways not found in settings"
    
    3648
    +
    
    3638 3649
     -- Note [Special unit-ids]
    
    3639 3650
     -- ~~~~~~~~~~~~~~~~~~~~~~~
    
    3640 3651
     -- Certain units are special to the compiler:
    

  • compiler/GHC/Runtime/Interpreter/C.hs
    ... ... @@ -8,7 +8,9 @@ where
    8 8
     
    
    9 9
     import GHC.Prelude
    
    10 10
     import GHC.Platform
    
    11
    +import GHC.Platform.Ways
    
    11 12
     import GHC.Data.FastString
    
    13
    +import GHC.Driver.Session
    
    12 14
     import GHC.Utils.Logger
    
    13 15
     import GHC.Utils.TmpFs
    
    14 16
     import GHC.Unit.Types
    
    ... ... @@ -18,11 +20,10 @@ import GHC.Unit.State
    18 20
     import GHC.Utils.Panic.Plain
    
    19 21
     import GHC.Linker.Executable
    
    20 22
     import GHC.Linker.Config
    
    21
    -import GHC.Utils.CliOption
    
    22 23
     
    
    23 24
     -- | Generate iserv program for the target
    
    24
    -generateIservC :: Logger -> TmpFs -> ExecutableLinkOpts -> UnitEnv -> IO FilePath
    
    25
    -generateIservC logger tmpfs opts unit_env = do
    
    25
    +generateIservC :: DynFlags -> Logger -> TmpFs -> ExecutableLinkOpts -> UnitEnv -> IO FilePath
    
    26
    +generateIservC dflags logger tmpfs opts unit_env = do
    
    26 27
       -- get the unit-id of the ghci package. We need this to load the
    
    27 28
       -- interpreter code.
    
    28 29
       let unit_state = ue_homeUnitState unit_env
    
    ... ... @@ -60,6 +61,12 @@ generateIservC logger tmpfs opts unit_env = do
    60 61
               -- must retain CAFs for running interpreted code.
    
    61 62
             , leKeepCafs = True
    
    62 63
     
    
    64
    +          -- link with -threaded if target has threaded RTS
    
    65
    +        , leWays =
    
    66
    +            let ways = leWays opts
    
    67
    +                ways' = addWay WayThreaded ways
    
    68
    +            in if targetHasRTSWays dflags ways' then ways' else ways
    
    69
    +
    
    63 70
               -- enable all rts options
    
    64 71
             , leRtsOptsEnabled = RtsOptsAll
    
    65 72
     
    

  • compiler/GHC/Runtime/Interpreter/Init.hs
    ... ... @@ -9,6 +9,7 @@ where
    9 9
     
    
    10 10
     
    
    11 11
     import GHC.Prelude
    
    12
    +import GHC.Driver.DynFlags
    
    12 13
     import GHC.Platform
    
    13 14
     import GHC.Platform.Ways
    
    14 15
     import GHC.Settings
    
    ... ... @@ -57,14 +58,15 @@ data InterpOpts = InterpOpts
    57 58
     
    
    58 59
     -- | Initialize code interpreter
    
    59 60
     initInterpreter
    
    60
    -  :: TmpFs
    
    61
    +  :: DynFlags
    
    62
    +  -> TmpFs
    
    61 63
       -> Logger
    
    62 64
       -> Platform
    
    63 65
       -> FinderCache
    
    64 66
       -> UnitEnv
    
    65 67
       -> InterpOpts
    
    66 68
       -> IO (Maybe Interp)
    
    67
    -initInterpreter tmpfs logger platform finder_cache unit_env opts = do
    
    69
    +initInterpreter dflags tmpfs logger platform finder_cache unit_env opts = do
    
    68 70
     
    
    69 71
       lookup_cache  <- liftIO $ mkInterpSymbolCache
    
    70 72
     
    
    ... ... @@ -125,7 +127,7 @@ initInterpreter tmpfs logger platform finder_cache unit_env opts = do
    125 127
               dynamic  = interpWays opts `hasWay` WayDyn
    
    126 128
             prog <- case interpProg opts of
    
    127 129
               -- build iserv program if none specified
    
    128
    -          "" -> generateIservC logger tmpfs (interpExecutableLinkOpts opts) unit_env
    
    130
    +          "" -> generateIservC dflags logger tmpfs (interpExecutableLinkOpts opts) unit_env
    
    129 131
               _ -> pure (interpProg opts ++ flavour)
    
    130 132
                 where
    
    131 133
                   flavour
    

  • hadrian/src/Packages.hs
    ... ... @@ -217,7 +217,7 @@ timeoutPath = "testsuite/timeout/install-inplace/bin/timeout" <.> exe
    217 217
     -- TODO: Can we extract this information from Cabal files?
    
    218 218
     -- | Some program packages should not be linked with Haskell main function.
    
    219 219
     nonHsMainPackage :: Package -> Bool
    
    220
    -nonHsMainPackage = (`elem` [hp2ps, iserv, unlit, ghciWrapper])
    
    220
    +nonHsMainPackage = (`elem` [hp2ps, unlit, ghciWrapper])
    
    221 221
     
    
    222 222
     
    
    223 223
     {-
    

  • hadrian/src/Rules/Gmp.hs
    ... ... @@ -126,6 +126,12 @@ gmpRules = do
    126 126
                     interpretInContext ctx $
    
    127 127
                     mconcat
    
    128 128
                         [ getStagedCCFlags
    
    129
    +                    -- gmp fails to configure with newer compilers
    
    130
    +                    -- that default to c23:
    
    131
    +                    -- https://gmplib.org/list-archives/gmp-devel/2025-January/006279.html.
    
    132
    +                    -- for now just manually specify -std=gnu11 until
    
    133
    +                    -- next upstream release.
    
    134
    +                    , arg "-std=gnu11"
    
    129 135
                         -- gmp symbols are only used by bignum logic in
    
    130 136
                         -- ghc-internal and shouldn't be exported by the
    
    131 137
                         -- ghc-internal shared library.
    

  • hadrian/src/Settings/Packages.hs
    ... ... @@ -41,6 +41,8 @@ packageArgs = do
    41 41
         libzstdLibraryDir <- getSetting LibZstdLibDir
    
    42 42
         stageVersion <- readVersion <$> (expr $ ghcVersionStage stage)
    
    43 43
     
    
    44
    +    rtsWays <- getRtsWays
    
    45
    +
    
    44 46
         mconcat
    
    45 47
             --------------------------------- base ---------------------------------
    
    46 48
             [ package base ? mconcat
    
    ... ... @@ -185,11 +187,15 @@ packageArgs = do
    185 187
             --
    
    186 188
             -- The Solaris linker does not support --export-dynamic option. It also
    
    187 189
             -- does not need it since it exports all dynamic symbols by default
    
    188
    -        , package iserv
    
    189
    -          ? expr isElfTarget
    
    190
    +        , package iserv ? mconcat [
    
    191
    +            expr isElfTarget
    
    190 192
               ? notM (expr $ anyTargetOs [OSFreeBSD, OSSolaris2])? mconcat
    
    191 193
               [ builder (Ghc LinkHs) ? arg "-optl-Wl,--export-dynamic" ]
    
    192 194
     
    
    195
    +            -- Link iserv with -threaded if possible
    
    196
    +          , builder (Cabal Flags) ? any (wayUnit Threaded) rtsWays `cabalFlag` "threaded"
    
    197
    +        ]
    
    198
    +
    
    193 199
             -------------------------------- haddock -------------------------------
    
    194 200
             , package haddockApi ?
    
    195 201
               builder (Cabal Flags) ? arg "in-ghc-tree"
    

  • libraries/ghc-internal/configure.ac
    ... ... @@ -195,28 +195,10 @@ dnl--------------------------------------------------------------------
    195 195
        if test "$HaveFrameworkGMP" = "YES" || test "$HaveLibGmp" = "YES"
    
    196 196
        then
    
    197 197
            AC_MSG_RESULT([no])
    
    198
    -       UseIntreeGmp=0
    
    199 198
            AC_CHECK_HEADER([gmp.h], , [AC_MSG_ERROR([Cannot find gmp.h])])
    
    200
    -
    
    201
    -       AC_MSG_CHECKING([GMP version])
    
    202
    -       AC_COMPUTE_INT(GhcGmpVerMj, __GNU_MP_VERSION, [#include <gmp.h>],
    
    203
    -           AC_MSG_ERROR([Unable to get value of __GNU_MP_VERSION]))
    
    204
    -       AC_COMPUTE_INT(GhcGmpVerMi, __GNU_MP_VERSION_MINOR, [#include <gmp.h>],
    
    205
    -           AC_MSG_ERROR([Unable to get value of __GNU_MP_VERSION_MINOR]))
    
    206
    -       AC_COMPUTE_INT(GhcGmpVerPl, __GNU_MP_VERSION_PATCHLEVEL, [#include <gmp.h>],
    
    207
    -           AC_MSG_ERROR([Unable to get value of __GNU_MP_VERSION_PATCHLEVEL]))
    
    208
    -       AC_MSG_RESULT([$GhcGmpVerMj.$GhcGmpVerMi.$GhcGmpVerPl])
    
    209
    -
    
    210 199
        else
    
    211 200
            AC_MSG_RESULT([yes])
    
    212
    -       UseIntreeGmp=1
    
    213 201
            HaveSecurePowm=1
    
    214
    -
    
    215
    -       AC_MSG_CHECKING([GMP version])
    
    216
    -       GhcGmpVerMj=6
    
    217
    -       GhcGmpVerMi=1
    
    218
    -       GhcGmpVerPl=2
    
    219
    -       AC_MSG_RESULT([$GhcGmpVerMj.$GhcGmpVerMi.$GhcGmpVerPl])
    
    220 202
        fi
    
    221 203
     
    
    222 204
        GMP_INSTALL_INCLUDES="HsIntegerGmp.h ghc-gmp.h"
    
    ... ... @@ -231,10 +213,6 @@ AC_SUBST(GMP_INSTALL_INCLUDES)
    231 213
     AC_SUBST(HaveLibGmp)
    
    232 214
     AC_SUBST(HaveFrameworkGMP)
    
    233 215
     AC_SUBST(HaveSecurePowm)
    
    234
    -AC_SUBST(UseIntreeGmp)
    
    235
    -AC_SUBST(GhcGmpVerMj)
    
    236
    -AC_SUBST(GhcGmpVerMi)
    
    237
    -AC_SUBST(GhcGmpVerPl)
    
    238 216
     
    
    239 217
     # Compute offsets/sizes used by jsbits/base.js
    
    240 218
     if test "$host" = "javascript-ghcjs"
    

  • libraries/ghc-internal/include/HsIntegerGmp.h.in
    1 1
     #pragma once
    
    2 2
     
    
    3
    -/* Whether GMP is embedded into ghc-internal */
    
    4
    -#define GHC_GMP_INTREE     @UseIntreeGmp@
    
    5
    -
    
    6
    -/* The following values denote the GMP version used during GHC build-time */
    
    7
    -#define GHC_GMP_VERSION_MJ @GhcGmpVerMj@
    
    8
    -#define GHC_GMP_VERSION_MI @GhcGmpVerMi@
    
    9
    -#define GHC_GMP_VERSION_PL @GhcGmpVerPl@
    
    10
    -#define GHC_GMP_VERSION \
    
    11
    -    (@GhcGmpVerMj@ * 10000 + @GhcGmpVerMi@ * 100 + @GhcGmpVerPl@)
    
    12
    -
    
    13 3
     /* Whether GMP supports mpz_powm_sec */
    
    14 4
     #define HAVE_SECURE_POWM @HaveSecurePowm@

  • utils/iserv/cbits/iservmain.c deleted
    1
    -#include <ghcversion.h>
    
    2
    -#  include <rts/PosixSource.h>
    
    3
    -#include <Rts.h>
    
    4
    -
    
    5
    -#include <HsFFI.h>
    
    6
    -
    
    7
    -int main (int argc, char *argv[])
    
    8
    -{
    
    9
    -    RtsConfig conf = defaultRtsConfig;
    
    10
    -
    
    11
    -    // We never know what symbols GHC will look up in the future, so
    
    12
    -    // we must retain CAFs for running interpreted code.
    
    13
    -    conf.keep_cafs = 1;
    
    14
    -
    
    15
    -    conf.rts_opts_enabled = RtsOptsAll;
    
    16
    -    extern StgClosure ZCMain_main_closure;
    
    17
    -    hs_main(argc, argv, &ZCMain_main_closure, conf);
    
    18
    -}

  • utils/iserv/iserv.cabal.in
    ... ... @@ -23,11 +23,17 @@ Category: Development
    23 23
     build-type: Simple
    
    24 24
     cabal-version: >=1.10
    
    25 25
     
    
    26
    +Flag threaded
    
    27
    +    Description: Link the iserv executable against the threaded RTS
    
    28
    +    Default: True
    
    29
    +    Manual: True
    
    30
    +
    
    26 31
     Executable iserv
    
    27 32
         Default-Language: Haskell2010
    
    28
    -    ghc-options: -no-hs-main
    
    33
    +    ghc-options: -fkeep-cafs -rtsopts
    
    34
    +    if flag(threaded)
    
    35
    +      ghc-options: -threaded
    
    29 36
         Main-Is: Main.hs
    
    30
    -    C-Sources: cbits/iservmain.c
    
    31 37
         Hs-Source-Dirs: src
    
    32 38
         include-dirs: .
    
    33 39
         Build-Depends: