From 40b15635772537b1ef1d271942ba6a001c46e1bf Mon Sep 17 00:00:00 2001 From: Nikolai Ponomarev Date: Tue, 19 Mar 2024 12:04:18 +0300 Subject: [PATCH 1/9] Bump Stack resolver & reformat --- stack.yaml | 6 +++--- stack.yaml.lock | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/stack.yaml b/stack.yaml index aee84f8..aa6ee7b 100644 --- a/stack.yaml +++ b/stack.yaml @@ -18,7 +18,7 @@ # resolver: ./custom-snapshot.yaml # resolver: https://example.com/snapshots/2023-01-01.yaml resolver: - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/11.yaml + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/13.yaml # User packages to be built. # Various formats can be used as shown in the example below. @@ -30,8 +30,8 @@ resolver: # - auto-update # - wai packages: -- distiller -- lang + - distiller + - lang # Dependency packages to be pulled from upstream that are not in the resolver. # These entries can reference officially published versions as well as # forks / in-progress versions pinned to a git hash. For example: diff --git a/stack.yaml.lock b/stack.yaml.lock index 433458b..99c6aff 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -6,8 +6,8 @@ packages: [] snapshots: - completed: - sha256: 2fdd7d3e54540062ef75ca0a73ca3a804c527dbf8a4cadafabf340e66ac4af40 - size: 712469 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/11.yaml + sha256: 6f0bea3ba5b07360f25bc886e8cff8d847767557a492a6f7f6dcb06e3cc79ee9 + size: 712905 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/13.yaml original: - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/11.yaml + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/13.yaml From 37c7fd2c3e0aeb633104755a020889de7baf8152 Mon Sep 17 00:00:00 2001 From: Nikolai Ponomarev Date: Tue, 19 Mar 2024 13:32:10 +0300 Subject: [PATCH 2/9] Add CI for build and unit tests --- .github/workflows/ci.yaml | 87 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..0f75a6c --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,87 @@ +name: CI + +on: + push: + branches: + # PRs can only use caches from their target branch. We therefore need to + # make sure we run on 'master' too. + - main + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + pedantic-build: + name: Pedantic build + runs-on: ubuntu-latest + steps: + - name: Clone project + uses: actions/checkout@v4 + + - name: Setup Haskell with Stack + uses: haskell-actions/setup@v2 + with: + enable-stack: true + stack-version: "latest" + + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ~/.stack + key: pedantic-${{ hashFiles('stack.yaml') }} + restore-keys: | + pedantic + + - name: Install dependencies + run: | + stack update + stack build --only-dependencies + + - name: Pedantic build + run: | + stack build --pedantic + + build-and-test: + name: Build and Test on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macOS-latest, windows-latest] + + steps: + - name: Clone project + uses: actions/checkout@v4 + + - name: Setup Haskell with Stack + uses: haskell-actions/setup@v2 + with: + enable-stack: true + stack-version: "latest" + + - name: Cache dependencies on Unix-like OS + if: startsWith(runner.os, 'Linux') || startsWith(runner.os, 'macOS') + uses: actions/cache@v4 + with: + path: ~/.stack + key: ${{ runner.os }}-${{ hashFiles('stack.yaml') }}-${{ matrix.extra-suffix }} + + - name: Cache dependencies on Windows + if: startsWith(runner.os, 'Windows') + uses: actions/cache@v4 + with: + path: | + ~\AppData\Roaming\stack + ~\AppData\Local\Programs\stack + key: ${{ runner.os }}-${{ hashFiles('stack.yaml') }}-${{ matrix.extra-suffix }} + + - name: Install dependencies + run: | + stack update + stack build --only-dependencies --test --bench --no-run-tests --no-run-benchmarks + - name: Build + run: stack build --test --bench --no-run-tests --no-run-benchmarks + + - name: Run tests + run: stack test From 8a1fcd616604339a2dabc14647db79a947b28568 Mon Sep 17 00:00:00 2001 From: Nikolai Ponomarev Date: Tue, 19 Mar 2024 14:11:03 +0300 Subject: [PATCH 3/9] Add pre-commit & README.md --- .gitignore | 2 ++ .pre-commit-config.yaml | 13 +++++++++++++ README.md | 26 ++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 .pre-commit-config.yaml create mode 100644 README.md diff --git a/.gitignore b/.gitignore index 1004cbb..435e4de 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,5 @@ cabal.project.local~ # Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) +# Because of prettier in pre-commit +node_modules/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..4f99c26 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,13 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: fix-byte-order-marker + - id: mixed-line-ending + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v4.0.0-alpha.8 + hooks: + - id: prettier diff --git a/README.md b/README.md new file mode 100644 index 0000000..3c95c16 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Lamagraph IL + +## Required tools + +### Pre-commit + +We use [pre-commit](https://pre-commit.com/) for general tidy up of files. +To install pre-commit run: + +```shell +pip install pre-commit # or install using your distro package manager +pre-commit install +``` + +To run pre-commit on all files run + +```shell +pre-commit run --all-files +``` + +## Editor + +Our editor of choice is [VS Code](https://code.visualstudio.com/) with following extensions: + +- [Haskell](https://marketplace.visualstudio.com/items?itemName=haskell.haskell) +- [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) for YAML formatting From da94e32e7ab8ec5e1d1a35f09f2fad8f1001fd40 Mon Sep 17 00:00:00 2001 From: Nikolai Ponomarev Date: Tue, 19 Mar 2024 14:13:20 +0300 Subject: [PATCH 4/9] Pre-commit format --- distiller/.gitignore | 2 +- lang/app/Main.hs | 2 +- lang/stack.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/distiller/.gitignore b/distiller/.gitignore index c368d45..76467e6 100644 --- a/distiller/.gitignore +++ b/distiller/.gitignore @@ -1,2 +1,2 @@ .stack-work/ -*~ \ No newline at end of file +*~ diff --git a/lang/app/Main.hs b/lang/app/Main.hs index f13b3e0..cb2559c 100644 --- a/lang/app/Main.hs +++ b/lang/app/Main.hs @@ -24,4 +24,4 @@ appendInExp = (Lambda "xs" (Lambda "ys" bodyOfAppend)) main :: IO () -main = print appendInExp \ No newline at end of file +main = print appendInExp diff --git a/lang/stack.yaml b/lang/stack.yaml index 24274a2..d74aefd 100644 --- a/lang/stack.yaml +++ b/lang/stack.yaml @@ -30,7 +30,7 @@ resolver: # - auto-update # - wai packages: -- . + - . # Dependency packages to be pulled from upstream that are not in the resolver. # These entries can reference officially published versions as well as # forks / in-progress versions pinned to a git hash. For example: From 78ea4db2cb47ff79d0481258cab256cf6a3a278d Mon Sep 17 00:00:00 2001 From: Nikolai Ponomarev Date: Tue, 19 Mar 2024 14:26:20 +0300 Subject: [PATCH 5/9] Add CI for pre-commit --- .github/workflows/build-and-test.yaml | 77 +++++++++++++++++++++++++++ .github/workflows/ci.yaml | 74 ++----------------------- .github/workflows/pre-commit.yaml | 18 +++++++ 3 files changed, 99 insertions(+), 70 deletions(-) create mode 100644 .github/workflows/build-and-test.yaml create mode 100644 .github/workflows/pre-commit.yaml diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml new file mode 100644 index 0000000..e61ba10 --- /dev/null +++ b/.github/workflows/build-and-test.yaml @@ -0,0 +1,77 @@ +on: + workflow_call: + +jobs: + pedantic-build: + name: Pedantic build + runs-on: ubuntu-latest + steps: + - name: Clone project + uses: actions/checkout@v4 + + - name: Setup Haskell with Stack + uses: haskell-actions/setup@v2 + with: + enable-stack: true + stack-version: "latest" + + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ~/.stack + key: pedantic-${{ hashFiles('stack.yaml') }} + restore-keys: | + pedantic- + + - name: Install dependencies + run: | + stack update + stack build --only-dependencies + + - name: Pedantic build + run: | + stack build --pedantic + + build-and-test: + name: Build and Test on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macOS-latest, windows-latest] + + steps: + - name: Clone project + uses: actions/checkout@v4 + + - name: Setup Haskell with Stack + uses: haskell-actions/setup@v2 + with: + enable-stack: true + stack-version: "latest" + + - name: Cache dependencies on Unix-like OS + if: startsWith(runner.os, 'Linux') || startsWith(runner.os, 'macOS') + uses: actions/cache@v4 + with: + path: ~/.stack + key: ${{ runner.os }}-${{ hashFiles('stack.yaml') }} + + - name: Cache dependencies on Windows + if: startsWith(runner.os, 'Windows') + uses: actions/cache@v4 + with: + path: | + ~\AppData\Roaming\stack + ~\AppData\Local\Programs\stack + key: ${{ runner.os }}-${{ hashFiles('stack.yaml') }} + + - name: Install dependencies + run: | + stack update + stack build --only-dependencies --test --bench --no-run-tests --no-run-benchmarks + + - name: Build + run: stack build --test --bench --no-run-tests --no-run-benchmarks + + - name: Run tests + run: stack test diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0f75a6c..68addd3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,75 +13,9 @@ concurrency: cancel-in-progress: true jobs: - pedantic-build: - name: Pedantic build - runs-on: ubuntu-latest - steps: - - name: Clone project - uses: actions/checkout@v4 - - - name: Setup Haskell with Stack - uses: haskell-actions/setup@v2 - with: - enable-stack: true - stack-version: "latest" - - - name: Cache dependencies - uses: actions/cache@v4 - with: - path: ~/.stack - key: pedantic-${{ hashFiles('stack.yaml') }} - restore-keys: | - pedantic - - - name: Install dependencies - run: | - stack update - stack build --only-dependencies - - - name: Pedantic build - run: | - stack build --pedantic + pre-commit: + uses: ./.github/workflows/pre-commit.yaml build-and-test: - name: Build and Test on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macOS-latest, windows-latest] - - steps: - - name: Clone project - uses: actions/checkout@v4 - - - name: Setup Haskell with Stack - uses: haskell-actions/setup@v2 - with: - enable-stack: true - stack-version: "latest" - - - name: Cache dependencies on Unix-like OS - if: startsWith(runner.os, 'Linux') || startsWith(runner.os, 'macOS') - uses: actions/cache@v4 - with: - path: ~/.stack - key: ${{ runner.os }}-${{ hashFiles('stack.yaml') }}-${{ matrix.extra-suffix }} - - - name: Cache dependencies on Windows - if: startsWith(runner.os, 'Windows') - uses: actions/cache@v4 - with: - path: | - ~\AppData\Roaming\stack - ~\AppData\Local\Programs\stack - key: ${{ runner.os }}-${{ hashFiles('stack.yaml') }}-${{ matrix.extra-suffix }} - - - name: Install dependencies - run: | - stack update - stack build --only-dependencies --test --bench --no-run-tests --no-run-benchmarks - - name: Build - run: stack build --test --bench --no-run-tests --no-run-benchmarks - - - name: Run tests - run: stack test + needs: pre-commit + uses: ./.github/workflows/build-and-test.yaml diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml new file mode 100644 index 0000000..e1785b2 --- /dev/null +++ b/.github/workflows/pre-commit.yaml @@ -0,0 +1,18 @@ +on: + workflow_call: + +jobs: + pre-commit: + name: Pre-commit + runs-on: ubuntu-latest + steps: + - name: Clone project + uses: actions/checkout@v4 + + - name: Install pre-commit + run: | + pip install pre-commit + + - name: Run pre-commit + run: | + pre-commit run --all-files From 29a9966137b7e80735d6aae63931dc71259a0541 Mon Sep 17 00:00:00 2001 From: Nikolai Ponomarev Date: Tue, 19 Mar 2024 14:38:10 +0300 Subject: [PATCH 6/9] Add CI for hlint --- .github/workflows/ci.yaml | 6 +++++- .github/workflows/hlint.yaml | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/hlint.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 68addd3..792ab91 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,6 +16,10 @@ jobs: pre-commit: uses: ./.github/workflows/pre-commit.yaml - build-and-test: + hlint: needs: pre-commit + uses: ./.github/workflows/hlint.yaml + + build-and-test: + needs: hlint uses: ./.github/workflows/build-and-test.yaml diff --git a/.github/workflows/hlint.yaml b/.github/workflows/hlint.yaml new file mode 100644 index 0000000..52a2e48 --- /dev/null +++ b/.github/workflows/hlint.yaml @@ -0,0 +1,19 @@ +on: + workflow_call: + +jobs: + hlint: + name: Hlint + runs-on: ubuntu-latest + steps: + - name: Clone project + uses: actions/checkout@v4 + + - name: Set up HLint + uses: haskell-actions/hlint-setup@v2 + + - name: Run HLint + uses: haskell-actions/hlint-run@v2 + with: + path: . + fail-on: warning From 02e1a7562bc738bf638c6d690fa562ad3e62049d Mon Sep 17 00:00:00 2001 From: Nikolai Ponomarev Date: Tue, 19 Mar 2024 14:53:18 +0300 Subject: [PATCH 7/9] Add fourmoulu with cfg & CI --- .github/workflows/ci.yaml | 6 +++- .github/workflows/fourmolu.yaml | 15 ++++++++++ README.md | 5 ++++ fourmolu.yaml | 50 +++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/fourmolu.yaml create mode 100644 fourmolu.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 792ab91..9b0dfd7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,8 +16,12 @@ jobs: pre-commit: uses: ./.github/workflows/pre-commit.yaml - hlint: + fourmolu: needs: pre-commit + uses: ./.github/workflows/fourmolu.yaml + + hlint: + needs: fourmolu uses: ./.github/workflows/hlint.yaml build-and-test: diff --git a/.github/workflows/fourmolu.yaml b/.github/workflows/fourmolu.yaml new file mode 100644 index 0000000..e685c35 --- /dev/null +++ b/.github/workflows/fourmolu.yaml @@ -0,0 +1,15 @@ +on: + workflow_call: + +jobs: + hlint: + name: Fourmolu + runs-on: ubuntu-latest + steps: + - name: Clone project + uses: actions/checkout@v4 + + - name: Run fourmolu + uses: haskell-actions/run-fourmolu@v9 + with: + version: "latest" diff --git a/README.md b/README.md index 3c95c16..9b26e2d 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,11 @@ To run pre-commit on all files run pre-commit run --all-files ``` +### Fourmolu + +We use [Fourmolu](https://fourmolu.github.io/) as a formatter for Haskell source files with our custom config. +**Fourmolu must be explicitly enabled in VS Code!** + ## Editor Our editor of choice is [VS Code](https://code.visualstudio.com/) with following extensions: diff --git a/fourmolu.yaml b/fourmolu.yaml new file mode 100644 index 0000000..0074c28 --- /dev/null +++ b/fourmolu.yaml @@ -0,0 +1,50 @@ +# Number of spaces per indentation step +indentation: 4 + +# Max line length for automatic line breaking +column-limit: 120 + +# Styling of arrows in type signatures (choices: trailing, leading, or leading-args) +function-arrows: trailing + +# How to place commas in multi-line lists, records, etc. (choices: leading or trailing) +comma-style: leading + +# Styling of import/export lists (choices: leading, trailing, or diff-friendly) +import-export-style: diff-friendly + +# Whether to full-indent or half-indent 'where' bindings past the preceding body +indent-wheres: false + +# Whether to leave a space before an opening record brace +record-brace-space: false + +# Number of spaces between top-level declarations +newlines-between-decls: 1 + +# How to print Haddock comments (choices: single-line, multi-line, or multi-line-compact) +haddock-style: multi-line + +# How to print module docstring +haddock-style-module: null + +# Styling of let blocks (choices: auto, inline, newline, or mixed) +let-style: auto + +# How to align the 'in' keyword with respect to the 'let' keyword (choices: left-align, right-align, or no-space) +in-style: right-align + +# Whether to put parentheses around a single constraint (choices: auto, always, or never) +single-constraint-parens: always + +# Output Unicode syntax (choices: detect, always, or never) +unicode: never + +# Give the programmer more choice on where to insert blank lines +respectful: true + +# Fixity information for operators +fixities: [] + +# Module reexports Fourmolu should know about +reexports: [] From def18e7d0c45ed772a2038b68c56eb5a35c308c6 Mon Sep 17 00:00:00 2001 From: Nikolai Ponomarev Date: Tue, 19 Mar 2024 14:55:18 +0300 Subject: [PATCH 8/9] Reformat with fourmolu --- distiller/Setup.hs | 1 + lang/Setup.hs | 1 + lang/app/Main.hs | 5 ++++- lang/src/Syntax.hs | 14 ++++++++++++-- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/distiller/Setup.hs b/distiller/Setup.hs index 9a994af..e8ef27d 100644 --- a/distiller/Setup.hs +++ b/distiller/Setup.hs @@ -1,2 +1,3 @@ import Distribution.Simple + main = defaultMain diff --git a/lang/Setup.hs b/lang/Setup.hs index 9a994af..e8ef27d 100644 --- a/lang/Setup.hs +++ b/lang/Setup.hs @@ -1,2 +1,3 @@ import Distribution.Simple + main = defaultMain diff --git a/lang/app/Main.hs b/lang/app/Main.hs index cb2559c..dd91cde 100644 --- a/lang/app/Main.hs +++ b/lang/app/Main.hs @@ -13,7 +13,10 @@ bodyOfAppend = Case (Variable "xs") [ (Pat "Nil" [], Variable "ys") - , (Pat "Cons" ["x'", "xs'"], Constructor "Cons" [Variable "x'", Application (Application (Function "append") (Variable "xs'")) (Variable "ys")]) + , + ( Pat "Cons" ["x'", "xs'"] + , Constructor "Cons" [Variable "x'", Application (Application (Function "append") (Variable "xs'")) (Variable "ys")] + ) ] appendInExp :: FunctionHeader diff --git a/lang/src/Syntax.hs b/lang/src/Syntax.hs index c3af044..7c7aef6 100644 --- a/lang/src/Syntax.hs +++ b/lang/src/Syntax.hs @@ -1,6 +1,11 @@ {-# LANGUAGE InstanceSigs #-} -module Syntax (Expression (Variable, Constructor, Lambda, Application, Case, Let, Function), Fun, Pattern (Pat), FunctionHeader (Header)) where +module Syntax ( + Expression (Variable, Constructor, Lambda, Application, Case, Let, Function), + Fun, + Pattern (Pat), + FunctionHeader (Header), +) where type Fun = String @@ -27,7 +32,12 @@ instance Show Expression where Lambda v exp' -> "(λ" ++ show v ++ "." ++ show exp' ++ ")" Constructor name exps -> "(" ++ name ++ foldr (\x acc -> "(" ++ show x ++ ")" ++ acc) "" exps ++ ")" Application exp1 exp2 -> "(" ++ show exp1 ++ ")(" ++ show exp2 ++ ")" - Case exp' ls -> "(case " ++ show exp' ++ "of\n" ++ foldr (\(pat, exp'') acc -> "\t" ++ show pat ++ " => " ++ show exp'' ++ "\n" ++ acc) "" ls ++ ")" + Case exp' ls -> + "(case " + ++ show exp' + ++ "of\n" + ++ foldr (\(pat, exp'') acc -> "\t" ++ show pat ++ " => " ++ show exp'' ++ "\n" ++ acc) "" ls + ++ ")" Let var exp1 exp2 -> "let " ++ show var ++ " = " ++ show exp1 ++ " in " ++ show exp2 Function f -> show f From 4574ce47de7024e914cdea5715446b40311d1c30 Mon Sep 17 00:00:00 2001 From: Nikolai Ponomarev Date: Tue, 19 Mar 2024 15:09:41 +0300 Subject: [PATCH 9/9] Add dependabot config --- .github/dependabot.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..74c65a5 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,9 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + labels: + - dependabot + - actions + schedule: + interval: "weekly"