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.
Supplemental Material
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- John T Boyland. 1996. Descriptional composition of compiler components. Technical Report. University of California.Google Scholar
- John Tang Boyland. 2005. Remote attribute grammars. Journal of the ACM 52, 4 ( 2005 ), 627-687. https://doi.org/10.1145/ 1082036.1082042 Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- Görel Hedin. 2000. Reference Attributed Grammars. Informatica (Slovenia) 24, 3 ( 2000 ).Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- Robin Milner, Mads Tofte, Robert Harper, and David MacQueen. 1997. The Definition of Standard ML, Revised. The MIT Press.Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
Index Terms
Knowing when to ask: sound scheduling of name resolution in type checkers derived from declarative specifications
Recommendations
Scopes as types
Scope graphs are a promising generic framework to model the binding structures of programming languages, bridging formalization and implementation, supporting the definition of type checkers and the automation of type safety proofs. However, previous ...
Incremental type-checking for free: using scope graphs to derive incremental type-checkers
Fast analysis response times in IDEs are essential for a good editor experience. Incremental type-checking can provide that in a scalable fashion. However, existing techniques are not reusable between languages. Moreover, mutual and dynamic ...
Type inference, principal typings, and let-polymorphism for first-class mixin modules
Proceedings of the tenth ACM SIGPLAN international conference on Functional programmingA mixin module is a programming abstraction that simultaneously generalizes λ-abstractions, records, and mutually recursive definitions. Although various mixin module type systems have been developed, no one has investigated principal typings or ...






Comments