Skip to content
Permalink
Browse files

Merge PR #268: Fix LLVM tests

* Proper JIT termination, try running all tests
* FastCC everywhere
  • Loading branch information
cwgoes committed Dec 21, 2019
1 parent 778c193 commit 22303774d2f54cad29d6ff5e8f29d0a6cec985d4
Showing with 29 additions and 25 deletions.
  1. +1 −1 .circleci/config.yml
  2. +1 −1 Makefile
  3. +6 −4 src/Juvix/Backends/LLVM/JIT/Execution.hs
  4. +20 −18 test/Backends/LLVM.hs
  5. +1 −1 test/Main.hs
@@ -36,7 +36,7 @@ jobs:
at: /root
- run:
name: Run tests
command: stack test --fast --test-arguments "--hide-successes --ansi-tricks false"
command: stack test --fast --test-arguments "--hide-successes --ansi-tricks false" +RTS -N4
no_output_timeout: 1200

workflows:
@@ -31,7 +31,7 @@ format:
find . -path ./.stack-work -prune -o -path ./archived -prune -o -type f -name "*.hs" -exec ormolu --mode inplace {} \;

test:
stack test --fast --test-arguments "--hide-successes --ansi-tricks false"
stack test --fast --test-arguments "--hide-successes --ansi-tricks false" +RTS -N4

repl-lib:
stack ghci juvix:lib
@@ -45,6 +45,7 @@ jitWith ∷ ∀ a b. Config → AST.Module → (EE.ExecutableModule EE.MCJIT →
jitWith config mod func = do
paramChan newChan
resultChan newChan
endChan newChan
void $ forkIO $ withContext $ \context
runJIT config context $ \executionEngine do
withModuleFromAST context mod $ \m
@@ -65,10 +66,10 @@ jitWith config mod func = do
res handler p
writeChan resultChan res
loop
Nothing terminate
Nothing terminate >> writeChan endChan ()
loop
let func param = writeChan paramChan (Just param) >> readChan resultChan
return (func, writeChan paramChan Nothing)
return (func, writeChan paramChan Nothing >> readChan endChan)

importAs ((AST.Name, DynamicImportTypeProxy) IO (Maybe DynamicFunc)) ( a b. (DynamicImport (a IO b), Typeable a, Typeable b) AST.Name Proxy a Proxy b IO (Maybe (a IO b)))
importAs imp name (Proxy Proxy a) (Proxy Proxy b) = do
@@ -91,6 +92,7 @@ dynamicImport ee = do
Just fn do
paramChan newChan
resultChan newChan
termChan newChan
let hsFunc = castImport fn a IO b
loop = do
param readChan paramChan
@@ -99,8 +101,8 @@ dynamicImport ee = do
res hsFunc p
writeChan resultChan res
loop
Nothing return ()
modifyMVar_ actions (pure . (:) (writeChan paramChan Nothing))
Nothing writeChan termChan () >> pure ()
modifyMVar_ actions (pure . (:) (writeChan paramChan Nothing >> readChan termChan))
void $ forkIO loop
let func a IO b
func param = writeChan paramChan (Just param) >> readChan resultChan
@@ -1,6 +1,7 @@
module Backends.LLVM where

import Juvix.Backends.LLVM.Codegen as Codegen
import Juvix.Backends.LLVM.Codegen.Types as Types
import Juvix.Backends.LLVM.JIT as JIT
import Juvix.Backends.LLVM.Net.EAC.Types as Types
import Juvix.Backends.LLVM.Net.Environment
@@ -14,6 +15,7 @@ import qualified LLVM.AST.Global as G
import qualified LLVM.AST.Instruction as I (function)
import qualified LLVM.AST.Linkage as L
import LLVM.AST.Name
import qualified LLVM.AST.Type as Type
import LLVM.AST.Type
import qualified LLVM.AST.Visibility as V
import LLVM.Context
@@ -26,12 +28,12 @@ backendLLVM ∷ T.TestTree
backendLLVM =
T.testGroup
"Backend LLVM"
[ fn_test_malloc_free_jit,
fn_test_example_jit
[ test_malloc_free_jit,
test_example_jit
]

fn_test_malloc_free_jit T.TestTree
fn_test_malloc_free_jit = T.testCase "malloc free module should jit" $ do
test_malloc_free_jit T.TestTree
test_malloc_free_jit = T.testCase "malloc free module should jit" $ do
(imp, kill) jitWith (Config None) mallocFreeModule dynamicImport
Just fn importAs imp "test" (Proxy Proxy Word32) (Proxy Proxy Word32)
res fn 7
@@ -47,7 +49,7 @@ mallocFreeModule =
Nothing
[ GlobalDefinition $
functionDefaults
{ G.returnType = voidStarTy,
{ G.returnType = (Types.pointerOf Type.i8),
G.name = Name "malloc",
G.parameters = ([Parameter (IntegerType {typeBits = 64}) (Name "size") []], False),
G.callingConvention = CC.Fast,
@@ -58,7 +60,7 @@ mallocFreeModule =
functionDefaults
{ G.returnType = voidTy,
G.name = Name "free",
G.parameters = ([Parameter voidStarTy (Name "") []], False),
G.parameters = ([Parameter (Types.pointerOf Type.i8) (Name "") []], False),
G.callingConvention = CC.Fast,
G.basicBlocks = [],
G.linkage = L.External
@@ -77,11 +79,11 @@ mallocFreeModule =
Right
( ConstantOperand
( C.GlobalReference
(ptr $ FunctionType {resultType = voidStarTy, argumentTypes = [IntegerType {typeBits = 64}], isVarArg = False})
(ptr $ FunctionType {resultType = (Types.pointerOf Type.i8), argumentTypes = [IntegerType {typeBits = 64}], isVarArg = False})
(Name "malloc")
)
),
callingConvention = CC.C,
callingConvention = CC.Fast,
returnAttributes = [],
arguments = [(ConstantOperand (C.Int {C.integerBits = 64, C.integerValue = 10}), [])],
functionAttributes = [],
@@ -93,13 +95,13 @@ mallocFreeModule =
Right
( ConstantOperand
( C.GlobalReference
(ptr $ FunctionType {resultType = voidTy, argumentTypes = [voidStarTy], isVarArg = False})
(ptr $ FunctionType {resultType = voidTy, argumentTypes = [(Types.pointerOf Type.i8)], isVarArg = False})
(Name "free")
)
),
callingConvention = CC.GHC,
callingConvention = CC.Fast,
returnAttributes = [],
arguments = [(LocalReference voidStarTy (UnName 1), [])],
arguments = [(LocalReference (Types.pointerOf Type.i8) (UnName 1), [])],
functionAttributes = [],
metadata = []
}
@@ -110,8 +112,8 @@ mallocFreeModule =
}
]

fn_test_example_jit T.TestTree
fn_test_example_jit = T.testCase "example module should jit function" $ do
test_example_jit T.TestTree
test_example_jit = T.testCase "example module should jit function" $ do
(imp, kill) jitWith (Config None) exampleModule dynamicImport
Just fn importAs imp "_foo" (Proxy Proxy Word32) (Proxy Proxy Word32)
res fn 7
@@ -174,11 +176,11 @@ exampleModule2 =
Right
( ConstantOperand
( C.GlobalReference
(ptr $ FunctionType {resultType = voidStarTy, argumentTypes = [IntegerType {typeBits = 64}], isVarArg = False})
(ptr $ FunctionType {resultType = (Types.pointerOf Type.i8), argumentTypes = [IntegerType {typeBits = 64}], isVarArg = False})
(Name "malloc")
)
),
callingConvention = CC.C,
callingConvention = CC.Fast,
returnAttributes = [],
arguments = [(ConstantOperand (C.Int {C.integerBits = 64, C.integerValue = 32}), [])],
functionAttributes = [],
@@ -209,13 +211,13 @@ exampleModule2 =
Right
( ConstantOperand
( C.GlobalReference
(ptr $ FunctionType {resultType = voidTy, argumentTypes = [voidStarTy], isVarArg = False})
(ptr $ FunctionType {resultType = voidTy, argumentTypes = [(Types.pointerOf Type.i8)], isVarArg = False})
(Name "free")
)
),
callingConvention = CC.C,
callingConvention = CC.Fast,
returnAttributes = [],
arguments = [(LocalReference voidStarTy (UnName 1), [])],
arguments = [(LocalReference (Types.pointerOf Type.i8) (UnName 1), [])],
functionAttributes = [],
metadata = []
}
@@ -34,7 +34,7 @@ backendTests =
T.testGroup
"Backend tests"
[ backendCircuit,
-- backendLLVM, these tests are causing LLVM errors
backendLLVM,
backendMichelson
]

0 comments on commit 2230377

Please sign in to comment.
You can’t perform that action at this time.