是否可以在编译时强制执行契约设计检查?

Is it possible to enforce Design by Contract checks at compile time?

阅读 Design by Contract tutorial 我偶然发现了以下行:

Contracts in Eiffel are not just wishful thinking. They can be monitored at run time under the control of compilation options.

后跟说明失败时会抛出异常。这让我觉得所有 require ensure invariant all 检查都可以在运行时执行或关闭。这个对吗?或者它们也可以在编译时使用适当的编译器选项强制执行?

有一个工具 AutoProof for verifying contracts at compile time. It performs some transformations ending up with an SMT instance that is checked by the Z3 SMT solver that tells whether all assertions hold. From the brief introduction, it follows that quite a bit of annotations is required to use it. Nevertheless, the tool was used to verify Base2, a set of container classes, similar to the standard classes of the Base library. The contracts rely on a so called Semantic Collaboration technique described in the corresponding papers (look for Publications at the AutoProof page).

有一些正在进行的research work to simplify techniques employed by AutoProof, fix existing issues, adapt it for use with void-safe systems and SCOOP(简单并发面向对象编程)。截至撰写本文时,该技术仍处于研究阶段,尚未准备好在生产环境中投入使用。主要障碍是复杂性和使用该技术所需的特殊培训。但是,基本思想非常笼统,允许在教学过程中使用该工具。