Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foreign Function Interface #1376

Merged
merged 65 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
9bccc79
Add frontend for FFI
qsctr Jun 25, 2022
1e18568
Add basic FFI for concrete backend (unix only)
qsctr Jun 28, 2022
7fcfeeb
Refactor FFI code out of Backend class
qsctr Jun 29, 2022
9a4de13
Clean up FFI code
qsctr Jun 29, 2022
b5ab79a
Handle dlopen/dlsym errors
qsctr Jul 1, 2022
6a07099
Handle FFI loading errors in remote API
qsctr Jul 1, 2022
c5ebac4
Call dlclose in ForeignImpl finalizer
qsctr Jul 6, 2022
20403c2
Panic on recursive foreign decl group
qsctr Jul 6, 2022
56af466
Revert "Panic on recursive foreign decl group"
qsctr Jul 6, 2022
7bac9db
Add cabal flag for FFI
qsctr Jul 6, 2022
9551a15
Debug check-exercises failure
qsctr Jul 6, 2022
7f43cf0
Load .dylib for FFI on macOS
qsctr Jul 6, 2022
e4a7a0f
Bump CI CACHE_VERSION
qsctr Jul 6, 2022
3456a7d
Debugging libffi on ubuntu 18.04 CI
qsctr Jul 7, 2022
b8b53a1
Add FFI for all integral types
qsctr Jul 13, 2022
0cf81a3
Refactor FFI marshalling code
qsctr Jul 13, 2022
543862d
Revert "Debugging libffi on ubuntu 18.04 CI"
qsctr Jul 13, 2022
9d7bb04
Improve FFI marshalling of Bits
qsctr Jul 13, 2022
ecace94
Fix type errors in ghc 9.0+
qsctr Jul 13, 2022
cc3366a
FFI: Support multi argument functions
qsctr Jul 14, 2022
d161e95
FFI: Refactor loading/unloading shared libraries
qsctr Jul 15, 2022
fb5122d
FFI: Fix argument passing order
qsctr Jul 16, 2022
21cf642
FFI: Add support for floats
qsctr Jul 18, 2022
f8221c2
FFI: Support type synonyms
qsctr Jul 18, 2022
47f6370
FFI: Support passing and returning arrays
qsctr Jul 21, 2022
2fc195f
FFI: Rename FFIRep to FFIType
qsctr Jul 21, 2022
e1ede19
FFI: Support passing and returning tuples
qsctr Jul 24, 2022
c2ac894
FFI: Support passing and returning records
qsctr Jul 25, 2022
3534826
FFI: Simplify placeholder type in Infer
qsctr Jul 26, 2022
45dfcaa
FFI: Add size polymorphism and improve type errors
qsctr Jul 29, 2022
5d41a82
FFI: Remove duplicate type constraint errors
qsctr Jul 29, 2022
e4880c9
FFI: Refactor eval code and add comments
qsctr Aug 1, 2022
7294acc
FFI: Set up tests
qsctr Aug 3, 2022
8d28f59
FFI: Try linking against ghc's libffi at runtime
qsctr Aug 3, 2022
1b36a13
FFI: Fix linker flags
qsctr Aug 3, 2022
7f904e0
FFI: copy libffi to dist/lib/ and cryptol/../lib
qsctr Aug 3, 2022
3fb609d
FFI: add ghc libffi for other cryptol executables
qsctr Aug 4, 2022
6366447
FFI: Add ffi flag for cryptol-remote-api
qsctr Aug 4, 2022
ae843a0
FFI: Add integral and float tests
qsctr Aug 4, 2022
65cb428
FFI: Copy libffi to bin
qsctr Aug 4, 2022
9efd822
FFI: Canonicalize module path for finding dylib
qsctr Aug 5, 2022
59f0b30
FFI: Print whether FFI is enabled in -v/:v command
qsctr Aug 5, 2022
6b1210d
FFI: Revert dynamic linking hacks for linux
qsctr Aug 5, 2022
d7a9cfe
FFI: Revert changes to cryptol-remote-api.cabal
qsctr Aug 5, 2022
fb7c989
FFI: Add libffi package fork as submodule
qsctr Aug 5, 2022
5c2a409
Merge branch 'master' into ffi
qsctr Aug 5, 2022
8827a5b
FFI: Move CI ffi test check to test job
qsctr Aug 5, 2022
70fc5e2
FFI: Add more tests
qsctr Aug 5, 2022
d529c16
Don't allow wild cards in FFI declarations.
yav Aug 8, 2022
3509438
Fix test
yav Aug 8, 2022
6cc5cec
FFI: Add explicit reloading and refactor eval code
qsctr Aug 10, 2022
33fd5c2
FFI: Define ForeignSrc when FFI disabled
qsctr Aug 10, 2022
7ae7489
FFI: Add test for reloading with new changes
qsctr Aug 10, 2022
c6162c6
FFI: Use evalFinType in marshalTyArg
qsctr Aug 10, 2022
b301d66
FFI: Revert CI CACHE_VERSION bump
qsctr Aug 10, 2022
8e4f749
FFI: Formatting
qsctr Aug 10, 2022
0bc3bb7
FFI: Add docs
qsctr Aug 11, 2022
36fcdb3
FFI: Use upstream libffi
qsctr Aug 11, 2022
60a342a
FFI: Improve docs
qsctr Aug 11, 2022
46cb2f9
Fix rangeWithin comparison
qsctr Aug 11, 2022
65ba788
FFI: Add test for type errors
qsctr Aug 11, 2022
9652cf4
FFI: Call proveImplication on validSchema in Infer
qsctr Aug 12, 2022
8a274d0
FFI: Don't panic in reference evaluator
qsctr Aug 12, 2022
4fd7e17
FFI: Add test for runtime errors
qsctr Aug 12, 2022
d933fa6
FFI: Improve docs
qsctr Aug 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ jobs:
name: test-lib ${{ matrix.target }}
run: |
export PATH=$PWD/bin:$PWD/dist/bin:$PATH
./bin/test-runner --ext=.icry -F -b --exe=dist/bin/cryptol ./tests/${{ matrix.target }}
if ${{ matrix.target != 'ffi' }} || dist/bin/cryptol -v | grep -q 'FFI enabled'; then
./bin/test-runner --ext=.icry -F -b --exe=dist/bin/cryptol ./tests/${{ matrix.target }}
fi

- if: matrix.suite == 'rpc'
shell: bash
Expand Down
14 changes: 12 additions & 2 deletions cry
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,21 @@ case $COMMAND in
test)
echo Running tests
setup_external_tools
if [ "$#" == "0" ]; then TESTS=tests; else TESTS=$*; fi
if [ "$#" == "0" ]; then
if cabal v2-exec cryptol -- -v | grep -q 'FFI enabled'; then
TESTS=(tests/*)
else
GLOBIGNORE="tests/ffi"
TESTS=(tests/*)
unset GLOBIGNORE
fi
else
TESTS=("$*")
fi
$BIN/test-runner --ext=.icry \
--exe=cabal \
-F v2-run -F -v0 -F exe:cryptol -F -- -F -b \
$TESTS
"${TESTS[@]}"
;;

rpc-test)
Expand Down
4 changes: 4 additions & 0 deletions cryptol-remote-api/src/CryptolServer/Exceptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ cryptolError modErr warns =
NotAParameterizedModule x ->
(20650, [ ("module", jsonPretty x)
])
FFILoadErrors x errs ->
(20660, [ ("module", jsonPretty x)
, ("errors", jsonList (map jsonPretty errs))
])
OtherFailure x ->
(29999, [ ("error", jsonString x)
])
Expand Down
15 changes: 15 additions & 0 deletions cryptol.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ flag relocatable
default: True
description: Don't use the Cabal-provided data directory for looking up Cryptol libraries. This is useful when the data directory can't be known ahead of time, like for a relocatable distribution.

flag ffi
default: True
description: Enable the foreign function interface

library
Default-language:
Haskell2010
Expand Down Expand Up @@ -81,6 +85,11 @@ library
else
build-depends: integer-gmp >= 1.0 && < 1.1

if flag(ffi)
build-depends: libffi >= 0.2,
unix
cpp-options: -DFFI_ENABLED

Build-tool-depends: alex:alex, happy:happy
hs-source-dirs: src

Expand Down Expand Up @@ -147,6 +156,9 @@ library
Cryptol.TypeCheck.TypeMap,
Cryptol.TypeCheck.TypeOf,
Cryptol.TypeCheck.Sanity,
Cryptol.TypeCheck.FFI,
Cryptol.TypeCheck.FFI.Error,
Cryptol.TypeCheck.FFI.FFIType,

Cryptol.TypeCheck.Solver.Types,
Cryptol.TypeCheck.Solver.SMT,
Expand All @@ -169,6 +181,8 @@ library
Cryptol.Backend,
Cryptol.Backend.Arch,
Cryptol.Backend.Concrete,
Cryptol.Backend.FFI,
Cryptol.Backend.FFI.Error,
Cryptol.Backend.FloatHelpers,
Cryptol.Backend.Monad,
Cryptol.Backend.SeqMap,
Expand All @@ -179,6 +193,7 @@ library
Cryptol.Eval,
Cryptol.Eval.Concrete,
Cryptol.Eval.Env,
Cryptol.Eval.FFI,
Cryptol.Eval.Generic,
Cryptol.Eval.Prims,
Cryptol.Eval.Reference,
Expand Down
3 changes: 2 additions & 1 deletion cryptol/CheckExercises.hs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ main = do

if Seq.null (rdReplout rd)
then do let cryCmd = (P.shell (exe ++ " --interactive-batch " ++ inFile ++ " -e"))
(cryEC, cryOut, _) <- P.readCreateProcessWithExitCode cryCmd ""
(cryEC, cryOut, cryErr) <- P.readCreateProcessWithExitCode cryCmd ""


Line lnReplinStart _ Seq.:<| _ <- return $ rdReplin rd
Expand All @@ -301,6 +301,7 @@ main = do
putStrLn $ "REPL error (replin lines " ++
show lnReplinStart ++ "-" ++ show lnReplinEnd ++ ")."
putStr cryOut
putStr cryErr
exitFailure
ExitSuccess -> do
-- remove temporary input file
Expand Down
Loading