mirror of
https://github.com/anoma/juvix.git
synced 2024-12-14 17:32:00 +03:00
2f4a3f809b
## Overview This PR makes the compiler pipeline thread-safe so that the test suite can be run in parallel. This is achieved by: * Removing use of `{get, set, with}CurrentDir` functions. * Adding locking around shared file resources like the the global-project and internal build directory. NB: **Locking is disabled for the main compiler target**, as it is single threaded they are not required. ## Run test suite in parallel To run the test suite in parallel you must add `--ta '+RTS -N -RTS'` to your stack test arguments. For example: ``` stack test --fast --ta '+RTS -N -RTS' ``` The `-N` instructs the Haskell runtime to choose the number of threads to use based on how many processors there are on your machine. You can use `-Nn` to see the number of threads to `n`. These flags are already [set in the Makefile](e6dca22cfd/Makefile (L26)
) when you or CI uses `stack test`. ## Locking The Haskell package [filelock](https://hackage.haskell.org/package/filelock) is used for locking. File locks are used instead of MVars because Juvix code does not control when new threads are created, they are created by the test suite. This means that MVars created by Juvix code will have no effect, because they are created independently on each test-suite thread. Additionally the resources we're locking live on the filesystem and so can be conveniently tagged by path. ### FileLock The filelock library is wrapped in a FileLock effect:e6dca22cfd/src/Juvix/Data/Effect/FileLock/Base.hs (L6-L8)
There is an [IO interpreter](e6dca22cfd/src/Juvix/Data/Effect/FileLock/IO.hs (L8)
) that uses filelock and an [no-op interpreter](e6dca22cfd/src/Juvix/Data/Effect/FileLock/Permissive.hs (L7)
) that just runs actions unconditionally. ### TaggedLock To make the file locks simpler to use a TaggedLock effect is introduced:e6dca22cfd/src/Juvix/Data/Effect/TaggedLock/Base.hs (L5-L11)
And convenience function:e6dca22cfd/src/Juvix/Data/Effect/TaggedLock.hs (L28)
This allows an action to be locked, tagged by a directory that may or may not exist. For example in the following code, an action is performed on a directory `root` that may delete the directory before repopulating the files. So the lockfile cannot be stored in the `root` itself.e6dca22cfd/src/Juvix/Extra/Files.hs (L55-L60)
## Pipeline As noted above, we only use locking in the test suite. The main app target pipeline is single threaded and so locking is unnecessary. So the interpretation of locks is parameterised so that locking can be disablede6dca22cfd/src/Juvix/Compiler/Pipeline/Run.hs (L64)
188 lines
5.2 KiB
Haskell
188 lines
5.2 KiB
Haskell
module BackendGeb.Compilation.Positive where
|
|
|
|
import BackendGeb.Compilation.Base
|
|
import Base
|
|
|
|
data PosTest = PosTest
|
|
{ _name :: String,
|
|
_relDir :: Path Rel Dir,
|
|
_file :: Path Rel File,
|
|
_expectedFile :: Path Rel File
|
|
}
|
|
|
|
root :: Path Abs Dir
|
|
root = relToProject $(mkRelDir "tests/Geb/positive/Compilation")
|
|
|
|
testDescr :: PosTest -> TestDescr
|
|
testDescr PosTest {..} =
|
|
let tRoot = root <//> _relDir
|
|
file' = tRoot <//> _file
|
|
expected' = tRoot <//> _expectedFile
|
|
in TestDescr
|
|
{ _testName = _name,
|
|
_testRoot = tRoot,
|
|
_testAssertion =
|
|
Steps $
|
|
gebCompilationAssertion tRoot file' expected'
|
|
}
|
|
|
|
allTests :: TestTree
|
|
allTests =
|
|
testGroup
|
|
"JuvixGeb positive compilation tests"
|
|
(map (mkTest . testDescr) tests)
|
|
|
|
tests :: [PosTest]
|
|
tests =
|
|
[ PosTest
|
|
"Test001: not function"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test001.juvix")
|
|
$(mkRelFile "out/test001.geb"),
|
|
PosTest
|
|
"Test002: pattern matching"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test002.juvix")
|
|
$(mkRelFile "out/test002.geb"),
|
|
PosTest
|
|
"Test003: inductive types"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test003.juvix")
|
|
$(mkRelFile "out/test003.geb"),
|
|
PosTest
|
|
"Test004: definitions"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test004.juvix")
|
|
$(mkRelFile "out/test004.geb"),
|
|
PosTest
|
|
"Test005: basic arithmetic"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test005.juvix")
|
|
$(mkRelFile "out/test005.geb"),
|
|
PosTest
|
|
"Test006: arithmetic"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test006.juvix")
|
|
$(mkRelFile "out/test006.geb"),
|
|
PosTest
|
|
"Test007: single-constructor inductive types"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test007.juvix")
|
|
$(mkRelFile "out/test007.geb"),
|
|
PosTest
|
|
"Test008: higher-order inductive types"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test008.juvix")
|
|
$(mkRelFile "out/test008.geb"),
|
|
PosTest
|
|
"Test009: let"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test009.juvix")
|
|
$(mkRelFile "out/test009.geb"),
|
|
PosTest
|
|
"Test010: functions returning functions with variable capture"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test010.juvix")
|
|
$(mkRelFile "out/test010.geb"),
|
|
PosTest
|
|
"Test011: applications with lets and cases in function position"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test011.juvix")
|
|
$(mkRelFile "out/test011.geb"),
|
|
PosTest
|
|
"Test012: mid-square hashing (unrolled)"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test012.juvix")
|
|
$(mkRelFile "out/test012.geb"),
|
|
PosTest
|
|
"Test013: recursion"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test013.juvix")
|
|
$(mkRelFile "out/test013.geb"),
|
|
PosTest
|
|
"Test014: tail recursion"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test014.juvix")
|
|
$(mkRelFile "out/test014.geb"),
|
|
PosTest
|
|
"Test015: tail recursion: Fibonacci numbers in linear time"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test015.juvix")
|
|
$(mkRelFile "out/test015.geb"),
|
|
PosTest
|
|
"Test016: local functions with free variables"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test016.juvix")
|
|
$(mkRelFile "out/test016.geb"),
|
|
PosTest
|
|
"Test017: recursion through higher-order functions"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test017.juvix")
|
|
$(mkRelFile "out/test017.geb"),
|
|
PosTest
|
|
"Test018: tail recursion through higher-order functions"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test018.juvix")
|
|
$(mkRelFile "out/test018.geb"),
|
|
PosTest
|
|
"Test019: higher-order functions"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test019.juvix")
|
|
$(mkRelFile "out/test019.geb"),
|
|
PosTest
|
|
"Test020: McCarthy's 91 function"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test020.juvix")
|
|
$(mkRelFile "out/test020.geb"),
|
|
PosTest
|
|
"Test021: fast exponentiation"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test021.juvix")
|
|
$(mkRelFile "out/test021.geb"),
|
|
PosTest
|
|
"Test022: mutual recursion"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test022.juvix")
|
|
$(mkRelFile "out/test022.geb"),
|
|
PosTest
|
|
"Test023: Euclid's algorithm"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test023.juvix")
|
|
$(mkRelFile "out/test023.geb"),
|
|
PosTest
|
|
"Test024: Ackermann function"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test024.juvix")
|
|
$(mkRelFile "out/test024.geb"),
|
|
PosTest
|
|
"Test025: mid-square hashing"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test025.juvix")
|
|
$(mkRelFile "out/test025.geb"),
|
|
PosTest
|
|
"Test026: recursive let"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test026.juvix")
|
|
$(mkRelFile "out/test026.geb"),
|
|
PosTest
|
|
"Test027: simple case expression"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test027.juvix")
|
|
$(mkRelFile "out/test027.geb"),
|
|
PosTest
|
|
"Test028: mutually recursive let expressions"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test028.juvix")
|
|
$(mkRelFile "out/test028.geb"),
|
|
PosTest
|
|
"Test029: pattern matching on natural numbers"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test029.juvix")
|
|
$(mkRelFile "out/test029.geb"),
|
|
PosTest
|
|
"Test030: recursion with unroll pragma"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "test030.juvix")
|
|
$(mkRelFile "out/test030.geb")
|
|
]
|