Object-oriented programs tend to be written using many common coding idioms, such as those captured by design patterns. While design patterns are useful, implementing them is often tedious and repetitive, requiring boilerplate code that distracts the programmer from more essential details. In this paper, we introduce Mason, a tool that synthesizes object-oriented programs from partial program pieces, and we apply it to automatically insert design patterns into programs. At the core of Mason is a novel technique we call type- and name-guided synthesis, in which an enumerative solver traverses a partial program to generate typing constraints; discharges constraints via program transformations guided by the names of constrained types and members; and backtracks when a constraint is violated or a candidate program fails unit tests. We also introduce two extensions to Mason: a non-local backtracking heuristic that uses execution traces, and a language of patterns that impose syntactic restrictions on missing names. We evaluate Mason on a suite of benchmarks to which Mason must add various well-known design patterns implemented as a library of program pieces. We find that Mason performs well when very few candidate programs satisfy its typing constraints and that our extensions can improve Mason's performance significantly when this is not the case. We believe that Mason takes an important step forward in synthesizing multi-class object-oriented programs using design patterns.


翻译:面向对象程序往往采用许多常见的编码惯用法编写,例如设计模式所捕获的那些模式。尽管设计模式很有用,但其实现过程通常繁琐且重复,需要大量样板代码,这使程序员从更本质的细节中分心。本文介绍Mason——一种能够从局部程序片段合成面向对象程序的工具,并将其应用于自动将设计模式插入程序中。Mason的核心是一种我们称为类型与名称引导合成的新技术:枚举求解器通过遍历局部程序生成类型约束;利用受约束类型及成员名称引导的程序变换来消解约束;并在约束被违反或候选程序未通过单元测试时进行回溯。我们还为Mason引入了两项扩展:一种利用执行轨迹的非局部回溯启发式策略,以及一种对缺失名称施加语法限制的模式语言。我们在基准测试集上评估Mason,该测试集要求Mason添加以程序片段库形式实现的各种经典设计模式。实验发现,当极少数候选程序满足其类型约束时,Mason表现良好;而在不满足此条件时,我们的扩展能显著提升Mason的性能。我们相信,Mason在使用设计模式合成多类别面向对象程序方面迈出了重要的一步。

0
下载
关闭预览

相关内容

大型语言模型系统中提示缺陷的分类学
专知会员服务
8+阅读 · 2025年9月19日
《大型语言模型代码生成》综述
专知会员服务
68+阅读 · 2024年6月4日
自动编程:大型语言模型及其他
专知会员服务
36+阅读 · 2024年5月12日
【Manning新书】面向数据编程降低软件复杂度,426页pdf
专知会员服务
88+阅读 · 2022年9月5日
【Manning新书】面向数据编程:减少软件复杂度,426页pdf
专知会员服务
81+阅读 · 2022年7月20日
基于模型系统的系统设计
科技导报
10+阅读 · 2019年4月25日
超像素、语义分割、实例分割、全景分割 傻傻分不清?
计算机视觉life
19+阅读 · 2018年11月27日
NLP中自动生产文摘(auto text summarization)
机器学习研究会
14+阅读 · 2017年10月10日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
2+阅读 · 2014年12月31日
VIP会员
相关基金
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
2+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员