Continuation Passing Style Transformation after Exception Analysis

예외상황 분석을 이용한 계산과정 전달 변환

  • 김정택 (한국과학기술원 전자전산학과) ;
  • 이광근 (한국과학기술원 전자전산학과)
  • Published : 2000.03.15

Abstract

ML's exception handling makes it possible to describe exceptional execution flows conveniently. Sometimes, current implementation of exception handling introduces unnecessary overhead. Our goal is to reduce this overhead by source-level transformation. To this end, we transform source programs into variant of continuation-passing style(CPS), replacing handle and raise expressions by continuation-catching and throwing expressions, respectively. CPS-transforming every expression, however, introduces a new cost. We therefore use an exception analysis to transform expressions selectively: if an expression is statically determined to involve exceptions then it is CPS-transformed; otherwise, it is left in direct style. In this article, we formalize this selective CPS transformation, prove its correctness, and present possible improvement for our transformation.

이 논문의 목적은 ML 프로그램의 소스(source)를 수정하여 ML의 예외상황 처리기의 수행속도를 개선하고자 하는 것이다. ML은 함수를 값으로 주고받을 수 있으며 타입을 이용하여 프로그램을 검사해 주는 언어이다. 이러한 ML의 예외상황 처리부분을 사용함으로서 프로그래머는 쉽게 자신의 프로그램의 예외적인 동작을 기술할 수 있다. 하지만, 이러한 예외상황을 처리하기 위해서는 많은 계산이 필요하기 때문에, 예외상황을 처리하는 프로그램 부분이 병목 현상을 일으키는 경우가 많다. 프로그램의 소스를 바꾸어서 예외상황 처리부분이 존재하지 않는 같은 동작을 하는 다른 프로그램으로 바꾸는 방법은 이미 알려져 있지만, 도리어 수행시간이 느려진다. 위의 바꾸는 방법은 '나중에 할 일을 넘겨주는 방식(Continuation Passing Style)'이라고 부르는 방식으로 프로그램의 소스를 바꾸는 방법을 조금 수정하여, 예외상황을 처리하는 부분을 위의 '나중에 할 일(continuation)'과 같은 방식으로 넘겨주어 예외상황 처리부분이 모두 사라지게 된다. 그러나, 이러한 방식은 모든 프로그램내 표현(expression)을 모두 위와 같은 방식으로 바꾸기 때문에, 이로 인해 발생하는 계산이 예외상황을 처리하는 계산보다 더 많아지게 된다. 이 논문에서는 이러한 단점을 개선하여 프로그램내에서 예외상황 처리부분을 없애는데 꼭 필요한 표현 만을 정적분석을 사용하여 골라내어 이를 선택적으로 변환하는 방법을 사용한다.

Keywords

References

  1. Andrew W. Appel. Compiling with Continuations. Cambridge University Press, New York, 1992
  2. Edoardo Biagioni, Ken Cline, Peter Lee, Chris Okasaki, and Chris Stone. Safe-for-space threads in Standard ML. Higher-Order and Symbolic Computation (Nee Lisp and Symbolic Computation), 11(2), 1998 https://doi.org/10.1023/A:1010016600604
  3. Olivier Danvy and Dirk Dussart. CPS transformation after binding-time analysis. Unpublished note, Department of Computer Science, University of Aarhus, April 1995
  4. Olivier Danvy and Andrzej Filinski. Representing control, a study of the CPS transformation. Mathematical Structures in Computer Science, 2(4):361-391, December 1992
  5. Olivier Danvy and John Hatcliff. CPS transformation after strictness analysis. ACM Letters on Programming Languages and Systems, 1(3):195-212, 1993 https://doi.org/10.1145/151640.151641
  6. Olivier Danvy and John Hatcliff. On the transformation between direct and continuation semantics. In Stephen Brookes, Michael Main, Austin Melton, Michael Mislove, and David Schmidt, editors, Proceedings of the 9th Conference on Mathematical Foundations of Programming Semantics, number 802 in Lecture Notes in Computer Science, pages 627-648, New Orleans, Louisiana, April 1993. Springer-Verlag https://doi.org/10.1007/3-540-58027-1_31
  7. Dirk Dussart. Topics in program specialization and analysis for statically typed functional languages. PhD thesis, Katholieke Universiteit Leuven, Leuven, Belgium, May 1997
  8. Matthias Felleisen. The Calculi of ${\lambda}$-v-CS Conversion: A Syntactic Theory of Control and State in Imperative Higher-Order Programming Languages. PhD thesis, Department of Computer Science, Indiana University, Bloomington, Indiana, August 1987
  9. John Hatcliff and Olivier Danvy, Thunks and the ${\lambda}$-calculus. Journal of Functional Programming, 7(2):303-319, 1997 https://doi.org/10.1017/S0956796897002748
  10. Gordon D. Plotkin Call-by-name, call-by-value and the ${\lambda}$-calculus. Theoretical Computer Science, 1:125-159, 1975 https://doi.org/10.1016/0304-3975(75)90017-1
  11. Gordon D. Plotkin. A structural approach to operational semantics. Technical Report FN-19, DAIMI, Department of Computer Science, University of Aarhus, Aarhus, Denmark, September 1981
  12. Paul Steckler and Mitchell Wand. Selective thunkification. In Baudouin Le Charlier, editor, Static Analysis, number 864 in Lecture Notes in Computer Science, pages 162-178, Namur, Belgium, September 1994. Springer-Verlag https://doi.org/10.1007/3-540-58485-4_39
  13. Kwangkeun Yi and Sukyoung Ryu, Towards a cost-effective estimation of unaught exceptions in SML programs. In Pascal Van Hentenryck, editor, Static Analysis, number 1302 in Lecture Notes in Computer Science, pages 98-113, Paris, France, September 1997. Springer-Verlag https://doi.org/10.1007/BFb0032736