OptiTrust is a tool for user-guided, source-to-source transformations.
It is described in this draft paper:
http://www.chargueraud.org/research/2024/optitrust/optitrust.pdf
The project webpage is:azrazerazerazerazer
OptiTrust is a research prototype, under active development.
Warning: in the current version, generating fully detailed HTML reports (with information about every substep) for our case studies requires a very large amount of memory, possibly more than available on your machine. We are working on making typechecking incremental to avoid this problem.
If you are interested in a demo, please get in touch with @charguer. cicici
- See
INSTALL.mdfor installation procedure, to set up the right version of OCaml/Clang/ClangML and configure VSCode/Codium, in particular. - See
INSTALL_EXTRA.mdfor a list of additional useful tools for program optimization. - See
VSCODE_CUSTOMIZE.mdfor useful tips for using VScode or VScodium. - Read the text below for high level comments on the organization of the repository.
- Check out
case_studies/matmul/matmul_check.mlandmatmul_check.cppto begin with---to produce a full trace you may need a lot of RAM.
Folders:
lib: implementation of the librarytests: for unit tests, one file per transformationtools: utilities for parsing, loading traces, execution (runner), testing (generalized runner)include: header files that need to be included in the C files that are processed using OptiTrustcase_studies: the case studies for OptiTrustdoc: tooling for extracting documentation from the .ml files and the minimal unit tests illustrating each transformation. Seedoc/doc.mdfor details on documentation generation._build(not committed): where generated files are produced_doc(not committed): where documentation files are produced
In the lib folder:
utils: extensions to the standard library of OCamlast: definition of data types for representing the AST (in particular the parser should only depend on the AST module)transfo: implementation of transformations, organized by categories; by convention takes a target as last argument; most often, transformations are ofunittype, and modify the AST by side-effect.framework:c: files specific to C, including the translation from C to lambda-calculus; and the C printertarget: for locating program pointsruntime: infrastructure for executing a script and producing output file and traces, or producing the diff for a specific lineppx_transfo: implement support for thelet%transfodeclarationresources: description of resource objects, and implementation in the typecheckerno_brace: special tooling for flattening sequences that appear inside sequences.
In the include folder, the main file is optitrust.h. This file:
- contains all the functions used to parse annotations; they start with
..(these annotations functions are nothing but a parsing hack, for attaching annotations in the code) - contains ghost functions, which are no-op operations used to change resources to alter the view on a memory (think of ghost functions as entailments in Separation Logic)
- contains logical functions, which are pure functions used only for stating specifications (think of logical functions as pure Coq functions).
In the tests and case_studies folders, for each unit test and each case study, we have several files:
.cpp: contains unoptimized code, plus annotations starting with__with arguments in strings; with use of the MINDEX macro for handling multidimensional arrays..ml: contains the transformation script, each transformation step starts with!!; on this file the user can request via the shortcut a "diff" for a step or a "trace"._out.cpp(not committed): contains the optimized code, produced when executing the.mlscript._exp.cpp: is a git-versioned copy of_out.cpp; the tester claims success if the_out.cppmatches the_exp.cpp; if legitimate changes are applied to the test, the_exp.cppfile should be manually updated to match the_out.cppfile (e.g., usingcpor using the dedicated./tester fixexpcommand).
When producing a trace (see shortcuts in INSTALL.md), the trace opens in a browser. In the trace display, on a given step, there are options to control the display:
- mode:
diffbetween before-step and after-step,code beforeandcode afterfor seeing the code in full before or after the step. If the diff for a step is empty, only the code is displayed. decode: to see the internal representation of the ASTprint types: to see all the type details associated with AST nodesshow: control whether to show only code, or code plus annotations, or code plus annotations plus resources available at every step, or same with all details on what resources each function call is consuming and producing. The detailed display should only be useful for debugging the typecheckerfull(on the left) shows all the details of the trace structure. Seedoc/interact.mdfor details on the working of the interactive shortcuts.
OptiTrust includes a commit hook to execute the unit tests (not the case studies, currently) before a commit.
To bypass the verification, use git commit --no-verify "my message".