Scope States: Guarding Safety of Name Resolution in Parallel Type Checkers

Compilers that can type check compilation units in parallel can make more efficient use of multi-core architectures, which are nowadays widespread. Developing parallel type checker implementations is complicated by the need to handle concurrency and synchronization of parallel compilation units. Dependencies between compilation units are induced by name resolution, and a parallel type checker needs to ensure that units have defined all relevant names before other units do a lookup. Mutually recursive references and implicitly discovered dependencies between compilation units preclude determining a static compilation order for many programming languages. In this paper, we present a new framework for implementing hierarchical type checkers that provides implicit parallel execution in the presence of dynamic and mutual dependencies between compilation units. The resulting type checkers can be written without explicit handling of communication or synchronization between different compilation units. We achieve this by providing type checkers with an API for name resolution based on scope graphs, a language-independent formalism that supports a wide range of binding patterns. We introduce the notion of scope state to ensure safe name resolution. Scope state tracks the completeness of a scope, and is used to decide whether a scope graph query between compilation units must be delayed. Our framework is implemented in Java using the actor paradigm. We evaluated our approach by parallelizing the solver for Statix, a meta-language for type checkers based on scope graphs, using our framework. This parallelizes every Statix-based type checker, provided its specification follows a split declaration-type style. Benchmarks show that the approach results in speedups for the parallel Statix solver of up to 5.0x on 8 cores for real-world code bases. 2012 ACM Subject Classification Software and its engineering → Compilers; Theory of computation → Parallel algorithms

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

[2]  Gul A. Agha,et al.  ACTORS - a model of concurrent computation in distributed systems , 1985, MIT Press series in artificial intelligence.

[3]  Patrik Reali,et al.  Structuring a Compiler with Active Objects , 2000, JMLC.

[4]  Keshav Pingali,et al.  Optimistic parallelism requires abstractions , 2007, PLDI '07.

[5]  Eelco Visser,et al.  Declarative Name Binding and Scope Rules , 2012, SLE.

[6]  Andrew W. Appel,et al.  Smartest recompilation , 1993, POPL '93.

[7]  Eelco Visser,et al.  The spoofax language workbench: rules for declarative specification of languages and IDEs , 2010, OOPSLA.

[8]  Other Contributors Are Indicated Where They Contribute The Free Software Foundation , 2017 .

[9]  Ondrej Lhoták,et al.  Actor-Based Parallel Dataflow Analysis , 2011, CC.

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

[11]  Sebastian Erdweg,et al.  A sound and optimal incremental build system with dynamic dependencies , 2015, OOPSLA 2015.

[12]  Markus Wenzel Shared-Memory Multiprocessing for Interactive Theorem Proving , 2013, ITP.

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

[14]  Markus Wenzel,et al.  Efficient parallel programming in Poly/ML and Isabelle/ML , 2010, DAMP '10.

[15]  David B. Wortman,et al.  Semantic analysis in a concurrent compiler , 1988, PLDI '88.

[16]  Laura M. Haas,et al.  Distributed deadlock detection , 1983, TOCS.

[17]  Ryan Newton,et al.  Parallel type-checking with haskell using saturating LVars and stream generators , 2016, PPOPP.

[18]  Robbert Krebbers,et al.  Knowing when to ask: sound scheduling of name resolution in type checkers derived from declarative specifications , 2020, Proc. ACM Program. Lang..

[19]  Eelco Visser,et al.  Scalable Incremental Building with Dynamic Task Dependencies , 2018, 2018 33rd IEEE/ACM International Conference on Automated Software Engineering (ASE).

[20]  Andrew W. Appel,et al.  Modern Compiler Implementation in Java , 1997 .

[21]  Görel Hedin,et al.  Concurrent circular reference attribute grammars , 2017, SLE.

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

[23]  Michael Eichberg,et al.  A programming model for semi-implicit parallelization of static analyses , 2020, ISSTA.

[24]  Makarius Wenzel Parallel Proof Checking in Isabelle/Isar , 2009 .

[25]  Ryan Newton,et al.  Freeze after writing: quasi-deterministic parallel programming with LVars , 2014, POPL.