An abstract interpretation framework for refactoring with application to extract methods with contracts

Patrick Cousot, Radhia Cousot, Francesco Logozzo, Michael Barnett

Research output: Chapter in Book/Report/Conference proceedingConference contribution

Abstract

Method extraction is a common refactoring feature provided by most modern IDEs. It replaces a user-selected piece of code with a call to an automatically generated method. We address the problem of automatically inferring contracts (precondition, postcondition) for the extracted method. We require the inferred contract: (a) to be valid for the extracted method (validity); (b) to guard the language and programmer assertions in the body of the extracted method by an opportune precondition (safety); (c) to preserve the proof of correctness of the original code when analyzing the new method separately (completeness); and (d) to be the most general possible (generality). These requirements rule out trivial solutions (e.g., inlining, projection, etc). We propose two theoretical solutions to the problem. The first one is simple and optimal. It is valid, safe, complete and general but unfortunately not effectively computable (except for unrealistic finiteness/decidability hypotheses). The second one is based on an iterative forward/backward method. We show it to be valid, safe, and, under reasonable assumptions, complete and general. We prove that the second solution subsumes the first. All justifications are provided with respect to a new, set-theoretic version of Hoare logic (hence without logic), and abstract of Hoare logic, revisited to avoid surprisingly unsound inference rules. We have implemented the new algorithms on the top of two industrial-strength tools (CCCheck and the Microsoft Roslyn CTP). Our experience shows that the analysis is both fast enough to be used in an interactive environment and precise enough to generate good annotations.

Original languageEnglish (US)
Title of host publicationSPLASH 2012
Subtitle of host publicationOOPSLA'12 - Proceedings of the 2012 ACM International Conference on Object Oriented Programming SystemsLanguages and Applications
Pages213-232
Number of pages20
DOIs
StatePublished - 2012
Event2012 ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2012 - Tucson, AZ, United States
Duration: Oct 19 2012Oct 26 2012

Publication series

NameProceedings of the Conference on Object-Oriented Programming Systems, Languages, and Applications, OOPSLA

Other

Other2012 ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2012
Country/TerritoryUnited States
CityTucson, AZ
Period10/19/1210/26/12

Keywords

  • Design by contract
  • Interpretation
  • Method extraction
  • Program transformation
  • Refactoring
  • Static analysis

ASJC Scopus subject areas

  • Software

Fingerprint

Dive into the research topics of 'An abstract interpretation framework for refactoring with application to extract methods with contracts'. Together they form a unique fingerprint.

Cite this