Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Reactive Imperative Programming with Dataflow Constraints

Published: 17 November 2014 Publication History

Abstract

Dataflow languages provide natural support for specifying constraints between objects in dynamic applications, where programs need to react efficiently to changes in their environment. In this article, we show that one-way dataflow constraints, largely explored in the context of interactive applications, can be seamlessly integrated in any imperative language and can be used as a general paradigm for writing performance-critical reactive applications that require efficient incremental computations. In our framework, programmers can define ordinary statements of the imperative host language that enforce constraints between objects stored in special memory locations designated as “reactive.” Reactive objects can be of any legal type in the host language, including primitive data types, pointers, arrays, and structures. Statements defining constraints are automatically re-executed every time their input memory locations change, letting a program behave like a spreadsheet where the values of some variables depend on the values of other variables. The constraint-solving mechanism is handled transparently by altering the semantics of elementary operations of the host language for reading and modifying objects. We provide a formal semantics and describe a concrete embodiment of our technique into C/C++, showing how to implement it efficiently in conventional platforms using off-the-shelf compilers. We discuss common coding idioms and relevant applications to reactive scenarios, including incremental computation, observer design pattern, data structure repair, and software visualization. The performance of our implementation is compared to problem-specific change propagation algorithms, as well as to language-centric approaches such as self-adjusting computation and subject/observer communication mechanisms, showing that the proposed approach is efficient in practice.

References

[1]
Martín Abadi, Tim Harris, and Mojtaba Mehrara. 2009. Transactional Memory with Strong Atomicity Using Off-the-Shelf Memory Protection Hardware. In Proceedings of the 14th ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming (PPoPP'09). 185--196.
[2]
Robin Abraham, Margaret M. Burnett, and Martin Erwig. 2008. Spreadsheet Programming. In Wiley Encyclopedia of Computer Science and Engineering. John Wiley & Sons, Inc.
[3]
Umut A. Acar. 2009. Self-Adjusting Computation: (An Overview). In Proceedings of the ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation (PEPM'09). 1--6.
[4]
Umut A. Acar, Amal Ahmed, and Matthias Blume. 2008. Imperative Self-Adjusting Computation. In POPL, George C. Necula and Philip Wadler (Eds.). ACM, 309--322.
[5]
Umut A. Acar, Guy E. Blelloch, and Robert Harper. 2006a. Adaptive Functional Programming. ACM Transactions on Programming Languages and Systems 28, 6 (2006), 990--1034.
[6]
Umut A. Acar, Guy E. Blelloch, Matthias Blume, and Kanat Tangwongsan. 2006b. An Experimental Analysis of Self-Adjusting Computation. In Proceedings of the ACM SIGPLAN 2006 Conference on Programming Language Design and Implementation (PLDI'06). 96--107.
[7]
Umut A. Acar, Guy E. Blelloch, Ruy Ley-Wild, Kanat Tangwongsan, and Duru Türkoglu. 2010. Traceable Data Types for Self-Adjusting Computation. In Proceedings of the ACM SIGPLAN 2006 Conference on Programming Language Design and Implementation (PLDI'10). 483--496.
[8]
Umut A. Acar, Matthias Blume, and Jacob Donham. 2013. A Consistent Semantics of Self-Adjusting Computation. Journal of Functional Programming 23, 3 (2013), 249--292.
[9]
Ravindra K. Ahuja, Thomas L. Magnanti, and James B. Orlin. 1993. Network Flows: Theory, Algorithms, and Applications. Prentice-Hall.
[10]
Bowen Alpern, Roger Hoover, Barry K. Rosen, Peter F. Sweeney, and F. Kenneth Zadeck. 1990. Incremental Evaluation of Computational Circuits. In Proceedings of the 1st Annual ACM-SIAM Symposium on Discrete Algorithms (SODA'90). 32--42.
[11]
Krzysztof R. Apt. 2003. Principles of Constraint Programming. Cambridge University Press.
[12]
Richard Bellmann. 1958. On a Routing Problem. Quarterly Applied Mathematics 16, 1 (1958), 87--90.
[13]
Christian Bessiere. 2006. Constraint Propagation. In Handbook of Constraint Programming, F. Rossi, P. van Beek, and T. Walsh (Eds.). Elsevier.
[14]
Peter A. Blume. 2007. The LabVIEW Style Book. Prentice Hall.
[15]
Alan Borning. 1981. The Programming Language Aspects of ThingLab, a Constraint-Oriented Simulation Laboratory. ACM Transactions on Programming Languages and Systems 3, 4 (1981), 353--387.
[16]
Frdric Boussinot and Jean-Ferdy Susini. 1998. The SugarCubes Tool Box: A Reactive Java Framework. Software: Practice and Experience 28, 14 (1998), 1531--1550.
[17]
Paul Caspi, Daniel Pilaud, Nicolas Halbwachs, and John Plaice. 1987. Lustre, a Declarative Language for Programming Synchronous Systems. In POPL. 178--188.
[18]
Craig Chambers, Bill Harrison, and John Vlissides. 2000. A Debate on Language and Tool Support for Design Patterns. In POPL. 277--289.
[19]
Yan Chen, Joshua Dunfield, and Umut A. Acar. 2012. Type-directed Automatic Incrementalization. In Proceedings of the 33rd ACM SIGPLAN Conference on Programming Language Design and Implementation. ACM, 299--310.
[20]
Gregory H. Cooper and Shriram Krishnamurthi. 2006. Embedding Dynamic Dataflow in a Call-by-Value Language. In ESOP. 294--308.
[21]
Antony Courtney. 2001. Frappé: Functional Reactive Programming in Java. In PADL. 29--44.
[22]
Patrick Cousot and Radhia Cousot. 1977. Abstract Interpretation: A Unified Lattice Model for Static Analysis of Programs by Construction or Approximation of Fixpoints. In POPL. 238--252.
[23]
Pierluigi Crescenzi, Camil Demetrescu, Irene Finocchi, and Rossella Petreschi. 2000. Reversible Execution and Visualization of Programs with Leonardo. Journal of Visual Languages and Computing 11, 2 (2000), 125--150.
[24]
Alan J. Demers, Thomas W. Reps, and Tim Teitelbaum. 1981. Incremental Evaluation for Attribute Grammars with Application to Syntax-Directed Editors. In POPL. 105--116.
[25]
Camil Demetrescu. 2001. Fully Dynamic Algorithms for Path Problems on Directed Graphs. Ph.D. Dissertation. Sapienza University of Rome.
[26]
Camil Demetrescu and Irene Finocchi. 2001. Smooth Animation of Algorithms in a Declarative Framework. Journal of Visual Languages and Computing 12, 3 (2001), 253--281.
[27]
Camil Demetrescu and Irene Finocchi. 2006. A Data-Driven Graphical Toolkit for Software Visualization. In Proceedings of the ACM 2006 Symposium on Software Visualization, Brighton, UK, September 4--5, 2006. ACM, 57--66.
[28]
Camil Demetrescu, Irene Finocchi, and Giuseppe F. Italiano. 2005. Dynamic Graphs. In Handbook on Data Structures and Applications, D. Mehta and S. Sahni (Eds.). CRC Press.
[29]
Camil Demetrescu, Irene Finocchi, and Andrea Ribichini. 2011. Reactive Imperative Programming with Dataflow Constraints. In Proceedings of the 26th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA'11). ACM, 407--426.
[30]
Camil Demetrescu, Irene Finocchi, and John T. Stasko. 2001. Specifying Algorithm Visualizations: Interesting Events or State Mapping? In Software Visualization. Lecture Notes in Computer Science, Vol. 2269. Springer, 16--30.
[31]
C. Demetrescu, A. V. Goldberg, and D. S. Johnson. 2009. The Shortest Path Problem: Ninth DIMACS Implementation Challenge. American Mathematical Society.
[32]
Brian Demsky and Martin Rinard. 2003. Automatic Detection and Repair of Errors in Data Structures. In Proceedings of the Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA'03). 78--95.
[33]
Jack B. Dennis, John B. Fosseen, and John P. Linderman. 1974. Data Flow Schemas. In Proceedings of the International Symposium on Theoretical Programming, Andrei Ershov and Valery A. Nepomniaschy (Eds.), Vol. 5. Springer, Berlin, 187--216.
[34]
Stephan Diehl. 2007. Software Visualization: Visualizing the Structure, Behaviour, and Evolution of Software. Springer.
[35]
Paul Dietz and Daniel Sleator. 1987. Two Algorithms for Maintaining Order in a List. In Proceedings of the 19th Annual ACM Symposium on Theory of Computing (STOC'87). 365--372.
[36]
Conal Elliott and Paul Hudak. 1997. Functional Reactive Animation. In Proceedings of the 1997 ACM SIGPLAN International Conference on Functional Programming (ICFP'97). 263--273.
[37]
Alan Ezust and Paul Ezust. 2006. An Introduction to Design Patterns in C++ with Qt 4. Prentice Hall.
[38]
Raphael A. Finkel. 1996. Advanced Programming Language Design. Addison-Wesley, Menlo Park, CA.
[39]
Bjorn Freeman-Benson and Alan Borning. 1992. Integrating Constraints with an Object-Oriented Language. In Proceedings of the European Conference on Object-Oriented Programming (ECOOP'92). 268--286.
[40]
Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. 1994. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley.
[41]
Michael Gorbovitski, Tom Rothamel, Yanhong A. Liu, and Scott D. Stoller. 2005. Implementing Incrementalization Across Object Abstraction. In Companion to the 20th Annual ACM SIGPLAN Conference on Object-oriented Programming, Systems, Languages, and Applications. ACM, 112--113.
[42]
Thorsten Groetker, Stan Liao, Grant Martin, and Stuart Swan. 2002. System Design with SystemC. Kluwer Academic.
[43]
Paul Le Guernic, Albert Benveniste, Patricia Bournai, and Thierry Gautier. 1986. SIGNAL - A Data Flow-Oriented Language for Signal Processing. IEEE Transactions on Acoustics, Speech and Signal Processing 34, 2 (1986), 362--374.
[44]
Matthew Hammer, Umut A. Acar, and Yan Chen. 2009. CEAL: A C-based Language for Self-Adjusting Computation. In Proceedings of the ACM SIGPLAN 2009 Conference on Programming Language Design and Implementation (PLDI'09). 25--37.
[45]
Matthew A. Hammer, Georg Neis, Yan Chen, and Umut A. Acar. 2011. Self-Adjusting Stack Machines. In OOPSLA, Cristina Videira Lopes and Kathleen Fisher (Eds.). ACM, 753--772.
[46]
Christian Holzbaur. 1992. Metastructures vs. Attributed Variables in the Context of Extensible Unification - Applied for the Implementation of CLP Languages. In Proceedings of the International Symposium on Programming Language Implementation and Logic Programming (PLILP'92). 260--268.
[47]
Christian Holzbaur and Thom Frühwirth. 1999. Compiling Constraint Handling Rules into Prolog with Attributed Variables. In Proceedings of the International Conference on Principles and Practice of Declarative Programming (PPDP'99). 117--133.
[48]
Roger Hoover. 1987. Incremental Graph Evaluation. Ph.D. Dissertation. Department of Computer Science, Cornell University, Ithaca, NY.
[49]
Paul Hudak, Simon Peyton Jones, and Philip Wadler (Eds.). 1992. Report on the Programming Language Haskell, a Non-Strict Purely Functional Language (Version 1.2). ACM SIGPLAN Notices 27, 5 (1992).
[50]
Scott E. Hudson. 1991. Incremental Attribute Evaluation: A Flexible Algorithm for Lazy Update. ACM Transactions on Programming Languages and Systems 13, 3 (1991), 315--341.
[51]
Daniel Ignatoff, Gregory H. Cooper, and Shriram Krishnamurthi. 2006. Crossing State Lines: Adapting Object-Oriented Frameworks to Functional Reactive Languages. In Proceedings of the 8th International Symposium on Functional and Logic Programming (FLOPS'06). 259--276.
[52]
ISO. 2007. The C Programming Language: ISO/IEC 9899:1999 Cor. 3:2007(E) - Technical Corrigendum 3. (2007).
[53]
Richard M. Karp and Raymond E. Miller. 1966. Properties of a Model for Parallel Computations: Determinancy, Termination, Queueing. SIAM Journal of Applied Mathematics 14, 6 (1966), 1390--1411.
[54]
Alan Kay. 1984. Computer Software. Scientific American 251, 3 (1984), 191--207.
[55]
Donald E. Knuth. 1968. Semantics of Context-Free Languages. Theory of Computing Systems 2, 2 (1968), 127--145.
[56]
Ruy Ley-Wild, Umut A. Acar, and Guy E. Blelloch. 2012. Non-Monotonic Self-Adjusting Computation. In Proceedings of the 21st European Symposium on Programming (ESOP'12), Helmut Seidl (Ed.), Vol. 7211. Springer, 476--496.
[57]
Yanhong A. Liu, Scott D. Stoller, Michael Gorbovitski, Tom Rothamel, and Yanni Ellen Liu. 2005. Incrementalization Across Object Abstraction. In Proceedings of the 20th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications. ACM, 473--486.
[58]
Yanhong A. Liu, Scott D. Stoller, and Tim Teitelbaum. 1998. Static Caching for Incremental Computation. ACM Transactions in Programming Languages and Systems 20, 3 (1998), 546--585.
[59]
Muhammad Zubair Malik, Khalid Ghori, Bassem Elkarablieh, and Sarfraz Khurshid. 2009. A Case for Automated Debugging Using Data Structure Repair. In Proceedings of the 2009 IEEE/ACM International Conference on Automated Software Engineering (ASE'09). 620--624.
[60]
Louis Mandel and Marc Pouzet. 2005. ReactiveML, a Reactive Extension to ML. In Proceedings of the International Symposium on Symposium on Principles and Practice of Declarative Programming (PPDP'05). 82--93.
[61]
Guillaume Marceau, Gregory H. Cooper, Jonathan P. Spiro, Shriram Krishnamurthi, and Steven P. Reiss. 2007. The Design and Implementation of a Dataflow Language for Scriptable Debugging. Automated Software Engineering 14, 1 (2007), 59--86.
[62]
Leo A. Meyerovich, Arjun Guha, Jacob Baskin, Gregory H. Cooper, Michael Greenberg, Aleks Bromfield, and Shriram Krishnamurthi. 2009. Flapjax: A Programming Language for Ajax Applications. In Proceedings of the 24th ACM SIGPLAN Conference Companion on Object Oriented Programming Systems Languages and Applications (OOPSLA'09). 1--20.
[63]
Mauro Mosconi and Marco Porta. 2000. Iteration Constructs in Data-Flow Visual Programming Languages. Computer Languages 26, 2--4 (2000), 67--104.
[64]
Brad A. Myers. 1990. Garnet: Comprehensive Support for Graphical, Highly-Interactive User Interfaces. IEEE Computer 23 (1990).
[65]
Brad A. Myers, Richard G. McDaniel, Robert C. Miller, Alan S. Ferrency, Andrew Faulring, Bruce D. Kyle, Andrew Mickish, Alex Klimovitski, and Patrick Doane. 1997. The Amulet Environment: New Models for Effective User Interface Software Development. IEEE Transactions on Software Engineering 23, 6 (1997), 347--365.
[66]
Henrik Nilsson, Antony Courtney, and John Peterson. 2002. Functional Reactive Programming, Continued. In Proceedings of the 2002 ACM SIGPLAN Workshop on Haskell (HASKELL'02). 51--64.
[67]
Ronald A. Olsson, Richard H. Crawford, and W. Wilson Ho. 1991. A Dataflow Approach to Event-Based Debugging. Software: Practice and Experience 21, 2 (1991), 209--229.
[68]
Sanjiva Prasad and S. Arun-Kumar. 2002. An Introduction to Operational Semantics. In Compiler Design Handbook: Optimizations and Machine Code. CRC Press, Boca Raton, FL, 841--890.
[69]
Blaine A. Price, Ronald M. Baecker, and Ian S. Small. 1993. A Principled Taxonomy of Software Visualization. Journal of Visual Languages and Computing 4, 3 (1993), 211--266.
[70]
William Pugh and Tim Teitelbaum. 1989. Incremental Computation via Function Caching. In Proceedings of the 16th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM, 315--328.
[71]
Ganesan Ramalingam and Thomas Reps. 1996. An Incremental Algorithm for a Generalization of the Shortest-Path Problem. Journal of Algorithms 21, 2 (1996), 267--305.
[72]
Thomas W. Reps, Carla Marceau, and Tim Teitelbaum. 1986. Remote Attribute Updating for Language-Based Editors. In Proceedings of the 13th Annual ACM Symposium on Principles of Programming Languages (POPL'86). 1--13.
[73]
Thomas W. Reps, Tim Teitelbaum, and Alan J. Demers. 1983. Incremental Context-Dependent Analysis for Language-Based Editors. ACM Transactions on Programming Languages and Systems 5, 3 (1983), 449--477.
[74]
Gruia-Catalin Roman, Kenneth C. Cox, C. Donald Wilcox, and Jerome Y. Plun. 1992. Pavane: A System for Declarative Visualization of Concurrent Computations. Journal of Visual Languages and Computing 3, 2 (1992), 161--193.
[75]
Ajeet Shankar and Rastislav Bodík. 2007. DITTO: Automatic Incrementalization of Data Structure Invariant Checks (in Java). In Proceedings of the 2007 ACM SIGPLAN Conference on Programming Language Design and Implementation. ACM, 310--319.
[76]
John T. Stasko, John Domingue, Mark H. Brown, and Blaine A. Price. 1997. Software Visualization. MIT Press, Cambridge, MA.
[77]
U.S. Census Bureau. 2002. UA Census 2000 TIGER/Line Files. U.S. Census Bureau. Washington, DC. Retrieved from http://www.census.gov/geo/www/tiger/.
[78]
Bradley T. Vander Zanden and Richard Halterman. 2001. Using Model Dataflow Graphs to Reduce the Storage Requirements of Constraints. ACM Transactions on Computer-Human Interaction 8, 3 (2001), 223--265.
[79]
Bradley T. Vander Zanden, Richard Halterman, Brad A. Myers, Rich McDaniel, Rob Miller, Pedro Szekely, Dario A. Giuse, and David Kosbie. 2001. Lessons Learned About One-Way, Dataflow Constraints in the Garnet and Amulet Graphical Toolkits. ACM Transactions on Programming Languages and Systems 23, 6 (2001), 776--796.
[80]
Bradley T. Vander Zanden, Richard Halterman, Brad A. Myers, Rob Miller, Pedro Szekely, Dario A. Giuse, David Kosbie, and Rich McDaniel. 2005. Lessons Learned from Programmers' Experiences with One-way Constraints. Software: Practice and Experience 35, 13 (2005), 1275--1298.
[81]
Zhanyong Wan and Paul Hudak. 2000. Functional Reactive Programming from First Principles. In Proceedings of the ACM SIGPLAN 2000 Conference on Programming Language Design and Implementation (PLDI'00). 242--252.
[82]
Neng-Fa Zhou. 2006. Programming Finite-Domain Constraint Propagators in Action Rules. Theory and Practice of Logic Programming 6 (2006), 483--507.

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Transactions on Programming Languages and Systems
ACM Transactions on Programming Languages and Systems  Volume 37, Issue 1
January 2015
170 pages
ISSN:0164-0925
EISSN:1558-4593
DOI:10.1145/2688877
Issue’s Table of Contents
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies 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 for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 17 November 2014
Revised: 01 December 2013
Accepted: 01 May 2013
Received: 01 December 2012
Published in TOPLAS Volume 37, Issue 1

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Reactive programming
  2. constraint solving
  3. data structure repair
  4. dataflow programming
  5. imperative programming
  6. incremental computation
  7. observer design pattern
  8. one-way dataflow constraints
  9. software visualization

Qualifiers

  • Research-article
  • Research
  • Refereed

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 672
    Total Downloads
  • Downloads (Last 12 months)67
  • Downloads (Last 6 weeks)9
Reflects downloads up to 13 Sep 2024

Other Metrics

Citations

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Get Access

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media