IntersectMBO / plutus

The Plutus language implementation and tools
Apache License 2.0
1.57k stars 479 forks source link

Support non-patched GHC outside of haskell.nix #4298

Closed kk-hainq closed 2 years ago

kk-hainq commented 2 years ago

Describe the feature you'd like

We would like to build anything that depends on plutus (notably things that depend on plutus-apps) with non-patched GHC outside of haskell.nix.

This repository is using a patched GHC: https://github.com/input-output-hk/plutus/blob/be021b6195a72a7ab6c2c5a898ab8a5cb0680506/nix/pkgs/haskell/default.nix#L31-L34

Which didn't have any API conflicts with non-patched GHCs until #4165 introduced GenTickish. This essentially forces the same patched GHC for every code base that has plutus as a dependency in any way, even when no Tickish machinery or even Plutus compilation is required. For example, a chain index client that only reads and prints data cannot be compiled by standard GHCs. This is not nice (see https://github.com/input-output-hk/plutus-apps/issues/180).

Not very clean, but a potential fix is just:

--- a/plutus-tx-plugin/src/PlutusTx/Compiler/Expr.hs
+++ b/plutus-tx-plugin/src/PlutusTx/Compiler/Expr.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP               #-}
 {-# LANGUAGE ConstraintKinds   #-}
 {-# LANGUAGE FlexibleContexts  #-}
 {-# LANGUAGE LambdaCase        #-}
@@ -59,6 +60,15 @@ import Data.Text qualified as T
 import Data.Text.Encoding qualified as TE
 import Data.Traversable

+-- Patched GHC from haskell.nix
+-- with experimental core interface files patch,
+-- and a fix for unboxed tuples in GHCi for HLS support.
+#if __GLASGOW_HASKELL_PATCHLEVEL2__ == 20210212
+type Tickish = GHC.GenTickish
+#else
+type Tickish = GHC.Tickish
+#endif
+
 {- Note [System FC and System FW]
 Haskell uses system FC, which includes type equalities and coercions.

@@ -852,7 +862,7 @@ compileExpr e = withContextM 2 (sdToTxt $ "Compiling expr:" GHC.<+> GHC.ppr e) $

 -- | Do your best to try to extract a source span from a tick
 -- See Note [What source locations to cover]
-getSourceSpan :: Maybe GHC.ModBreaks -> GHC.GenTickish pass -> Maybe GHC.RealSrcSpan
+getSourceSpan :: Maybe GHC.ModBreaks -> Tickish pass -> Maybe GHC.RealSrcSpan
 getSourceSpan _ GHC.SourceNote{GHC.sourceSpan=src} = Just src
 getSourceSpan _ GHC.ProfNote{GHC.profNoteCC=cc} =
   case cc of

Describe alternatives you've considered

We either have to Nixify all related codebases or maintain an ad-hoc GHC to bump or use plutus and related dependencies. Both are not desirable in several cases.

I guess something like:

nix-env -iA hix -f https://github.com/input-output-hk/haskell.nix/tarball/master
hix-shell --argstr compiler-nix-name ghc810420210212 --run 'cabal build'

Also counts. It's still Nix & patched GHC, but at least without the .nix files.

michaelpj commented 2 years ago

This is caused by https://github.com/input-output-hk/haskell.nix/issues/1280, which is indeed annoying.

@angerman it would be nice to fix that, so things at least build with unpatched GHCs.

angerman commented 2 years ago

It's on the agenda to get vanilla GHCs in.

michaelpj commented 2 years ago

Workaround merged, but it would be good to fix this in haskell.nix, in particular the workaround is fragile and will break if we update our GHC.