# Iteratively Composing Statically Verified Traits

**Authors:** Isaac Oscar Gariano (VUW), Marco Servetto (VUW), Alex Potanin (VUW),, Hrshikesh Arora (VUW)

arXiv: 1902.09685 · 2019-08-21

## TL;DR

This paper presents a method using metaprogramming and extended traits with contracts to generate correct-by-construction code, reducing reliance on slow static verification and ensuring correctness through composition checks.

## Contribution

It introduces a novel trait composition approach with contract checking that guarantees correctness of generated code without re-verification.

## Key findings

- Generated code is correct by construction.
- Method reduces static verification overhead.
- Applied to optimize power function with known exponent.

## Abstract

Static verification relying on an automated theorem prover can be very slow and brittle: since static verification is undecidable, correct code may not pass a particular static verifier. In this work we use metaprogramming to generate code that is correct by construction. A theorem prover is used only to verify initial "traits": units of code that can be used to compose bigger programs.   In our work, meta-programming is done by trait composition, which starting from correct code, is guaranteed to produce correct code. We do this by extending conventional traits with pre- and post-conditions for the methods; we also extend the traditional trait composition (+) operator to check the compatibility of contracts. In this way, there is no need to re-verify the produced code.   We show how our approach can be applied to the standard "power" function example, where metaprogramming generates optimised, and correct, versions when the exponent is known in advance.

## Full text

_Full body text omitted from this summary view._ Fetch the complete paper as Markdown: https://tomesphere.com/paper/1902.09685/full.md

---
Source: https://tomesphere.com/paper/1902.09685