skip to main content

Intensional datatype refinement: with application to scalable verification of pattern-match safety

Published:04 January 2021Publication History
Skip Abstract Section

Abstract

The pattern-match safety problem is to verify that a given functional program will never crash due to non-exhaustive patterns in its function definitions. We present a refinement type system that can be used to solve this problem. The system extends ML-style type systems with algebraic datatypes by a limited form of structural subtyping and environment-level intersection. We describe a fully automatic, sound and complete type inference procedure for this system which, under reasonable assumptions, is worst-case linear-time in the program size. Compositionality is essential to obtaining this complexity guarantee. A prototype implementation for Haskell is able to analyse a selection of packages from the Hackage database in a few hundred milliseconds.

References

  1. Alexander Aiken. 1999. Introduction to set constraint-based program analysis. Science of Computer Programming 35, 2 ( 1999 ), 79-111. https://doi.org/10.1016/S0167-6423 ( 99 ) 00007-6 Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Alexander Aiken and Edward L. Wimmers. 1992. Solving Systems of Set Constraints (Extended Abstract). In Proceedings of the Seventh Annual Symposium on Logic in Computer Science (LICS '92), Santa Cruz, California, USA, June 22-25, 1992. 329-340.Google ScholarGoogle Scholar
  3. Alexander Aiken and Edward L. Wimmers. 1993. Type Inclusion Constraints and Type Inference. In FPCA. 31-41.Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Alexander Aiken, Edward L. Wimmers, and T. K. Lakshman. 1994a. Soft Typing with Conditional Types. In Conference Record of POPL'94: 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Portland, Oregon, USA, January 17-21, 1994. 163-173.Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Alexander Aiken, Edward L. Wimmers, and T. K. Lakshman. 1994b. Soft typing with conditional types. In Proceedings of the 21st ACM SIGPLAN-SIGACT symposium on Principles of programming languages. Association for Computing Machinery, 163-173. https://doi.org/10.1145/174675.177847 Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Alexander Aiken, Edward L. Wimmers, and Jens Palsberg. 1999. Optimal Representations of Polymorphic Types with Subtyping. Higher-Order and Symbolic Computation 12, 3 ( 1999 ), 237-282. https://doi.org/10.1023/A:1010056315933 Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Roberto M. Amadio and Luca Cardelli. 1993. Subtyping recursive types. ACM Trans. Program. Lang. Syst. 15, 4 ( 1993 ), 575-631. https://doi.org/10.1145/155183.155231 Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Leo Bachmair, Harald Ganzinger, and Uwe Waldmann. 1993. Set constraints are the monadic class. In Proceedings Eighth Annual IEEE Symposium on Logic in Computer Science. IEEE, 75-83.Google ScholarGoogle ScholarCross RefCross Ref
  9. Giuseppe Castagna, Tommaso Petrucciani, and Kim Nguyen. 2016. Set-theoretic types for polymorphic variants. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming. Association for Computing Machinery, 378-391. https://doi.org/10.1145/2951913.2951928 Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Giuseppe Castagna and Zhiwu Xu. 2011. Set-theoretic foundation of parametric polymorphism and subtyping. In Proceedings of the 16th ACM SIGPLAN international conference on Functional programming. Association for Computing Machinery, 94-106. https://doi.org/10.1145/2034773.2034788 Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Toby Cathcart Burn, C.-H. Luke Ong, and Steven J. Ramsay. 2017. Higher-order constrained horn clauses for verification. Proc. ACM Program. Lang. 2, POPL ( 2017 ), Article 11. https://doi.org/10.1145/3158099 Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Stephen Dolan and Alan Mycroft. 2017. Polymorphism, subtyping, and type inference in MLsub. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages. Association for Computing Machinery, 60-72. https://doi.org/10.1145/3009837.3009882 Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Joshua Dunfield. 2007. Refined typechecking with Stardust. In Proceedings of the 2007 workshop on Programming languages meets program verification. Association for Computing Machinery, 21-32. https://doi.org/10.1145/1292597.1292602 Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Joshua Dunfield. 2017. Extensible Datasort Refinements. In European Symposium on Programming Languages and Systems, Hongseok Yang (Ed.). Springer Berlin Heidelberg, 476-503. https://doi.org/10.1007/978-3-662-54434-1_18 Google ScholarGoogle ScholarCross RefCross Ref
  15. Joseph Eremondi. 2019. Set Constraints, Pattern Match Analysis, and SMT. In Trends in Functional Programming-20th International Symposium, TFP 2019, Vancouver, BC, Canada, June 12-14, 2019, Revised Selected Papers (Lecture Notes in Computer Science), William J. Bowman and Ronald Garcia (Eds.), Vol. 12053. Springer, 121-141. https://doi.org/10.1007/978-3-030-47147-7_6 Google ScholarGoogle ScholarCross RefCross Ref
  16. Manuel Fähndrich and Alexander Aiken. 1996. Making Set-Constraint Based Program Analyses Scale. In First Workshop on Set Constraints at CP' 96.Google ScholarGoogle Scholar
  17. Manuel Fähndrich, Jefrey S. Foster, Zhendong Su, and Alexander Aiken. 1998. Partial online cycle elimination in inclusion constraint graphs. In Proceedings of the ACM SIGPLAN 1998 conference on Programming language design and implementation. Association for Computing Machinery, 85-96. https://doi.org/10.1145/277650.277667 Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Cormac Flanagan and Matthias Felleisen. 1999. Componential set-based analysis. ACM Trans. Program. Lang. Syst. 21, 2 ( 1999 ), 370-416. https://doi.org/10.1145/316686.316703 Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Tim Freeman and Frank Pfenning. 1991. Refinement types for ML. In Proceedings of the ACM SIGPLAN 1991 conference on Programming language design and implementation. Association for Computing Machinery, 268-277. https://doi.org/10. 1145/113445.113468 Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Jacques Garrigue. 2002. Simple Type Inference for Structural Polymorphism. In International Workshop on Foundations of Object-Oriented Languages (FOOL).Google ScholarGoogle Scholar
  21. Sebastian Graf, Simon Peyton Jones, and Ryan G. Scott. 2020. Lower your guards: a compositional pattern-match coverage checker. Proc. ACM Program. Lang. 4, ICFP ( 2020 ), 107 : 1-107 : 30. https://doi.org/10.1145/3408989 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Jörgen Gustavsson and Josef Svenningsson. 2001. Constraint Abstractions. In Symposium on Programs as Data Objects, Olivier Danvy and Andrzej Filinski (Eds.). Springer Berlin Heidelberg, 63-83.Google ScholarGoogle Scholar
  23. John Harrison. 2009. Handbook of Practical Logic and Automated Reasoning. Cambridge University Press.Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Nevin Heintze. 1994. Set-based analysis of ML programs. In Proceedings of the 1994 ACM conference on LISP and functional programming. Association for Computing Machinery, 306-317. https://doi.org/10.1145/182409.182495 Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Nevin Heintze, Spiro Michaylov, and Peter Stuckey. 1992. CLP(R) and some electrical engineering problems. Journal of Automated Reasoning 9, 2 ( 1992 ), 231-260.Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Nevin Charles Heintze. 1992. Set based program analysis. Thesis.Google ScholarGoogle Scholar
  27. My Hoang and John C. Mitchell. 1995. Lower bounds on type inference with subtypes. In Proceedings of the 22nd ACM SIGPLAN-SIGACT symposium on Principles of programming languages. Association for Computing Machinery, 176-185. https://doi.org/10.1145/199448.199481 Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Naoki Kobayashi. 2013. Model Checking Higher-Order Programs. J. ACM 60, 3 ( 2013 ), Article 20. https://doi.org/10.1145/ 2487241.2487246 Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. N. Kobayashi and C. L. Ong. 2009. A Type System Equivalent to the Modal Mu-Calculus Model Checking of Higher-Order Recursion Schemes. In IEEE Symposium on Logic In Computer Science. 179-188. https://doi.org/10.1109/LICS. 2009.29 Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Naoki Kobayashi, Takeshi Tsukada, and Keiichi Watanabe. 2018. Higher-Order Program Verification via HFL Model Checking. In European Symposium on Programming Languages and Systems, Amal Ahmed (Ed.). Springer International Publishing, 711-738.Google ScholarGoogle ScholarCross RefCross Ref
  31. Dexter Kozen, Jens Palsberg, and Michael I. Schwartzbach. 1995. Eficient recursive subtyping. Mathematical Structures in Computer Science 5, 1 ( 1995 ), 113-125. https://doi.org/10.1017/S0960129500000657 Google ScholarGoogle ScholarCross RefCross Ref
  32. Luc Maranget. 2007. Warnings for pattern matching. J. Funct. Program. 17, 3 ( 2007 ), 387-421. https://doi.org/10.1017/ S0956796807006223 Google ScholarGoogle ScholarCross RefCross Ref
  33. Neil Mitchell and Colin Runciman. 2008. Not all patterns, but enough: an automatic verifier for partial but suficient pattern matching. In Proceedings of the first ACM SIGPLAN symposium on Haskell. Association for Computing Machinery, 49-60. https://doi.org/10.1145/1411286.1411293 Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Phuc C. Nguyen, Sam Tobin-Hochstadt, and David Van Horn. 2014. Soft contract verification. In Proceedings of the 19th ACM SIGPLAN international conference on Functional programming, Gothenburg, Sweden, September 1-3, 2014, Johan Jeuring and Manuel M. T. Chakravarty (Eds.). ACM, 139-152. https://doi.org/10.1145/2628136.2628156 Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Martin Odersky, Martin Sulzmann, and Martin Wehr. 1999. Type Inference with Constrained Types. TAPOS 5, 1 ( 1999 ), 35-55.Google ScholarGoogle Scholar
  36. C.-H. Luke Ong and Steven J. Ramsay. 2011. Verifying higher-order functional programs with pattern-matching algebraic data types. In Proceedings of the 38th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages. Association for Computing Machinery, 587-598. https://doi.org/10.1145/1926385.1926453 Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. C. L. Ong. 2006. On Model-Checking Trees Generated by Higher-Order Recursion Schemes. In IEEE Symposium on Logic in Computer Science. 81-90. https://doi.org/10.1109/LICS. 2006.38 Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Matthew Pickering, Gergo Érdi, Simon Peyton Jones, and Richard A. Eisenberg. 2016. Pattern synonyms. In Proceedings of the 9th International Symposium on Haskell, Haskell 2016, Nara, Japan, September 22-23, 2016, Geofrey Mainland (Ed.). ACM, 80-91. https://doi.org/10.1145/2976002.2976013 Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. François Pottier. 1998. Type inference in the presence of subtyping: from theory to practice. Thesis.Google ScholarGoogle Scholar
  40. François Pottier. 2000. A Versatile Constraint-Based Type Inference System. Nordic J. of Computing 7, 4 (Dec. 2000 ), 312-347.Google ScholarGoogle Scholar
  41. François Pottier. 2001. Simplifying Subtyping Constraints: A Theory. Information and Computation 170, 2 ( 2001 ), 153-183. https://doi.org/10.1006/inco. 2001.2963 Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Jakob Rehof. 1997. Minimal typings in atomic subtyping. In Proceedings of the 24th ACM SIGPLAN-SIGACT symposium on Principles of programming languages. Association for Computing Machinery, 278-291. https://doi.org/10.1145/263699. 263738 Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Jakob Rehof and Torben Æ. Mogensen. 1999. Tractable constraints in finite semilattices. Science of Computer Programming 35, 2 ( 1999 ), 191-221.Google ScholarGoogle Scholar
  44. Patrick M. Rondon, Ming Kawaguci, and Ranjit Jhala. 2008. Liquid types. In Proceedings of the 29th ACM SIGPLAN Conference on Programming Language Design and Implementation. Association for Computing Machinery, 159-169. https://doi.org/10.1145/1375581.1375602 Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Zhendong Su, Manuel Fähndrich, and Alexander Aiken. 2000. Projection merging: reducing redundancies in inclusion constraint graphs. In Proceedings of the 27th ACM SIGPLAN-SIGACT symposium on Principles of programming languages. Association for Computing Machinery, 81-95. https://doi.org/10.1145/325694.325706 Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Martin Sulzmann, Manuel M. T. Chakravarty, Simon Peyton Jones, and Kevin Donnelly. 2007. System F with Type Equality Coercions. In Proceedings of the 2007 ACM SIGPLAN International Workshop on Types in Languages Design and Implementation (TLDI '07). Association for Computing Machinery, New York, NY, USA, 53-66. https://doi.org/10.1145/ 1190315.1190324 Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. Tachio Terauchi. 2010. Dependent types from counterexamples. In Proceedings of the 37th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages. Association for Computing Machinery, 119-130. https://doi.org/10. 1145/1706299.1706315 Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. Valery Trifonov and Scott Smith. 1996. Subtyping constrained types. In Static Analysis Symposium, Radhia Cousot and David A. Schmidt (Eds.). Springer Berlin Heidelberg, 349-365.Google ScholarGoogle ScholarCross RefCross Ref
  49. Hiroshi Unno and Naoki Kobayashi. 2009. Dependent type inference with interpolants. In Proceedings of the 11th ACM SIGPLAN conference on Principles and practice of declarative programming. Association for Computing Machinery, 277-288. https://doi.org/10.1145/1599410.1599445 Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. Niki Vazou, Alexander Bakst, and Ranjit Jhala. 2015. Bounded refinement types. In Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming. Association for Computing Machinery, 48-61. https://doi.org/10. 1145/2784731.2784745 Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. Niki Vazou, Eric L. Seidel, Ranjit Jhala, Dimitrios Vytiniotis, and Simon Peyton-Jones. 2014. Refinement types for Haskell. In Proceedings of the 19th ACM SIGPLAN international conference on Functional programming. Association for Computing Machinery, 269-282. https://doi.org/10.1145/2628136.2628161 Google ScholarGoogle ScholarDigital LibraryDigital Library
  52. Mahesh Viswanathan and Ramesh Viswanathan. 2004. A Higher Order Modal Fixed Point Logic. In CONCUR 2004-Concurrency Theory, Philippa Gardner and Nobuko Yoshida (Eds.). Springer Berlin Heidelberg, 512-528.Google ScholarGoogle ScholarCross RefCross Ref
  53. Dimitrios Vytiniotis, Simon L. Peyton Jones, Koen Claessen, and Dan Rosén. 2013. HALO: haskell to logic through denotational semantics. In The 40th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL '13, Rome, Italy-January 23-25, 2013, Roberto Giacobazzi and Radhia Cousot (Eds.). ACM, 431-442. https: //doi.org/10.1145/2429069.2429121 Google ScholarGoogle ScholarDigital LibraryDigital Library
  54. Hongwei Xi and Frank Pfenning. 1999. Dependent types in practical programming. In Proceedings of the 26th ACM SIGPLAN-SIGACT symposium on Principles of programming languages. Association for Computing Machinery, 214-227. https://doi.org/10.1145/292540.292560 Google ScholarGoogle ScholarDigital LibraryDigital Library
  55. Dana N. Xu, Simon L. Peyton Jones, and Koen Claessen. 2009. Static contract checking for Haskell. In Proceedings of the 36th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2009, Savannah, GA, USA, January 21-23, 2009, Zhong Shao and Benjamin C. Pierce (Eds.). ACM, 41-52. https://doi.org/10.1145/1480881.1480889 Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Intensional datatype refinement: with application to scalable verification of pattern-match safety

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        Full Access

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!