Thesis-Joqvist-Final
Total Page:16
File Type:pdf, Size:1020Kb
Contributions to Declarative Implementation of Static Program Analysis Öqvist, Jesper 2018 Document Version: Publisher's PDF, also known as Version of record Link to publication Citation for published version (APA): Öqvist, J. (2018). Contributions to Declarative Implementation of Static Program Analysis. Department of Computer Science, Lund University. Total number of authors: 1 Creative Commons License: Unspecified General rights Unless other specific re-use rights are stated the following general rights apply: Copyright and moral rights for the publications made accessible in the public portal are retained by the authors and/or other copyright owners and it is a condition of accessing publications that users recognise and abide by the legal requirements associated with these rights. • Users may download and print one copy of any publication from the public portal for the purpose of private study or research. • You may not further distribute the material or use it for any profit-making activity or commercial gain • You may freely distribute the URL identifying the publication in the public portal Read more about Creative commons licenses: https://creativecommons.org/licenses/ Take down policy If you believe that this document breaches copyright please contact us providing details, and we will remove access to the work immediately and investigate your claim. LUND UNIVERSITY PO Box 117 221 00 Lund +46 46-222 00 00 Contributions to Declarative Implementation of Static Program Analysis Jesper Öqvist Doctoral Dissertation, 2019 Department of Computer Science Lund University ISBN 978-91-7753-944-5 (printed) ISBN 978-91-7753-945-2 (electronic) ISSN 1404-1219 Dissertation 61, 2019 LU-CS-DISS: 2019-01 Department of Computer Science Lund University Box 118 SE-221 00 Lund Sweden Email: [email protected] Typeset using LATEX. Printed in Sweden by Tryckeriet i E-huset, Lund, 2019. © 2019 Jesper Öqvist iii Abstract Programming languages are ever evolving, with new languages being invented to solve new problems, and old languages being extended to solve old problems in new ways. With the continued evolution of programming languages, and with new and improved static program analyses, we need flexible systems for building our static analyses and compilers. Declarative programming with Reference Attribute Grammars (RAGs) is a fruitful approach for building extensible and maintainable static program analyses and compilers. With declarative programming, code is easier to write, easier to understand, and easier to extend. This thesis presents contributions to declarative static program analysis imple- mentation with RAGs. In particular, I have developed new language extensions for the Java programming language, as well as new static analyses and tools for Java, based on the extensible Java compiler ExtendJ. Language extensions include an im- plementation of Java 7, and a new programming mechanism, multiplicities. A new static analysis-based tool presented in this thesis is a regression test selection tool, which reduces testing time for Java software development. My contributions also include new design patterns for declaratively specifying static analyses in RAGs, and significant improvements to the ExtendJ compiler. My work in ExtendJ includes developing the first version of the compiler with fully declarative static analysis. This dissertation also includes contributions to RAGs, including new algorithms for concurrent attribute evaluation with implementation in the JastAdd metacompiler. With these new algorithms, it is possible to parallelize any RAG-implemented anal- ysis. In particular, I parallelized static analysis in the ExtendJ compiler to achieve a twofold speedup and orders of magnitude reduction of latency. iv Acknowledgements This work was in part funded by the Swedish Research Council under grant 621- 2012-4727 and by a 2015 Google Faculty Research Award for supporting concurrent analyses in interactive programming tools. This dissertation would not exist if not for Prof. Görel Hedin. Görel convinced me to start my PhD studies and supervised me along the way. She told me what to do, corrected my mistakes, and listened to my weird ideas. I owe Görel my greatest thanks in helping me complete all of this work. I owe much gratitude to my beloved wife, Elise. She is the chillest wife, in the parlance of our times. Elise kept me sane and healthy while writing this thesis. I am also very grateful for our many fun travels and outings during my time as Ph.D. student. Thank you Prof. Boris Magnusson for co-supervising me and for the test selection collaboration. Thank you Emma Söderberg for co-supervising me, for getting me into running (RuntimeException), for hosting me at Google for my first internship, and for many fun collaborations related to JastAdd and other projects during my PhD studies. Thank you Prof. Friedrich Steimann for the multiplicities collaboration. It was fun to visit your department in Germany and to work intensely to complete most of the implementation in a week. Thank you Niklas Fors, Alfred Åkesson, and Christoff Bürger for collaborations related to JastAdd development and compiler construction. For entertaining and enlightening discussions during the time-honored tradition of fika, I would like to thank Christoph Reichenbach, Flavius Gruian, Linus Åkesson, Maj Stenmark, Pierre Moreau, Jonas Skeppstedt, Gustav Cedersjö, Noric Couderc, and all of my other colleagues at the computer science department in Lund, past and present. Thank you Erik Hogeman for the Java 8 project. Thank you to all the excellent people whom I had the pleasure to work with at Modelon (Jesper, Jon, Jonathan, Axel) and Google Mountain View (Ciera, Karl, Valentyn, Hans, Eddie). Thank you Arun Chauhan for hosting me during my second internship. The diagrams in this thesis would not look as nice without a few essential LATEXpackages. Thus, I owe my gratitude to the authors of the PGF/TikZ pack- ages, and especially Sašo Živanović for developing the excellent Forest package which I used for drawing all trees in the thesis. I was considering making a list of enemies and placing Måns Magnusson on it for distracting me with programming problems. However, I finished the thesis on time so I think we can continue to be friends. v Contribution Statement The following papers are included in this dissertation: Paper I Jesper Öqvist and Görel Hedin. “Extending the JastAdd Extensible Java Compiler to Java 7”. In Proceedings of the 10th International Conference on Principles and Practicies of Programming on the Java Platform: Virtual Machines, Languages, and Tools (PPPJ’13), ACM, pp. 147–152. Stuttgart, Germany, 2013. Paper II Friedrich Steimann, Jesper Öqvist, and Görel Hedin. “Multitudes of Ob- jects: First Implementation and Case Study for Java”. In Journal of Object Technology, Vol. 13, no. 5 (November 2014), pp. 1:1–33. Paper III Jesper Öqvist, Görel Hedin, and Boris Magnusson. “Extraction-Based Regression Test Selection” In Proceedings of the 13th International Conference on Principles and Practices of Programming on the Java Platform: Virtual Machines, Languages, and Tools (PPPJ’16), ACM, pp. 5:1–5:10. Lugano, Switzerland, 2016. Paper IV Jesper Öqvist and Görel Hedin. “Concurrent Circular Reference Attribute Grammars”. In Proceedings of the 10th ACM SIGPLAN International Confer- ence on Software Language Engineering (SLE 2017), pp. 151–162. Vancouver, BC, Canada, 2017. This thesis includes an extended version of this paper, with correctness proofs for the algorithms. This extended version of the paper was published as a technical report (report number 103, Lund University, 2017). The table below indicates the responsibilities Jesper Öqvist had in writing each paper: Paper Writing Concepts Implementation Evaluation Algorithm I YES YES YES YES N/A II partial no YES YES N/A III yes partial YES YES yes IV YES YES YES YES YES Capital letters indicate roles where Jesper Öqvist took primary responsibility for the given role. For Paper III, Jesper Öqvist wrote the first drafts of the paper, and then took main responsibility to finish the implementation and evaluation parts. For Paper II, Friedrich Steimann wrote the majority of the paper, with Jesper Öqvist taking responsibility for writing about implementation and evaluation as well as designing some of the figures/diagrams. For all papers, Jesper Öqvist developed the implementation and empirical evaluation. For Paper IV, Jesper Öqvist wrote all proofs, with feedback from Görel Hedin. Contents Introduction 1 I Introduction 3 1 Introduction . 3 2 Background . 6 3 Using RAGs for Extensible Analyses . 27 4 The ExtendJ Java Compiler . 36 5 Contributions . 54 6 Conclusions . 66 References . 66 Included Papers 75 I Extending the JastAdd Extensible Java Compiler to Java 7 77 1 Introduction . 77 2 The JastAddJ Compiler . 78 3 Try With Resources . 80 4 The Diamond Operator . 84 5 Evaluation . 86 6 Related Work . 90 7 Conclusion . 91 References . 91 II Multitudes of Objects: First Implementation and Case Study for Java 95 1 Introduction . 95 2 Using Collections for Representing Multitudes of Objects . 97 3 Programming with Multiplicities . 100 4 Multiplicities for Java . 104 5 Implementation . 109 6 Case Study . 112 7 Related Work . 122 viii CONTENTS 8 Future Work . 125 9 Conclusion . 126 References . 127 III Extraction-Based Regression Test Selection 131 1 Introduction . 131 2 Extraction-Based Test Selection . 133 3 Updating the dependency graph . 140 4 Dependencies for Java . 140 5 Tool implementation . 143 6 Evaluation