Skip to content

Commit 50f02e0

Browse files
committed
Merge branch 'master' into 32-ES-to-master
2 parents 6f54f60 + 15fdfe6 commit 50f02e0

File tree

85 files changed

+1162
-416
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1162
-416
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@ cabal.sandbox.config
1818
*.eventlog
1919
.stack-work/
2020
cabal.project.local
21+
cabal.project.local~
2122
.HTF/
2223
output/
2324
*.ibc
2425
*.agdai
2526
.output
2627
.grin-output/
28+
grin/.end-to-end-test/
2729
.vscode/
30+
*.out
31+
*.out.ll
32+
*.out.s
33+
.ghc.environment.*

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ before_install:
3232

3333
install:
3434
- stack update
35-
- travis_wait 120 stack --no-terminal --install-ghc test --only-dependencies
35+
- travis_wait 120 stack --no-terminal --install-ghc test --only-dependencies --coverage
3636

3737
script:
3838
- mkdir .output
39-
- stack --no-terminal test --coverage
40-
- stack exec grin -- grin/grin/sum_simple.grin
39+
- stack test grin:grin-end-to-end-test grin:grin-test --coverage
40+
- stack exec grin -- grin/grin/sum_simple.grin --quiet
4141

4242
after_script:
4343
- travis_retry curl -L https://github.com/rubik/stack-hpc-coveralls/releases/download/v0.0.4.0/shc-linux-x64-8.0.1.tar.bz2 | tar -xj
44-
- ./shc grin grin-test
44+
- ./shc --repo-token=8QkWaPJlRbej9X5N5AaXSommTtN7uEqRT combined all

BACKERS.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<h2 align="center">Bronze via Patreon</h2>
99

1010
- Stephen Diehl
11+
- Christopher Goes
1112

1213
<h2 align="center">Generous Backers via Patreon ($50+)</h2>
1314

@@ -17,6 +18,7 @@
1718
- Peter Kadlot
1819
- Michael Koloberdin
1920
- William Harvey
21+
- Steven Kane
2022
<!--50 end-->
2123

2224
<h2 align="center">Backers via Patreon</h2>
@@ -40,4 +42,17 @@
4042
- Kametrixom Tikara
4143
- Denis Redozubov
4244
- Andrei Dziahel
45+
- Oleh Stolyar
46+
- Alberto Centelles
47+
- Tom Hunger
48+
- Mirzhan Irkegulov
49+
- James MacAulay
50+
- Adam S E
51+
- Michael
52+
- Chai T. Rex
53+
- Malte Brandy
54+
- Tanner Doshier
55+
- Brooklyn Zelenka
56+
- Jaseem Abid
57+
- Callan McGill
4358
<!--10 end-->

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# GRIN
22

3-
[![Build Status](https://travis-ci.org/grin-compiler/grin.svg?branch=master)](https://travis-ci.org/grin-compiler/grin) [![Coverage Status](https://coveralls.io/repos/github/grin-tech/grin/badge.svg?branch=master)](https://coveralls.io/github/grin-tech/grin?branch=master)
3+
[![Build Status](https://travis-ci.org/grin-compiler/grin.svg?branch=master)](https://travis-ci.org/grin-compiler/grin) [![Coverage Status](https://coveralls.io/repos/github/grin-compiler/grin/badge.svg?branch=master)](https://coveralls.io/github/grin-compiler/grin?branch=master)
44
[![Gitter chat](https://badges.gitter.im/grin-compiler/grin.png)](https://gitter.im/Grin-Development/Lobby)
55

66
The name GRIN is short for *Graph Reduction Intermediate Notation*, and it is an intermediate language for graph reduction. GRIN is the optimizer and code generator component of the GRIN Compiler project which includes language frontends for *Haskell*, *Idris* and *Agda*.
7-
To get the big picture of the project check the [project website](https://grin-compiler.github.io/).
7+
To get the big picture of the project check the [project website](https://grin-compiler.github.io/).
88
For an overview of the optimizer read
99
<a href="http://nbviewer.jupyter.org/github/grin-compiler/grin/blob/master/papers/The GRIN Project.pdf">
1010
The GRIN Project
@@ -15,13 +15,13 @@ Code Optimisation Techniques for Lazy Functional Languages
1515

1616
We presented the core ideas of GRIN at Haskell Exchange 2018. [slides](https://docs.google.com/presentation/d/1QsZ3Kyy3XIco-qba1biRmzuMzz8o2uCBqA9DMtnqP2c/edit?usp=sharing) [video](https://skillsmatter.com/skillscasts/12390-grin-an-alternative-haskell-compiler-backend)
1717

18-
Read our paper [A modern look at GRIN, an optimizing functional language back end](http://nbviewer.jupyter.org/github/Anabra/grin/blob/fd9de6d3b9c7ec5f4aa7d6be41285359a73494e3/papers/stcs-2019/article/tex/main.pdf) (2019) to get an overview of GRIN related projects and other whole program compilers i.e. *Boquist GRIN, UHC, JHC, LHC, HRC, MLton*
18+
Read our paper [A modern look at GRIN, an optimizing functional language back end](https://nbviewer.jupyter.org/github/Anabra/grin/blob/65177587f4ea0586801e582f1f3750b2d46351a2/papers/stcs-2019/article/tex/main.pdf) (2019) to get an overview of GRIN related projects and other whole program compilers i.e. *Boquist GRIN, UHC, JHC, LHC, HRC, MLton*
1919

2020
Also check the GRIN transformation [example from Boquist PhD](http://nbviewer.jupyter.org/github/grin-compiler/grin/blob/master/papers/boquist.pdf#page=317) and an [example from our implementation](https://github.com/grin-compiler/grin/tree/master/grin/grin/sum-simple-output).
2121

2222
## Support
2323

24-
The project is supported by these awesome [backers](https://github.com/grin-compiler/grin/blob/master/BACKERS.md).
24+
The project is supported by these awesome [backers](https://github.com/grin-compiler/grin/blob/master/BACKERS.md).
2525
If you'd like to join them, please consider become a backer or sponsor on [Patreon](https://www.patreon.com/csaba_hruska).
2626

2727

@@ -49,7 +49,7 @@ If you'd like to join them, please consider become a backer or sponsor on [Patre
4949
Example using Homebrew on macOS:
5050

5151
```bash
52-
$ brew install llvm-hs/llvm/llvm-7.0
52+
$ brew install llvm-hs/llvm/llvm-7
5353
```
5454

5555
#### Debian/Ubuntu
@@ -96,7 +96,7 @@ stack build
9696
stack exec -- grin grin/grin/opt-stages-high-level/stage-00.grin
9797
```
9898
## How to Contribute
99-
See: [Issues / Tasks for new contributors](https://github.com/grin-compiler/grin/issues/3)
99+
See: [Issues / Tasks for new contributors](https://github.com/grin-compiler/grin/issues/3)
100100
Keep it simple: We follow the fundamentals laid down in [HaskellerZ - Feb 2018 - Getting things done in Haskell](https://www.youtube.com/watch?v=-X1vrxQUETM)
101101

102102
## Example Front-End
@@ -150,10 +150,10 @@ Transformation | Schema
150150
[case hoisting][153] <br><br> _source code:_ <br> [CaseHoisting.hs] <br><br> _test:_ <br> [CaseHoistingSpec.hs] | [<img src="images/case-hoisting.png" width="500">][153]
151151
[whnf update elimination][149] <br><br> _source code:_ <br> __TODO__ <br><br> _test:_ <br> __TODO__ | [<img src="images/whnf-update-elimination.png" width="500">][149]
152152
[common sub-expression elimination][164] <br><br> _source code:_ <br> [CSE.hs] <br><br> _test:_ <br> [CSESpec.hs] | [<img src="images/common-sub-expression-elimination-1.png" width="500"><img src="images/common-sub-expression-elimination-2.png" width="500">][164]
153-
[constant propagation][159] <br><br> _source code:_ <br> [ConstantPropagation.hs] <br><br> _test:_ <br> [ConstantPropagationSpec.hs] |
154-
[dead function elimination][169] <br><br> _source code:_ <br> [SimpleDeadFunctionElimination.hs] <br><br> _test:_ <br> [SimpleDeadFunctionEliminationSpec.hs] |
155-
[dead variable elimination][170] <br><br> _source code:_ <br> [SimpleDeadVariableElimination.hs] <br><br> _test:_ <br> [SimpleDeadVariableEliminationSpec.hs] |
156-
[dead parameter elimination][171] <br><br> _source code:_ <br> [SimpleDeadParameterElimination.hs] <br><br> _test:_ <br> [SimpleDeadParameterEliminationSpec.hs] |
153+
[constant propagation][159] <br><br> _source code:_ <br> [ConstantPropagation.hs] <br><br> _test:_ <br> [ConstantPropagationSpec.hs] |
154+
[dead function elimination][169] <br><br> _source code:_ <br> [SimpleDeadFunctionElimination.hs] <br><br> _test:_ <br> [SimpleDeadFunctionEliminationSpec.hs] |
155+
[dead variable elimination][170] <br><br> _source code:_ <br> [SimpleDeadVariableElimination.hs] <br><br> _test:_ <br> [SimpleDeadVariableEliminationSpec.hs] |
156+
[dead parameter elimination][171] <br><br> _source code:_ <br> [SimpleDeadParameterElimination.hs] <br><br> _test:_ <br> [SimpleDeadParameterEliminationSpec.hs] |
157157

158158
[129]: http://nbviewer.jupyter.org/github/grin-compiler/grin/blob/master/papers/boquist.pdf#page=129
159159
[134]: http://nbviewer.jupyter.org/github/grin-compiler/grin/blob/master/papers/boquist.pdf#page=134

default.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
let
2+
haskell = import ./nix/haskell.nix;
3+
llvm-overlay = self: super: {
4+
llvm-config = self.llvm_7;
5+
};
6+
extra-overlays = [ llvm-overlay ];
7+
pkgs = import ./nix/packages.nix (haskell // {
8+
overlays = haskell.overlays ++ extra-overlays;
9+
});
10+
in
11+
pkgs.haskell-nix.stackProject {
12+
src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; };
13+
}

docs/MemoryManagement.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ related: [Dead data elimination](http://nbviewer.jupyter.org/github/grin-compile
1313

1414
## Sample Project
1515
[Sample project](https://github.com/robinvd/lang-experiments) for LLVM stack map based GC.
16+
17+
## Readings
18+
- http://craftinginterpreters.com/garbage-collection.html

grin/LICENSE

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2017, Andor Pénzes, Csaba Hruska
1+
Copyright (c) 2017, Andor Pénzes, Csaba Hruska, Péter Podlovics
22

33
All rights reserved.
44

@@ -13,9 +13,10 @@ modification, are permitted provided that the following conditions are met:
1313
disclaimer in the documentation and/or other materials provided
1414
with the distribution.
1515

16-
* Neither the name of Csaba Hruska, Peter Divianszky nor the names of other
17-
contributors may be used to endorse or promote products derived
18-
from this software without specific prior written permission.
16+
* Neither the name of Andor Pénzes, Csaba Hruska, Péter Podlovics
17+
nor the names of other contributors may be used to endorse or
18+
promote products derived from this software without specific
19+
prior written permission.
1920

2021
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2122
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

grin/app/GrinCLI.hs renamed to grin/app/CLI/Lib.hs

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{-# LANGUAGE LambdaCase #-}
2-
module Main where
2+
module CLI.Lib where
33

44
import Control.Monad
55
import Data.Map (Map(..))
@@ -17,10 +17,12 @@ import System.IO
1717

1818
import Grin.Grin
1919
import Grin.PrimOpsPrelude
20-
import Grin.Parse hiding (value)
20+
import Grin.Parse
2121
import Grin.Nametable as Nametable
2222
import Pipeline.Pipeline
2323

24+
25+
2426
data Options = Options
2527
{ optFiles :: [FilePath]
2628
, optTrans :: [PipelineStep]
@@ -29,6 +31,8 @@ data Options = Options
2931
, optQuiet :: Bool
3032
, optLoadBinary :: Bool
3133
, optSaveBinary :: Bool
34+
, optCFiles :: [FilePath]
35+
, optDontFailOnLint :: Bool
3236
} deriving Show
3337

3438
flg c l h = flag' c (mconcat [long l, help h])
@@ -118,7 +122,8 @@ pipelineOpts =
118122
<|> flg (Pass [Sharing Compile, Sharing Optimise, Sharing RunPure]) "sharing-opt" "Compiles, optimizes and runs the sharing analysis"
119123
<|> flg (Pass [LVA Compile, CBy Compile, RunCByWithLVA]) "cby-with-lva" "Compiles the live variable and created-by analyses, then runs the created-by analysis using the LVA result"
120124
<|> flg DeadCodeElimination "dce" "Dead Code Elimination"
121-
<|> flg PureEval "eval" "Evaluate the grin program (pure)"
125+
<|> flg (PureEval False) "eval" "Evaluate the grin program (pure)"
126+
<|> (PureEval <$> (option auto (mconcat [long "eval-with-statistics", help "Evaluate the grin program (pure) and render heap statistics."])))
122127
<|> flg JITLLVM "llvm" "JIT with LLVM"
123128
<|> flg PrintAST "ast" "Print the Abstract Syntax Tree"
124129
<|> (SaveExecutable False . Abs <$> (strOption (mconcat [short 'o', long "save-elf", help "Save an executable ELF"])))
@@ -130,6 +135,7 @@ pipelineOpts =
130135
<|> flg ConfluenceTest "confluence-test" "Checks transformation confluence by generating random two pipelines which reaches the fix points."
131136
<|> flg PrintErrors "print-errors" "Prints the error log"
132137

138+
133139
maybeRenderingOpt :: String -> Maybe RenderingOption
134140
maybeRenderingOpt = M.parseMaybe renderingOpt
135141

@@ -149,14 +155,18 @@ printGrinWithOpt = flip PrintGrin id <$> option (maybeReader maybeRenderingOpt)
149155
<> help "Print the actual grin code with a given rendering option [simple | with-externals]"
150156
<> metavar "OPT" )
151157

152-
options :: IO Options
153-
options = execParser $ info
154-
(pipelineArgs <**> helper)
155-
(mconcat
156-
[ fullDesc
157-
, progDesc "grin compiler"
158-
, header "grin compiler"
159-
])
158+
options :: [String] -> IO Options
159+
options args = do
160+
let res = execParserPure defaultPrefs
161+
(info
162+
(pipelineArgs <**> helper)
163+
(mconcat
164+
[ fullDesc
165+
, progDesc "grin compiler"
166+
, header "grin compiler"
167+
]))
168+
args
169+
handleParseResult res
160170
where
161171
pipelineArgs = Options
162172
<$> some (argument str (metavar "FILES..."))
@@ -184,20 +194,44 @@ options = execParser $ info
184194
[ long "save-binary-intermed"
185195
, help "Save intermediate results in binary format"
186196
])
197+
<*> many (strOption (mconcat
198+
[ short 'C'
199+
, long "c-file"
200+
, help "The path for the runtime implementation in C"]))
201+
<*> switch (mconcat
202+
[ long "continue-on-failed-lint"
203+
, help "Do not fail on lint errors"
204+
])
187205

188-
main :: IO ()
189-
main = do
206+
mainWithArgs :: [String] -> IO ()
207+
mainWithArgs args = do
190208
hSetBuffering stdout NoBuffering
191-
Options files steps outputDir noPrelude quiet loadBinary saveBinary <- options
209+
Options
210+
files
211+
steps
212+
outputDir
213+
noPrelude
214+
quiet
215+
loadBinary
216+
saveBinary
217+
cFiles
218+
continueOnLint
219+
<- options args
192220
forM_ files $ \fname -> do
193221
(mTypeEnv, program) <- if loadBinary
194222
then do
195223
((,) Nothing . Nametable.restore) <$> Binary.decodeFile fname
196224
else do
197225
content <- Text.readFile fname
198-
let (typeEnv, program') = either (error . M.parseErrorPretty' content) id $ parseGrinWithTypes fname content
226+
let (typeEnv, program') = either (error . M.errorBundlePretty) id $ parseGrinWithTypes fname content
199227
pure $ (Just typeEnv, if noPrelude then program' else concatPrograms [primPrelude, program'])
200-
let opts = defaultOpts { _poOutputDir = outputDir, _poFailOnLint = True, _poLogging = not quiet, _poSaveBinary = saveBinary }
228+
let opts = defaultOpts
229+
{ _poOutputDir = outputDir
230+
, _poFailOnLint = not continueOnLint
231+
, _poLogging = not quiet
232+
, _poSaveBinary = saveBinary
233+
, _poCFiles = cFiles
234+
}
201235
case steps of
202236
[] -> void $ optimize opts program [] postPipeline
203237
_ -> void $ pipeline opts mTypeEnv program steps

grin/app/CLI/Main.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Main where
2+
3+
import System.Environment (getArgs)
4+
import CLI.Lib (mainWithArgs)
5+
6+
7+
main :: IO ()
8+
main = do
9+
args <- getArgs
10+
mainWithArgs args

grin/default.nix

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)