Adventure of a Lifetime: Extract Method Refactoring for Rust

Author:

Thy Sewen1ORCID,Costea Andreea2ORCID,Gopinathan Kiran3ORCID,Sergey Ilya3ORCID

Affiliation:

1. Yale-NUS College, Singapore, Singapore

2. National University of Singapore, Singapores, Singapore

3. National University of Singapore, Singapore, Singapore

Abstract

We present a design and implementation of the automated "Extract Method" refactoring for Rust programs. Even though Extract Method is one of the most well-studied and widely used in practice automated refactorings, featured in all major IDEs for all popular programming languages, implementing it soundly for Rust is surprisingly non-trivial due to the restrictions of the Rust's ownership and lifetime-based type system. In this work, we provide a systematic decomposition of the Extract Method refactoring for Rust programs into a series of program transformations, each concerned with satisfying a particular aspect of Rust type safety, eventually producing a well-typed Rust program. Our key discovery is the formulation of Extract Method as a composition of naive function hoisting and a series of automated program repair procedures that progressively make the resulting program "more well-typed" by relying on the corresponding repair oracles. Those oracles include a novel static intra-procedural ownership analysis that infers correct sharing annotations for the extracted function's parameters, and the lifetime checker of rustc, Rust's reference compiler. We implemented our approach in a tool called REM---an automated Extract Method refactoring built on top of IntelliJ IDEA plugin for Rust. Our extensive evaluation on a corpus of changes in five popular Rust projects shows that REM (a) can extract a larger class of feature-rich code fragments into semantically correct functions than other existing refactoring tools, (b) can reproduce method extractions performed manually by human developers in the past, and (c) is efficient enough to be used in interactive development.

Funder

Singapore Ministry of Education

Publisher

Association for Computing Machinery (ACM)

Subject

Safety, Risk, Reliability and Quality,Software

Reference50 articles.

1. Lars Ole Andersen . 1994. Program analysis and specialization for the C programming language. Ph. D. Dissertation . University of Copenhagen. Denmark. Lars Ole Andersen. 1994. Program analysis and specialization for the C programming language. Ph. D. Dissertation. University of Copenhagen. Denmark.

2. Isaiah Ayooluwa Ledru Sylvestre and Ivy Roy. 2020. Rewriting the GNU Coreutils in Rust. https://lwn.net/Articles/857599/ Isaiah Ayooluwa Ledru Sylvestre and Ivy Roy. 2020. Rewriting the GNU Coreutils in Rust. https://lwn.net/Articles/857599/

3. Refactoring support for class library migration

4. Ownership types for safe programming

5. Capabilities for Sharing

Cited by 1 articles. 订阅此论文施引文献 订阅此论文施引文献,注册后可以免费订阅5篇论文的施引文献,订阅后可以查看论文全部施引文献

1. Behind the Intent of Extract Method Refactoring: A Systematic Literature Review;IEEE Transactions on Software Engineering;2024-04

同舟云学术

1.学者识别学者识别

2.学术分析学术分析

3.人才评估人才评估

"同舟云学术"是以全球学者为主线,采集、加工和组织学术论文而形成的新型学术文献查询和分析系统,可以对全球学者进行文献检索和人才价值评估。用户可以通过关注某些学科领域的顶尖人物而持续追踪该领域的学科进展和研究前沿。经过近期的数据扩容,当前同舟云学术共收录了国内外主流学术期刊6万余种,收集的期刊论文及会议论文总量共计约1.5亿篇,并以每天添加12000余篇中外论文的速度递增。我们也可以为用户提供个性化、定制化的学者数据。欢迎来电咨询!咨询电话:010-8811{复制后删除}0370

www.globalauthorid.com

TOP

Copyright © 2019-2024 北京同舟云网络信息技术有限公司
京公网安备11010802033243号  京ICP备18003416号-3