一句话:提出 Metamorph,利用 Dafny 验证器反例与分段距离度量,将大型对象的长方法调用序列合成化为加权 A* 搜索。
程序合成旨在生成满足规约的代码。本文从形式化 API 规约合成方法调用序列来构造满足性质的对象,用于自动测试生成。连续调用求解代价高,现有方法常限制调用次数。作者提出 Metamorph:用 Dafny 验证器反例逐次分析方法调用效果,降低 SMT 查询复杂度;并用距离度量比较反例指导搜索。其分段距离将对象状态视为原子约束合取,经整数规划组合各调用可满足的约束,给出调用数的可证下界,并把合成化为加权 A* 搜索。在链表、队列、数组、二叉树和图六个基准上,每实例最多合成 57 次调用,优于基线;与 DTest 集成后能覆盖 AWS 加密材料提供者库中 DTest 漏掉的部分,并为简单虚拟机生成可执行字节码。
Program synthesis aims to produce code that adheres to user-provided specifications. In this work, we focus on synthesizing sequences of calls to formally specified APIs to generate objects that satisfy certain properties. This problem is particularly relevant in automated test generation, where a test engine may need an object with specific properties to trigger a given execution path. Constructing instances of complex data structures may require dozens of method calls, but reasoning about consecutive calls is computationally expensive, and existing work typically limits the number of calls in the solution. In this paper, we focus on synthesizing such long sequences of method calls in the Dafny programming language. To that end, we introduce Metamorph, a synthesis tool that uses counterexamples returned by the Dafny verifier to reason about the effects of method calls one at a time, limiting the complexity of solver queries. We also aim to limit the overall number of SMT queries by comparing the counterexamples using two distance metrics we develop for guiding the synthesis process. In particular, we introduce a novel piecewise distance metric, which puts a provably correct lower bound on the number of method calls in the solution and allows us to frame the synthesis problem as weighted A* search. When computing piecewise distance, we view object states as conjunctions of atomic constraints, identify constraints that each method call can satisfy, and combine this information using integer programming. We evaluate Metamorph’s ability to generate large objects on six benchmarks defining key data structures: linked lists, queues, arrays, binary trees, and graphs. Metamorph can successfully construct programs that require up to 57 method calls per instance and compares favorably to an alternative baseline approach. Additionally, we integrate Metamorph with DTest, Dafny’s automated test generation toolkit, and show that Metamorph can synthesize test inputs for parts of the AWS Cryptographic Material Providers Library that DTest alone is not able to cover. Finally, we use Metamorph to generate executable bytecode for a simple virtual machine, demonstrating that the techniques described here are more broadly applicable in the context of specification-guided synthesis.
@article{paperbot3218,
title = {Metamorph: Synthesizing Large Objects from Dafny Specifications},
author = {Aleksandr Fedchin and Alexander Y. Bai and Jeffrey S. Foster},
journal = {Proceedings of the ACM on Programming Languages},
volume = {9},
number = {OOPSLA1},
year = {2025},
doi = {10.1145/3720448}
}