Skip to main content

Incremental Analysis of Logic Programs with Assertions and Open Predicates

  • Conference paper
  • First Online:
Logic-Based Program Synthesis and Transformation (LOPSTR 2019)

Abstract

Generic components are a further abstraction over the concept of modules, introducing dependencies on other (not necessarily available) components implementing specified interfaces. They have become a key concept in large and complex software applications. Despite undeniable advantages, generic code is also anti-modular. Precise analysis (e.g., for detecting bugs or optimizing code) requires such code to be instantiated with concrete implementations, potentially leading to expensive combinatorial explosion. In this paper we claim that incremental, whole program analysis can be very beneficial in this context, and alleviate the anti-modularity nature of generic code. We propose a simple Horn-clause encoding of generic programs, using open predicates and assertions, and we introduce a new incremental, multivariant analysis algorithm that reacts incrementally not only to changes in program clauses, but also to changes in the assertions, upon which large parts of the analysis graph may depend. We also discuss the application of the proposed techniques in a number of practical use cases. In addition, as a realistic case study, we apply the proposed techniques in the analysis of the LPdoc documentation system. We argue that the proposed traits are a convenient and elegant abstraction for modular generic programming, and that our preliminary results support our thesis that the new incrementality-related features added to the analysis bring promising advantages in this context.

Research partially funded by MINECO TIN2015-67522-C3-1-R TRACES project, FPU grant 16/04811, and the Madrid P2018/TCS-4339 BLOQUES-CM program. We are also grateful to the anonymous reviewers for their useful comments.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    We denote the calling conditions with \(\mathtt {calls}\) (plural) for historic reasons, and to avoid confusion with the higher order predicate in Prolog call/2.

  2. 2.

    For space reasons we only consider static predicates and modules. Predicates whose definition may change during execution, or modules that are dynamically loaded/unloaded at run time can also be dealt with, using various techniques, and in particular the incremental analysis proposed.

  3. 3.

    In this paper we only focus on traits as interfaces. The actual design in Ciao supports default implementations, which makes them closer to traits in Rust.

References

  1. Bruynooghe, M.: A practical framework for the abstract interpretation of logic programs. J. Logic Program. 10, 91–124 (1991)

    Article  MathSciNet  Google Scholar 

  2. Cabeza, D., Hermenegildo, M.: A new module system for prolog. In: Lloyd, J., et al. (eds.) CL 2000. LNCS (LNAI), vol. 1861, pp. 131–148. Springer, Heidelberg (2000). https://doi.org/10.1007/3-540-44957-4_9

    Chapter  Google Scholar 

  3. Chatterjee, K., Choudhary, B., Pavlogiannis, A.: Optimal Dyck reachability for data-dependence and alias analysis. PACMPL 2(POPL), 1–30 (2018)

    Google Scholar 

  4. Cousot, P., Cousot, R.: Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints. In: Proceedings of POPL 1977, pp. 238–252. ACM Press (1977)

    Google Scholar 

  5. Donovan, A.A.A., Kernighan, B.W.: The Go Programming Language, Professional Computing. Addison-Wesley, Boston (2015)

    Google Scholar 

  6. Dumortier, V., Janssens, G., Simoens, W., García de la Banda, M.: Combining a definiteness and a freeness abstraction for CLP languages. In: Workshop on LP Synthesis and Transformation (1993)

    Google Scholar 

  7. Flanagan, C.: Hybrid type checking. In: 33rd ACM Symposium on Principles of Programming Languages (POPL 2006), pp. 245–256, January 2006

    Google Scholar 

  8. Garcia-Contreras, I., Morales, J.F., Hermenegildo, M.V.: Multivariant assertion-based guidance in abstract interpretation. In: Mesnard, F., Stuckey, P.J. (eds.) LOPSTR 2018. LNCS, vol. 11408, pp. 184–201. Springer, Cham (2019). https://doi.org/10.1007/978-3-030-13838-7_11

    Chapter  Google Scholar 

  9. Hermenegildo, M., Puebla, G., Bueno, F., Lopez-Garcia, P.: Integrated program debugging, verification, and optimization using abstract interpretation (and The Ciao System Preprocessor). Sci. Comput. Program. 58(1–2), 115–140 (2005)

    Google Scholar 

  10. Hermenegildo, M.: A documentation generator for (C)LP systems. In: Lloyd, J., et al. (eds.) CL 2000. LNCS (LNAI), vol. 1861, pp. 1345–1361. Springer, Heidelberg (2000). https://doi.org/10.1007/3-540-44957-4_90

    Chapter  Google Scholar 

  11. Hermenegildo, M.V., Morales, J.: The LPdoc documentation generator. Ref. Manual (v3.0). Technical report, July 2011. http://ciao-lang.org

  12. Hermenegildo, M.V., Puebla, G., Bueno, F.: Using global analysis, partial specifications, and an extensible assertion language for program validation and debugging. In: Apt, K.R., Marek, V.W., Truszczynski, M., Warren, D.S. (eds.) The Logic Programming Paradigm, pp. 161–192. Springer, Heidelberg (1999). https://doi.org/10.1007/978-3-642-60085-2_7

    Chapter  Google Scholar 

  13. Hermenegildo, M.V., Puebla, G., Marriott, K., Stuckey, P.: Incremental analysis of constraint logic programs. ACM TOPLAS 22(2), 187–223 (2000)

    Article  Google Scholar 

  14. Hudak, P., et al.: Report on the programming language Haskell. Haskell special issue. ACM SIGPLAN Not. 27(5), 1–164 (1992)

    Google Scholar 

  15. Klabnik, S., Nichols, C.: The Rust Programming Language. No Starch Press, San Francisco (2018)

    Google Scholar 

  16. Méndez-Lojo, M., Navas, J., Hermenegildo, M.V.: A flexible, (C)LP-based approach to the analysis of object-oriented programs. In: King, A. (ed.) LOPSTR 2007. LNCS, vol. 4915, pp. 154–168. Springer, Heidelberg (2008). https://doi.org/10.1007/978-3-540-78769-3_11

    Chapter  MATH  Google Scholar 

  17. Mora, F., Li, Y., Rubin, J., Chechik, M.: Client-specific equivalence checking. In: 33rd ACM/IEEE International Conference on Automated Software Engineering, pp. 441–451. ASE (2018)

    Google Scholar 

  18. Namolaru, M.: Devirtualization in GCC. In: Proceedings of the GCC Developers’ Summit, pp. 125–133 (2006)

    Google Scholar 

  19. Navas, J., Bueno, F., Hermenegildo, M.: Efficient top-down set-sharing analysis using cliques. In: Van Hentenryck, P. (ed.) PADL 2006. LNCS, vol. 3819, pp. 183–198. Springer, Heidelberg (2005). https://doi.org/10.1007/11603023_13

    Chapter  Google Scholar 

  20. Puebla, G., Albert, E., Hermenegildo, M.: Abstract interpretation with specialized definitions. In: Yi, K. (ed.) SAS 2006. LNCS, vol. 4134, pp. 107–126. Springer, Heidelberg (2006). https://doi.org/10.1007/11823230_8

    Chapter  Google Scholar 

  21. Puebla, G., Bueno, F., Hermenegildo, M.: An assertion language for constraint logic programs. In: Deransart, P., Hermenegildo, M.V., Małuszynski, J. (eds.) Analysis and Visualization Tools for Constraint Programming. LNCS, vol. 1870, pp. 23–61. Springer, Heidelberg (2000). https://doi.org/10.1007/10722311_2

    Chapter  Google Scholar 

  22. Puebla, G., Bueno, F., Hermenegildo, M.: Combined static and dynamic assertion-based debugging of constraint logic programs. In: Bossi, A. (ed.) LOPSTR 1999. LNCS, vol. 1817, pp. 273–292. Springer, Heidelberg (2000). https://doi.org/10.1007/10720327_16

    Chapter  MATH  Google Scholar 

  23. Siek, J.G., Taha, W.: Gradual typing for functional languages. In: Scheme and Functional Programming Workshop, pp. 81–92 (2006)

    Google Scholar 

  24. Swift, T., Warren, D.: XSB: extending prolog with tabled logic programming. TPLP 12(1–2), 157–187 (2012). https://doi.org/10.1017/S1471068411000500

    Article  MathSciNet  MATH  Google Scholar 

  25. Vandevoorde, D., Josuttis, N.M.: C++ Templates. Addison-Wesley Longman Publishing Co. Inc., Boston (2002)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Isabel Garcia-Contreras .

Editor information

Editors and Affiliations

A Assertions

A Assertions

Assertions may not be exactly represented in the abstract domain used by the analyzer. We recall some definitions (adapted from [22]) which are instrumental to correctly approximate the properties of the assertions during the analysis (Fig. 6).

Definition 3 (Set of Calls for which a Property Formula Trivially Succeeds (Trivial Success Set))

Given a conjunction L of property literals and the definitions for each of these properties in P, we define the trivial success set of L in P as:

figure t
Fig. 6.
figure 6

Applying assertions.

where \(\theta |Var(L)\) above denotes the projection of \(\theta \) onto the variables of L, and \(\models \) denotes that \(\theta '\) is a more general constraint than \(\theta \) (entailment). Intuitively, TS(LP) is the set of constraints \(\theta \) for which the literal L succeeds without adding new constraints to \(\theta \) (i.e., without constraining it further). For example, given the following program P:

figure u

and \(L=list(X)\), both \(\theta _1 = \{ X = [1,2] \}\) and \(\theta _2 = \{ X = [1,A] \}\) are in the trivial success set of L in P, since calling \((X=[1,2],list(X))\) returns \(X=[1,2]\) and calling \((X=[1,A],list(X))\) returns \(X=[1,A]\). However, \(\theta _3 = \{ X = [1|\_] \}\) is not, since a call to \((X = [1|Y], list(X))\) will further constrain the term [1|Y], returning \(X = [1|Y], Y=[]\). We define abstract counterparts for Definition 3:

Definition 4 (Abstract Trivial Success Subset of a Property Formula)

Under the same conditions of Definition 3, given an abstract domain \(D_\alpha \), \(\lambda ^-_{TS(L,P)} \in D_\alpha \) is an abstract trivial success subset of L in P iff \(\gamma (\lambda ^-_{TS(L,P)})\subseteq TS(L,P)\).

Definition 5 (Abstract Trivial Success Superset of a Property Formula)

Under the same conditions of Definition 4, an abstract constraint \(\lambda ^+_{TS(L,P)}\) is an abstract trivial success superset of L in P iff \(\gamma (\lambda ^+_{TS(L,P)})\supseteq TS(L,P)\).

I.e., \(\lambda ^-_{TS(L,P)}\) and \(\lambda ^+_{TS(L,P)}\) are, respectively, safe under- and over-approximations of TS(LP). These abstractions come useful when the properties expressed in the assertions cannot be represented exactly in the abstract domain.

Rights and permissions

Reprints and permissions

Copyright information

© 2020 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Garcia-Contreras, I., Morales, J.F., Hermenegildo, M.V. (2020). Incremental Analysis of Logic Programs with Assertions and Open Predicates. In: Gabbrielli, M. (eds) Logic-Based Program Synthesis and Transformation. LOPSTR 2019. Lecture Notes in Computer Science(), vol 12042. Springer, Cham. https://doi.org/10.1007/978-3-030-45260-5_3

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-45260-5_3

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-45259-9

  • Online ISBN: 978-3-030-45260-5

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics