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

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.

[1]  Eelco Visser,et al.  A Theory of Name Resolution , 2015, ESOP.

[2]  Henk Alblas,et al.  Attribute Evaluation Methods , 1991, Attribute Grammars, Applications and Systems.

[3]  Guido Wachsmuth,et al.  A constraint language for static semantic analysis based on scope graphs , 2015, PEPM.

[4]  Görel Hedin,et al.  Circular reference attributed grammars - their evaluation and applications , 2003, Sci. Comput. Program..

[5]  Janusz A. Brzozowski,et al.  Derivatives of Regular Expressions , 1964, JACM.

[6]  Torbjörn Ekman,et al.  The jastadd extensible java compiler , 2007, OOPSLA.

[7]  Görel Hedin,et al.  Reference Attributed Grammars , 2000, Informatica.

[8]  Richard S. Bird Using circular programs to eliminate multiple traversals of data , 2004, Acta Informatica.

[9]  Torbjörn Ekman,et al.  Demand-driven evaluation of collection attributes , 2009, Automated Software Engineering.

[10]  Eelco Visser,et al.  Scopes as types , 2018, Proc. ACM Program. Lang..

[11]  Akira Sasaki,et al.  Circular attribute grammars with remote attribute references and their evaluators , 2009, New Generation Computing.

[12]  Torbjörn Ekman,et al.  The JastAdd system - modular extensible compiler construction , 2007, Sci. Comput. Program..

[13]  Eelco Visser,et al.  Towards Language-Parametric Semantic Editor Services Based on Declarative Type System Specifications (Brave New Idea Paper) , 2019, ECOOP.

[14]  John Tang Boyland,et al.  Remote attribute grammars , 2005, JACM.

[15]  Eric Van Wyk,et al.  Silver: An extensible attribute grammar system , 2008, Sci. Comput. Program..

[16]  Thomas Johnsson,et al.  Attribute grammars as a functional programming paradigm , 1987, FPCA.

[17]  Peter Beike,et al.  The Definition Of Standard Ml Revised , 2016 .

[18]  Peter W. O'Hearn,et al.  Local Reasoning about Programs that Alter Data Structures , 2001, CSL.

[19]  Torbjörn Ekman,et al.  Modular Name Analysis for Java Using JastAdd , 2005, GTTSE.

[20]  John Boyland,et al.  Descriptional Composition of Compiler Components , 1996 .

[21]  Martin Odersky,et al.  Type Inference with Constrained Types , 1999, Theory Pract. Object Syst..

[22]  Thom W. Frühwirth,et al.  Theory and Practice of Constraint Handling Rules , 1998, J. Log. Program..

[23]  Chris Moss,et al.  Cut and Paste - defining the impure Primitives of Prolog , 1986, ICLP.