Taming the Wildcards: Combining Definition- and Use-Site Variance

被引:0
作者
Altidor, John [1 ]
Huang, Shan Shan [2 ]
Smaragdakis, Yannis [1 ,3 ]
机构
[1] Univ Massachusetts, Dept Comp Sci, Amherst, MA 01003 USA
[2] LogicBlox Inc, Atlanta, GA 30309 USA
[3] Univ Athens, Dept Informat, Athens 15784, Greece
基金
美国国家科学基金会;
关键词
Design; Languages; variance; definition-site variance; use-site variance; wildcards; language extensions;
D O I
10.1145/1993316.1993569
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
Variance allows the safe integration of parametric and subtype polymorphism. Two flavors of variance, definition-site versus use-site variance, have been studied and have had their merits hotly debated. Definition-site variance (as in Scala and C#) offers simple type-instantiation rules, but causes fractured definitions of naturally invariant classes; Use-site variance (as in Java) offers simplicity in class definitions, yet complex type-instantiation rules that elude most programmers. We present a unifying framework for reasoning about variance. Our framework is quite simple and entirely denotational, that is, it evokes directly the definition of variance with a small core calculus that does not depend on specific type systems. This general framework can have multiple applications to combine the best of both worlds: for instance, it can be used to add use-site variance annotations to the Scala type system. We show one such application in detail: we extend the Java type system with a mechanism that modularly infers the definition-site variance of type parameters, while allowing use-site variance annotations on any type-instantiation. Applying our technique to six Java generic libraries (including the Java core library) shows that 20-58% (depending on the library) of generic definitions are inferred to have single-variance; 8-63% of method signatures can be relaxed through this inference, and up to 91% of existing wildcard annotations are unnecessary and can be elided.
引用
收藏
页码:602 / 613
页数:12
相关论文
共 22 条
  • [1] *AP SOFTW FDN, AP COMM COLL LIB VER
  • [2] Bloch J., CLOSURES CONTROVERSY
  • [3] Boumillion K., GUAVA GOOGLE CORE LI
  • [4] COOK WR, 1989, ECOOP 89
  • [5] DAUTELLE JM, JSR275 MEAS UNITS
  • [6] DAY M, 1995, OOPSLA 95, P95
  • [7] Emir B., 2006, ECOOP 06
  • [8] Ernst E., 2008, ECOOP 08
  • [9] Friedman E., GNU TROVE HIGH PERFO
  • [10] Griswold D., 1993, OOPSLA 93