From 193f916bdb76a432736897652fcd2ceeb432c0a7 Mon Sep 17 00:00:00 2001 From: "L. S. Leary" Date: Sun, 10 Feb 2019 10:36:11 +1300 Subject: [PATCH 01/18] Repinned and refactored nix files such that nix can actually build grin. --- default.nix | 18 ++++++++++ grin/default.nix | 41 --------------------- nix/free.nix | 20 ----------- nix/llvm-hs-pretty.nix | 20 ----------- nix/llvm-hs-pure.nix | 20 ----------- nix/llvm-hs.nix | 26 -------------- nix/llvm.nix | 11 ++++++ nix/pkgs.nix | 8 +++++ shell.nix | 82 +++++------------------------------------- 9 files changed, 45 insertions(+), 201 deletions(-) create mode 100644 default.nix delete mode 100644 grin/default.nix delete mode 100644 nix/free.nix delete mode 100644 nix/llvm-hs-pretty.nix delete mode 100644 nix/llvm-hs-pure.nix delete mode 100644 nix/llvm-hs.nix create mode 100644 nix/llvm.nix create mode 100644 nix/pkgs.nix diff --git a/default.nix b/default.nix new file mode 100644 index 00000000..598d76e0 --- /dev/null +++ b/default.nix @@ -0,0 +1,18 @@ +{ pkgs ? import nix/pkgs.nix }: + +let + hlib = pkgs.haskell.lib; + hpkg = pkgs.haskell.packages.ghc844; +in + +hpkg.developPackage { + root = ./grin; + overrides = self: super: { + Diff = hlib.dontCheck super.Diff; + llvm-hs = super.llvm-hs.override (oa: { + llvm-config = pkgs.llvm_7; + }); + }; + modifier = drv: hlib.addBuildTool drv (import nix/llvm.nix {}); + returnShellEnv = false; +} diff --git a/grin/default.nix b/grin/default.nix deleted file mode 100644 index a1d2558d..00000000 --- a/grin/default.nix +++ /dev/null @@ -1,41 +0,0 @@ -{ Diff, mkDerivation, ansi-wl-pprint, base, bimap, bytestring, comonad -, containers, criterion, deepseq, directory, extra, filepath, free -, functor-infix, generic-random, ghc, ghc-paths, haskeline, hspec -, hspec-discover, llvm-hs, llvm-hs-pretty, llvm-hs-pure -, logict, megaparsec, microlens, microlens-mtl, microlens-platform -, microlens-th, monad-gen, mtl, neat-interpolation -, optparse-applicative, pretty-show, pretty-simple, process -, QuickCheck, quickcheck-instances, recursion-schemes, set-extra -, stdenv, template-haskell, text, text-short -, transformers, unix, vector -}: -mkDerivation { - pname = "grin"; - version = "0.1.0.0"; - src = ./.; - isLibrary = true; - isExecutable = true; - libraryHaskellDepends = [ - Diff ansi-wl-pprint base bimap bytestring comonad containers deepseq - directory extra filepath free functor-infix generic-random ghc - hspec llvm-hs llvm-hs-pretty llvm-hs-pure logict megaparsec - microlens microlens-mtl microlens-platform microlens-th monad-gen - mtl neat-interpolation optparse-applicative pretty-show - pretty-simple process QuickCheck quickcheck-instances recursion-schemes - set-extra template-haskell text text-short transformers vector - ]; - executableHaskellDepends = [ - ansi-wl-pprint base containers directory filepath ghc ghc-paths - haskeline llvm-hs-pretty megaparsec microlens microlens-mtl - microlens-platform microlens-th mtl optparse-applicative - pretty-show pretty-simple process recursion-schemes text - transformers unix - ]; - testHaskellDepends = [ - base containers deepseq functor-infix hspec hspec-discover - QuickCheck vector - ]; - benchmarkHaskellDepends = [ base criterion ]; - homepage = "https://github.com/githubuser/grin#readme"; - license = stdenv.lib.licenses.bsd3; -} diff --git a/nix/free.nix b/nix/free.nix deleted file mode 100644 index 958978b6..00000000 --- a/nix/free.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ mkDerivation, base, bifunctors, comonad, containers, distributive -, exceptions, mtl, prelude-extras, profunctors, semigroupoids -, semigroups, stdenv, template-haskell, transformers -, transformers-compat -}: -mkDerivation { - pname = "free"; - version = "4.12.4"; - sha256 = "c9fe45aae387855626ecb5a0fea6afdb207143cb00af3b1f715d1032d2d08784"; - revision = "2"; - editedCabalFile = "0gmib9bmswrqhl47cp5b871v9f44v9yidzxpljkszy49y9qdf560"; - libraryHaskellDepends = [ - base bifunctors comonad containers distributive exceptions mtl - prelude-extras profunctors semigroupoids semigroups - template-haskell transformers transformers-compat - ]; - homepage = "http://github.com/ekmett/free/"; - description = "Monads for free"; - license = stdenv.lib.licenses.bsd3; -} diff --git a/nix/llvm-hs-pretty.nix b/nix/llvm-hs-pretty.nix deleted file mode 100644 index e412b501..00000000 --- a/nix/llvm-hs-pretty.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ mkDerivation, array, base, bytestring, directory, filepath -, llvm-hs, llvm-hs-pure, mtl, pretty-show, stdenv, tasty -, tasty-golden, tasty-hspec, tasty-hunit, text, transformers -, wl-pprint-text -}: -mkDerivation { - pname = "llvm-hs-pretty"; - version = "0.2.0.0"; - sha256 = "90ce478f6386f836e3b646186c4fe4d72598cc938d8fbb150718a1bbf4f4738c"; - libraryHaskellDepends = [ - array base bytestring llvm-hs-pure text wl-pprint-text - ]; - testHaskellDepends = [ - base directory filepath llvm-hs llvm-hs-pure mtl pretty-show tasty - tasty-golden tasty-hspec tasty-hunit text transformers - ]; - homepage = "https://github.com/llvm-hs/llvm-hs-pretty"; - description = "Pretty printer for LLVM IR"; - license = stdenv.lib.licenses.mit; -} diff --git a/nix/llvm-hs-pure.nix b/nix/llvm-hs-pure.nix deleted file mode 100644 index 7c52a0f9..00000000 --- a/nix/llvm-hs-pure.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ mkDerivation, attoparsec, base, bytestring, containers, fail -, hspec, mtl, stdenv, tasty, tasty-hunit, tasty-quickcheck -, template-haskell, text, transformers, unordered-containers -}: -mkDerivation { - pname = "llvm-hs-pure"; - version = "5.1.2"; - sha256 = "c4d0993aacda72107e6d34865421f128b8c27b586b95a68e2a3e94700645d954"; - libraryHaskellDepends = [ - attoparsec base bytestring containers fail mtl template-haskell - transformers unordered-containers - ]; - testHaskellDepends = [ - base bytestring containers hspec mtl tasty tasty-hunit - tasty-quickcheck text transformers unordered-containers - ]; - homepage = "http://github.com/llvm-hs/llvm-hs/"; - description = "Pure Haskell LLVM functionality (no FFI)"; - license = stdenv.lib.licenses.bsd3; -} diff --git a/nix/llvm-hs.nix b/nix/llvm-hs.nix deleted file mode 100644 index edea0e0f..00000000 --- a/nix/llvm-hs.nix +++ /dev/null @@ -1,26 +0,0 @@ -{ mkDerivation, array, attoparsec, base, bytestring, Cabal -, containers, exceptions, llvm-config, llvm-hs-pure, mtl -, pretty-show, QuickCheck, stdenv, tasty, tasty-hunit -, tasty-quickcheck, template-haskell, temporary, transformers -, utf8-string -}: -mkDerivation { - pname = "llvm-hs"; - version = "5.1.3"; - sha256 = "ccdac4683f56135ba83ed0883231f686d1784e9bc7f072a34fcf041e0661976b"; - revision = "1"; - editedCabalFile = "0r8xgz6r2miw1l3az343jwz8f9jgzqywxnzl2xhanv05g3i462yh"; - setupHaskellDepends = [ base Cabal containers ]; - libraryHaskellDepends = [ - array attoparsec base bytestring containers exceptions llvm-hs-pure - mtl template-haskell transformers utf8-string - ]; - libraryToolDepends = [ llvm-config ]; - testHaskellDepends = [ - base bytestring containers llvm-hs-pure mtl pretty-show QuickCheck - tasty tasty-hunit tasty-quickcheck temporary transformers - ]; - homepage = "http://github.com/llvm-hs/llvm-hs/"; - description = "General purpose LLVM bindings"; - license = stdenv.lib.licenses.bsd3; -} diff --git a/nix/llvm.nix b/nix/llvm.nix new file mode 100644 index 00000000..a8c389cc --- /dev/null +++ b/nix/llvm.nix @@ -0,0 +1,11 @@ +{ pkgs ? import ./pkgs.nix }: + +pkgs.runCommand + "llvm-7-links" + { buildInputs = [ pkgs.llvm_7 ]; } + '' + mkdir -p $out/bin + cd $out/bin + ln -s ${pkgs.llvm_7}/bin/llc llc-7 + ln -s ${pkgs.llvm_7}/bin/opt opt-7 + '' diff --git a/nix/pkgs.nix b/nix/pkgs.nix new file mode 100644 index 00000000..b9c74793 --- /dev/null +++ b/nix/pkgs.nix @@ -0,0 +1,8 @@ +let + pinned = (import {}).fetchFromGitHub { + owner = "NixOS"; + repo = "nixpkgs-channels"; + rev = "ffc604e55790dbf575187738e1c3778231e8f5a9"; + sha256 = "1kw37ab6abkrjn65zhh0jcnfb3bzk1p14d178sp8489kn9gxy12v"; + }; +in import pinned {} diff --git a/shell.nix b/shell.nix index 256a363e..c10737f8 100644 --- a/shell.nix +++ b/shell.nix @@ -1,74 +1,8 @@ -{ fetchFromGitHub ? (import {}).fetchFromGitHub -# peg nix packages to specific version -, pkgs ? - import - ( fetchFromGitHub - { - owner = "NixOS"; - repo = "nixpkgs-channels"; - rev = "696c6bed4e8e2d9fd9b956dea7e5d49531e9d13f"; - sha256 = "1v3yrpj542niyxp0h3kffsdjwlrkvj0mg4ljb85d142gyn3sdzd4"; - } - ) {} -}: -let - # extract the Haskell dependencies of a package - extractHaskellDependencies = (hpkg: - with builtins; - let - isHaskellPkg = x: (isAttrs x) && (x ? pname) && (x ? version) && (x ? env); - packagesFromDrv = x: - let - inputs = - (x.buildInputs or []) ++ - (x.nativeBuildInputs or []) ++ - (x.propagatedBuildInputs or []) ++ - (x.propagatedNativeBuildInputs or []); - - in - (filter isHaskellPkg inputs); - go1 = s: xs: foldl' go2 s xs; - go2 = s: x: - if s ? "${x.pname}" - then s - else go1 (s // {"${x.pname}" = x;}) (packagesFromDrv x); - in assert isAttrs hpkg; attrNames (go1 {} (packagesFromDrv hpkg))); - - # Haskell custom overrides - haskellPackages = pkgs.haskell.packages.ghc822.override (old: - { overrides = self: super: - { - free = self.callPackage ./nix/free.nix {}; - functor-infix = pkgs.haskell.lib.doJailbreak (super.functor-infix); - llvm-hs = self.callPackage ./nix/llvm-hs.nix {llvm-config = pkgs.llvm_5;}; - llvm-hs-pure = self.callPackage ./nix/llvm-hs-pure.nix {}; - llvm-hs-pretty = pkgs.haskell.lib.dontCheck (self.callPackage ./nix/llvm-hs-pretty.nix {}); - }; - }); - - # the grin package - grin = pkgs.haskellPackages.callPackage ./grin {}; - # grin's dependencies - grinDeps = extractHaskellDependencies grin; - # use a GHC with all the Hakell dependencies and the documentation for them and a Hoogle server to search them - ghcWith = haskellPackages.ghcWithHoogle (hs: map (x: builtins.getAttr x hs) grinDeps); - - llc5 = pkgs.runCommand "llc5" - { - buildInputs = [pkgs.llvm_5]; - } - '' - mkdir -p $out/bin - cd $out/bin - ln -s ${pkgs.llvm_5}/bin/llc llc-5.0 - ''; -in -# environment setup with all the needed tools -pkgs.runCommand "grin-shell" - { - shellHook = '' - eval $(egrep ^export ${ghcWith}/bin/ghc) - ''; - buildInputs = [ghcWith llc5 pkgs.llvm_5 haskellPackages.cabal-install]; - } - "touch $out" +{ pkgs ? import nix/pkgs.nix }: + +let grin = import ./. { inherit pkgs; }; +in pkgs.haskell.packages.ghc844.shellFor { + withHoogle = true; + packages = p: [ grin ]; + inherit (grin.env) nativeBuildInputs; +} From 64dffc82de03ac88aa538ac497235a847caf935a Mon Sep 17 00:00:00 2001 From: "L. S. Leary" Date: Sun, 10 Feb 2019 10:42:05 +1300 Subject: [PATCH 02/18] Migrate megaparsec from 6.5 to 7. --- grin/app/GrinCLI.hs | 2 +- grin/grin.cabal | 4 ++-- grin/src/Grin/Parse.hs | 2 +- grin/src/Grin/Parse/AST.hs | 10 +++++----- grin/src/Grin/Parse/Basic.hs | 8 ++++---- grin/src/Grin/Parse/TypeEnv.hs | 6 +++--- grin/src/Grin/TH.hs | 2 +- grin/src/Pipeline/Eval.hs | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/grin/app/GrinCLI.hs b/grin/app/GrinCLI.hs index 31ee796c..967586f4 100644 --- a/grin/app/GrinCLI.hs +++ b/grin/app/GrinCLI.hs @@ -159,7 +159,7 @@ main = do ((,) Nothing . Nametable.restore) <$> Binary.decodeFile fname else do content <- Text.readFile fname - let (typeEnv, program') = either (error . M.parseErrorPretty' content) id $ parseGrinWithTypes fname content + let (typeEnv, program') = either (error . M.errorBundlePretty) id $ parseGrinWithTypes fname content pure $ (Just typeEnv, if noPrelude then program' else concatPrograms [primPrelude, program']) let opts = defaultOpts { _poOutputDir = outputDir, _poFailOnLint = True, _poLogging = not quiet, _poSaveBinary = saveBinary } case steps of diff --git a/grin/grin.cabal b/grin/grin.cabal index 448c53dc..6544664c 100644 --- a/grin/grin.cabal +++ b/grin/grin.cabal @@ -124,7 +124,7 @@ library bimap, mtl, comonad, - megaparsec, + megaparsec ==7.0.*, pretty-show, vector, deepseq, @@ -175,7 +175,7 @@ executable grin , grin , recursion-schemes , ansi-wl-pprint - , megaparsec + , megaparsec ==7.0.* , containers , process , pretty-show diff --git a/grin/src/Grin/Parse.hs b/grin/src/Grin/Parse.hs index a5c9fad5..d3dda555 100644 --- a/grin/src/Grin/Parse.hs +++ b/grin/src/Grin/Parse.hs @@ -14,5 +14,5 @@ import Grin.TypeEnvDefs import Grin.Parse.AST import Grin.Parse.TypeEnv -parseGrinWithTypes :: String -> Text -> Either (ParseError Char Void) (TypeEnv, Exp) +parseGrinWithTypes :: String -> Text -> Either (ParseErrorBundle Text Void) (TypeEnv, Exp) parseGrinWithTypes filename content = (,) <$> parseMarkedTypeEnv filename content <*> parseGrin filename content diff --git a/grin/src/Grin/Parse/AST.hs b/grin/src/Grin/Parse/AST.hs index 0c74d15c..23792cb6 100644 --- a/grin/src/Grin/Parse/AST.hs +++ b/grin/src/Grin/Parse/AST.hs @@ -95,7 +95,7 @@ literal = (try $ LFloat . realToFrac <$> signedFloat) <|> (try $ LInt64 . fromIntegral <$> signedInteger) <|> (try $ LBool <$> (True <$ kw "#True" <|> False <$ kw "#False")) <|> (try $ LString <$> lexeme (C.char '#' *> quotedString)) <|> - (try $ LChar <$> lexeme (C.string "#'" *> (escaped <|> anyChar) <* C.char '\'')) + (try $ LChar <$> lexeme (C.string "#'" *> (escaped <|> anySingle) <* C.char '\'')) satisfyM :: (a -> Bool) -> Parser a -> Parser a satisfyM pred parser = do @@ -138,17 +138,17 @@ tyP = grinModule :: Parser Exp grinModule = Program <$> (concat <$> many (try externalBlock)) <*> many def <* sc <* eof -parseGrin :: String -> Text -> Either (ParseError Char Void) Exp +parseGrin :: String -> Text -> Either (ParseErrorBundle Text Void) Exp parseGrin filename content = runParser grinModule filename (withoutTypeAnnots content) parseProg :: Text -> Exp -parseProg src = either (error . parseErrorPretty' src) id . parseGrin "" $ withoutTypeAnnots src +parseProg src = either (error . errorBundlePretty) id . parseGrin "" $ withoutTypeAnnots src parseDef :: Text -> Exp -parseDef src = either (error . parseErrorPretty' src) id . runParser def "" $ withoutTypeAnnots src +parseDef src = either (error . errorBundlePretty) id . runParser def "" $ withoutTypeAnnots src parseExpr :: Text -> Exp -parseExpr src = either (error . parseErrorPretty' src) id . runParser (expr pos1) "" $ withoutTypeAnnots src +parseExpr src = either (error . errorBundlePretty) id . runParser (expr pos1) "" $ withoutTypeAnnots src withoutTypeAnnots :: Text -> Text diff --git a/grin/src/Grin/Parse/Basic.hs b/grin/src/Grin/Parse/Basic.hs index a6ccc280..2372df66 100644 --- a/grin/src/Grin/Parse/Basic.hs +++ b/grin/src/Grin/Parse/Basic.hs @@ -95,8 +95,8 @@ set p = Set.fromList <$> bracedList p set1 :: Ord a => Parser a -> Parser (Set a) set1 p = Set.fromList <$> bracedList p -anySingle :: MonadParsec e s m => m (Token s) -anySingle = satisfy (const True) +-- anySingle :: MonadParsec e s m => m (Token s) +-- anySingle = satisfy (const True) anySingleBut :: MonadParsec e s m => Token s -> m (Token s) anySingleBut t = satisfy (/= t) @@ -108,7 +108,7 @@ escaped :: Parser Char escaped = string "\\\"" >> pure '"' quotedVar :: Parser Name -quotedVar = packName <$ char '"' <*> someTill (escaped <|> anyChar) (char '"') +quotedVar = packName <$ char '"' <*> someTill (escaped <|> anySingle) (char '"') escapedStringChar :: Parser Char escapedStringChar = @@ -123,7 +123,7 @@ escapedStringChar = (string "\\v" >> pure '\v') quotedString :: Parser Text -quotedString = fromString <$> (char '"' *> manyTill (escapedStringChar <|> anyChar) (char '"')) +quotedString = fromString <$> (char '"' *> manyTill (escapedStringChar <|> anySingle) (char '"')) simpleVar :: Parser Name simpleVar = (\c s -> packName $ c : s) <$> oneOf allowedInitial <*> many (alphaNumChar <|> oneOf allowedSpecial) diff --git a/grin/src/Grin/Parse/TypeEnv.hs b/grin/src/Grin/Parse/TypeEnv.hs index e62ce831..eb134874 100644 --- a/grin/src/Grin/Parse/TypeEnv.hs +++ b/grin/src/Grin/Parse/TypeEnv.hs @@ -113,15 +113,15 @@ entriesToTypeEnv xs = flip execState emptyTypeEnv $ do -- parses a type environment (without code) parseTypeEnv :: Text -> TypeEnv -parseTypeEnv src = either (error . parseErrorPretty' src) id +parseTypeEnv src = either (error . errorBundlePretty) id . runParser typeEnv "" $ src -- parses type marked type annotations (even interleaved with code) parseMarkedTypeEnv' :: Text -> TypeEnv -parseMarkedTypeEnv' src = either (error . parseErrorPretty' src) id $ parseMarkedTypeEnv "" src +parseMarkedTypeEnv' src = either (error . errorBundlePretty) id $ parseMarkedTypeEnv "" src -parseMarkedTypeEnv :: String -> Text -> Either (ParseError Char Void) TypeEnv +parseMarkedTypeEnv :: String -> Text -> Either (ParseErrorBundle Text Void) TypeEnv parseMarkedTypeEnv filename src = runParser markedTypeEnv filename (withoutCodeLines src) withoutCodeLines :: Text -> Text diff --git a/grin/src/Grin/TH.hs b/grin/src/Grin/TH.hs index 8d44969c..eb493234 100644 --- a/grin/src/Grin/TH.hs +++ b/grin/src/Grin/TH.hs @@ -51,7 +51,7 @@ progConst = QuasiQuoter { quoteExp = \input -> do let src = T.pack $ normalizeQQInput input case P.parseGrin "" src of - Left e -> fail $ parseErrorPretty' src e + Left e -> fail (errorBundlePretty e) Right p -> liftDataWithText p , quotePat = undefined , quoteType = undefined diff --git a/grin/src/Pipeline/Eval.hs b/grin/src/Pipeline/Eval.hs index b2e23b9d..58d94f85 100644 --- a/grin/src/Pipeline/Eval.hs +++ b/grin/src/Pipeline/Eval.hs @@ -29,7 +29,7 @@ eval' :: Reducer -> String -> IO RTVal eval' reducer fname = do content <- Text.readFile fname case parseGrin fname content of - Left err -> error $ parseErrorPretty' content err + Left err -> error (errorBundlePretty err) Right program -> case reducer of PureReducer -> Reducer.Pure.reduceFun program "grinMain" From c0ceacc7667b8b3e10e8dbf09c515827fd0891b2 Mon Sep 17 00:00:00 2001 From: "L. S. Leary" Date: Sun, 10 Feb 2019 10:50:19 +1300 Subject: [PATCH 03/18] Migrate QuickCheck from 2.11 to 2.12. --- grin/grin.cabal | 4 ++-- grin/src/Test/Test.hs | 2 +- grin/test/Transformations/Optimising/ConstantFoldingSpec.hs | 4 ++-- .../Transformations/Simplifying/CaseSimplificationSpec.hs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/grin/grin.cabal b/grin/grin.cabal index 6544664c..f12d103a 100644 --- a/grin/grin.cabal +++ b/grin/grin.cabal @@ -155,7 +155,7 @@ library hspec-core, extra, logict, - QuickCheck, + QuickCheck ==2.12.*, quickcheck-instances, neat-interpolation, template-haskell, @@ -205,7 +205,7 @@ test-suite grin-test , hspec , hspec-core , hspec-discover - , QuickCheck + , QuickCheck ==2.12.* , deepseq , vector , text diff --git a/grin/src/Test/Test.hs b/grin/src/Test/Test.hs index bdbc368b..56b7d5e0 100644 --- a/grin/src/Test/Test.hs +++ b/grin/src/Test/Test.hs @@ -903,4 +903,4 @@ instance Solve G.Prog where _ -> mzero changed :: (Testable prop) => Exp -> Exp -> prop -> Property -changed old new = cover (old /= new) 1 "Transformation has effect" +changed old new = cover 1 (old /= new) "Transformation has effect" diff --git a/grin/test/Transformations/Optimising/ConstantFoldingSpec.hs b/grin/test/Transformations/Optimising/ConstantFoldingSpec.hs index 76ea5c30..7eb86438 100644 --- a/grin/test/Transformations/Optimising/ConstantFoldingSpec.hs +++ b/grin/test/Transformations/Optimising/ConstantFoldingSpec.hs @@ -132,8 +132,8 @@ smallerThan transformed original = let sizeReduced = programSize transformed sizeOriginal = programSize original in - cover (sizeReduced == sizeOriginal) 0 "Non Reduced" $ - cover (sizeReduced < sizeOriginal) 1 "Reduced" $ + cover 0 (sizeReduced == sizeOriginal) "Non Reduced" $ + cover 1 (sizeReduced < sizeOriginal) "Reduced" $ (sizeReduced <= sizeOriginal) checkUniqueNames :: Exp -> Property diff --git a/grin/test/Transformations/Simplifying/CaseSimplificationSpec.hs b/grin/test/Transformations/Simplifying/CaseSimplificationSpec.hs index b38951dc..647a0b50 100644 --- a/grin/test/Transformations/Simplifying/CaseSimplificationSpec.hs +++ b/grin/test/Transformations/Simplifying/CaseSimplificationSpec.hs @@ -71,7 +71,7 @@ spec = do varTagCover :: Exp -> Property -> Property varTagCover exp = within 10000000 {-microsecond-} . - cover (getAny $ valuesInCases (Any . isVarTagNode) exp) 1 "Case with VarTagNode" + cover 1 (getAny $ valuesInCases (Any . isVarTagNode) exp) "Case with VarTagNode" programSizeDoesNotChange :: Exp -> Property programSizeDoesNotChange exp = varTagCover exp $ unchangedSize exp $ caseSimplification exp From 60fce1c120072ac56e433c8f99f3def53366affc Mon Sep 17 00:00:00 2001 From: "L. S. Leary" Date: Sun, 10 Feb 2019 10:52:03 +1300 Subject: [PATCH 04/18] Misc. --- grin/app/GrinCLI.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grin/app/GrinCLI.hs b/grin/app/GrinCLI.hs index 967586f4..21769f5d 100644 --- a/grin/app/GrinCLI.hs +++ b/grin/app/GrinCLI.hs @@ -12,7 +12,7 @@ import Options.Applicative import Grin.Grin import Grin.PrimOpsPrelude -import Grin.Parse hiding (value) +import Grin.Parse -- hiding (value) import Grin.Nametable as Nametable import Pipeline.Pipeline From 9927dcd99bbfe9f2f94dec515d342f16683d1a9b Mon Sep 17 00:00:00 2001 From: "L. S. Leary" Date: Mon, 11 Feb 2019 00:06:07 +1300 Subject: [PATCH 05/18] Get building with stack too (partial work). --- default.nix | 5 ++++- stack.yaml | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/default.nix b/default.nix index 598d76e0..ca00fbf5 100644 --- a/default.nix +++ b/default.nix @@ -13,6 +13,9 @@ hpkg.developPackage { llvm-config = pkgs.llvm_7; }); }; - modifier = drv: hlib.addBuildTool drv (import nix/llvm.nix {}); + modifier = drv: hlib.addBuildTools drv [ + (import nix/llvm.nix {}) + pkgs.llvm_7 + ]; returnShellEnv = false; } diff --git a/stack.yaml b/stack.yaml index 088a22dc..8a2b8eb8 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: nightly-2018-11-07 +resolver: nightly-2019-02-09 # due to functor-infix allow-newer: true @@ -16,8 +16,6 @@ extra-deps: - monad-gen-0.3.0.1 - functor-infix-0.0.5 - QuickCheck-GenT-0.2.0 - - megaparsec-6.5.0 - - neat-interpolation-0.3.2.2 - set-extra-1.4.1 - llvm-hs-pretty-0.6.1.0 From 044f8643cb28bc622c49bad236e9da4e6eac967d Mon Sep 17 00:00:00 2001 From: Luc Tielen Date: Sun, 8 Dec 2019 11:52:14 +0100 Subject: [PATCH 06/18] Add end2end test output to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5c9255bb..af377e61 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ output/ *.agdai .output .grin-output/ +grin/.end-to-end-test/ .vscode/ *.out *.out.ll From 9aceda4d00a3efc2c2bb685efa4d7af6fceafb63 Mon Sep 17 00:00:00 2001 From: Luc Tielen Date: Sun, 8 Dec 2019 11:55:28 +0100 Subject: [PATCH 07/18] Pin to newer nixpkgs commit --- default.nix | 1 + nix/pkgs.nix | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/default.nix b/default.nix index ca00fbf5..10bc67f8 100644 --- a/default.nix +++ b/default.nix @@ -12,6 +12,7 @@ hpkg.developPackage { llvm-hs = super.llvm-hs.override (oa: { llvm-config = pkgs.llvm_7; }); + llvm-hs-pretty = hlib.unmarkBroken super.llvm-hs-pretty; }; modifier = drv: hlib.addBuildTools drv [ (import nix/llvm.nix {}) diff --git a/nix/pkgs.nix b/nix/pkgs.nix index b9c74793..b8a8ec34 100644 --- a/nix/pkgs.nix +++ b/nix/pkgs.nix @@ -1,8 +1,8 @@ let - pinned = (import {}).fetchFromGitHub { - owner = "NixOS"; - repo = "nixpkgs-channels"; - rev = "ffc604e55790dbf575187738e1c3778231e8f5a9"; - sha256 = "1kw37ab6abkrjn65zhh0jcnfb3bzk1p14d178sp8489kn9gxy12v"; + commit = "2adf2d615cf8f6c6be49a0e54dc9ebf551dcf70f"; + pinned = builtins.fetchTarball { + name = "nixpkgs-19.09"; + url = "https://github.com/nixos/nixpkgs/archive/${commit}.tar.gz"; + sha256 = "0w8zgj38di4ssw6s0bxdb9rgksqfszsa3304863xic4bzsvkql9b"; }; in import pinned {} From d2ff162ad465e8d01508c62a6fa2ad85832ec0ca Mon Sep 17 00:00:00 2001 From: Luc Tielen Date: Sun, 8 Dec 2019 11:55:50 +0100 Subject: [PATCH 08/18] Add clang-7 as dependency --- default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/default.nix b/default.nix index 10bc67f8..7ad132fa 100644 --- a/default.nix +++ b/default.nix @@ -16,6 +16,7 @@ hpkg.developPackage { }; modifier = drv: hlib.addBuildTools drv [ (import nix/llvm.nix {}) + pkgs.clang_7 pkgs.llvm_7 ]; returnShellEnv = false; From 08e0bd3567656e9b2d68956528ac7f3e9e2f4b2f Mon Sep 17 00:00:00 2001 From: Luc Tielen Date: Sun, 8 Dec 2019 17:19:56 +0100 Subject: [PATCH 09/18] Add more files to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index af377e61..4935ed89 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ cabal.sandbox.config *.eventlog .stack-work/ cabal.project.local +cabal.project.local~ .HTF/ output/ *.ibc @@ -29,3 +30,4 @@ grin/.end-to-end-test/ *.out *.out.ll *.out.s +.ghc.environment.* From a2dfd1cded41adb9321651ffe56cf72a47c2e8e0 Mon Sep 17 00:00:00 2001 From: Luc Tielen Date: Sun, 8 Dec 2019 17:20:16 +0100 Subject: [PATCH 10/18] Update Diff dependency --- grin/grin.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grin/grin.cabal b/grin/grin.cabal index 7f1f6e12..f31975bb 100644 --- a/grin/grin.cabal +++ b/grin/grin.cabal @@ -166,7 +166,7 @@ library quickcheck-instances, neat-interpolation, template-haskell, - Diff, + Diff == 0.4.*, random, set-extra, deepseq, From 835678650c2690c71017d107639c1461b92329aa Mon Sep 17 00:00:00 2001 From: Luc Tielen Date: Sun, 8 Dec 2019 17:22:59 +0100 Subject: [PATCH 11/18] Use GHC865 with nix, point to same llvm-hs fork as stack --- default.nix | 9 +++++---- nix/llvm-hs-pretty.nix | 19 +++++++++++++++++++ nix/llvm-hs.nix | 7 +++++++ shell.nix | 2 +- 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 nix/llvm-hs-pretty.nix create mode 100644 nix/llvm-hs.nix diff --git a/default.nix b/default.nix index 7ad132fa..177a0ae8 100644 --- a/default.nix +++ b/default.nix @@ -2,17 +2,18 @@ let hlib = pkgs.haskell.lib; - hpkg = pkgs.haskell.packages.ghc844; + hpkg = pkgs.haskell.packages.ghc865; + llvm-hs = import ./nix/llvm-hs.nix; in hpkg.developPackage { root = ./grin; overrides = self: super: { - Diff = hlib.dontCheck super.Diff; - llvm-hs = super.llvm-hs.override (oa: { + llvm-hs = hlib.dontCheck (self.callCabal2nix "llvm-hs" "${llvm-hs}/llvm-hs" { llvm-config = pkgs.llvm_7; }); - llvm-hs-pretty = hlib.unmarkBroken super.llvm-hs-pretty; + llvm-hs-pure = self.callCabal2nix "llvm-hs-pure" "${llvm-hs}/llvm-hs-pure" {}; + llvm-hs-pretty = self.callPackage ./nix/llvm-hs-pretty.nix {}; }; modifier = drv: hlib.addBuildTools drv [ (import nix/llvm.nix {}) diff --git a/nix/llvm-hs-pretty.nix b/nix/llvm-hs-pretty.nix new file mode 100644 index 00000000..03b9bb35 --- /dev/null +++ b/nix/llvm-hs-pretty.nix @@ -0,0 +1,19 @@ +{ mkDerivation, array, base, bytestring, directory, filepath +, llvm-hs, llvm-hs-pure, mtl, prettyprinter, tasty, tasty-golden +, tasty-hspec, tasty-hunit, text, transformers, stdenv +}: +mkDerivation { + pname = "llvm-hs-pretty"; + version = "0.6.1.0"; + sha256 = "12w1rkkaf50jl2vdkyk4xpvjmsxzjbfkdyklaq5p6b8ykw872pda"; + libraryHaskellDepends = [ + array base bytestring llvm-hs-pure prettyprinter text + ]; + testHaskellDepends = [ + base directory filepath llvm-hs llvm-hs-pure mtl tasty tasty-golden + tasty-hspec tasty-hunit text transformers + ]; + description = "A pretty printer for LLVM IR"; + license = stdenv.lib.licenses.mit; + hydraPlatforms = stdenv.lib.platforms.none; +} diff --git a/nix/llvm-hs.nix b/nix/llvm-hs.nix new file mode 100644 index 00000000..ec6dea2c --- /dev/null +++ b/nix/llvm-hs.nix @@ -0,0 +1,7 @@ +let + url = "https://github.com/csabahruska/llvm-hs"; + ref = "llvm-7"; + rev = "868e23a13942703255979369defdb49ac57b6866"; + repo = builtins.fetchGit { inherit url ref rev; }; +in + repo diff --git a/shell.nix b/shell.nix index c10737f8..981d7045 100644 --- a/shell.nix +++ b/shell.nix @@ -1,7 +1,7 @@ { pkgs ? import nix/pkgs.nix }: let grin = import ./. { inherit pkgs; }; -in pkgs.haskell.packages.ghc844.shellFor { +in pkgs.haskell.packages.ghc865.shellFor { withHoogle = true; packages = p: [ grin ]; inherit (grin.env) nativeBuildInputs; From 0784573caceae77353e34e4e7b4c388f9d4a4f15 Mon Sep 17 00:00:00 2001 From: Luc Tielen Date: Sun, 8 Dec 2019 17:28:05 +0100 Subject: [PATCH 12/18] Always use same compiler in shell.nix and default.nix --- default.nix | 4 ++-- shell.nix | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/default.nix b/default.nix index 177a0ae8..d3a82782 100644 --- a/default.nix +++ b/default.nix @@ -1,8 +1,8 @@ -{ pkgs ? import nix/pkgs.nix }: +{ compiler ? "ghc865", pkgs ? import nix/pkgs.nix }: let hlib = pkgs.haskell.lib; - hpkg = pkgs.haskell.packages.ghc865; + hpkg = pkgs.haskell.packages."${compiler}"; llvm-hs = import ./nix/llvm-hs.nix; in diff --git a/shell.nix b/shell.nix index 981d7045..afda174f 100644 --- a/shell.nix +++ b/shell.nix @@ -1,7 +1,11 @@ { pkgs ? import nix/pkgs.nix }: -let grin = import ./. { inherit pkgs; }; -in pkgs.haskell.packages.ghc865.shellFor { +let + compiler = "ghc865"; + grin = import ./. { inherit compiler pkgs; }; +in + +pkgs.haskell.packages."${compiler}".shellFor { withHoogle = true; packages = p: [ grin ]; inherit (grin.env) nativeBuildInputs; From 16fc9ee5365b1e7b53d80d0c08d5a1fa03bd8d3e Mon Sep 17 00:00:00 2001 From: Luc Tielen Date: Sun, 8 Dec 2019 17:52:32 +0100 Subject: [PATCH 13/18] Provide cabal and ghcid when in nix-shell --- shell.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shell.nix b/shell.nix index afda174f..cc2da059 100644 --- a/shell.nix +++ b/shell.nix @@ -2,11 +2,13 @@ let compiler = "ghc865"; + hpkg = pkgs.haskell.packages."${compiler}"; grin = import ./. { inherit compiler pkgs; }; in -pkgs.haskell.packages."${compiler}".shellFor { +hpkg.shellFor { withHoogle = true; packages = p: [ grin ]; + buildInputs = with hpkg; [ cabal-install ghcid ]; inherit (grin.env) nativeBuildInputs; } From 692329a39598717f7a10c8a492ce5ab03bddfe5c Mon Sep 17 00:00:00 2001 From: Luc Tielen Date: Sun, 8 Dec 2019 18:21:01 +0100 Subject: [PATCH 14/18] Point to lts-14.16 stackage version --- stack.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stack.yaml b/stack.yaml index fd5a9caa..25a6097b 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: nightly-2019-02-09 +resolver: lts-14.16 # due to functor-infix allow-newer: true From 70625b81d87a17bcd9ce3e2dd911321d1ec4ca95 Mon Sep 17 00:00:00 2001 From: Luc Tielen Date: Tue, 10 Dec 2019 21:39:47 +0100 Subject: [PATCH 15/18] Update dependency versions --- grin/grin.cabal | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grin/grin.cabal b/grin/grin.cabal index f31975bb..2b7f082b 100644 --- a/grin/grin.cabal +++ b/grin/grin.cabal @@ -162,11 +162,11 @@ library hspec-core, extra, logict, - QuickCheck ==2.12.*, + QuickCheck ==2.13.*, quickcheck-instances, neat-interpolation, template-haskell, - Diff == 0.4.*, + Diff, random, set-extra, deepseq, @@ -214,7 +214,7 @@ test-suite grin-test , hspec , hspec-core , hspec-discover - , QuickCheck ==2.12.* + , QuickCheck ==2.13.* , deepseq , vector , text From a730ec167cc70487b5027d62ec80b708570ad4f8 Mon Sep 17 00:00:00 2001 From: Luc Tielen Date: Wed, 11 Dec 2019 20:59:17 +0100 Subject: [PATCH 16/18] Use haskell.nix to keep stack and nix approaches in sync --- default.nix | 33 +++++++++++---------------------- nix/haskell-nix-src.json | 7 +++++++ nix/haskell.nix | 8 ++++++++ nix/llvm-hs-pretty.nix | 19 ------------------- nix/llvm-hs.nix | 7 ------- nix/llvm.nix | 2 +- nix/packages.nix | 10 ++++++++++ nix/pkgs.nix | 8 -------- shell.nix | 22 ++++++++++------------ 9 files changed, 47 insertions(+), 69 deletions(-) create mode 100644 nix/haskell-nix-src.json create mode 100644 nix/haskell.nix delete mode 100644 nix/llvm-hs-pretty.nix delete mode 100644 nix/llvm-hs.nix create mode 100644 nix/packages.nix delete mode 100644 nix/pkgs.nix diff --git a/default.nix b/default.nix index d3a82782..84eb41b3 100644 --- a/default.nix +++ b/default.nix @@ -1,24 +1,13 @@ -{ compiler ? "ghc865", pkgs ? import nix/pkgs.nix }: - let - hlib = pkgs.haskell.lib; - hpkg = pkgs.haskell.packages."${compiler}"; - llvm-hs = import ./nix/llvm-hs.nix; -in - -hpkg.developPackage { - root = ./grin; - overrides = self: super: { - llvm-hs = hlib.dontCheck (self.callCabal2nix "llvm-hs" "${llvm-hs}/llvm-hs" { - llvm-config = pkgs.llvm_7; - }); - llvm-hs-pure = self.callCabal2nix "llvm-hs-pure" "${llvm-hs}/llvm-hs-pure" {}; - llvm-hs-pretty = self.callPackage ./nix/llvm-hs-pretty.nix {}; + haskell = import ./nix/haskell.nix; + llvm-overlay = self: super: { + llvm-config = self.llvm_7; }; - modifier = drv: hlib.addBuildTools drv [ - (import nix/llvm.nix {}) - pkgs.clang_7 - pkgs.llvm_7 - ]; - returnShellEnv = false; -} + extra-overlays = [ llvm-overlay ]; + pkgs = import ./nix/packages.nix (haskell // { + overlays = haskell.overlays ++ extra-overlays; + }); +in + pkgs.haskell-nix.stackProject { + src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; }; + } diff --git a/nix/haskell-nix-src.json b/nix/haskell-nix-src.json new file mode 100644 index 00000000..b7744e52 --- /dev/null +++ b/nix/haskell-nix-src.json @@ -0,0 +1,7 @@ +{ + "url": "https://github.com/input-output-hk/haskell.nix", + "rev": "ebdc0030e6973629c1ed7dba53c1b1d154c3e75e", + "date": "2019-12-11T01:12:46+00:00", + "sha256": "1q25sw8kz7r0wwzq780qq1cgsiy1g7iwnywckixa28psim8rp2nw", + "fetchSubmodules": false +} diff --git a/nix/haskell.nix b/nix/haskell.nix new file mode 100644 index 00000000..0770819d --- /dev/null +++ b/nix/haskell.nix @@ -0,0 +1,8 @@ +let + spec = builtins.fromJSON (builtins.readFile ./haskell-nix-src.json); + haskell-nix-src = builtins.fetchGit { + name = "haskell-lib"; + inherit (spec) url rev; + }; +in + import haskell-nix-src diff --git a/nix/llvm-hs-pretty.nix b/nix/llvm-hs-pretty.nix deleted file mode 100644 index 03b9bb35..00000000 --- a/nix/llvm-hs-pretty.nix +++ /dev/null @@ -1,19 +0,0 @@ -{ mkDerivation, array, base, bytestring, directory, filepath -, llvm-hs, llvm-hs-pure, mtl, prettyprinter, tasty, tasty-golden -, tasty-hspec, tasty-hunit, text, transformers, stdenv -}: -mkDerivation { - pname = "llvm-hs-pretty"; - version = "0.6.1.0"; - sha256 = "12w1rkkaf50jl2vdkyk4xpvjmsxzjbfkdyklaq5p6b8ykw872pda"; - libraryHaskellDepends = [ - array base bytestring llvm-hs-pure prettyprinter text - ]; - testHaskellDepends = [ - base directory filepath llvm-hs llvm-hs-pure mtl tasty tasty-golden - tasty-hspec tasty-hunit text transformers - ]; - description = "A pretty printer for LLVM IR"; - license = stdenv.lib.licenses.mit; - hydraPlatforms = stdenv.lib.platforms.none; -} diff --git a/nix/llvm-hs.nix b/nix/llvm-hs.nix deleted file mode 100644 index ec6dea2c..00000000 --- a/nix/llvm-hs.nix +++ /dev/null @@ -1,7 +0,0 @@ -let - url = "https://github.com/csabahruska/llvm-hs"; - ref = "llvm-7"; - rev = "868e23a13942703255979369defdb49ac57b6866"; - repo = builtins.fetchGit { inherit url ref rev; }; -in - repo diff --git a/nix/llvm.nix b/nix/llvm.nix index a8c389cc..19c19f6d 100644 --- a/nix/llvm.nix +++ b/nix/llvm.nix @@ -1,4 +1,4 @@ -{ pkgs ? import ./pkgs.nix }: +{ pkgs ? import ./packages.nix {} }: pkgs.runCommand "llvm-7-links" diff --git a/nix/packages.nix b/nix/packages.nix new file mode 100644 index 00000000..d9a729f3 --- /dev/null +++ b/nix/packages.nix @@ -0,0 +1,10 @@ +let + commit = "4c6e9a553872366e485766fa8b574b54b15957f8"; + nixpkgs = builtins.fetchTarball { + name = "nixpkgs-19.09"; + url = "https://github.com/nixos/nixpkgs/archive/${commit}.tar.gz"; + sha256 = "1az9yg2lwwfw3aypi6bdsk7ghld2963vqdp8ajkxciyxdfkaxb3b"; + }; + pkgs = import nixpkgs; +in + pkgs diff --git a/nix/pkgs.nix b/nix/pkgs.nix deleted file mode 100644 index b8a8ec34..00000000 --- a/nix/pkgs.nix +++ /dev/null @@ -1,8 +0,0 @@ -let - commit = "2adf2d615cf8f6c6be49a0e54dc9ebf551dcf70f"; - pinned = builtins.fetchTarball { - name = "nixpkgs-19.09"; - url = "https://github.com/nixos/nixpkgs/archive/${commit}.tar.gz"; - sha256 = "0w8zgj38di4ssw6s0bxdb9rgksqfszsa3304863xic4bzsvkql9b"; - }; -in import pinned {} diff --git a/shell.nix b/shell.nix index cc2da059..6cc8d1be 100644 --- a/shell.nix +++ b/shell.nix @@ -1,14 +1,12 @@ -{ pkgs ? import nix/pkgs.nix }: - let - compiler = "ghc865"; - hpkg = pkgs.haskell.packages."${compiler}"; - grin = import ./. { inherit compiler pkgs; }; + pkgs = import ./nix/packages.nix {}; + llvm-links = import ./nix/llvm.nix { inherit pkgs; }; + haskellPkgs = import ./.; in - -hpkg.shellFor { - withHoogle = true; - packages = p: [ grin ]; - buildInputs = with hpkg; [ cabal-install ghcid ]; - inherit (grin.env) nativeBuildInputs; -} + haskellPkgs.shellFor { + buildInputs = with pkgs.haskellPackages; [ + llvm-links + hlint + ghcid + ]; + } From 90a70938b853e5e1afae3dea9cae8833beaded87 Mon Sep 17 00:00:00 2001 From: Luc Tielen Date: Sat, 14 Dec 2019 10:26:19 +0100 Subject: [PATCH 17/18] Allow specifying llvm tooling via env vars --- grin/src/Pipeline/Pipeline.hs | 15 ++++++++++----- nix/llvm.nix | 11 ----------- shell.nix | 6 ++++-- 3 files changed, 14 insertions(+), 18 deletions(-) delete mode 100644 nix/llvm.nix diff --git a/grin/src/Pipeline/Pipeline.hs b/grin/src/Pipeline/Pipeline.hs index fa5192e0..d96cbd57 100644 --- a/grin/src/Pipeline/Pipeline.hs +++ b/grin/src/Pipeline/Pipeline.hs @@ -82,6 +82,7 @@ import qualified AbstractInterpretation.EffectTracking.CodeGenBase as ET import qualified AbstractInterpretation.Sharing.CodeGen as Sharing import qualified Reducer.LLVM.CodeGen as CGLLVM import qualified Reducer.LLVM.JIT as JITLLVM +import System.Environment ( lookupEnv ) import System.Directory import qualified System.Process import Data.Bifunctor @@ -718,23 +719,27 @@ saveLLVM path = do pipelineLog "* to LLVM *" void $ liftIO $ CGLLVM.toLLVM llName code pipelineLog"* LLVM X64 codegen *" - callCommand $ printf "opt-7 -O3 %s | llc-7 -o %s" llName (sName :: String) + llcExe <- liftIO $ fromMaybe "llc-7" <$> lookupEnv "GRIN_LLC" + optExe <- liftIO $ fromMaybe "opt-7" <$> lookupEnv "GRIN_OPT" + callCommand $ printf "%s -O3 %s | %s -o %s" optExe llName llcExe (sName :: String) saveExecutable :: Bool -> Path -> PipelineM () saveExecutable debugSymbols path = do pipelineLog "* generate llvm x64 optcode *" let grinOptCodePath = Rel "grin-opt-code" + clangExe <- liftIO $ fromMaybe "clang-7" <$> lookupEnv "GRIN_CC" + llcExe <- liftIO $ fromMaybe "llc-7" <$> lookupEnv "GRIN_LLC" pipelineStep $ SaveLLVM grinOptCodePath grinOptCodeFile <- relPath grinOptCodePath fname <- relPath path pipelineLog "* generate executable *" callCommand $ printf - ("llc-7 -O3 -relocation-model=pic -filetype=obj %s.ll" ++ if debugSymbols then " -debugger-tune=gdb" else "") - grinOptCodeFile + ("%s -O3 -relocation-model=pic -filetype=obj %s.ll" ++ if debugSymbols then " -debugger-tune=gdb" else "") + llcExe grinOptCodeFile cfg <- ask callCommand $ printf - ("clang-7 -O3 %s %s.o -s -o %s" ++ if debugSymbols then " -g" else "") - (intercalate " " $ _poCFiles cfg) grinOptCodeFile fname + ("%s -O3 %s %s.o -s -o %s" ++ if debugSymbols then " -g" else "") + clangExe (intercalate " " $ _poCFiles cfg) grinOptCodeFile fname debugTransformation :: (Exp -> Exp) -> PipelineM () debugTransformation t = do diff --git a/nix/llvm.nix b/nix/llvm.nix deleted file mode 100644 index 19c19f6d..00000000 --- a/nix/llvm.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ pkgs ? import ./packages.nix {} }: - -pkgs.runCommand - "llvm-7-links" - { buildInputs = [ pkgs.llvm_7 ]; } - '' - mkdir -p $out/bin - cd $out/bin - ln -s ${pkgs.llvm_7}/bin/llc llc-7 - ln -s ${pkgs.llvm_7}/bin/opt opt-7 - '' diff --git a/shell.nix b/shell.nix index 6cc8d1be..5dcd9e5e 100644 --- a/shell.nix +++ b/shell.nix @@ -1,12 +1,14 @@ let pkgs = import ./nix/packages.nix {}; - llvm-links = import ./nix/llvm.nix { inherit pkgs; }; haskellPkgs = import ./.; in haskellPkgs.shellFor { buildInputs = with pkgs.haskellPackages; [ - llvm-links hlint ghcid ]; + + GRIN_CC = "${pkgs.clang_7}/bin/clang"; + GRIN_OPT = "${pkgs.llvm_7}/bin/opt"; + GRIN_LLC = "${pkgs.llvm_7}/bin/llc"; } From fa7d5a2f0f642ae2339058911268b26b3f48c477 Mon Sep 17 00:00:00 2001 From: Luc Tielen Date: Tue, 17 Dec 2019 18:35:04 +0100 Subject: [PATCH 18/18] Minor cleanups to cabal file --- grin/app/CLI/Lib.hs | 2 +- grin/grin.cabal | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/grin/app/CLI/Lib.hs b/grin/app/CLI/Lib.hs index d1b334a7..cd452ddf 100644 --- a/grin/app/CLI/Lib.hs +++ b/grin/app/CLI/Lib.hs @@ -17,7 +17,7 @@ import System.IO import Grin.Grin import Grin.PrimOpsPrelude -import Grin.Parse -- hiding (value) +import Grin.Parse import Grin.Nametable as Nametable import Pipeline.Pipeline diff --git a/grin/grin.cabal b/grin/grin.cabal index 2b7f082b..d4d3c7f7 100644 --- a/grin/grin.cabal +++ b/grin/grin.cabal @@ -131,7 +131,7 @@ library bimap, mtl, comonad, - megaparsec ==7.0.*, + megaparsec, pretty-show, vector, deepseq, @@ -162,7 +162,7 @@ library hspec-core, extra, logict, - QuickCheck ==2.13.*, + QuickCheck, quickcheck-instances, neat-interpolation, template-haskell, @@ -182,7 +182,7 @@ executable grin , grin , recursion-schemes , ansi-wl-pprint - , megaparsec ==7.0.* + , megaparsec , containers , process , pretty-show @@ -214,7 +214,7 @@ test-suite grin-test , hspec , hspec-core , hspec-discover - , QuickCheck ==2.13.* + , QuickCheck , deepseq , vector , text