Resource-Guided Program Synthesis

Resource-Guided Program Synthesis

Resource-Guided Program Synthesis Tristan Knoth Di Wang University of California, San Diego Carnegie Mellon University [email protected] [email protected] Nadia Polikarpova Jan Hoffmann University of California, San Diego Carnegie Mellon University [email protected] [email protected] Abstract ACM Reference Format: This article presents resource-guided synthesis, a technique Tristan Knoth, Di Wang, Nadia Polikarpova, and Jan Hoffmann. 2019. for synthesizing recursive programs that satisfy both a func- Resource-Guided Program Synthesis. In Proceedings of the 40th ACM SIGPLAN Conference on Programming Language Design and Imple- tional specification and a symbolic resource bound. The tech- mentation (PLDI ’19), June 22ś26, 2019, Phoenix, AZ, USA. ACM, New nique is type-directed and rests upon a novel type system that York, NY, USA, 16 pages. https://doi.org/10.1145/3314221.3314602 combines polymorphic refinement types with potential an- notations of automatic amortized resource analysis. The type system enables efficient constraint-based type checking and 1 Introduction can express precise refinement-based resource bounds. The In recent years, program synthesis has emerged as a promis- proof of type soundness shows that synthesized programs ing technique for automating low-level aspects of program- are correct by construction. By tightly integrating program ming [24, 61, 66]. Synthesis technology enables users to create exploration and type checking, the synthesizer can leverage programs by describing desired behavior with input-output the user-provided resource bound to guide the search, ea- examples [18ś20, 22, 47, 60, 70, 71], natural language [72], and gerly rejecting incomplete programs that consume too many partial or complete formal specifications35 [ , 39, 51, 52, 63]. If resources. An implementation in the resource-guided synthe- the input is a formal specification, synthesis algorithms can sizer ReSyn is used to evaluate the technique on a range of re- not only create a program but also a proof that the program cursive data structure manipulations. The experiments show meets the given specification [39, 51, 52, 63]. that ReSyn synthesizes programs that are asymptotically Oneofthegreatestchallengesinsoftwaredevelopmentisto more efficient than those generated by a resource-agnostic write programs that are not only correct but also efficient with synthesizer. Moreover, synthesis with ReSyn is faster than a respect to memory usage, execution time, or domain specific naive combination of synthesis and resource analysis. ReSyn resource metrics. For this reason, automatically optimizing is also able to generate implementations that have a constant program performance has long been a goal of synthesis, and resource consumption for fixed input sizes, which can be used several existing techniques tackle this problem for low-level to mitigate side-channel attacks. straight-line code [9, 49, 50, 56, 57] or add efficient synchro- nization to concurrent programs [11, 12, 21, 28]. However, the CCS Concepts · Software and its engineering → Auto- developed techniques are not applicable to recent advances in matic programming; · Theory of computation → Auto- the synthesis of high-level looping or recursive programs ma- mated reasoning; nipulating custom data structures [22, 35, 39, 47, 51, 52]. These Keywords Program Synthesis, Automated Amortized Re- techniques lack the means to analyze and understand the re- source Analysis, Refinement Types source usage of the synthesized programs. Consequently, they cannot take into account the program’s efficiency and simply return the first program that arises during the search and Permission to make digital or hard copies of all or part of this work for satisfies the functional specification. personal or classroom use is granted without fee provided that copies In this work, we study the problem of synthesizing high-level are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights recursive programs given both a functional specification of for components of this work owned by others than the author(s) must a program and a bound on its resource usage. A naive solu- be honored. Abstracting with credit is permitted. To copy otherwise, or tion would be to first generate a program using conventional republish, to post on servers or to redistribute to lists, requires prior specific program synthesis and then use existing automatic static re- permission and/or a fee. Request permissions from [email protected]. source analyses [15, 32, 48] to check whether its resource PLDI ’19, June 22ś26, 2019, Phoenix, AZ, USA usage satisfies the bound. Note, however, that for recursive © 2019 Copyright held by the owner/author(s). Publication rights licensed to ACM. programs, both synthesis and resource analysis are undecid- ACM ISBN 978-1-4503-6712-7/19/06...$15.00 able in theory and expensive in practice. Instead, in this paper https://doi.org/10.1145/3314221.3314602 we propose resource-guided synthesis: an approach that tightly 379 PLDI ’19, June 22ś26, 2019, Phoenix, AZ, USA Tristan Knoth, Di Wang, Nadia Polikarpova, and Jan Hoffmann integrates program synthesis and resource analysis, and uses functional language with Booleans and lists, where type re- the resource bound to guide the synthesis process, generating finements are restricted to linear inequalities over lengths programs that are efficient by construction. of lists. However, we structure the formal development to emphasize that Re2 can be extended with user-defined data Type-Driven Synthesis In a nutshell, the idea of this work types, more expressive refinements, or non-linear potential is to combine type-driven program synthesis, pioneered in the annotations. The proof strategy itself is a contribution of this work on Synquid [51], with type-based automatic amortized paper. The type soundness of the logical refinement part of the resource analysis (AARA) [31, 33, 34, 37] as implemented in systemisinspiredbyTiML[48].Themainnoveltyisthesound- Resource Aware ML (RaML) [30]. Type-driven synthesis and ness proof of the potential annotations using a small-step cost AARA are a perfect match because they are both based on semantics instead of RaML’s big-step evaluation semantics. decidable, constraint-based type systems that can be easily Type-Driven Synthesis with Re2 The second contribution checked with off-the-shelf constraint solvers. of this paper is a resource-guided synthesis algorithm based on In Synqid, program specifications are written as refine- Re2. In Sec. 4, we first develop a system of synthesis rules that ment types [41, 68]. The key to efficient synthesis is round-trip prescribe how to derive well-typed programs from Re2 types, type checking, which uses an SMT solver to aggressively prune and prove its soundness wrt. the Re2 type system. We then the search space by rejecting partial programs that do not show how to algorithmically derive programs using a combi- meet the specification (see Sec. 2.1). Until now, types have only nation of backtracking search and constraint solving. In par- been used in the context of synthesis to specify functional ticular this requires solving a new form of constraints we call properties. resource constraints, which are constrained linear inequalities AARA is a type-based technique for automatically deriv- over unknown numeric refinement terms. To solve resource ing symbolic resource bounds for functional programs. The constraints, we develop a custom solver based on counter- idea is to add resource annotations to data types, in order example guided inductive synthesis [62] and SMT [17]. to specify a potential function that maps values of that type to non-negative numbers. The type system ensures that the The ReSyn Synthesizer The third contribution of this paper initial potential is sufficient to cover the cost of the evaluation. is the implementation and experimental evaluation of the first By a priori fixing the shape of the potential functions, type resource-aware synthesizer for recursive programs. We imple- inference can be reduced to linear programming (see Sec. 2.2). mented our synthesis algorithm in a tool called ReSyn, which takes as input (1) a goal type that specifies the logical refine- The Re2 Type System The first contribution of this paper mentsandresourcerequirementsoftheprogram,and(2)types is a new type system, which we dub Re2Ðfor refinements and of components (i.e. library functions that the program may resourcesÐthat combines polymorphic refinement types with call). ReSyn then synthesizes a program that provably meets AARA (Sec. 3). Re2 is a conservative extension of Synqid’s the specification (assuming the soundness of components). refinement type system and RaML’s affine type system with To evaluate the scalability of the synthesis algorithm and linear potential annotations. As a result, Re2 can express log- the quality of the synthesized programs, we compare ReSyn ical assertions that are required for effectively specifying with baseline Synqid on a variety of general-purpose data program synthesis problems. In addition, the type system structure operations, such as eliminating duplicates from a features annotations of numeric sort in the same refinement list or computing common elements between two lists. The language to express potential functions. Using such annota- evaluation (Sec. 5) shows that ReSyn is able to synthesize tions, programmers can express precise resource bounds that programs

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    16 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us