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

Shoggoth: A Formal Foundation for Strategic Rewriting

Published: 05 January 2024 Publication History
  • Get Citation Alerts
  • Abstract

    Rewriting is a versatile and powerful technique used in many domains. Strategic rewriting allows programmers to control the application of rewrite rules by composing individual rewrite rules into complex rewrite strategies. These strategies are semantically complex, as they may be nondeterministic, they may raise errors that trigger backtracking, and they may not terminate.
    Given such semantic complexity, it is necessary to establish a formal understanding of rewrite strategies and to enable reasoning about them in order to answer questions like: How do we know that a rewrite strategy terminates? How do we know that a rewrite strategy does not fail because we compose two incompatible rewrites? How do we know that a desired property holds after applying a rewrite strategy?
    In this paper, we introduce Shoggoth: a formal foundation for understanding, analysing and reasoning about strategic rewriting that is capable of answering these questions. We provide a denotational semantics of System S, a core language for strategic rewriting, and prove its equivalence to our big-step operational semantics, which extends existing work by explicitly accounting for divergence. We further define a location-based weakest precondition calculus to enable formal reasoning about rewriting strategies, and we prove this calculus sound with respect to the denotational semantics. We show how this calculus can be used in practice to reason about properties of rewriting strategies, including termination, that they are well-composed, and that desired postconditions hold. The semantics and calculus are formalised in Isabelle/HOL and all proofs are mechanised.

    References

    [1]
    Alejandro Aguirre, Shin-ya Katsumata, and Satoshi Kura. 2022. Weakest preconditions in fibrations. Math. Struct. Comput. Sci., 32, 4 (2022), 472–510. https://doi.org/10.1017/S0960129522000330
    [2]
    Carolyn Jane Anderson, Nate Foster, Arjun Guha, Jean-Baptiste Jeannin, Dexter Kozen, Cole Schlesinger, and David Walker. 2014. NetKAT: semantic foundations for networks. In The 41st Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’14, San Diego, CA, USA, January 20-21, 2014, Suresh Jagannathan and Peter Sewell (Eds.). ACM, 113–126. https://doi.org/10.1145/2535838.2535862
    [3]
    Marcello M. Bonsangue and Joost N. Kok. 1992. Semantics, Orderings and Recursion in the Weakest Precondition Calculus. In Sematics: Foundations and Applications, REX Workshop, Beekbergen, The Netherlands, June 1-4, 1992, Proceedings, J. W. de Bakker, Willem P. de Roever, and Grzegorz Rozenberg (Eds.) (LNCS, Vol. 666). Springer, 91–109. https://doi.org/10.1007/3-540-56596-5_30
    [4]
    Peter Borovanský, Claude Kirchner, Hélène Kirchner, Pierre-Etienne Moreau, and Marian Vittek. 1996. ELAN: A logical framework based on computational systems. In First International Workshop on Rewriting Logic and its Applications, RWLW 1996, Asilomar Conference Center, Pacific Grove, CA, USA, September 3-6, 1996, José Meseguer (Ed.) (Electronic Notes in Theoretical Computer Science, Vol. 4). Elsevier, 35–50. https://doi.org/10.1016/S1571-0661(04)00032-5
    [5]
    Martin Bravenboer, Karl Trygve Kalleberg, Rob Vermaas, and Eelco Visser. 2008. Stratego/XT 0.17. A language and toolset for program transformation. Sci. Comput. Program., 72, 1-2 (2008), 52–70. https://doi.org/10.1016/j.scico.2007.11.003
    [6]
    Ernie Cohen, Markus Dahlweid, Mark A. Hillebrand, Dirk Leinenbach, Michal Moskal, Thomas Santen, Wolfram Schulte, and Stephan Tobies. 2009. VCC: A Practical System for Verifying Concurrent C. In Theorem Proving in Higher Order Logics, 22nd International Conference, TPHOLs 2009, Munich, Germany, August 17-20, 2009. Proceedings, Stefan Berghofer, Tobias Nipkow, Christian Urban, and Makarius Wenzel (Eds.) (LNCS, Vol. 5674). Springer, 23–42. https://doi.org/10.1007/978-3-642-03359-9_2
    [7]
    Stephen A. Cook. 1978. Soundness and Completeness of an Axiom System for Program Verification. SIAM J. Comput., 7, 1 (1978), 70–90. https://doi.org/10.1137/0207005
    [8]
    Alcino Cunha and Joost Visser. 2007. Transformation of Structure-Shy Programs: Applied to XPath Queries and Strategic Functions. In Proceedings of the 2007 ACM SIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation (PEPM ’07). Association for Computing Machinery, New York, NY, USA. 11–20. isbn:9781595936202 https://doi.org/10.1145/1244381.1244385
    [9]
    Nachum Dershowitz. 1985. Computing with Rewrite Systems. Inf. Control., 65, 2/3 (1985), 122–157. https://doi.org/10.1016/S0019-9958(85)80003-6
    [10]
    Marco Devesas Campos and Paul Blain Levy. 2018. A Syntactic View of Computational Adequacy. In Foundations of Software Science and Computation Structures, Christel Baier and Ugo Dal Lago (Eds.). Springer International Publishing, Cham. 71–87. isbn:978-3-319-89366-2
    [11]
    Edsger W. Dijkstra. 1975. Guarded Commands, Nondeterminacy and Formal Derivation of Programs. Commun. ACM, 18, 8 (1975), 453–457. https://doi.org/10.1145/360933.360975
    [12]
    Cormac Flanagan, K. Rustan M. Leino, Mark Lillibridge, Greg Nelson, James B. Saxe, and Raymie Stata. 2002. Extended Static Checking for Java. In Proceedings of the 2002 ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), Berlin, Germany, June 17-19, 2002, Jens Knoop and Laurie J. Hendren (Eds.). ACM, 234–245. https://doi.org/10.1145/512529.512558
    [13]
    Robert W. Floyd. 1967. Assigning Meanings to Programs. Proceedings of Symposium on Applied Mathematics, 19 (1967), 19–32. https://doi.org/10.1007/978-94-011-1793-7_4
    [14]
    Rongxiao Fu, Ornela Dardha, and Michel Steuwer. 2023. Traced Types for Safe Strategic Rewriting. arxiv:2304.14154.
    [15]
    Sergey Goncharov and Lutz Schröder. 2013. A Relatively Complete Generic Hoare Logic for Order-Enriched Effects. In 28th Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2013, New Orleans, LA, USA, June 25-28, 2013. IEEE Computer Society, 273–282. https://doi.org/10.1109/LICS.2013.33
    [16]
    Bastian Hagedorn, Johannes Lenfers, Thomas Koehler, Xueying Qin, Sergei Gorlatch, and Michel Steuwer. 2020. Achieving high-performance the functional way: a functional pearl on expressing high-performance optimizations as rewrite strategies. Proc. ACM Program. Lang., 4, ICFP (2020), 92:1–92:29. https://doi.org/10.1145/3408974
    [17]
    Bastian Hagedorn, Johannes Lenfers, Thomas Koehler, Xueying Qin, Sergei Gorlatch, and Michel Steuwer. 2023. Achieving High Performance the Functional Way: Expressing High-Performance Optimizations as Rewrite Strategies. Commun. ACM, 66, 3 (2023), 89–97. https://doi.org/10.1145/3580371
    [18]
    Matthew Hennessy and Gordon D. Plotkin. 1979. Full Abstraction for a Simple Parallel Programming Language. In Mathematical Foundations of Computer Science 1979, Proceedings, 8th Symposium, Olomouc, Czechoslovakia, September 3-7, 1979, Jirí Becvár (Ed.) (LNCS, Vol. 74). Springer, 108–120. https://doi.org/10.1007/3-540-09526-8_8
    [19]
    Tony Hoare. 1969. An Axiomatic Basis for Computer Programming. Commun. ACM, 12, 10 (1969), 576–580. https://doi.org/10.1145/363235.363259
    [20]
    Tony Hoare, Bernhard Möller, Georg Struth, and Ian Wehrman. 2011. Concurrent Kleene Algebra and its Foundations. J. Log. Algebraic Methods Program., 80, 6 (2011), 266–296. https://doi.org/10.1016/j.jlap.2011.04.005
    [21]
    Patricia Johann, Alex Simpson, and Janis Voigtländer. 2010. A Generic Operational Metatheory for Algebraic Effects. In Proceedings of the 25th Annual IEEE Symposium on Logic in Computer Science, LICS 2010, 11-14 July 2010, Edinburgh, United Kingdom. IEEE Computer Society, 209–218. https://doi.org/10.1109/LICS.2010.29
    [22]
    Markus Kaiser and Ralf Lämmel. 2009. An Isabelle/HOL-based model of Stratego-like traversal strategies. In Proceedings of the 11th International ACM SIGPLAN Conference on Principles and Practice of Declarative Programming, September 7-9, 2009, Coimbra, Portugal, António Porto and Francisco Javier López-Fraguas (Eds.). ACM, 93–104. https://doi.org/10.1145/1599410.1599423
    [23]
    Richard B. Kieburtz. 2001. A Logic for Rewriting Strategies. Electronic Notes in Theoretical Computer Science, 58, 2 (2001), 138–154. issn:1571-0661 https://doi.org/10.1016/S1571-0661(04)00283-X STRATEGIES 2001, 4th International Workshop on Strategies in Automated Deduction - Selected Papers (in connection with IJCAR 2001)
    [24]
    James Koppel. 2023. Typed Multi-Language Strategy Combinators. In Eelco Visser Commemorative Symposium, EVCS 2023, April 5, 2023, Delft, The Netherlands, Ralf Lämmel, Peter D. Mosses, and Friedrich Steimann (Eds.) (OASIcs, Vol. 109). Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 16:1–16:9. https://doi.org/10.4230/OASIcs.EVCS.2023.16
    [25]
    Dexter Kozen. 1991. A Completeness Theorem for Kleene Algebras and the Algebra of Regular Events. In Proceedings of the Sixth Annual Symposium on Logic in Computer Science (LICS ’91), Amsterdam, The Netherlands, July 15-18, 1991. IEEE Computer Society, 214–225. https://doi.org/10.1109/LICS.1991.151646
    [26]
    Dexter Kozen. 1997. Kleene Algebra with Tests. ACM Trans. Program. Lang. Syst., 19, 3 (1997), 427–443. https://doi.org/10.1145/256167.256195
    [27]
    Dexter Kozen. 1999. On Hoare Logic and Kleene Algebra with Tests. In 14th Annual IEEE Symposium on Logic in Computer Science, Trento, Italy, July 2-5, 1999. IEEE Computer Society, 167–172. https://doi.org/10.1109/LICS.1999.782610
    [28]
    Ralf Lämmel. 2003. Typed generic traversal with term rewriting strategies. J. Log. Algebraic Methods Program., 54, 1-2 (2003), 1–64. https://doi.org/10.1016/S1567-8326(02)00028-0
    [29]
    Ralf Lämmel. 2007. Scrap Your Boilerplate with XPath-like Combinators. In Proceedings of the 34th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’07). Association for Computing Machinery, New York, NY, USA. 137–142. isbn:1595935754 https://doi.org/10.1145/1190216.1190240
    [30]
    Ralf Lämmel, Simon Thompson, and Markus Kaiser. 2013. Programming errors in traversal programs over structured data. Science of Computer Programming, 78, 10 (2013), 1770–1808.
    [31]
    Ralf Lämmel and Joost Visser. 2002. Design patterns for functional strategic programming. In Proceedings of the 2002 ACM SIGPLAN Workshop on Rule-Based Programming, Pittsburgh, Pennsylvania, USA, 2002, Bernd Fischer and Eelco Visser (Eds.). ACM, 1–14. https://doi.org/10.1145/570186.570187
    [32]
    K. Rustan M. Leino. 2005. Efficient weakest preconditions. Inf. Process. Lett., 93, 6 (2005), 281–288. https://doi.org/10.1016/j.ipl.2004.10.015
    [33]
    K. Rustan M. Leino. 2010. Dafny: An Automatic Program Verifier for Functional Correctness. In Logic for Programming, Artificial Intelligence, and Reasoning - 16th International Conference, LPAR-16, Dakar, Senegal, April 25-May 1, 2010, Revised Selected Papers, Edmund M. Clarke and Andrei Voronkov (Eds.) (LNCS, Vol. 6355). Springer, 348–370. https://doi.org/10.1007/978-3-642-17511-4_20
    [34]
    Xavier Leroy and Hervé Grall. 2009. Coinductive big-step operational semantics. Information and Computation, 207, 2 (2009), 284–304. issn:0890-5401 https://doi.org/10.1016/j.ic.2007.12.004 Special issue on Structural Operational Semantics (SOS)
    [35]
    Carroll Morgan. 1994. Programming from specifications, 2nd Edition. Prentice Hall. isbn:978-0-13-123274-7
    [36]
    Tobias Nipkow, Lawrence C. Paulson, and Markus Wenzel. 2002. Isabelle/HOL: A Proof Assistant for Higher-Order Logic (LNCS, Vol. 2283). Springer. https://doi.org/10.1007/3-540-45949-9
    [37]
    Gordon Plotkin and John Power. 2001. Adequacy for Algebraic Effects. In Foundations of Software Science and Computation Structures, Furio Honsell and Marino Miculan (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 1–24. isbn:978-3-540-45315-4
    [38]
    Gordon D. Plotkin. 1976. A Powerdomain Construction. SIAM J. Comput., 5, 3 (1976), 452–487. https://doi.org/10.1137/0205035
    [39]
    Xueying Qin, Liam O’Connor, Rob van Glabbeek, Peter Höfner, Ohad Kammar, and Michel Steuwer. 2023. Artifact for Shoggoth - A Formal Foundation for Strategic Rewriting. https://doi.org/10.5281/zenodo.10125602
    [40]
    Alex Simpson. 2004. Computational adequacy for recursive types in models of intuitionistic set theory. Annals of Pure and Applied Logic, 130, 1 (2004), 207–275. issn:0168-0072 https://doi.org/10.1016/j.apal.2003.12.005 Papers presented at the 2002 IEEE Symposium on Logic in Computer Science (LICS)
    [41]
    Jeff Smits and Eelco Visser. 2020. Gradually typing strategies. In Proceedings of the 13th ACM SIGPLAN International Conference on Software Language Engineering, SLE 2020, Virtual Event, USA, November 16-17, 2020, Ralf Lämmel, Laurence Tratt, and Juan de Lara (Eds.). ACM, 1–15. https://doi.org/10.1145/3426425.3426928
    [42]
    Matthieu Sozeau. 2014. Proof-relevant rewriting strategies in Coq. In At Coq Workshop. https://www.irif.fr/~letouzey/types2014/abstract-13.pdf
    [43]
    J.E. Stoy. 1985. Denotational Semantics: The Scott-Strachey Approach to Programming Language Theory. MIT Press. isbn:9780262690768 lccn:77011962 https://books.google.co.uk/books?id=jM0mAAAAMAAJ
    [44]
    Wouter Swierstra and Tim Baanen. 2019. A Predicate Transformer Semantics for Effects (Functional Pearl). Proc. ACM Program. Lang., 3, ICFP (2019), Article 103, jul, 26 pages. https://doi.org/10.1145/3341707
    [45]
    Eelco Visser. 2001. Stratego: A Language for Program Transformation Based on Rewriting Strategies System Description of Stratego 0.5. In Rewriting Techniques and Applications, Aart Middeldorp (Ed.) (LNCS, Vol. 2051). Springer, 357–361. isbn:978-3-540-45127-3 https://doi.org/10.1007/3-540-45127-7_27
    [46]
    Eelco Visser, Zine El-Abidine Benaissa, and Andrew P. Tolmach. 1998. Building Program Optimizers with Rewriting Strategies. In Proceedings of the third ACM SIGPLAN International Conference on Functional Programming (ICFP ’98), Baltimore, Maryland, USA, September 27-29, 1998, Matthias Felleisen, Paul Hudak, and Christian Queinnec (Eds.). ACM, 13–26. https://doi.org/10.1145/289423.289425
    [47]
    Eelco Visser and Zine El-Abidine Benaissa. 1998. A Core Language for Rewriting. Electronic Notes in Theoretical Computer Science, 15 (1998), 422–441. issn:1571-0661 https://doi.org/10.1016/S1571-0661(05)80027-1 International Workshop on Rewriting Logic and its Applications
    [48]
    Guido Wachsmuth, Gabriël D. P. Konat, and Eelco Visser. 2014. Language Design with the Spoofax Language Workbench. IEEE Softw., 31, 5 (2014), 35–43. https://doi.org/10.1109/MS.2014.100
    [49]
    Jana Wagemaker, Nate Foster, Tobias Kappé, Dexter Kozen, Jurriaan Rot, and Alexandra Silva. 2022. Concurrent NetKAT - Modeling and analyzing stateful, concurrent networks. In Programming Languages and Systems - 31st European Symposium on Programming, ESOP 2022, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2022, Munich, Germany, April 2-7, 2022, Proceedings, Ilya Sergey (Ed.) (LNCS, Vol. 13240). Springer, 575–602. https://doi.org/10.1007/978-3-030-99336-8_21
    [50]
    Victor L. Winter and Mahadevan Subramaniam. 2004. The transient combinator, higher-order strategies, and the distributed data problem. Sci. Comput. Program., 52 (2004), 165–212. https://doi.org/10.1016/j.scico.2004.03.006

    Recommendations

    Comments

    Information & Contributors

    Information

    Published In

    cover image Proceedings of the ACM on Programming Languages
    Proceedings of the ACM on Programming Languages  Volume 8, Issue POPL
    January 2024
    2820 pages
    EISSN:2475-1421
    DOI:10.1145/3554315
    Issue’s Table of Contents
    This work is licensed under a Creative Commons Attribution 4.0 International License.

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 05 January 2024
    Published in PACMPL Volume 8, Issue POPL

    Permissions

    Request permissions for this article.

    Check for updates

    Badges

    Author Tags

    1. mechanised formalisation
    2. program transformation
    3. semantics
    4. strategic rewriting
    5. weakest preconditions

    Qualifiers

    • Research-article

    Funding Sources

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • 0
      Total Citations
    • 287
      Total Downloads
    • Downloads (Last 12 months)287
    • Downloads (Last 6 weeks)42
    Reflects downloads up to 09 Aug 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