Extending Type Inference to Variational Programs

Through the use of conditional compilation and related tools, many software projects can be used to generate a huge number of related programs. The problem of typing such variational software is difficult. The brute-force strategy of generating all variants and typing each one individually is: (1) usually infeasible for efficiency reasons and (2) produces results that do not map well to the underlying variational program. Recent research has focused mainly on efficiency and addressed only the problem of type checking. In this work we tackle the more general problem of variational type inference and introduce variational types to represent the result of typing a variational program. We introduce the variational lambda calculus (VLC) as a formal foundation for research on typing variational programs. We define a type system for VLC in which VLC expressions are mapped to correspondingly variational types. We show that the type system is correct by proving that the typing of expressions is preserved over the process of variation elimination, which eventually results in a plain lambda calculus expression and its corresponding type. We identify a set of equivalence rules for variational types and prove that the type unification problem modulo these equivalence rules is unitary and decidable; we also present a sound and complete unification algorithm. Based on the unification algorithm, the variational type inference algorithm is an extension of algorithm W. We show that it is sound and complete and computes principal types. We also consider the extension of VLC with sum types, a necessary feature for supporting variational data types, and demonstrate that the previous theoretical results also hold under this extension. Finally, we characterize the complexity of variational type inference and demonstrate the efficiency gains over the brute-force strategy.

[1]  William R. Cook,et al.  Product lines of theorems , 2011, OOPSLA '11.

[2]  Walid Taha,et al.  MetaML and multi-stage programming with explicit annotations , 2000, Theor. Comput. Sci..

[3]  Mira Mezini,et al.  Variability management with feature-oriented programming and aspects , 2004, SIGSOFT '04/FSE-12.

[4]  Robert Grimm,et al.  SuperC: parsing all of C by taming the preprocessor , 2012, PLDI.

[5]  Greg Nelson,et al.  Fast Decision Procedures Based on Congruence Closure , 1980, JACM.

[6]  Andrew Lumsdaine,et al.  Static computation and reflection , 2008 .

[7]  Lerina Aversano,et al.  Handling preprocessor-conditioned declarations , 2002, Proceedings. Second IEEE International Workshop on Source Code Analysis and Manipulation.

[8]  Mariangiola Dezani-Ciancaglini,et al.  The "Relevance" of Intersection and Union Types , 1997, Notre Dame J. Formal Log..

[9]  Walid Taha,et al.  A Semantic Analysis of C++ Templates , 2006, ECOOP.

[10]  Bjarne Stroustrup,et al.  Concepts: linguistic support for generic programming in C++ , 2006, OOPSLA '06.

[11]  Matthias Blume,et al.  Building a Family of Compilers , 2008, 2008 12th International Software Product Line Conference.

[12]  Jeremy G. Siek,et al.  Incremental type-checking for type-reflective metaprograms , 2010, GPCE '10.

[13]  Don Batory,et al.  Scaling step-wise refinement , 2003, 25th International Conference on Software Engineering, 2003. Proceedings..

[14]  Bjarne Stroustrup,et al.  A Formalism for C , 2005 .

[15]  Paliath Narendran,et al.  Unification Theory , 2001, Handbook of Automated Reasoning.

[16]  Pierre-Yves Schobbens,et al.  Symbolic model checking of software product lines , 2011, 2011 33rd International Conference on Software Engineering (ICSE).

[17]  Benjamin C. Pierce,et al.  Types and programming languages: the next generation , 2003, 18th Annual IEEE Symposium of Logic in Computer Science, 2003. Proceedings..

[18]  Sebastian Erdweg,et al.  Variability-aware parsing in the presence of lexical macros and conditional compilation , 2011, OOPSLA '11.

[19]  Stephen R. Davis,et al.  The C++ Preprocessor , 2011 .

[20]  James R. Larus,et al.  Reflective program generation with patterns , 2006, GPCE '06.

[21]  Sven Apel,et al.  Virtual Separation of Concerns - A Second Chance for Preprocessors , 2009, J. Object Technol..

[22]  Shan Shan Huang,et al.  cJ: enhancing java with safe type conditions , 2007, AOSD.

[23]  Sebastian Erdweg,et al.  A variability-aware module system , 2012, OOPSLA '12.

[24]  Jaakko Järvi,et al.  Algorithm specialization in generic programming: challenges of constrained generics in C++ , 2006, PLDI '06.

[25]  Todd D. Millstein,et al.  Statically scoped object adaptation with expanders , 2006, OOPSLA '06.

[26]  Peter A. Darnell,et al.  The C Preprocessor , 1991 .

[27]  Bjarne Stroustrup,et al.  Specifying C++ concepts , 2006, POPL '06.

[28]  Martin Erwig,et al.  The Choice Calculus: A Representation for Software Variation , 2011, TSEM.

[29]  William R. Cook,et al.  Safe composition of product lines , 2007, GPCE '07.

[30]  Jia Liu,et al.  Refinements and multi-dimensional separation of concerns , 2003, ESEC/FSE-11.

[31]  Sven Apel,et al.  Type safety for feature-oriented product lines , 2010, Automated Software Engineering.

[32]  Shan Shan Huang,et al.  Expressive and safe static reflection with MorphJ , 2008, PLDI '08.

[33]  Marvin V. Zelkowitz,et al.  Programming Languages: Design and Implementation , 1975 .

[34]  Sven Apel,et al.  Granularity in software product lines , 2008, 2008 ACM/IEEE 30th International Conference on Software Engineering.

[35]  Simon L. Peyton Jones,et al.  Imperative functional programming , 1993, POPL '93.

[36]  Shmuel Katz,et al.  MAVEN: modular aspect verification and interference analysis , 2010, Formal Methods Syst. Des..

[37]  Gunter Saake,et al.  Type checking annotation-based product lines , 2012, TSEM.

[38]  U. Norell,et al.  Towards a practical programming language based on dependent type theory , 2007 .

[39]  Peyton Jones,et al.  Haskell 98 language and libraries : the revised report , 2003 .

[40]  Christian Prehofer,et al.  Feature-Oriented Programming: A Fresh Look at Objects , 1997, ECOOP.

[41]  Eugene Miya,et al.  On "Software engineering" , 1985, SOEN.

[42]  Frank Pfenning,et al.  Dependent types in practical programming , 1999, POPL '99.

[43]  Shan Shan Huang,et al.  Morphing: Structurally shaping a class by reflecting on others , 2011, TOPL.

[44]  Bjarne Stroustrup,et al.  The Design and Evolution of C , 1994 .

[45]  Tzilla Elrad,et al.  Aspect-oriented programming: Introduction , 2001, CACM.

[46]  Claus Brabrand,et al.  Intraprocedural dataflow analysis for software product lines , 2012, AOSD.

[47]  Bjarne Steensgaard,et al.  Points-to analysis in almost linear time , 1996, POPL '96.

[48]  Mira Mezini,et al.  Conquering aspects with Caesar , 2003, AOSD '03.

[49]  Andrew Lumsdaine,et al.  Toward foundations for type-reflective metaprogramming , 2009, GPCE '09.

[50]  Pierre-Yves Schobbens,et al.  Model checking lots of systems: efficient verification of temporal properties in software product lines , 2010, 2010 ACM/IEEE 32nd International Conference on Software Engineering.

[51]  Michaël Rusinowitch,et al.  Unification Modulo ACUI Plus Distributivity Axioms , 2004, Journal of Automated Reasoning.

[52]  Manuvir Das,et al.  Unification-based pointer analysis with directional assignments , 2000, PLDI '00.

[53]  William R. Cook,et al.  Mixin-based inheritance , 1990, OOPSLA/ECOOP '90.

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

[55]  Simon L. Peyton Jones,et al.  Dynamic typing as staged type inference , 1998, POPL '98.

[56]  Sven Apel,et al.  Feature featherweight java: a calculus for feature-oriented programming and stepwise refinement , 2008, GPCE '08.

[57]  Sven Apel,et al.  Strategies for product-line verification: Case studies and experiments , 2013, 2013 35th International Conference on Software Engineering (ICSE).

[58]  Shmuel Katz,et al.  A closer look at aspect interference and cooperation , 2012, AOSD '12.

[59]  Christine Paulin-Mohring,et al.  Inductive Definitions in the system Coq - Rules and Properties , 1993, TLCA.

[60]  Kerstin Mueller,et al.  Software Product Line Engineering Foundations Principles And Techniques , 2016 .

[61]  Ute Dreher Generic Programming And The Stl Using And Extending The C Standard Template Library , 2016 .

[62]  Pierre-Yves Schobbens,et al.  Simulation-based abstractions for software product-line model checking , 2012, 2012 34th International Conference on Software Engineering (ICSE).

[63]  J. A. Robinson,et al.  A Machine-Oriented Logic Based on the Resolution Principle , 1965, JACM.

[64]  William R. Cook,et al.  Fitting the pieces together: a machine-checked model of safe composition , 2009, ESEC/FSE '09.

[65]  Martin Erwig,et al.  An error-tolerant type system for variational lambda calculus , 2012, ICFP.

[66]  Patricia Johann,et al.  Foundations for structured programming with GADTs , 2008, POPL '08.

[67]  Koji Kagawa,et al.  Polymorphic variants in Haskell , 2006, Haskell '06.

[68]  Thomas Leich,et al.  TypeChef: toward type checking #ifdef variability in C , 2010, FOSD '10.

[69]  Christian Lengauer,et al.  Large-Scale Variability-Aware Type Checking and Dataflow Analysis , 2012 .

[70]  Martin Erwig,et al.  Counter-factual typing for debugging type errors , 2014, POPL.

[71]  Tobias Nipkow,et al.  Term rewriting and all that , 1998 .

[72]  Robert E. Tarjan,et al.  Variations on the Common Subexpression Problem , 1980, J. ACM.

[73]  Don S. Batory,et al.  On the modularity of feature interactions , 2008, GPCE '08.

[74]  Kyo Chul Kang,et al.  Feature-Oriented Domain Analysis (FODA) Feasibility Study , 1990 .

[75]  David Abrahams,et al.  C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond (C++ In-Depth Series) , 2004 .

[76]  Gilles Dowek,et al.  Principles of programming languages , 1981, Prentice Hall International Series in Computer Science.

[77]  Krzysztof Czarnecki,et al.  Generative programming - methods, tools and applications , 2000 .

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

[79]  Sven Apel,et al.  An Overview of Feature-Oriented Software Development , 2009, J. Object Technol..

[80]  Martin Sulzmann A General Type Inference Framework for Hindley/Milner Style Systems , 2001, FLOPS.

[81]  Gul A. Agha,et al.  Concurrent object-oriented programming , 1993, CACM.

[82]  Shan Shan Huang,et al.  Statically safe program generation with safegen , 2005, GPCE'05.

[83]  Simon L. Peyton Jones,et al.  Template meta-programming for Haskell , 2002, Haskell '02.

[84]  Roberto Di Cosmo,et al.  Extensional normalisation and type-directed partial evaluation for typed lambda calculus with sums , 2004, POPL.

[85]  William R. Cook,et al.  A machine-checked model of safe composition , 2009, FOAL '09.

[86]  Klaus Pohl,et al.  Software Product Line Engineering , 2005 .

[87]  Sven Apel,et al.  A calculus for uniform feature composition , 2010, TOPL.

[88]  Walid Taha,et al.  Concoqtion: indexed types now! , 2007, PEPM '07.

[89]  Peter J. Stuckey,et al.  Under Consideration for Publication in J. Functional Programming Hm(x) Type Inference Is Clp(x) Solving , 2022 .

[90]  Franz Baader,et al.  Unification theory , 1986, Decis. Support Syst..