• Keine Ergebnisse gefunden

This dissertation extends the notion of cost relations and provides new methods to solve them that overcome the previously mentioned limitations. Cost relations are extended with the inclusion of output variables, support for multiple constraint sets, and support for both positive and negative costs (although the bound computation is limited for CRS with negative costs).

Cost relations are also given a new denotational semantics that considers non-terminating execu-tions explicitly. This semantics facilitates reasoning about cost compositionally and it constitutes a solid foundation for future cost analyses based on cost relations.

The new method for solving cost relations is called CoFloCo (ControlFlow refinement ofCost Rela-tions) and is divided into three phases:

1. Preprocessing: This phase reduces any mutually recursive cost relations to cost relations that only have direct recursion using unfolding. This phase existed in previous approaches but it has been reformulated for the extended cost relations.

2. Control-flow refinement: This phase refines the cost relations incrementally. For each cost relation, it partitions all possible evaluations into a set of execution patterns, calledchains. The execution patterns are simpler than the complete CR and more precise invariants can be inferred for each of them. The results of the refinement can be propagated to other cost relations. The control flow refinement distinguishes explicitly between terminating and non-terminating execution patterns.

3. Bound computation: This phase infers upper and lower bounds for each of the cost relations, also incrementally. The main element of the bound inference is a novel cost representation called cost structurethat can represent multiple complex upper and lower bounds. With cost structures, the bound inference and composition can be reduced to the solution of (relatively) small linear programming problems that can be performed efficiently.

All steps in the analysis have been proven sound with respect to the cost relation semantics.

Although this method focuses on the second phase of the cost relation approach, i.e. the cost relation solving, small modifications have been done on the overall approach to obtain cost relations. Figure1.15 contains a diagram with the complete approach divided in two phasesCR extractionandCR solutionand the modified approach with theNew CR solutionmethod. As mentioned in the previous section, in order to obtain amortized costs it is necessary to take the output variables of the cost relations into account.

Therefore, the new approach skips theinput-output size analysisof the cost relation extraction procedure (see Section1.2.2).

This step had two purposes: To remove the output variables from the cost relations and to enrich the cost relations with input-output size relations. In the new approach, input-output size relations are inferred during the control-flow refinement phase. This has additional advantages:

• The size relations inferred with the input-output size analysis are often too imprecise. This is because the size analysis ignores the internal control-flow of the cost relations and obtains a sin-gle input-output size relation (a linear constraint set) for each cost relation. These size relations inferred during the control-flow refinement phase can be much more precise because they are spe-cialized for each possible execution pattern and they are generated taking the control flow of the cost relations into account.

• In the new approach, the cost relation extraction becomes simpler because part of the reasoning is moved to the cost relation solution. This is positive because the first phase of the analysis, i.e. the cost relation extraction, is language dependent whereas the second phase can be re-used across different languages. Therefore, making the first phase simpler facilitates the creation of new frontends and the application of this approach to other languages.

The techniques described in this dissertation have been implemented in an open source tool called CoFloCo7 and an extensive experimental evaluation has been conducted. CoFloCo has been used to analyze imperative programs written in C, functional programs written in ABS and cost relations generated from term rewrite systems. CoFloCo has been compared to the following state-of-the-art tools: Loopus [SZV17], KoAT [BEF+16], C4B [CHS15], PUBS [AGM13,ABAG13], Rank [ADFG10] and RAML [HDW17].

1.3.1 Overview of the Publications

The papers published during my PhD are included below in two categories: papers whose results are included in this thesis and others. Within each category, the papers are presented in chronological order.

Each item contains a short description of the work, its relation to this thesis, and whether I was the main author of the paper.

Publications Included in this Thesis

Resource analysis of complex programs with cost equations (APLAS 2014) [FH14] [Main author]:

This paper presents a control-flow refinement of cost relations and a bound computation method for cost relations with input and output variables. Chapter 5 contains an updated and extended version of the control-flow refinement. The bound computation method has been superseded by an improved method from a later publication [Flo16].

Upper and Lower Amortized Cost Bounds of Programs Expressed as Cost Relations (FM 2016) [Flo16]

[Single author]: This paper presents a method to solve cost relations that are the result of the control-flow refinement presented in [FH14]. This method can infer upper and lower bounds and presents increased precision for programs that present amortized cost. Chapter6contains an updated and extended version of this algorithm.

Other Publications

May-happen-in-parallel based deadlock analysis for concurrent objects (FMOODS/FORTE 2013) [FAG13] [Main author]: This paper presents a deadlock analysis for programs written in a lan-guage for concurrent objects (ABS [JHS+11]) based on the results of a points-to analysis and a may-happen-in-parallel analysis [AFG12].

7 https://github.com/aeflores/CoFloCo/

1.3. Contributions 17

Termination and Cost Analysis of Loops with Concurrent Interleavings(ATVA 2013) [AFGM13]: This paper presents a termination and cost analysis for programs written in ABS. This analysis uses the cost relation approach but focuses on the first part of the analysis. In particular, it focuses on dealing with the concurrent interleaving among different parts of a distributed system and it uses cost relation solvers (like the one presented in this thesis) as a black box.

SACO: Static Analyzer for Concurrent Objects (TACAS 2014) [AAF+14]: This is a tool paper that presents SACO a static analysis tool for ABS programs that integrates several analyses such as termination, cost, deadlock and may-happen-in-parallel. Although the description of this tool is not included in the dissertation, the prototype implementation of the analysis presented in this dissertation (CoFloCo) has been integrated in the tool SACO and SACO has been used in the experimental evaluation.

May-Happen-in-Parallel Analysis with Condition Synchronization (FOPARA 2015) [AFG15]: This publication presents an extension of the may-happen-in-parallel analysis of [AFG12] to treat addi-tional synchronization mechanisms.

May-Happen-in-Parallel Analysis for Actor-Based Concurrency(TOCL 2016) [AFGM16]: This paper is the journal version of [AFG12]. It presents an extended may-happen-in-parallel for ABS programs with increased precision. It includes an improved formalization of the analysis, soundness proofs and a more detailed discussion about the complexity of the analysis.

Rely-Guarantee Termination and Cost Analyses of Loops with Concurrent Interleavings (JAR 2017) [AFGM17]: This paper is the journal version of [AFGM13]. It extends the analyses of [AFGM13] with several improvements and includes detailed soundness proofs.

1.3.2 Structure of the Dissertation

The rest of the dissertation is organized as follows:

Chapter2: Informal Account This chapter provides an informal description of the analysis based on the examples discussed so far.

Chapter3: Technical Background This chapter establishes the notation, defines cost relations formally, their semantics, their cost and the definitions of upper and lower bounds.

Chapter5: Preprocessing This chapter details several cost preserving transformations that are used to simplify cost relations systems and reduce indirect recursion to direct recursion.

Chapter5: Refinement This chapter presents the control-flow refinement of cost relations together with its soundness proofs. The chapter includes control-flow refinement presented in [FH14] adapted to the new semantics. The chapter also includes:

• An extension of this work to support cost relations with multiple (non-linear) recursion

• A more detailed discussion on the inference of two types of invariants: chain summariesand calling contexts

• Soundness proofs

Chapter6: Bound computation This chapter presents the bound computation algorithm. This algorithm infers cost structures for each of the execution patterns detected in the control-flow refinement phase. The algorithm is an extension of the one presented in [Flo16]. In addition to the original algorithm, the chapter includes:

• An extension of the algorithm to support cost relations with multiple (non-linear) recursion

• A description of how to infer piece-wise defined bounds from the results of the bound analysis

• Soundness proofs

Chapter7: Evaluation This chapter includes an extensive experimental evaluation of the tool CoFloCo divided in several parts:

Imperative programs First, CoFloCo is evaluated against a benchmark of (small) challenging pro-grams written in C and taken from the literature. The tool is used to obtain upper and lower bounds and it is compared to other state-of-the-art tools: Loopus [SZV17], KoAT [BEF+16], C4B [CHS15], PUBS [AGM13,ABAG13] and Rank [ADFG10].

Second, the evaluations from the work [SZV17] are replicated with the latest version of CoFloCo. These consist on the analysis of a large benchmark of C programs (1650 functions) and the analysis of a reduced set of challenging loop iteration patterns. In these evaluations, only upper bounds are computed.

Functional Programs CoFloCo is compared to RAML [HDW17] on a small benchmark of examples taken from the evaluation of RAML. The examples are translated by hand from Ocaml to ABS and SACO [AAF+14] is used to generate cost relations from the ABS programs.

Term Rewrite Systems Recently, a translation from term rewrite systems to cost relations has been implemented [NFB+17] and an evaluation has been performed on the examples from the category “Runtime Complexity - Innermost Rewriting” of the Termination Competition 20168. Here, the cost relations resulting from this translation have been analyzed with the latest version of CoFloCo and with PUBS [ABAG13].

Chapter8: Related Work This chapter discusses related work.

Chapter9: Conclusion This chapter concludes this thesis by summarizing its contributions.

Chapter10: Limitations and Future Work This chapter discusses some limitations of the present work and possible directions for future work.

AppendixA: Implementation Details This appendix describes some details regarding the implementa-tion of CoFloCo.

8 http://termination-portal.org/wiki/Termination_Competition/

1.3. Contributions 19

2 Informal Account

This chapter contains an informal description of the different phases of the analysis and an illustration of how it obtains bounds of the challenging examples presented in the introduction (Section1.2.4).

2.1 Preprocessing

The starting point of the analysis is a cost relation system that describes the cost of a program. All approaches for solving cost relations share a common preprocessing step. This step detects the strongly connected components in the cost relations’ call graph and transforms the mutually recursive definitions into direct recursion using unfolding. Once this step is completed, the cost relations can be sorted in a sequence〈C1,C2,· · ·,Cn〉such that eachCi can only contain recursive calls toCi and non-recursive calls toCj with j>i.

Consider Program 3 (in Page 7) whose cost relations without output variables are in Figure 1.8(in Page 9). The cost relations of popSome and if2 can be reduced to direct recursion by unfolding the call to if2 in CR popSome. In addition, the cost relations can be further simplified by unfolding the call to if1 in CRwh. The result of the unfolding is in Figure 2.1. Note that the cost relation popSome contains the return variable of the function so. The output variables of whhave not been included to keep the presentation simple (they are not necessary to obtain a precise cost). The ordered sequence of cost relations is 〈amortized,wh,popSome〉. The rest of the analysis is performed incrementally and bottom-up, that is, starting from CRpopSomeand finishing with CRamortized.