Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
10.1145/1993498.1993569acmconferencesArticle/Chapter ViewAbstractPublication PagespldiConference Proceedingsconference-collections
research-article

Taming the wildcards: combining definition- and use-site variance

Published: 04 June 2011 Publication History

Abstract

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.

References

[1]
J. Altidor, S. S. Huang, and Y. Smaragdakis. Taming the wildcards: Combining definition- and use-site variance (extended version). http://www.cs.umass.edu/ yannis/variance-extended2011.pdf.
[2]
P. America and F. van der Linden. A parallel object-oriented language with inheritance and subtyping. In OOPSLA/ECOOP '90: Proc. of the European Conf. on object-oriented programming on Object-oriented programming systems, languages, and applications, 1990.
[3]
Apache Software Foundation. Apache commons-collections library. http://larvalabs.com/collections/. Version 4.01.
[4]
J. Bloch. The closures controversy. http://www.javac.info/bloch-closures-controversy.ppt. Accessed Nov. 2010.
[5]
K. Boumillion and J. Levy. Guava: Google core libraries for Java 1.5
[6]
. http://code.google.com/p/guava-libraries/. Accessed Nov. 2010.
[7]
G. Bracha and D. Griswold. Strongtalk: typechecking smalltalk in a production environment. In OOPSLA '93: Proc. of the Conf. on Object-oriented programming systems, languages, and applications, 1993.
[8]
N. Cameron, S. Drossopoulou, and E. Ernst. A model for Java with wildcards. In ECOOP '08: Proc. of the 22nd European Conf. on Object-Oriented Programming, 2008.
[9]
R. Cartwright and J. Guy L. Steele. Compatible genericity with run-time types for the Java programming language. In OOPSLA '98: Proc. of the 13th ACM SIGPLAN Conf. on Object-oriented programming, systems, languages, and applications, 1998.
[10]
W. Cook. A proposal for making eiffel type-safe. In ECOOP '89: Proc. of the 3rd European Conf. on Object-Oriented Programming, 1989.
[11]
J.-M. Dautelle et al. Jscience. http://jscience.org/. Accessed Nov. 2010.
[12]
J.-M. Dautelle and W. Keil. Jsr-275: Measures and units. http://www.jcp.org/en/jsr/detail?id=275. Accessed Nov. 2010.
[13]
M. Day, R. Gruber, B. Liskov, and A. C. Myers. Subtypes vs. where clauses: constraining parametric polymorphism. In OOPSLA '95: Proc. of the tenth annual Conf. on Object-oriented programming systems, languages, and applications, 1995.
[14]
B. Emir, A. Kennedy, C. Russo, and D. Yu. Variance and generalized constraints for C\# generics. In ECOOP '06: Proc. of the European Conf. on Object-Oriented Programming, 2006.
[15]
E. Friedman and R. Eden. Gnu Trove: High-performance collections library for Java. http://trove4j.sourceforge.net/. Version 2.1.0.
[16]
A. Hejlsberg, S. Wiltamuth, and P. Golde. C\# Language Specification. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, 2003.
[17]
S. S. Huang, D. Zook, and Y. Smaragdakis. cJ: Enhancing Java with safe type conditions. In Proc. of the 6th Intl. Conf. on Aspect-Oriented Software Development, 2007.
[18]
A. Igarashi and M. Viroli. Variant parametric types: A flexible subtyping scheme for generics. ACM Trans. Program. Lang. Syst., 28(5):795--847, 2006.
[19]
A. Kennedy and D. Syme. Transposing f to c\#: expressivity of parametric polymorphism in an object-oriented language: Research articles. Concurr. Comput. : Pract. Exper., 16:707--733, 2004.
[20]
A. Kiezun, M. Ernst, F. Tip, and R. Fuhrer. Refactoring for parameterizing Java classes. In ICSE '07: Proc. of the 29th Intl. Conf. on Software Engineering, 2007.
[21]
M. Odersky. The Scala Language Specification v 2.8. 2010.
[22]
A. Salcianu. Java program analysis utilities library. http://jpaul.sourceforge.net/. Version 2.5.1.
[23]
K. K. Thorup and M. Torgersen. Unifying genericity: Combining the benefits of virtual types and parameterized classes. In ECOOP '99: Proc. of the European Conf. on Object-Oriented Programming, 1999.
[24]
M. Torgersen, C. P. Hansen, E. Ernst, P. von der Ahe, G. Bracha, and N. Gafter. Adding wildcards to the Java programming language. In SAC '04: Proc. of the 2004 Symposium on Applied Computing, 2004.\endthebibliography

Cited By

View all
  • (2022)Structural refinement typesProceedings of the 7th ACM SIGPLAN International Workshop on Type-Driven Development10.1145/3546196.3550163(15-27)Online publication date: 6-Sep-2022
  • (2019)Casting about in the dark: an empirical study of cast operations in Java programsProceedings of the ACM on Programming Languages10.1145/33605843:OOPSLA(1-31)Online publication date: 10-Oct-2019
  • (2014)Refactoring Java generics by inferring wildcards, in practiceACM SIGPLAN Notices10.1145/2714064.266020349:10(271-290)Online publication date: 15-Oct-2014
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
PLDI '11: Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation
June 2011
668 pages
ISBN:9781450306638
DOI:10.1145/1993498
  • General Chair:
  • Mary Hall,
  • Program Chair:
  • David Padua
  • cover image ACM SIGPLAN Notices
    ACM SIGPLAN Notices  Volume 46, Issue 6
    PLDI '11
    June 2011
    652 pages
    ISSN:0362-1340
    EISSN:1558-1160
    DOI:10.1145/1993316
    Issue’s Table of Contents
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 04 June 2011

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. definition-site variance
  2. language extensions
  3. use-site variance
  4. variance
  5. wildcards

Qualifiers

  • Research-article

Conference

PLDI '11
Sponsor:

Acceptance Rates

Overall Acceptance Rate 406 of 2,067 submissions, 20%

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)17
  • Downloads (Last 6 weeks)0
Reflects downloads up to 08 Feb 2025

Other Metrics

Citations

Cited By

View all
  • (2022)Structural refinement typesProceedings of the 7th ACM SIGPLAN International Workshop on Type-Driven Development10.1145/3546196.3550163(15-27)Online publication date: 6-Sep-2022
  • (2019)Casting about in the dark: an empirical study of cast operations in Java programsProceedings of the ACM on Programming Languages10.1145/33605843:OOPSLA(1-31)Online publication date: 10-Oct-2019
  • (2014)Refactoring Java generics by inferring wildcards, in practiceACM SIGPLAN Notices10.1145/2714064.266020349:10(271-290)Online publication date: 15-Oct-2014
  • (2014)Refactoring Java generics by inferring wildcards, in practiceProceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & Applications10.1145/2660193.2660203(271-290)Online publication date: 15-Oct-2014
  • (2012)Constrained kindsACM SIGPLAN Notices10.1145/2398857.238467547:10(811-830)Online publication date: 19-Oct-2012
  • (2012)Constrained kindsProceedings of the ACM international conference on Object oriented programming systems languages and applications10.1145/2384616.2384675(811-830)Online publication date: 19-Oct-2012
  • (2012)Java wildcards meet definition-site varianceProceedings of the 26th European conference on Object-Oriented Programming10.1007/978-3-642-31057-7_23(509-534)Online publication date: 11-Jun-2012
  • (2011)Taming the wildcardsACM SIGPLAN Notices10.1145/1993316.199356946:6(602-613)Online publication date: 4-Jun-2011
  • (2022)Verifying Whiley Programs with BoogieJournal of Automated Reasoning10.1007/s10817-022-09619-166:4(747-803)Online publication date: 20-Mar-2022
  • (2012)Precise static analysis for generic programs in object oriented languagesACM SIGSOFT Software Engineering Notes10.1145/2180921.218093737:3(1-6)Online publication date: 16-May-2012

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media