Patrick Bahr IT University of Copenhagen

Partial Compiler Calculation with Skew Bisimilarity

Patrick Bahr
Submitted for peer review, July 2024.

Abstract

Compiler calculation is a technique for deriving a correct-by-construction compiler from the specification of the compiler's correctness. In this setting, the compiler specification typically states that the semantics of each compiled program is bisimilar to the semantics of the original source program, i.e. both programs have the same behaviour. However, full bisimilarity for all source programs is too strong of a requirement for complex source languages with unsafe behaviour for which the compiler need not make any guarantees, e.g. because programs that exhibit unsafe behaviour are ruled out by the type checker. This has been long recognised and exploited in compiler verification, but to date no calculation technique can handle such partial specifications. To address this, we propose a generalisation of bisimilarity, called skew bisimilarity, that allows us to weaken the compiler specification so that we may safely ignore unsafe behaviour when calculating a compiler for the specification. We demonstrate that skew bisimilarity enables us to derive more efficient compilers while at the same time obtaining the same strong correctness guarantees for safe source programs.

We further show that – even for languages without unsafe behaviour – skew bisimilarity provides a powerful generalisation of bisimilarity that enables a novel calculation technique for reasoning about register machines. This improves on existing compiler calculation techniques for register machines, which are limited to terminating source languages without effects. To demonstrate the effectiveness of skew bisimilarity as a proof technique, we calculate compilers for a variety of languages, including the first calculation of a compiler for a typed concurrent lambda calculus that targets a register machine.

Categories: Compilers, Formal Verification

Tags: Program Calculation, Graphs, Bisimilarity, Choice Trees