|
| 1 | +\page cpp-api-and-modularisation Libcprover-cpp and Modularisation |
| 2 | + |
| 3 | +**Date**: 22 Jun 2023 |
| 4 | +**Updated**: 22 Jun 2023 |
| 5 | +**Author **: Fotis Koutoulakis, [email protected] |
| 6 | +**Domain**: Architecture, API |
| 7 | +**Description**: This document outlines our thinking about the rearchitecting of |
| 8 | + CBMC using the C++ API (`Libcprover-cpp`) as the central module and the |
| 9 | + transitioning of other tools to use that as a basis. |
| 10 | + |
| 11 | +## Motivation && Current State of Affairs |
| 12 | + |
| 13 | +CProver is a collection of tools fitting various program analysis needs. It |
| 14 | +has been the product of the evolution of the codebase of the model-checking |
| 15 | +tool for C (`CBMC`), after it has been adopted with various front-ends/back-ends |
| 16 | +and various auxilliary tools. |
| 17 | + |
| 18 | +During this time, the repository has grown organically, using some guidelines |
| 19 | +for development that were based on tradition and intuition rather than some |
| 20 | +tight development guide. This development model has been successful for most |
| 21 | +of CProver's life, based on its nature as a hybrid industrial/academic and |
| 22 | +experimental/applied tool. However, it has had the side-effect of accruing |
| 23 | +some code duplication and technical debt. It has also made the codebase harder |
| 24 | +to understand/develop and integrate with, especially for someone who is new |
| 25 | +to the codebase. |
| 26 | + |
| 27 | +The above concerns have generated discussions about the breaking down of |
| 28 | +CProver into modules, with cleaner interfaces and tighter boundary control |
| 29 | +between them, making the code easier to integrate in other projects (by making |
| 30 | +the various component modules easier to combine and reuse) and making the |
| 31 | +codebase easier to understand and maintain. |
| 32 | + |
| 33 | +## The Plan Going Forward |
| 34 | + |
| 35 | +Given the above outline, we have reached a point where we are strongly motivated |
| 36 | +to take action to better componentise and modularise CProver. |
| 37 | + |
| 38 | +It's also an opportune time for us, given the existence of `Libcprover-cpp` |
| 39 | +the C++ API that we built to support interfacing with Rust (for now - other |
| 40 | +languages may be coming in the future): we can use this as the basis of |
| 41 | +development for an API exposing the interfaces of the various other modules |
| 42 | +and refactor them into the better-defined shape we want them to take on |
| 43 | +an incremental basis. |
| 44 | + |
| 45 | +Of course, this is a project that is massive in scope, potentially being |
| 46 | +exposed to further scope creep. We acknowledge that any effort to do what |
| 47 | +we have discussed already is going to be a multi-year effort from our end, |
| 48 | +and that we will need community alignment to achieve the outcome we're |
| 49 | +looking for. |
| 50 | + |
| 51 | +This is why we are looking into testing the approach on a smaller component |
| 52 | +first, to get a better feel for the amount of effort and any challenges |
| 53 | +lurking in the dark. |
| 54 | + |
| 55 | +## `goto-bmc` and `libcprover-cpp` |
| 56 | + |
| 57 | +One of the objectives of our modularisation efforts is to decouple the |
| 58 | +various components `CBMC` is based on (front-ends, backends, etc) to allow |
| 59 | +for reuse/recombination. As a first segue into the larger effort, we wanted |
| 60 | +a tool focusing only on running symex (the backend of our analysis engine) |
| 61 | +on a GOTO-binary that has been preprocessed into an appropriate form. |
| 62 | + |
| 63 | +We took the first steps for that in [cbmc#7762](https://github.com/diffblue/cbmc/pull/7762). |
| 64 | + |
| 65 | +The aim of the PR was not only to allow for the tool with the narrower-scope |
| 66 | +to come to life, but also to see if we could expose just enough of the |
| 67 | +process to the C++ API and use that as the basis of the new tool. |
| 68 | + |
| 69 | +This whole process has been very informational: we found out that not only |
| 70 | +we *can* use the C++ API in that capacity, but also that extending the API |
| 71 | +as and when we need to, and doing the various refactorings to the other tools |
| 72 | +on a Just-In-Time basis is viable. |
| 73 | + |
| 74 | +There have been, however, some limitations: |
| 75 | + |
| 76 | +* The C++ API is still nascent, and as such its support for various workflows |
| 77 | + is just not present (at first). We can (and do) build things fast, as and |
| 78 | + when we need them - but it's nowhere near feature complete to provide for |
| 79 | + all of a user's workflows at the time of this writing. |
| 80 | + |
| 81 | +* CProver tools have primarily been based on textual output to report on the |
| 82 | + results of their function (be it analysis, or transformations, etc). This |
| 83 | + hasn't been a problem up until this point (with the caveat that occassionally |
| 84 | + requests for support of new textual formats come up and adding support for |
| 85 | + those has become a laborious process). |
| 86 | + |
| 87 | + There's a need however for the separation of concerns between the production |
| 88 | + of the results by the analysis engine and the presentation layer for those. |
| 89 | + |
| 90 | +We're working towards addressing these teething problems, but while we're |
| 91 | +still operating on those, we have to accept some compromises in the architecture |
| 92 | +of the code while we're iterating or stabilising several of the new or |
| 93 | +refactored parts. |
| 94 | + |
| 95 | +Be advised that some constructs may pop up in some limited locations |
| 96 | +in the codebase that may appear questionable. We're only asking for |
| 97 | +some patience while we're working out the best way to refactor them into |
| 98 | +an architecture that is more cohesive with the long term vision for the |
| 99 | +platform. |
| 100 | + |
| 101 | +From our end, we will do our best to avoid any spillover effects to |
| 102 | +other areas of the codebase, and to avoid introducing any behavioural |
| 103 | +regressions while we're implementing the above plan. |
0 commit comments