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篇论文的施引文献,订阅后可以查看论文全部施引文献