不可达代码的演算
A Calculus for Unreachable Code
AI总结:
本文提出首个不可达代码演算,用两类项重写规则刻画编译器删除与分支消除变换,并通过新逻辑关系证明正确性且对应 Racket、LLVM 实践。
摘要:
在 Racket、LLVM IR、Rust 以及其他现代语言中,程序员和静态分析可以通过特殊注解提示程序的某些部分是不可达的。与关于未定义行为的其他假设一样,编译器会假定这些提示正确,并据此对程序进行激进变换。尽管由未定义行为引发的编译期变换常常令编译器编写者和开发者感到困惑,但我们表明,由不可达代码引发的变换,其本质可以提炼为一组出人意料地少而简单的形式规则。具体而言,遵循通过演算理解语言现象这一成熟传统,我们提出了首个面向不可达性的演算。其利用不可达性的项重写规则分为两类:第一类允许编译器删除不可达点下游的任意代码,以及不可达点上游的任意无副作用代码;第二类由在条件表达式的某个分支不可达时消除该条件表达式的规则组成。我们使用一种新颖的逻辑关系证明这些规则的正确性,并考察它们如何对应于 Racket 和 LLVM 中由不可达性引发的变换。
英文摘要:
In Racket, the LLVM IR, Rust, and other modern languages, programmers and static analyses can hint, with special annotations, that certain parts of a program are unreachable. Same as other assumptions about undefined behavior; the compiler assumes these hints are correct and transforms the program aggressively. While compile-time transformations due to undefined behavior often perplex compiler writers and developers, we show that the essence of transformations due to unreachable code can be distilled in a surprisingly small set of simple formal rules. Specifically, following the well-established tradition of understanding linguistic phenomena through calculi, we introduce the first calculus for unreachable. Its term-rewriting rules that take advantage of unreachable fall into two groups. The first group allows the compiler to delete any code downstream of unreachable, and any effect-free code upstream of unreachable. The second group consists of rules that eliminate conditional expressions when one of their branches is unreachable. We show the correctness of the rules with a novel logical relation, and we examine how they correspond to transformations due to unreachable in Racket and LLVM.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。