Skip to content

Commit 1db3d0b

Browse files
author
potanin
committed
Aiming for ACSC2017.
1 parent a227263 commit 1db3d0b

20 files changed

+8606
-0
lines changed

papers/ACSC2017/background.tex

Lines changed: 367 additions & 0 deletions
Large diffs are not rendered by default.

papers/ACSC2017/conclusion.tex

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
\section{Conclusion}\label{C:con}
2+
% Documentation of API is necessary.
3+
This work has explored refactoring and providing tool-support within the context of the Rust programming language. Utilizing existing infrastructure provided by the compiler, this work identifies extensions which help facilitate common automated refactorings. In a more general sense, this work attempts to build upon existing work done on refactoring by documenting specific decisions made in building a refactoring tool (which might normally only be encoded in the source code of an actual tool), and attempting to analyze the decisions made by others.
4+
5+
% Rust provides some unique obstacles in providing automated refactorings...
6+
7+
At the moment the provided tool supports renaming of local and global variables, fields, function arguments, structs, enum and functions (or methods). Beyond renaming, it also allows reification and elision of lifetime parameters for functions and methods and has preliminary support for inlining of local variables. These refactorings in particular highlight the idiosyncrasies of Rust, ensuring that the analyses performed here are some of the first of its kind. The complete limitations of these refactorings are not yet fully known, but there exists a current suite of tests to ensure that there are no obvious flaws in the approach. The presence of bugs in the compiler is a real problem to generality, but without real world use and more contribution to testing, finding these corner cases appears to be difficult.
8+
9+
At the moment, Rust lacks significant refactoring tool-support and evidently requires more work particularly within the compiler to enable further, valuable progress. Although a preliminary tool has been provided, there are many avenues for continuing work and the hope is that this first investigation provides useful insight for future efforts. Understanding the required context and the necessary infrastructure has been a major part of this work. In particular, learning and understanding Rust has been incredibly challenging, as it introduces concepts rarely used elsewhere. Continuation of this work should allow greater focus on implementing a more difficult and comprehensive set of refactorings for Rust.
10+
11+
\section{Appendix}\label{C:appen}
12+
\section{Eclipse refactorings}
13+
\begin{center}
14+
\begin{figure}
15+
\scalebox{0.9}{
16+
\begin{tabular}{ l | l | l }
17+
Rename &
18+
Move &
19+
Extract Method \\
20+
Extract Local Variable &
21+
Extract Constant &
22+
Inline \\
23+
Move Type to New File &
24+
Extract Superclass &
25+
Extract Interface \\
26+
Push Down &
27+
Pull Up &
28+
Extract Class \\
29+
Introduce Indirection &
30+
Introduce Factory &
31+
Introduce Parameter \\
32+
Encapsulate Field &
33+
Generalize Declared Type &
34+
Migrate JAR File \\
35+
Change Method Signature &
36+
Convert Anon. Class to Nested &
37+
Convert Local Variable to Field \\
38+
Use Supertype Where Possible &
39+
Introduce Parameter Object &
40+
Infer Generic Type Arguments
41+
\end{tabular}
42+
}
43+
\caption{List of refactorings supported by Eclipse}
44+
\label{Fig:eclipse}
45+
\end{figure}
46+
\end{center}

papers/ACSC2017/evaluation.tex

Lines changed: 290 additions & 0 deletions
Large diffs are not rendered by default.

papers/ACSC2017/futurework.tex

Lines changed: 102 additions & 0 deletions
Large diffs are not rendered by default.

papers/ACSC2017/garming.bib

Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
%% This BibTeX bibliography file was created using BibDesk.
2+
%% http://www.cs.ucsd.edu/~mmccrack/bibdesk.html
3+
4+
5+
%% Created for neil at 2002-12-09 14:04:13 +1300
6+
7+
@misc{rustcore15,
8+
author = "{The Rust Core Team}",
9+
title = {{Announcing Rust 1.0 - The Rust Programming Language Blog}},
10+
howpublished = {\url{http://blog.rust-lang.org/2015/05/15/Rust-1.0.html}},
11+
year=2015,
12+
}
13+
14+
@misc{rustbook15,
15+
author = "{The Rust Community}",
16+
title = {{The Rust programming Language}},
17+
howpublished = {\url{https://doc.rust-lang.org/book/README.html}},
18+
year=2015,
19+
}
20+
21+
@misc{faq15,
22+
author = "{The Rust Project Developers}",
23+
title = {{The Rust Project FAQ}},
24+
howpublished = {\url{https://doc.rust-lang.org/complement-project-faq.html}},
25+
year=2015,
26+
}
27+
28+
@misc{traitexample15,
29+
author = "{The Rust Community}",
30+
title = {{Traits}},
31+
howpublished = {\url{http://rustbyexample.com/trait.html}},
32+
year=2015,
33+
}
34+
35+
@misc{docowner15,
36+
author = "{The Rust Community}",
37+
title = {{Ownership}},
38+
howpublished = {\url{https://doc.rust-lang.org/book/ownership.html}},
39+
year=2015,
40+
}
41+
42+
@misc{docborrow15,
43+
author = "{The Rust Community}",
44+
title = {{Borrowing}},
45+
howpublished = {\url{https://doc.rust-lang.org/book/references-and-borrowing.html}},
46+
year=2015,
47+
}
48+
49+
@misc{docmod15,
50+
author = "{The Rust Community}",
51+
title = {{Crates and Modules}},
52+
howpublished = {\url{http://static.rust-lang.org/doc/master/book/crates-and-modules.html}},
53+
year=2015,
54+
}
55+
56+
@misc{openhub15,
57+
author = "{Black Duck Open HUB}",
58+
title = {{Rust (programming language)}},
59+
howpublished = {\url{http://code.openhub.net/project?pid=&ipid=301463}},
60+
year=2015,
61+
}
62+
63+
@misc{makefile15,
64+
author = "{The Rust Community}",
65+
title = {{Rust Wiki - Compiler Snapshots}},
66+
howpublished = {\url{https://github.com/rust-lang/rust-wiki-backup/blob/master/Note-compiler-snapshots.md}},
67+
year=2015,
68+
}
69+
70+
@misc{examplecrates15,
71+
author = "{The Rust Community}",
72+
title = {{Crates)}},
73+
howpublished = {\url{http://rustbyexample.com/crates.html}},
74+
year=2015,
75+
}
76+
77+
@misc{driver15,
78+
author = "{The Rust Community}",
79+
title = {{librustc\_driver -- driver.rs}},
80+
howpublished = {\url{https://github.com/rust-lang/rust/blob/master/src/librustc_driver/driver.rs}},
81+
year=2015,
82+
}
83+
84+
@misc{dxr15,
85+
author = "{Github}",
86+
title = {{Rust DXR plugin}},
87+
howpublished = {\url{https://github.com/nrc/dxr/blob/rust5/dxr/plugins/rust/__init__.py}},
88+
year=2015,
89+
}
90+
91+
@misc{docpath15,
92+
author = "{The Rust Community}",
93+
title = {{Struct syntax::ast::Path}},
94+
howpublished = {\url{http://doc.rust-lang.org/syntax/ast/struct.Path.html}},
95+
year=2015,
96+
}
97+
98+
@misc{doc15,
99+
author = "{The Rust Community}",
100+
title = {{Rust Documentation}},
101+
howpublished = {\url{https://doc.rust-lang.org/}},
102+
year=2015,
103+
}
104+
105+
@misc{keep15,
106+
author = {Keep, Daniel},
107+
title = {{A Practical Intro to Macros in Rust 1.0}},
108+
howpublished = {\url{https://danielkeep.github.io/practical-intro-to-macros.html}},
109+
year=2015,
110+
}
111+
112+
@article{foote1997big,
113+
title={Big ball of mud},
114+
author={Foote, Brian and Yoder, Joseph},
115+
journal={Pattern languages of program design},
116+
volume={4},
117+
pages={654--692},
118+
year={1997}
119+
}
120+
121+
@phdthesis{opdyke1992refactoring,
122+
title={Refactoring object-oriented frameworks},
123+
author={Opdyke, William F},
124+
year={1992},
125+
school={University of Illinois at Urbana-Champaign}
126+
}
127+
128+
@phdthesis{schafer2010specification,
129+
title={Specification, Implementation and Verification of Refactorings},
130+
author={Schafer, Max},
131+
year={2010},
132+
school={Oxford University}
133+
}
134+
135+
@misc{gofmt15,
136+
author = "{The Go Authors}",
137+
title = {{Command gofmt}},
138+
howpublished = {\url{https://golang.org/cmd/gofmt/}},
139+
year=2015,
140+
}
141+
142+
@misc{gofix11,
143+
author = {Cox, Russ},
144+
title = {{Introducing Gofix}},
145+
howpublished = {\url{http://blog.golang.org/introducing-gofix}},
146+
year=2011,
147+
}
148+
149+
@misc{gorename15,
150+
author = "{The Go Authors}",
151+
title = {{Rename: check.go}},
152+
howpublished = {\url{https://github.com/golang/tools/blob/master/refactor/rename/check.go}},
153+
year=2015,
154+
}
155+
156+
@phdthesis{stocker2010scala,
157+
title={Scala refactoring},
158+
author={Stocker, Mirko},
159+
year={2010},
160+
school={HSR Hochschule f{\"u}r Technik Rapperswil}
161+
}
162+
163+
@misc{scala15,
164+
author = "{Scala Refactoring}",
165+
title = {{Scala Refactoring: Refactorings}},
166+
howpublished = {\url{http://scala-refactoring.org/screenshots/}},
167+
year=2015,
168+
}
169+
170+
@phdthesis{brown2008tool,
171+
title={Tool Support for Refactoring Haskell Programs},
172+
author={Brown, Christopher Mark},
173+
year={2008},
174+
school={University of Kent}
175+
}
176+
177+
@article{baumer2001integrating,
178+
title={Integrating refactoring support into a Java development tool},
179+
author={B{\"a}umer, Dirk and Gamma, Erich and Kiezun, Adam},
180+
journal={OOPSLA’01 Companion},
181+
year={2001}
182+
}
183+
184+
@misc{widmer07,
185+
author = {Widmer, Tobias},
186+
title = {{Unleashing the Power of Refactoring}},
187+
howpublished = {\url{http://www.eclipse.org/articles/article.php?file=Article-Unleashing-the-Power-of-Refactoring/index.html}},
188+
year=2007,
189+
}
190+
191+
@misc{cratesio15,
192+
author = {Crates.io},
193+
title = {{Cargo: The Rust Community's crate host}},
194+
howpublished = {\url{https://crates.io/}},
195+
year=2015,
196+
}
197+
198+
@article{carruth2011clang,
199+
title={{Clang MapReduce-Automatic C++ Refactoring at Google Scale}},
200+
author={Carruth, C},
201+
journal={Google Inc},
202+
year={2011}
203+
}
204+
205+
@misc{jetbrains15,
206+
author = {Jetbrains},
207+
title = {{Multi-language Refactorings}},
208+
howpublished = {\url{https://www.jetbrains.com/idea/features/refactoring.html}},
209+
year=2015,
210+
}
211+
212+
@inproceedings{jemerov2008implementing,
213+
title={{Implementing refactorings in IntelliJ IDEA}},
214+
author={Jemerov, Dmitry},
215+
booktitle={Proceedings of the 2nd Workshop on Refactoring Tools},
216+
pages={13},
217+
year={2008},
218+
organization={ACM}
219+
}
220+
221+
@book{fowler99,
222+
Year = {1999},
223+
Title = {Refactoring: Improving the Design of Existing Code},
224+
Address = {Reading, Massachusetts, USA},
225+
Publisher = {Addison-Wesley},
226+
Author = {Fowler, Martin and Beck, Kent}}
227+
228+
@inproceedings{sculthorpe,
229+
title={{The HERMIT in the Tree}},
230+
author={Sculthorpe, Neil and Farmer, Andrew and Beck, Kent},
231+
booktitle={{24th Symposium on Implementation and Application of Functional Languages, 2012}},
232+
pages={86--103},
233+
year={2013},
234+
organization={Springer}
235+
}
236+
237+
@misc{elisionrules,
238+
author = "{The Rust Community}",
239+
title = {{RFC - Lifetime elision}},
240+
howpublished = {\url{https://github.com/rust-lang/rfcs/blob/master/text/0141-lifetime-elision.md}},
241+
year=2014,
242+
}
243+
244+
245+
@misc{pwalton,
246+
author = "{Walton, P. (Mozilla)}",
247+
title = {{Why in the Rust language functions are not pure by default? -- Email}},
248+
howpublished = {\url{https://mail.mozilla.org/pipermail/rust-dev/2013-January/002903.html}},
249+
year=2013,
250+
}
251+
252+
@inproceedings{effects,
253+
title={{Lightweight polymorphic effects}},
254+
author={Rytz, Lukas and Odersky, Martin and Philipp Haller},
255+
booktitle={{Object-Oriented Programming -- ECOOP}},
256+
pages={258--282},
257+
year={2012},
258+
organization={Springer}
259+
}
260+
261+
@misc{inherit,
262+
author = "{The Rust Community}",
263+
title = {{RFC - Efficient code reuse}},
264+
howpublished = {\url{https://github.com/rust-lang/rfcs/issues/349}},
265+
year=2014,
266+
}
267+
268+
@inproceedings{graph,
269+
title={{Formalising behaviour preserving program transformations}},
270+
author={Mens, Tom and Demeyer, Serge and Janssens, Dirk },
271+
booktitle={{International Conferenceon Graph Transformation (ICGT 2002)}},
272+
pages={286--301},
273+
year={2002},
274+
organization={Springer-Verlag}
275+
}
276+
277+
@article{aop,
278+
title={The paradoxical success of aspect-oriented programming},
279+
author={Steimann, Friedrich},
280+
journal={ACM Sigplan Notices},
281+
volume={41},
282+
pages={481--497},
283+
year={2006}
284+
}
285+
286+
@misc{rrproject,
287+
author = {Sam, Garming},
288+
title = {{rust-refactor: Rust refactoring project}},
289+
howpublished = {\url{https://github.com/GSam/rust-refactor}},
290+
year=2015,
291+
}
292+
293+
@misc{rfmt,
294+
author = "{The Rust Community}",
295+
title = "{rustfmt: Format Rust code}",
296+
howpublished = {\url{https://github.com/nrc/rustfmt}},
297+
year=2015,
298+
}
299+
300+

papers/ACSC2017/introduction.tex

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
\section{Introduction}\label{C:intro}
2+
This work is concerned with the analysis and implementation of tools to support the automated refactoring of Rust programs. The resulting refactoring tool built is written in Rust and available from Github under an MIT license \cite{rrproject}. The purpose of this chapter is to describe the overall work presented in this document and to begin to describe aspects of the motivation for pursuing this work. In Section \ref{S:rustintro} and Section \ref{S:refactorintro}, the context of the project is introduced with Rust and refactoring. In Section \ref{S:implemented}, the definite list of refactorings supported by the tool is described, along with a brief description of each. Lastly, in Section \ref{S:outline}, a summary of the subsequent chapters and the remaining document is given.
3+
4+
%In Section \ref{S:contrib}, the contributions made by this work are described.
5+
%In Chapter \ref{C:us} we explain how to use this document, and the \texttt{vuwproject} style. In Chapter \ref{C:ex} we say some things about \LaTeX, and in Chapter \ref{C:con} we give our conclusions.
6+
7+
\subsection{Introducing the Rust programming language}\label{S:rustintro}
8+
9+
% http://blog.rust-lang.org/2015/05/15/Rust-1.0.html
10+
11+
The Rust programming language, as of May 2015, reached the 1.0 milestone \cite{rustcore15}. Backed by Mozilla and Mozilla Research, Rust is open source and generates a number of contributions from the community. As a modern memory-safe systems programming language, the aim for the language is to provide reliable and efficient systems by combining the performance of low level control, with the convenience and guarantees of higher level constructs. All of this is achieved without a garbage collector or runtime and allows interoperability with no overhead with C. Rust enforces an ownership system to restrict the duplication of references through borrowing and lifetimes, while still aiming for `zero cost abstractions'. Using these techniques, Rust prevents dangling pointers and a whole class of related issues concerning iterator invalidation, concurrency and more \cite{rustbook15}.
12+
13+
Rust has been a number of years in the making, beginning as a side-project in 2006 \cite{faq15}, but only with this public 1.0 release has many of the standard library API stabilized. In order to further present itself as a stable and mature language, there is still another component which has yet to be adequately tackled: tooling. Developers commonly use a rich set of tools to simplify the task of building complex software with IDE, editors and debuggers. Such tools can improve productivity and providing tools specific to a language may help to encourage adoption.
14+
15+
\subsection{The issue of refactoring}\label{S:refactorintro}
16+
Refactoring is the act of performing functionality preserving code transformation. Traditionally, these transformations needed to be performed manually, but in recent years, a number of tools to aid and automate refactorings have arisen in many programming languages such as Java or C++ \cite{brown2008tool}. Manual transformations, including editor search-and-replace are potentially prone to error and so performing tool-assisted refactoring which guarantees some measure of correctness can provide much greater confidence in changes.
17+
18+
%\subsection{Contributions of this work}\label{S:contrib}
19+
%The main purpose of this work is to produce a proof-of-concept refactoring tool which utilizes existing infrastructure made available by the Rust compiler. With continuing expectations for change within the language and compiler and a number of API are still undergoing stabilization, a refactoring tool would prove beneficial for users at risk of changes breaking their code underneath them. In particular, API changes which convert global functions e.g. foo(A, B) to A.foo(B), to methods acting on an object are common and providing hopefully this work provides some insight into the necessary work to achieve such a refactoring.
20+
21+
%Exploring the necessary barriers to implementing a refactoring tool, proposals or implementation of extensions to the Rust compiler are brought forth and help to identify current shortcomings with providing refactoring tools for the Rust programming language and work necessary to improve the capability of Rust to support refactoring. Additionally, the current extent of the ability for the compiler to facilitate refactoring is evaluated and a number of internal or unstable API are assessed. The compile driver API which provides the ability for Rust code to invoke the compiler is a primary example of code which has seen little real world usage. The name resolution module within the compiler is another key example used in this work for performing refactoring, being used in a manner not originally intended or imagined despite providing part of the functionality required for implementing such a tool.
22+
23+
% This work also attempts to provide initial evaluations as to the effectiveness and practicality of the current tool. Furthermore it aims to identify the most useful refactorings not currently supported by the tool and the most useful future changes required within the compiler for further iterations on the current work.
24+
25+
%Implemented tool and refactorings
26+
\subsection{Contributions}\label{S:implemented}
27+
The main purpose of this work is to produce a proof-of-concept refactoring tool which utilizes existing infrastructure made available by the Rust compiler. The idea was to produce a tool which may be run to provide a set of refactorings, which may continue to be extended in the future. The list of implemented refactorings is as follows:
28+
29+
%Although listed here, further details can be found on these refactorings in Chapters \ref{C:wd}, \ref{C:impl} and \ref{C:eval}.
30+
31+
\begin{itemize}
32+
\item {\bfseries Renaming local and global variables} -- Variables declared within a function or method, or in a global namespace
33+
%\item {\bfseries Renaming global variables} -- Variables in a global namespace
34+
\item {\bfseries Renaming function arguments} -- Renaming local variables declared by a function or method signature
35+
\item {\bfseries Renaming fields} -- Struct-local members
36+
\item {\bfseries Renaming functions and methods} -- Statically or dynamically dispatched functions, and functions belonging to objects, including overridden methods
37+
\item {\bfseries Renaming structs} -- Custom data types declaring fields and methods
38+
\item {\bfseries Renaming enumerations} -- Enumerated data types declaring fields and methods
39+
\item {\bfseries Inlining local variables} -- Replacing usages of a local variable with its initializing expression
40+
\item {\bfseries Reification of lifetime parameters} -- Reintroducing inferred lifetimes for function and method signatures
41+
\item {\bfseries Elision of lifetime parameters} -- Removing lifetimes in function and method signatures that may be inferred (by the compiler)
42+
\end{itemize}
43+
44+
%[WHAT MAKES IT HARD?] Namespaces, local and anonymous blocks, macros...
45+
In performing this work, this project has helped understand difficulties with the Rust language and building refactoring tools, such as the hygienic macro-system. The first investigation of providing functionality for inlining a local variable in Rust has been presented here, as well as reification and elision of lifetime parameters (transformations whose natures are specific to Rust). As the user of an infrequently used compiler API, a number of general shortcomings have been identified with the overall approach, with several patches being submitted to the Rust compiler to help facilitate this work. It is the hope that some of these considerations are noted as the Rust compiler continues to evolve.
46+
47+
\subsection{Document outline}\label{S:outline}
48+
In Chapter \ref{C:back}, we explore the prior related work and background knowledge required in understanding the work presented in this document. In Chapter \ref{C:wd}, we explain the general concepts of Rust refactoring, while in Chapter \ref{C:impl}, we discuss details of the implementation, focusing specifically on the tool itself and its associated design decisions. In Chapter \ref{C:eval}, we discuss opportunities for evaluation of the tool and the current extent of testing for refactorings provided by the tool and overall validity. In Chapter \ref{C:future}, we propose a number of further extensions to the tool, to the Rust compiler and in general, outline areas of future work while providing useful insights gained during the course of this work. Lastly, Chapter \ref{C:con} presents a summary, and gives conclusions about this work.

0 commit comments

Comments
 (0)