Abstract
In this paper, we address the different conceptual and technical difficulties encountered when embedding CHR into an imperative host language. We argue that a tight, natural integration leads to a powerful programming language extension, intuitive to both CHR and imperative programmers. We show how to compile CHR to highly optimized imperative code. To this end, we first review the well-established CHR compilation scheme, and survey the large body of possible optimizations. We then show that this scheme, when used for compilation to imperative target languages, leads to stack overflows. We therefore introduce new optimizations that considerably improve the performance of recursive CHR programs. Rules written using tail calls are even guaranteed to run in constant space. We implemented systems for both Java and C, following the language design principles and compilation scheme presented in this paper, and show that our implementations outperform other state-of-the-art CHR compilers by several orders of magnitude.
Preview
Unable to display preview. Download preview PDF.
Similar content being viewed by others
References
The Constraint Handling Rules (CHR) programming language homepage, http://www.cs.kuleuven.be/~dtai/projects/CHR/
Frühwirth, T.: Theory and practice of Constraint Handling Rules. J. Logic Programming, Special Issue on Constraint Logic Programming 37(1–3), 95–138 (1998)
Sneyers, J., Van Weert, P., Schrijvers, T., De Koninck, L.: As time goes by: Constraint Handling Rules — a survey of CHR research between 1998 and 2007. Journal of Theory and Practice of Logic Programming (submitted, 2008)
Holzbaur, C., Frühwirth, T.: A Prolog Constraint Handling Rules compiler and runtime system. In: [76], pp. 369–388
Schrijvers, T.: Analyses, optimizations and extensions of Constraint Handling Rules. Ph.D thesis, K.U.Leuven, Belgium (June 2005)
Schrijvers, T., Demoen, B.: The K.U.Leuven CHR system: Implementation and application. In: [77], pp. 8–12
Duck, G.J.: Compilation of Constraint Handling Rules. Ph.D thesis, University of Melbourne, Australia (December 2005)
Holzbaur, C., GarcÃa de la Banda, M., Stuckey, P.J., Duck, G.J.: Optimizing compilation of Constraint Handling Rules in HAL. In: [78], pp. 503–531
Abdennadher, S., Krämer, E., Saft, M., Schmauß, M.: JACK: A Java Constraint Kit. In: Hanus, M. (ed.) WFLP 2001: Proc. 10th Intl. Workshop on Functional and (Constraint) Logic Programming, Kiel, Germany. ENTCS, vol. 64, pp. 1–17. Elsevier, Amsterdam (2002), http://pms.ifi.lmu.de/software/jack/
Vitorino, J., Aurelio, M.: Chord (2005), http://chord.sourceforge.net/
Wolf, A.: Adaptive constraint handling with CHR in Java. In: Walsh, T. (ed.) CP 2001. LNCS, vol. 2239, pp. 256–270. Springer, Heidelberg (2001)
Van Weert, P.: The K.U.Leuven JCHR system (2008), http://www.cs.kuleuven.be/~petervw/JCHR/
Wuille, P.: CCHR: The fastest CHR implementation, in C (2008), http://www.cs.kuleuven.be/~pieterw/CCHR/
Frühwirth, T.: Constraint Handling Rules. Cambridge University Press, Cambridge (to appear, 2008)
Duck, G.J., Stuckey, P.J., GarcÃa de la Banda, M., Holzbaur, C.: The refined operational semantics of Constraint Handling Rules. In: Demoen, B., Lifschitz, V. (eds.) ICLP 2004. LNCS, vol. 3132, pp. 90–104. Springer, Heidelberg (2004)
Duck, G.J., Stuckey, P.J., GarcÃa de la Banda, M., Holzbaur, C.: Extending arbitrary solvers with Constraint Handling Rules. In: PPDP 2003, Uppsala, Sweden, pp. 79–90. ACM Press, New York (2003)
Abdennadher, S.: Rule-based Constraint Programming: Theory and Practice. Habilitationsschrift, Institute of Computer Science, LMU, Munich, Germany (July 2001)
Abdennadher, S., Schütz, H.: CHR ∨ , a flexible query language. In: Andreasen, T., Christiansen, H., Larsen, H. (eds.) FQAS 1998. LNCS, vol. 1495, pp. 1–14. Springer, Heidelberg (1998)
Krämer, E.: A generic search engine for a Java Constraint Kit. Diplomarbeit, Institute of Computer Science, LMU, Munich, Germany (January 2001)
Wolf, A.: Intelligent search strategies based on adaptive Constraint Handling Rules. In: [78], pp. 567–594 (2005)
da Figueira Filho, C.S., Ramalho, G.L.: JEOPS - the java embedded object production system. In: Monard, M.C., Sichman, J.S. (eds.) SBIA 2000 and IBERAMIA 2000. LNCS, vol. 1952, p. 53. Springer, Heidelberg (2000)
Pachet, F.: On the embeddability of production rules in object-oriented languages. Journal of Object-Oriented Programming 8(4), 19–24 (1995)
Pachet, F. (ed.): EOOPS 1994: Proc. OOPSLA 1994 Workshop on Embedded Object-Oriented Production Systems, Portland, Oregon, USA (October 2004)
Bouaud, J., Voyer, R.: Behavioral match: Embedding production systems and objects. In: [23]
Van Weert, P., Schrijvers, T., Demoen, B.: K.U.Leuven JCHR: a user-friendly, flexible and efficient CHR system for Java. In: [79], pp. 47–62
Wuille, P., Schrijvers, T., Demoen, B.: CCHR: the fastest CHR implementation, in C. In: [80], pp. 123–137
Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, Reading (1995)
Schrijvers, T., Demoen, B., Duck, G.J., Stuckey, P.J., Frühwirth, T.: Automatic implication checking for CHR constraints. In: RULE 2005: 6th Intl. Workshop on Rule-Based Programming, Nara, Japan, January 2006. ENTCS, vol. 147(1), pp. 93–111. Elsevier, Amsterdam (2006)
Fages, F., de Oliveira Rodrigues, C.M., Martinez, T.: Modular chr with ask and tell. In: [81], pp. 95–110
Kernighan, B.W., Ritchie, D., Ritchie, D.M.: C Programming Language, 2nd edn. Prentice Hall PTR, Englewood Cliffs (1988)
Van Weert, P.: K.U.Leuven JCHR User’s Manual (2008). In: [12]
Gosling, J., Joy, B., Steele, G., Bracha, G.: The Java Language Specification, 3rd edn. The Java Series. Prentice Hall, Englewood Cliffs (2005)
Bracha, G.: Generics in the Java Programming Language (July 2004) (Tutorial)
Sun Microsystems, Inc.: The Collections framework: API’s and developer guides (2008), http://java.sun.com/javase/6/docs/technotes/guides/collections/
Sun Microsystems, Inc.: JavaBeans (2008), http://java.sun.com/products/javabeans/
Van Weert, P.: Compiling Constraint Handling Rules to Java: A reconstruction. Technical Report CW 521, K.U.Leuven, Dept. Comp. Sc. (August 2008)
Sneyers, J., Schrijvers, T., Demoen, B.: The computational power and complexity of Constraint Handling Rules. In: [79], pp. 3–17
De Koninck, L., Sneyers, J.: Join ordering for Constraint Handling Rules. In: [80], pp. 107–121
Duck, G.J., Schrijvers, T.: Accurate functional dependency analysis for Constraint Handling Rules. In: [79], pp. 109–124
Schrijvers, T., Stuckey, P.J., Duck, G.J.: Abstract interpretation for Constraint Handling Rules. In: Barahona, P., Felty, A. (eds.) PPDP 2005, Lisbon, Portugal, July 2005, pp. 218–229. ACM Press, New York (2005)
Sneyers, J., Schrijvers, T., Demoen, B.: Guard reasoning in the refined operational semantics of CHR. In: Schrijvers, T., Frühwirth, T. (eds.) Constraint Handling Rules. LNCS(LNAI), vol. 5388, pp. 213–244. Springer, Heidelberg (2008)
Sneyers, J., Schrijvers, T., Demoen, B.: Memory reuse for CHR. In: Etalle, S., Truszczyński, M. (eds.) ICLP 2006. LNCS, vol. 4079, pp. 72–86. Springer, Heidelberg (2006)
Van Weert, P.: Optimization of CHR propagation rules. In: ICLP 2008: Proc. 24rd Intl. Conf. Logic Programming, Udine, Italy, December 2008. LNCS. Springer, Heidelberg (accepted, 2008)
Sneyers, J., Schrijvers, T., Demoen, B.: Dijkstra’s algorithm with Fibonacci heaps: An executable description in CHR. In: [82], pp. 182–191
Holzbaur, C., Frühwirth, T.: Compiling Constraint Handling Rules into Prolog with attributed variables. In: Nadathur, G. (ed.) PPDP 1999. LNCS, vol. 1702, pp. 117–133. Springer, Heidelberg (1999)
Rossi, F., van Beek, P., Walsh, T. (eds.): Handbook of Constraint Programming. Foundations of Artificial Intelligence. Elsevier, Amsterdam (2006)
Holzbaur, C.: Metastructures versus attributed variables in the context of extensible unification. In: Proc. 4th Intl. Symposium on Programming Language Implementation and Logic Programming, pp. 260–268. Springer, Heidelberg (1992)
Schulte, C., Stuckey, P.J.: Efficient constraint propagation engines. Under consideration for ACM Transactions on Programming Languages and Systems (2008)
Schrijvers, T., Demoen, B.: Antimonotony-based delay avoidance for CHR. Technical Report CW 385, K.U.Leuven, Dept. Comp. Sc (July 2004)
Van Weert, P.: A tale of histories. In: [81], pp. 79–94
Probst, M.: Proper tail recursion in C. Diplomarbeit, Institute of Computer Languages, Vienna University of Technology (2001)
Free Software Foundation: GCC, the GNU Compiler Collection (2008), http://gcc.gnu.org/
Bauer, A.: Compilation of functional programming languages using GCC—Tail calls. Master’s thesis, Institut für Informatik, Technische Univ. München (2003)
Lindholm, T., Yellin, F.: The Java\(^\textsc{TM}\) Virtual Machine Specification, 2nd edn. Prentice Hall, Englewood Cliffs (1999)
Sun Microsystems, Inc.: Java SE HotSpot at a glance (2008), http://java.sun.com/javase/technologies/hotspot/
Clements, J., Felleisen, M.: A tail-recursive machine with stack inspection. ACM Trans. on Prog. Languages and Systems (TOPLAS) 26(6), 1029–1052 (2004)
Baker, H.G.: CONS should not CONS its arguments, part II: Cheney on the M.T.A. SIGPLAN Notices 30(9), 17–20 (1995)
Ganz, S.E., Friedman, D.P., Wand, M.: Trampolined style. In: Intl. Conf. on Functional Programming, pp. 18–27 (1999)
Wielemaker, J.: An overview of the swi-prolog programming environment. In: Proc. 13th Intl. Workshop on Logic Programming Environments, Mumbai, India (2003), http://www.swi-prolog.org/
Santos Costa, V., et al.: YAP Prolog, http://www.ncc.up.pt/yap/
Chin, W.N., Sulzmann, M., Wang, M.: A type-safe embedding of Constraint Handling Rules into Haskell. Honors thesis, School of Computing, National University of Singapore (2003)
Stuckey, P.J., Sulzmann, M., Wazny, J.: The Chameleon system. In: [77], pp. 13–32
Stuckey, P.J., Sulzmann, M.: A theory of overloading. ACM TOPLAS 27(6), 1216–1269 (2005)
Duck, G.J.: HaskellCHR (2004), http://www.cs.mu.oz.au/~gjd/haskellchr/
Lam, E.S., Sulzmann, M.: A concurrent Constraint Handling Rules semantics and its implementation with software transactional memory. In: DAMP 2007: Proc. ACM SIGPLAN Workshop on Declarative Aspects of Multicore Programming, Nice, France. ACM Press, New York (2007)
Stahl, M.: STMCHR. In: CHR Homepage [1] (2007)
Schmauß, M.: An implementation of CHR in Java. Diplomarbeit, Institute of Computer Science, LMU, Munich, Germany (November 1999)
Abdennadher, S., Saft, M.: A visualization tool for Constraint Handling Rules. In: Kusalik, A. (ed.) WLPE 2001, Paphos, Cyprus (December 2001)
Robin, J., Vitorino, J.: ORCAS: Towards a CHR-based model-driven framework of reusable reasoning components. In: [82], pp. 192–199
Menezes, L., Vitorino, J., Aurelio, M.: A high performance CHR\({}^\lor\) execution engine. In: [79], pp. 35–45
Wolf, A., Gruenhagen, T., Geske, U.: On incremental adaptation of CHR derivations. In: [76], pp. 389–416
Forgy, C.: Rete: A fast algorithm for the many pattern/many object pattern match problem. Artificial Intelligence 19, 17–37 (1982)
Miranker, D.P., Brant, D.A., Lofaso, B., Gadbois, D.: On the performance of lazy matching in production systems. In: Proc. 8th Intl. Conf. on Artificial Intelligence, pp. 685–692 (1990)
Friedman-Hill, E., et al.: Jess, the rule engine for the Java platform (2008), http://www.jessrules.com/
JBoss: Drools (2008), http://labs.jboss.com/drools/
Holzbaur, C., Frühwirth, T. (eds.): Special Issue on Constraint Handling Rules. Journal of Applied Artificial Intelligence 14(4) (2000)
Frühwirth, T., Meister, M. (eds.): CHR 2004: 1st Workshop on Constraint Handling Rules: Selected Contributions, Ulm, Germany (May 2004)
Abdennadher, S., Frühwirth, T., Holzbaur, C.: Special Issue on Constraint Handling Rules. Theory and Practice of Logic Programming, vol. 5(4–5). Cambridge University Press, Cambridge (2005)
Schrijvers, T., Frühwirth, T. (eds.): CHR 2005: Proc. 2nd Workshop on Constraint Handling Rules. CHR 2005. K.U.Leuven, Dept. Comp. Sc., Technical report CW 421, Sitges, Spain (2005)
Djelloul, K., Duck, G.J., Sulzmann, M. (eds.): CHR 2007: Proc. 4th Workshop on Constraint Handling Rules. CHR 2007, Porto, Portugal (September 2007)
Schrijvers, T., Raiser, F., Frühwirth, T. (eds.): CHR 2008: Proc. 5th Workshop on Constraint Handling Rules. CHR 2008. RISC Report Series 08-10, University of Linz, Austria, Hagenberg, Austria (July 2008)
Fink, M., Tompits, H., Woltran, S. (eds.): WLP 2006: Proc. 20th Workshop on Logic Programming. T.U.Wien, Austria, INFSYS Research report 1843-06-02, Vienna, Austria (February 2006)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2008 Springer-Verlag Berlin Heidelberg
About this chapter
Cite this chapter
Van Weert, P., Wuille, P., Schrijvers, T., Demoen, B. (2008). CHR for Imperative Host Languages. In: Schrijvers, T., Frühwirth, T. (eds) Constraint Handling Rules. Lecture Notes in Computer Science(), vol 5388. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-92243-8_7
Download citation
DOI: https://doi.org/10.1007/978-3-540-92243-8_7
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-92242-1
Online ISBN: 978-3-540-92243-8
eBook Packages: Computer ScienceComputer Science (R0)