skip to main content

Knowing when to ask: sound scheduling of name resolution in type checkers derived from declarative specifications

Published:13 November 2020Publication History
Skip Abstract Section

Abstract

There is a large gap between the specification of type systems and the implementation of their type checkers, which impedes reasoning about the soundness of the type checker with respect to the specification. A vision to close this gap is to automatically obtain type checkers from declarative programming language specifications. This moves the burden of proving correctness from a case-by-case basis for concrete languages to a single correctness proof for the specification language. This vision is obstructed by an aspect common to all programming languages: name resolution. Naming and scoping are pervasive and complex aspects of the static semantics of programming languages. Implementations of type checkers for languages with name binding features such as modules, imports, classes, and inheritance interleave collection of binding information (i.e., declarations, scoping structure, and imports) and querying that information. This requires scheduling those two aspects in such a way that query answers are stable—i.e., they are computed only after all relevant binding structure has been collected. Type checkers for concrete languages accomplish stability using language-specific knowledge about the type system.

In this paper we give a language-independent characterization of necessary and sufficient conditions to guarantee stability of name and type queries during type checking in terms of critical edges in an incomplete scope graph. We use critical edges to give a formal small-step operational semantics to a declarative specification language for type systems, that achieves soundness by delaying queries that may depend on missing information. This yields type checkers for the specified languages that are sound by construction—i.e., they schedule queries so that the answers are stable, and only accept programs that are name- and type-correct according to the declarative language specification. We implement this approach, and evaluate it against specifications of a small module and record language, as well as subsets of Java and Scala.

Skip Supplemental Material Section

Supplemental Material

Auxiliary Presentation Video

Automatically deriving type checkers from declarative programming language specifications is an approach to close the gap between specifications and implementations of type systems. Importantly, this moves the question of implementation correctness from each individual concrete language to the specification language. Achieving this is complicated by name resolution: features such as mutually recursive modules and type dependent names require the implementation to schedule aggregation and querying of binding information to ensure stable query answers. We present critical edges as a characterization of the conditions to guarantee stability of name binding queries in an incomplete scope graph. We use critical edges to give a small-step operational semantics to a declarative specification language for type systems, that achieves soundness by delaying queries that may depend on missing information, allowing us to derive type checkers from specifications that are sound by construction.

References

  1. Henk Alblas. 1991. Attribute Evaluation Methods. In Attribute Grammars, Applications and Systems (LNCS, Vol. 545 ). Springer, 48-113. https://doi.org/10.1007/3-540-54572-7_3 Google ScholarGoogle ScholarCross RefCross Ref
  2. Richard S. Bird. 1984. Using Circular Programs to Eliminate Multiple Traversals of Data. Acta Informatica 21 ( 1984 ), 239-250. https://doi.org/10.1007/BF00264249 Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. John T Boyland. 1996. Descriptional composition of compiler components. Technical Report. University of California.Google ScholarGoogle Scholar
  4. John Tang Boyland. 2005. Remote attribute grammars. Journal of the ACM 52, 4 ( 2005 ), 627-687. https://doi.org/10.1145/ 1082036.1082042 Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Janusz A. Brzozowski. 1964. Derivatives of Regular Expressions. Journal of the ACM 11, 4 ( 1964 ), 481-494. https: //doi.org/10.1145/321239.321249 Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Torbjörn Ekman and Görel Hedin. 2005. Modular Name Analysis for Java Using JastAdd. In Generative and Transformational Techniques in Software Engineering (LNCS, Vol. 4143 ). Springer, 422-436. https://doi.org/10.1007/11877028_18 Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Torbjörn Ekman and Görel Hedin. 2007a. The JastAdd extensible Java compiler. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA). ACM, 1-18. https: //doi.org/10.1145/1297027.1297029 Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Torbjörn Ekman and Görel Hedin. 2007b. The JastAdd system-modular extensible compiler construction. Science of Computer Programming 69, 1-3 ( 2007 ), 14-26. https://doi.org/10.1016/j.scico. 2007. 02.003 Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Thom W. Frühwirth. 1998. Theory and Practice of Constraint Handling Rules. The Journal of Logic Programming 37, 1-3 ( 1998 ), 95-138. https://doi.org/10.1016/S0743-1066 ( 98 ) 10005-5 Google ScholarGoogle ScholarCross RefCross Ref
  10. Görel Hedin. 2000. Reference Attributed Grammars. Informatica (Slovenia) 24, 3 ( 2000 ).Google ScholarGoogle Scholar
  11. Thomas Johnsson. 1987. Attribute grammars as a functional programming paradigm. In Functional Programming Languages and Computer Architecture (LNCS, Vol. 274 ). Springer, 154-173. https://doi.org/10.1007/3-540-18317-5_10 Google ScholarGoogle ScholarCross RefCross Ref
  12. Eva Magnusson, Torbjörn Ekman, and Görel Hedin. 2009. Demand-driven evaluation of collection attributes. Automated Software Engineering 16, 2 ( 2009 ), 291-322. https://doi.org/10.1007/s10515-009-0046-z Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Eva Magnusson and Görel Hedin. 2003. Circular Reference Attributed Grammars-Their Evaluation and Applications. ENTCS 82, 3 ( 2003 ), 532-554. https://doi.org/10.1016/S1571-0661 ( 05 ) 82627-1 Google ScholarGoogle ScholarCross RefCross Ref
  14. Robin Milner, Mads Tofte, Robert Harper, and David MacQueen. 1997. The Definition of Standard ML, Revised. The MIT Press.Google ScholarGoogle Scholar
  15. Chris Moss. 1986. Cut and Paste-defining the impure Primitives of Prolog. In International Conference on Logic Programming (ICLP (LNCS, Vol. 225 ). Springer, 686-694. https://doi.org/10.1007/3-540-16492-8_118 Google ScholarGoogle ScholarCross RefCross Ref
  16. Pierre Neron, Andrew P. Tolmach, Eelco Visser, and Guido Wachsmuth. 2015. A Theory of Name Resolution. In European Symposium on Programming (LNCS, Vol. 9032 ). Springer, 205-231. https://doi.org/10.1007/978-3-662-46669-8_9 Google ScholarGoogle ScholarCross RefCross Ref
  17. Martin Odersky, Martin Sulzmann, and Martin Wehr. 1999. Type Inference with Constrained Types. Theory and Practice of Object Systems (TAPOS) 5, 1 ( 1999 ), 35-55. https://doi.org/10.1002/(SICI) 1096-9942 ( 199901 /03)5: 1 < 35 : :AID-TAPO4>3.0. CO; 2-4 Google ScholarGoogle ScholarCross RefCross Ref
  18. Peter W. O'Hearn, John C. Reynolds, and Hongseok Yang. 2001. Local Reasoning about Programs that Alter Data Structures. In Computer Science Logic ( CSL) (LNCS, Vol. 2142 ). Springer, 1-19. https://doi.org/10.1007/3-540-44802-0_1 Google ScholarGoogle ScholarCross RefCross Ref
  19. Daniël A. A. Pelsmaeker, Hendrik van Antwerpen, and Eelco Visser. 2019. Towards Language-Parametric Semantic Editor Services Based on Declarative Type System Specifications (Brave New Idea Paper). In European Conference on Object-Oriented Programming (ECOOP) (LIPIcs, Vol. 134 ). Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik. https: //doi.org/10.4230/LIPIcs.ECOOP. 2019.26 Google ScholarGoogle ScholarCross RefCross Ref
  20. François Pottier and Diddier Rémy. 2005. The Essence of ML Type Inference. In Advanced Topics in Types and Programming Languages. The MIT Press, 389-489.Google ScholarGoogle Scholar
  21. Arjen Rouvoet, Hendrik van Antwerpen, Casper Bach Poulsen, Robbert Krebbers, and Eelco Visser. 2020a. Haskell Implementation of Ministatix, and Scala, Java, and LMR Case Studies. https://doi.org/10.5281/zenodo.4068064 Google ScholarGoogle ScholarCross RefCross Ref
  22. Arjen Rouvoet, Hendrik van Antwerpen, Casper Bach Poulsen, Robbert Krebbers, and Eelco Visser. 2020b. Knowing When to Ask: Extended Version. ( 2020 ). https://doi.org/10.5281/zenodo.4091445 Google ScholarGoogle ScholarCross RefCross Ref
  23. Akira Sasaki and Masataka Sassa. 2003. Circular Attribute Grammars with Remote Attribute References and their Evaluators. New Generation Computing 22, 1 ( 2003 ), 37-60. https://doi.org/10.1007/BF03037280 Google ScholarGoogle ScholarCross RefCross Ref
  24. Hendrik van Antwerpen, Pierre Néron, Andrew P. Tolmach, Eelco Visser, and Guido Wachsmuth. 2016. A constraint language for static semantic analysis based on scope graphs. In Proceedings of the ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation (PEPM). ACM, 49-60. https://doi.org/10.1145/2847538.2847543 Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Hendrik van Antwerpen, Casper Bach Poulsen, Arjen Rouvoet, and Eelco Visser. 2018. Scopes as types. Proceedings of the ACM on Programming Languages 2, Object-oriented Programming, Systems, Languages, and Applications (OOPSLA) ( 2018 ), 114 : 1-114 : 30. https://doi.org/10.1145/3276484 Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Eric Van Wyk, Derek Bodin, Jimin Gao, and Lijesh Krishnan. 2010. Silver: An extensible attribute grammar system. Science of Computer Programming 75, 1-2 ( 2010 ), 39-54. https://doi.org/10.1016/j.scico. 2009. 07.004 Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Knowing when to ask: sound scheduling of name resolution in type checkers derived from declarative specifications

      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!