A compiler architecture for domain-specific type error diagnosis

Abstract Domain-specific languages (DSLs) permeate current programming practices. An important kind of DSLs includes those developed and integrated within a host language, which we call embedded or internal DSLs. Unfortunately, embedded DSLs usually fall short on domain-specific error diagnosis, that is, they do not give control to DSL authors over how errors are reported to the programmer. As a consequence, implementation details of the DSL leak through in error messages, and programmers need to understand the internals of the DSL implementation to fix their code in a productive way. This paper addresses the challenge of building a compiler with integrated support for domain-specific error diagnosis. We assume that the type system is described using a constraint-based approach, and constraint solving is specified using rewrite rules. Domain information can then be injected at constraint gathering time via type rules, during constraint solving via specialized rules and axioms, and finally at blaming and reparation time via transformations. Furthermore, we define error contexts as a way to control the order in which solving and blaming proceeds. We engineer domain-specific error diagnosis in such a way that the compiler can also reuse the techniques for improving general error diagnosis.

[1]  Jurriaan Hage,et al.  Heuristics for Type Error Discovery and Recovery , 2006, IFL.

[2]  Jurriaan Hage,et al.  Implementation and Application of Functional Languages , 2011, Lecture Notes in Computer Science.

[3]  Jurriaan Hage,et al.  Strategies for Solving Constraints in Type and Effect Systems , 2009, Electron. Notes Theor. Comput. Sci..

[4]  Peter J. Stuckey,et al.  A theory of overloading , 2002, ICFP '02.

[5]  Ralf Lämmel,et al.  Strongly typed heterogeneous collections , 2004, Haskell '04.

[6]  A. Serrano Mena,et al.  Context-Dependent Type Error Diagnosis for Functional Languages , 2016 .

[7]  Bastiaan Heeren,et al.  Top quality type error Messages , 2005 .

[8]  J Hage DOMain Specific Type Error Diagnosis (DOMSTED) , 2014 .

[9]  Bart Demoen,et al.  A Flexible Search Framework for CHR , 2009, Constraint Handling Rules.

[10]  Manu Sridharan,et al.  Tech Report : A Practical Framework for Type Inference Error Explanation , 2016 .

[11]  Paul Hudak,et al.  Building domain-specific embedded languages , 1996, CSUR.

[12]  Bruce J. McAdam On the Unification of Substitutions in Type Interfaces , 1998, IFL.

[13]  Jurriaan Hage,et al.  Type Error Diagnosis for Embedded DSLs by Two-Stage Specialized Type Rules , 2016, ESOP.

[14]  Frank Pfenning,et al.  Higher-order abstract syntax , 1988, PLDI '88.

[15]  Bruce J. McAdam How to Repair Type Errors Automatically , 2001, Scottish Functional Programming Workshop.

[16]  Jurriaan Hage,et al.  Lightweight soundness for towers of language extensions , 2017, PEPM.

[17]  Adam Gundry A typechecker plugin for units of measure: domain-specific constraint solving in GHC Haskell , 2015, Haskell.

[18]  Jurriaan Hage,et al.  Type Class Directives , 2005, PADL.

[19]  Peter J. Stuckey,et al.  A Framework for Extended Algebraic Data Types , 2006, FLOPS.

[20]  Mark P. Jones,et al.  Instance chains: type class programming without overlapping instances , 2010, ICFP '10.

[21]  Simon L. Peyton Jones,et al.  OutsideIn(X) Modular type inference with local assumptions , 2011, J. Funct. Program..

[22]  Peter J. Stuckey,et al.  Type Processing by Constraint Reasoning , 2006, APLAS.

[23]  Simon L. Peyton Jones,et al.  Associated type synonyms , 2005, ICFP '05.

[24]  Sebastian Erdweg,et al.  Sound type-dependent syntactic language extension , 2016, POPL.

[25]  Simon L. Peyton Jones,et al.  Practical type inference for arbitrary-rank types , 2007, Journal of Functional Programming.

[26]  Jurriaan Hage,et al.  Scripting the type inference process , 2003, ICFP '03.

[27]  Zvonimir Pavlinovic,et al.  Practical SMT-based type error localization , 2015, ICFP.

[28]  Simon L. Peyton Jones,et al.  Guarded impredicative polymorphism , 2018, PLDI.

[29]  Eelco Visser,et al.  DSL Engineering - Designing, Implementing and Using Domain-Specific Languages , 2013 .

[30]  Robin Milner,et al.  Principal type-schemes for functional programs , 1982, POPL '82.

[31]  Simon L. Peyton Jones,et al.  Understanding functional dependencies via constraint handling rules , 2007, J. Funct. Program..

[32]  Kwangkeun Yi,et al.  Proofs about a folklore let-polymorphic type inference algorithm , 1998, TOPL.

[33]  Martin Odersky,et al.  Improving Human-Compiler Interaction Through Customizable Type Feedback , 2014 .

[34]  David Raymond Christiansen Reflect on Your Mistakes ! Lightweight Domain-Specific Error Messages , 2014 .

[35]  Daan Leijen,et al.  Helium, for learning Haskell , 2003, Haskell '03.

[36]  A. Serrano Mena,et al.  From Attribute Grammars to Constraint Handling Rules , 2016 .

[37]  Bruce James McAdam On the unification of substitutions in type inference , 1999 .

[38]  Danfeng Zhang,et al.  Toward general diagnosis of static errors , 2014, POPL.