Lily is an experimental C++ linter based on linear types. It is a result of my bachelor thesis.
git clone --recursive-submodules $REPO_URL
Please use the Nix package manager if possible, it makes everything way, way easier.
Alternatively if you don't want to build the project yourself, you can just use a prebuilt Docker image, see here.
nix-build --attr lily default.nix
The resulting executable is located in result/bin/
.
If you wish to install it onto your system using Nix,
use nix-env -f default.nix -iA lily
.
You may also build a more static version of the executable by using static-exe
instead of lily
in the commands above.
Use nix-shell shell.nix
to create a development shell --
a shell with all development dependencies such as Cabal, GHC, etc.
You can use normal Cabal commands when in Nix shell to work on Lily:
- To build Lily using Cabal (better for development, incremental builds):
cabal new-build lily
- To build and run Lily using Cabal with some arguments in
$ARGS
:
cabal new-run lily -- $ARGS
- To open a GHCi REPL using Cabal:
cabal new-repl lily
The niv tool is used to manage the version of nixpkgs. It is currently pinned to a version of nixpkgs for which lily builds and works.
To update the version of nixpkgs, use the command niv update
in the development nix-shell.
Requires Nix, Docker. Warning: Creates a ~300MB image.
- Create and load the image using Nix
docker load -i $(nix-build --attr docker default.nix)
- Run the image in current directory
docker run -itv $PWD:/data lily-docker lily [ARGS...]
Example usage:
docker run -itv $PWD:/data lily-docker lily lint examples/various.cpp
Seek the Cabal CI workflow in this repository for guidance.
- Ensure that your GHC version is 8.8.3
- Ensure that you have Clang installed with libraries
- Install my clang-pure fork located in the
deps/
folder using Cabal/Stack. For more instructions, view the fileDEV.md
indeps/clang-pure
. Ideally it should be built bycabal new-build
in the main folder but who knows? - Install this project using Cabal/Stack.
- Pray that everything worked.
Assuming that $LILY
is the way to invoke Lily
as it might depend on which installation was chosen.
Use the following command to lint an example file examples/doublemove.cpp
:
$LILY lint examples/doublemove.cpp
A common issue might be assigning a type to an expression from some C++ library.
In order to add your own annotations, modify the initialInferState
function in src/Type/Infer.hs
.
Note that std::move
is there as a functioning example of a user-added annotation.