一句话:提出基于归纳程序合成与神经引导的命令式到函数式 API 代码转译方法,工具 NGST2 显著优于多个基线。
主流语言虽引入函数式 API,但缺乏自动把既有命令式代码转译为函数式变体的技术。本文提出基于归纳程序合成的转译方法,核心观察是源/目标程序大多满足 trace-compatibility:不仅共享语法相同的底层表达式,其在对应执行轨迹中的取值也相同。据此设计神经引导合成算法,采用名为 cognate grammar network(CGN)的新型神经架构,并用 concolic execution 依据中间值剪枝部分程序。作者实现工具 NGST2,将命令式 Java/Python 代码分别转译为使用 Stream 与 functools 的变体。实验显示 NGST2 显著优于多个基线,神经架构与剪枝技术对效果至关重要。
While many mainstream languages such as Java, Python, and C# increasingly incorporate functional APIs to simplify programming and improve parallelization/performance, there are no effective techniques that can be used to automatically translate existing imperative code to functional variants using these APIs. Motivated by this problem, this paper presents a transpilation approach based on inductive program synthesis for modernizing existing code. Our method is based on the observation that the overwhelming majority of source/target programs in this setting satisfy an assumption that we call trace-compatibility: not only do the programs share syntactically identical low-level expressions, but these expressions also take the same values in corresponding execution traces. Our method leverages this observation to design a new neural-guided synthesis algorithm that (1) uses a novel neural architecture called cognate grammar network (CGN) and (2) leverages a form of concolic execution to prune partial programs based on intermediate values that arise during a computation. We have implemented our approach in a tool called NGST2 and use it to translate imperative Java and Python code to functional variants that use the Stream and functools APIs respectively. Our experiments show that NGST2 significantly outperforms several baselines and that our proposed neural architecture and pruning techniques are vital for achieving good results.
@article{paperbot1526,
title = {Automated transpilation of imperative to functional code using neural-guided program synthesis},
author = {Benjamin Mariano and Yanju Chen and Yu Feng and Greg Durrett and Işil Dillig},
journal = {Proceedings of the ACM on Programming Languages},
volume = {6},
number = {OOPSLA1},
year = {2022},
doi = {10.1145/3527315}
}