Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build with ghc(js) 9.8.2 + 9.10.1 #502

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

ymeister
Copy link
Contributor

@ymeister ymeister commented Aug 3, 2024

Needs reflex-frp/patch#56.


For haskell.nix:
default.nix:

let deps = {
      "haskell.nix" = builtins.fetchTarball {
        url = "https://github.com/input-output-hk/haskell.nix/archive/d8c50dcaf3d3d589829ee9be9d5dba8279b8cc59.tar.gz";
        sha256 = "0a5hgryz6nszmy67yf1aks399h2aw0nj845518c4prs5c6ns1z7p";
      };
      patch = pkgs.fetchFromGitHub {
        owner = "ymeister";
        repo = "patch";
        rev = "2170c364450d5827a21dbcd817131d5def6e4767";
        sha256 = "0cnk89h3z0xkfa7jyz9ihycvpa0ak8kyslfl7labkwf6qi3qh80s";
      };
    };

    haskellNix = import deps."haskell.nix" {};

    # Import nixpkgs and pass the haskell.nix provided nixpkgsArgs
    pkgs = import
      # haskell.nix provides access to the nixpkgs pins which are used by our CI,
      # hence you will be more likely to get cache hits when using these.
      # But you can also just use your own, e.g. '<nixpkgs>'.
      haskellNix.sources.nixpkgs-unstable
      # These arguments passed to nixpkgs, include some patches and also
      # the haskell.nix functionality itself as an overlay.
      haskellNix.nixpkgsArgs;

    source-repository-packages = packages:
      builtins.zipAttrsWith
        (k: vs:
          if k == "cabalProjectLocal" then pkgs.lib.strings.concatStringsSep "\n" vs
          else builtins.zipAttrsWith (_: pkgs.lib.lists.last) vs
        )
        (pkgs.lib.lists.forEach packages (p:
          let input = builtins.unsafeDiscardStringContext p;
          in {
            inputMap."${input}" = { name = builtins.baseNameOf p; outPath = p; rev = "HEAD"; };
            cabalProjectLocal = ''
              source-repository-package
                type: git
                location: ${input}
                tag: HEAD
            '';
          }
        ));

    haskellDeps = source-repository-packages [
      deps.patch
    ];

    project = pkgs: pkgs.haskell-nix.project {
      src = ./.;

      inherit (haskellDeps) inputMap cabalProjectLocal;

      shell.withHaddock = if pkgs.stdenv.hostPlatform.isGhcjs then false else true;

      compiler-nix-name = "ghc910";
    };

in {
  ghc = project pkgs;
  ghc-js = project pkgs.pkgsCross.ghcjs;
}

shell.nix:

let projects = import ./default.nix;
    project = projects.ghc;
    pkgs = project.pkgs;
in project.shellFor {
  tools = {
    cabal = "latest";
  };

  buildInputs = with pkgs; [
    nodejs-slim_latest
  ];

  # Sellect cross compilers to include.
  crossPlatforms = ps: with ps; [
    ghcjs # Adds support for `javascript-unknown-ghcjs-cabal build` in the shell
  ];

  shellHook = ''
    function setup_cabal_to_nix {
      cabal_project_drv="$(nix-store -q --references "${project.plan-nix.drvPath}" | grep ".*-cabal.project.drv" - | head -n 1)"
      [ ! -z "$cabal_project_drv" ] && cabal_project_out="$(nix-store -q --outputs "$cabal_project_drv" | head -n 1)"
      [ ! -z "$cabal_project_out" ] && \cp -f "$cabal_project_out" cabal.project.local && chmod u+w cabal.project.local

      if [ -f cabal.project.local ]; then
        mkdir -p .nix
        store_paths="$(cat cabal.project.local | sed -n 's#.*\(/nix/store/.*\)#\1#p')"
        echo "$store_paths" | while read store_path; do
          target=".nix/$(echo "$store_path" | sed -n 's#/nix/store/\(.*\)#\1#p' | sed 's#/#-#g')"
          [ ! -e "$target" ] && cp -rf "$store_path" "$target" && chmod u+w -R "$target"
          sed -i "s#$store_path#$(readlink -f "$target")#g" cabal.project.local
        done
      fi
    }

    setup_cabal_to_nix 1> /dev/null
  '';
}

For nixpkgs:

From patch PR:

When building on ghc js, requires single-core building (https://gitlab.haskell.org/ghc/ghc/-/issues/25083#note_578275).

For nix:

patch = haskellLib.overrideCabal (drv: { enableParallelBuilding = false; }) super.patch;

@ymeister ymeister changed the title Build with ghc(js) 9.10 Build with ghc(js)-9.10 Aug 4, 2024
@ymeister ymeister changed the title Build with ghc(js)-9.10 Build with ghc(js) 9.8.2 + 9.10.1 Aug 7, 2024
@ymeister ymeister force-pushed the ghc(js)-9.10 branch 2 times, most recently from 313a9b1 to b62dfbc Compare August 7, 2024 04:49
@ymeister
Copy link
Contributor Author

ymeister commented Aug 7, 2024

Needs reflex-frp/patch#56 to be in hackage to pass the CI.

@Ericson2314
Copy link
Member

Hoping to land #499 first to separate warnings/cabal cleanup vs new versions a bit.

Ericson2314 added a commit that referenced this pull request Sep 27, 2024
PR #502 contains some other orthogonal cleanups.
Ericson2314 added a commit that referenced this pull request Sep 27, 2024
PR #502 contains some other orthogonal cleanups.
Ericson2314 added a commit that referenced this pull request Sep 27, 2024
PR #502 contains some other orthogonal cleanups.
@@ -679,15 +678,12 @@ instance (Reflex t, IsString a) => IsString (Behavior t a) where

instance Reflex t => Monad (Behavior t) where
a >>= f = pull $ sample a >>= sample . f
-- Note: it is tempting to write (_ >> b = b); however, this would result in (fail x >> return y) succeeding (returning y), which violates the law that (a >> b = a >>= \_ -> b), since the implementation of (>>=) above actually will fail. Since we can't examine 'Behavior's other than by using sample, I don't think it's possible to write (>>) to be more efficient than the (>>=) above.
Copy link
Member

@alexfmpe alexfmpe Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryantrinkle is this concern gone now that MonadFail got pulled out?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we could use the simpler implementation now.

Comment on lines +43 to +64
install :: [CommandLineOption] -> [CoreToDo] -> CoreM [CoreToDo]
install [] p = do
liftIO $ putStrLn $ showSDocUnsafe $ ppr p
let f = \case
simpl@(CoreDoSimplify _) -> [CoreDoSpecialising, simpl]
x -> [x]
return $ makeInlinable : concatMap f p
install options@(_:_) p = do
msg MCInfo $ "Reflex.Optimizer: ignoring " <> fromString (show $ length options) <> " command-line options"
install [] p

makeInlinable :: CoreToDo
makeInlinable = CoreDoPluginPass "MakeInlinable" $ \modGuts -> do
let f v = setIdInfo v $ let i = idInfo v in
setInlinePragInfo i $ let p = inlinePragInfo i in
if isDefaultInlinePragma p
then defaultInlinePragma { inl_inline = Inlinable (inl_src p) }
else p
newBinds = flip map (mg_binds modGuts) $ \case
NonRec b e -> NonRec (f b) e
Rec bes -> Rec $ map (first f) bes
return $ modGuts { mg_binds = newBinds }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why duplicate this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They differ for different GHC versions:

simpl@(CoreDoSimplify _ _) -> [CoreDoSpecialising, simpl]

vs
simpl@(CoreDoSimplify _) -> [CoreDoSpecialising, simpl]

then defaultInlinePragma { inl_inline = Inlinable (inl_src p) }

vs
then defaultInlinePragma { inl_inline = Inlinable }

You could of course separate the common logic and reuse in both, but IMO time spent on trying to do so is simply not worth it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just delete "Reflex Optimizer" completely. It never really worked very well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants