Computer Science Conference Presentations, Computer Science Posters and Proceedings 10-20-2016 First-class effect reflection for effect-guided programming Yuheng Long Iowa State University Yu David Liu State University of New York at Binghamton Hridesh Rajan Iowa State University, [email protected] Follow this and additional works at: http://lib.dr.iastate.edu/cs_conf Part of the Software Engineering Commons Recommended Citation Long, Yuheng; Liu, Yu David; and Rajan, Hridesh, "First-class effect reflection for effect-guided programming" (2016). Computer Science Conference Presentations, Posters and Proceedings. 16. http://lib.dr.iastate.edu/cs_conf/16 This Conference Proceeding is brought to you for free and open access by the Computer Science at Iowa State University Digital Repository. It has been accepted for inclusion in Computer Science Conference Presentations, Posters and Proceedings by an authorized administrator of Iowa State University Digital Repository. For more information, please contact [email protected]. First-class effect reflection for effect-guided programming Abstract This paper introduces a novel type-and-effect calculus, first-class effects, where the computational effect of an expression can be programmatically reflected, passed around as values, and analyzed at run time. A broad range of designs “hard-coded” in existing effect-guided analyses — from thread scheduling, version-consistent software updating, to data zeroing — can be naturally supported through the programming abstractions. The core technical development is a type system with a number of features, including a hybrid type system that integrates static and dynamic effect analyses, a refinement type system to verify application-specific effect management properties, a double-bounded type system that computes both over-approximation of effects and their under-approximation. We introduce and establish a notion of soundness called trace consistency, defined in terms of how the effect and trace correspond. The property sheds foundational insight on “good” first-class effect programming. Disciplines Computer Sciences | Software Engineering Comments This article is published as Long, Yuheng, Yu David Liu, and Hridesh Rajan. "First-class effect reflection for effect-guided programming." In Proceedings of the 2016 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications, pp. 820-837. ACM, 2016. doi: 10.1145/3022671.2984037. Posted with permission. Rights © ACM, 2016. This is the author's version of the work. It is posted here by permission of ACM for your personal use. Not for redistribution. The definitive version was published in Proceedings of the 2016 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications, 2016. https://doi.org/10.1145/2983990.2984037 This conference proceeding is available at Iowa State University Digital Repository: http://lib.dr.iastate.edu/cs_conf/16 Preprint First-Class Effect Reflection for Effect-Guided Programming Yuheng Longα, Yu David Liuβ, and Hridesh Rajanγ α,γ Iowa State University, βSUNY Binghamton α,γ fcsgzlong,[email protected] β[email protected] Abstract comes part of the program itself. The resulting calculus, λfe, This paper introduces a novel type-and-effect calculus, first- is endowed with powerful programming abstractions: class effects, where the computational effect of an expression [EFFECT REFLECTION] Programmers can query the ef- can be programmatically reflected, passed around as values, fect of any expression e through a λfe primitive, query e. and analyzed at run time. A broad range of designs “hard- The result is a first-class value we call effect closure, which coded” in existing effect-guided analyses — from thread contains the queried expression e and e’s effects, in the scheduling, version-consistent software updating, to data ze- form of memory region accesses. For convenience, we call roing — can be naturally supported through the program- e the passenger expression of the closure. ming abstractions. The core technical development is a type [EFFECT INSPECTION] The memory access details repre- system with a number of features, including a hybrid type sented by an effect closure can be analyzed through a λ ef- system that integrates static and dynamic effect analyses, fe fect pattern matching expression, enabling effect-based dis- a refinement type system to verify application-specific ef- patch to naturally support effect-guided programming. fect management properties, a double-bounded type system that computes both over-approximation of effects and their [EFFECT REALIZATION] The dual of effect reflection is under-approximation. We introduce and establish a notion of effect realization: the realize x expression evaluates the soundness called trace consistency, defined in terms of how passenger expression of the effect closure x. the effect and trace correspond. The property sheds founda- Foundationally, effect reflection and effect realization are tional insight on “good” first-class effect programming. the introduction and elimination of first-class effects, in the form of effect closures. As effect closures may cross modu- 1. Introduction larity boundaries, it can be viewed as “effect-carrying code.” The direct benefit of λfe is its support in flexible effect- Type-and-effect systems, either purely static [36, 42, 52], dy- guided programming. For example, thread scheduling in namic [4, 29, 46] or hybrid [2, 34], have proven to be useful concurrent programs is an active and prolific area of re- for program construction, reasoning, and verification. In ex- search [29, 44, 46]. With λfe, programmers can flexibly isting approaches, the logic of accessing effects and making develop a variety of thread management strategies through decisions over them is defined by the language designer, and principled λfe programming. We will further demonstrate a supported by the compiler or the runtime system. The end- broad range of applications beyond thread scheduling in §8 user programmer is generally a consumer of the “hardcoded” and §B. Overall, a variety of meta-level designs currently logic for effect management. “hidden” behind the compiler and language runtime are now Our work is motivated by two fundamental questions. in the hands of programmers. First, are there benefits of empowering programmers with With great power comes great responsibility1. The grand application-specific effect management? Second, is there a challenge of designing an expressive and flexible program- principled design for the effect management, so that pro- ming model lies in principled and precise reasoning. The grammers are endowed with powerful abstractions while in core technical development of λfe is a type system with the meantime provided with strong correctness guarantees? a number of features. First, effect reflection is designed first-class effects In this paper, we develop , a novel type- through dynamic typing, resulting in a hybrid type-and- and-effect system where the effects of program expressions effect system [2, 34] that employs run-time information are available as first-class values to programmers. The life- to improve precision. Second, λfe provides static guaran- cycle of effect management over program expressions be- tees to application-specific effect management properties through refinement types, promoting “correct-by-design” effect-guided programming. Third, λfe computes not only [Copyright notice will appear here once ’preprint’ option is removed.] 1 Marvel’s Spiderman 2nd submission to OOPSLA’16 1 2016/7/25 - - - - - - - - - - - - - - - - - - - Server - - - - - - - - - - - - - - - - - - - - notation meaning 1 let buf = refr 0 in query e effect reflection 2 let scheduler = λ x1:exact, x2:exact. effcase x : T where P ) e predicated effect dispatch 3 let (p, c) = effcase x1: realize e effect realization 4 | EC(l ∼ u) where wrr <<: l =>(x1, x2) x ∼ y lower bound effect x & upper bound y 5 | default =>(x2, x1) in EC(x ∼ y) effect closure type 6 {wrr <<: c |−> wrr <<: p} realize p; realize c x <<:y effect x is a subset of y - - - - - - - - - - - - - - - - - - - - Client - - - - - - - - - - - - - - - - - - - - |−> logical implication 7 let reader = (query !buf) in {P }e refinement type 8 let writer = (query buf := 1) in wrr write effect to region r 9 scheduler reader writer exact lower and upper bounds are equal Figure 1. A Producer-First Scheduler (The new notations introduced by first-class effects are explained on the right.) the over-approximation of effects, the may-effect, but also tively, created by the Client side of the program (lines 7-9). their under-approximation, the must-effect. The duality uni- According to a well-known scheduling strategy for multi- fies the common theme of permission [24] vs. obligation [7] threaded programs [33], data producer should be scheduled in effect reasoning. Fourth, we establish a stronger notion before its consumer. For this program, the programmer may of soundness called trace consistency, defined in terms of wish writer to be scheduled before the reader, regard- how the effect and the trace (the “post-execution effect”) less of whether scheduler reader writer appears correspond. To maintain trace consistency, we introduce a on line 9, or scheduler writer reader. notion of polarity to predicates defined over effects, provid- In λfe, the query expression can retrieve the effects of ing a general solution to a long-standing problem in type- the tasks, on lines 7-8. The resulting
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages30 Page
-
File Size-