Algorithmic Resource Verification
Total Page:16
File Type:pdf, Size:1020Kb
Algorithmic Resource Verification THÈSE NO 7885 (2017) PRÉSENTÉE LE 9 NOVEMBRE 2017 À LA FACULTÉ INFORMATIQUE ET COMMUNICATIONS LABORATOIRE D'ANALYSE ET DE RAISONNEMENT AUTOMATISÉS PROGRAMME DOCTORAL EN INFORMATIQUE ET COMMUNICATIONS ÉCOLE POLYTECHNIQUE FÉDÉRALE DE LAUSANNE POUR L'OBTENTION DU GRADE DE DOCTEUR ÈS SCIENCES PAR Ravichandhran KANDHADAI MADHAVAN acceptée sur proposition du jury: Prof. M. Odersky, président du jury Prof. V. Kuncak, directeur de thèse Prof. R. Majumdar, rapporteur Dr G. Ramalingam, rapporteur Prof. J. Larus, rapporteur Suisse 2017 This thesis is dedicated to my maternal grandmother. Observing her I learnt what it means to work hard and be devoted. Acknowledgements As I reflect upon my journey through my PhD I feel a sense of elation but at the same time an overwhelming sense of gratitude to many people who made me realize this dream. I take this opportunity to thank them all. First and foremost, I thank my advisor Professor Viktor Kuncak for the very many ways in which he has helped me during the course of my PhD. It is impossible for me to imagine a person who would have more faith and confidence in me than my advisor. His presence felt like having a companion with immense knowledge and experience who is working side-by-side with me towards my PhD. Besides his help with the technical aspects of the research, he was a great source of moral support. He shared my elation and pride when I was going through a high phase, my disappointment and dejection during paper rejections, and my effort, nervousness and excitement while working on numerous submission deadlines. I also thank him for all the big responsibilities that he had trusted me with: mentoring interns, managing several aspects of teaching like setting up questions, leading teaching assistants and giving substitute lectures. These were great experiences that I, retrospectively, think I am very fortunate to have had. I am very grateful to him that he had overlooked many of my blunders and mistakes in discharging my responsibilities and have always been very kind and supportive. Since it is impossible to elucidate all ways in which he has helped me, I would conclude by saying that I would always be proud to be called his advisee and I hope that I can live up to the trust and confidence he has in me in the future as well. I thank Dr. G. Ramalingam for being a constant source of inspiration and guidance all through my research career. He has helped me in my career in numerous ways: first as a great teacher, later as a great mentor and always as a great, supportive friend. I developed and honed much of my research skills by observing him. What I find amazing and contagious is his rational and deep reasoning not just about research problems but also about issues in life. I hope to have absorbed a bit of that skill having been in close acquaintance with him for these many years. I thank him for motivating me to pursue a PhD, to join EPFL and to work with my advisor. This thesis would not have been possible without his advise and motivation. I am very happy and proud that this dissertation is reviewed by him. I thank Professor Martin Odersky for being an excellent teacher and a source of inspiration. I greatly enjoyed the conversations we had and enjoyed working with him as a teaching assistant. I am very grateful to him for being very supportive about my research, and for presiding over the defense jury. I thank other members of the defense committee: Professor Jim Larus and Professor Rupak Majumdar for reviewing my dissertation and providing me very valuable i Acknowledgements comments and feedback on the research, despite their very busy schedules. I greatly enjoyed discussing my research with them. I thank Pratik Fegade and Sumith Kulal who in the course of their internships helped with im- proving the system and the approach described in this dissertation. Particularly, I thank Pratik Fegade for contributions to the development of the techniques detailed in section 3.8 of this dissertation, and Sumith Kulal for helping carry out many experiments detailed in section 5. I thank my current and past lab mates Mikaël Mayer, Jad Hamza, Manos Koukoutos, Nicolas Voirol, Etienne Kneuss, Tihomir Gvero, Regis Blanc, Eva Darulova, Manohar Jonalagedda, Ivan Kuraj, Hossein Hojjat, Phillipe Suter, Andrew Reynolds, Mukund Raghothaman, Georg Schimd, Marco Antognini, Romain Edelmann, and also many other friends and colleagues. I enjoyed the numerous discussions I had with them in the lab, over meals, during outing and in every other place we were caught up in. In their company I felt like a truly important person. In particular, I thank Mikaël Mayer for being an amazing friend and collaborator all through my PhD life – with him I could freely share my successes as well as my frustrations. I thank Fabien Salvi for providing great computing infrastructure and for accommodating each and every request of mine no matter how urgent and time constrained they were. I thank Sylvie Jankow for her kindness and help with administrative tasks. Furthermore, I thank Professor K.V. Raghavan for being an excellent advisor of my master’s thesis and for being a constant source of encouragement. I thank him for persuading me to continue with a research career and eventually pursue PhD. I am also thankful to him and Professor Deepak D’Souza for introducing me to the area of program analysis. I fell in love with this amazing field at that very instant, and it feels like the rest of my research path was a foregone conclusion. I thank Dr. Sriram Rajamani for being a great source of inspiration and support in my research career. Last but not the least, I thank my amazing family for their never ending love, support and sacrifices. I thank my parents for, well, everything I am today. I thank my sister, my grand- mother and my brother-in-law for their limitless love and support. I thank my nieces Abi and Apoorva for showing me that life outside research can also be awesome. It is funny that they were born, grew and went to school while I was still pursuing my PhD. And, of course, I thank my wife Nikhila for her love and encouragement and, more importantly, for tolerating all my quirks. I thank numerous other friends, colleagues and relatives who I, unfortunately, could not mention but have made my PhD years the best phase in my life so far. Lausanne, August 2017 Ravichandhran Kandhadai Madhavan ii Preface Is the program I have written efficient? This is a question we face from the very moment we discover what programming is all about. The improvements in absolute performance of hardware systems have made this question more important than ever, because analytical behavior becomes more pronounced with large sizes of the data that today’s applications manipulate. Despite the importance of this question, there are surprisingly few techniques and tools that can help the developer answer such questions. Program verification is an active area of research, yet most approaches for software focus on safety verification of the values that the program computes. For performance, one often relies on testing, which is not only very incomplete, but provides little help in capturing the reasons for the behavior of the program. This thesis presents a system that can automatically verify efficiency of programs. The verified bounds are guaranteed to hold for all program inputs. The prototypical examples of resources are time (for example, the number of operations performed), or notions related to memory usage (for example, the number of allocation steps performed). These bounds are properties of the algorithms, not of the unerlying hardware implementation. The presented system is remarkable in that it suffices for the developers to provide only sketches of the bounds that are expected to hold (corresponding to expected asymptotic complexity). The system can infer the concrete coefficients automatically and confirm the resource bounds. The paradigm supported by the approach in this thesis is purely functional, making it feasible to consider verification of very sophisticated data structures. Indeed, a “by product” of this thesis is that the author verified a version of rather non-trivial Conc Trees data structure that was introduced by Dr. Aleksandar Prokopec, and that play an important role in parallel collections framework of Scala. The thesis deals with subtleties of verifying performance of programs in the presence of higher-order functions. What is more, the thesis supports efficient functional programming in practice through treatment of the construct inspired by imperative behavior: memoization (caching). Memoization, and it special case, lazy evaluation, are known to improve efficiency of functional programs both in practice and in asymptotic terms, so they make functional programming languages more practical. Yet, reasoning about the performance in the presence of these constructs introduces substantial aspects of state into the model. The thesis shows how to make specification and verification feasible even under this challanging scenario. iii Preface Verification of program correctness has been a long road, and we are starting to see practical solutions that are cost-effective, especially for functional programs. With each step along this road, the gap in reasoning ability between developers and tools is narrowing. The work in this thesis makes a big step along an under-explored dimension of program meaning—reasoning about performance bounds. Given the extent to which program development is driven by performance considerations, closing this gap is likely to have not only great benefits for verifying programs, but will also open up new applications that leverage reliable performance information to improve and adapt software systems.