Reference. A Semantic Foundation for Sound Gradual Typing

Gradually typed programming languages provide a way forward in the debate between static and dynamic typing. In a gradual language, statically typed and dynamically typed programs can intermingle, and dynamically typed scripts can be gradually migrated to a statically typed style. In a sound gradually typed language, static type information is just as reliable as in a static language, establishing correctness of type-based refactoring and optimization. To ensure this in the presence of dynamic typing, runtime type casts are inserted automatically at the boundary between static and dynamic code. However the design of these languages is somewhat ad hoc, with little guidance on how to ensure that static reasoning principles are valid. In my dissertation, I present a semantic framework for design and metatheoretic analysis of gradually typed languages based on the theory of embedding-projection pairs. I show that this semantics enables proofs of the fundamental soundness theorems of gradual typing, and that it is robust, applying it to different evaluation orders and programming features.

Cite

Cite as @new_dissertation_2020 (helia, typst) · \cite{new_dissertation_2020} (LaTeX)
BibTeX
bibtex · 7 lines
@phdthesis{new_dissertation_2020,
 title = {A Semantic Foundation for Sound Gradual Typing},
 author = {New, Max S.},
 year = {2020},
 url = {https://maxsnew.com/docs/dissertation.pdf},
 school = {Northeastern University}
}
hayagriva YAML (typst)
yaml · 8 lines
new_dissertation_2020:
  type: thesis
  title: A Semantic Foundation for Sound Gradual Typing
  author: New, Max S.
  date: 2020
  organization: Northeastern University
  url: https://maxsnew.com/docs/dissertation.pdf
  genre: Doctoral dissertation
Cites 86 works (10 here)
With notes (10)

Graduality and Parametricity: Together Again for the First Time new_jamner_ahmed_2020

Parametric polymorphism and gradual typing have proven to be a difficult combination, with no language yet produced that satisfies the fundamental theorems of each: parametricity and graduality. Notably, Toro, Labrada, and Tanter (POPL 2019) conjecture that for any gradual extension of System F that uses dynamic type generation, graduality and parametricity are “simply incompatible”. However, we argue that it is not graduality and parametricity that are incompatible per se, but instead that combining the syntax of System F with dynamic type generation as in previous work necessitates type-directed computation, which we show has been a common source of graduality and parametricity violations in previous work.

We then show that by modifying the syntax of universal and existential types to make the type name generation explicit, we remove the need for type-directed computation, and get a language that satisfies both graduality and parametricity theorems. The language has a simple runtime semantics, which can be explained by translation to a statically typed language where the dynamic type is interpreted as a dynamically extensible sum type. Far from being in conflict, we show that the parametricity theorem follows as a direct corollary of a relational interpretation of the graduality property.

PDF · DOI · pldb

Call-by-name Gradual Type Theory new_licata_2020_lmcs

We present gradual type theory, a logic and type theory for call-by-name gradual typing. We define the central constructions of gradual typing (the dynamic type, type casts and type error) in a novel way, by universal properties relative to new judgments for gradual type and term dynamism, which were developed in blame calculi and to state the “gradual guarantee” theorem of gradual typing. Combined with the ordinary extensionality (𝜂) principles that type theory provides, we show that most of the standard operational behavior of casts is uniquely determined by the gradual guarantee. This provides a semantic justification for the definitions of casts, and shows that non-standard definitions of casts must violate these principles. Our type theory is the internal language of a certain class of preorder categories called equipments. We give a general construction of an equipment interpreting gradual type theory from a 2-category representing non-gradual types and programs, which is a semantic analogue of Findler and Felleisen’s definitions of contracts, and use it to build some concrete domain-theoretic models of gradual typing.
DOI · arXiv

How to evaluate the performance of gradual type systems greenman_etal_2019

A sound gradual type system ensures that untyped components of a program can never break the guarantees of statically typed components. This assurance relies on runtime checks, which in turn impose performance overhead in proportion to the frequency and nature of interaction between typed and untyped components. The literature on gradual typing lacks rigorous descriptions of methods for measuring the performance of gradual type systems. This gap has consequences for the implementors of gradual type systems and developers who use such systems. Without systematic evaluation of mixed-typed programs, implementors cannot precisely determine how improvements to a gradual type system affect performance. Developers cannot predict whether adding types to part of a program will significantly degrade (or improve) its performance. This paper presents the first method for evaluating the performance of sound gradual type systems. The method quantifies both the absolute performance of a gradual type system and the relative performance of two implementations of the same gradual type system. To validate the method, the paper reports on its application to 20 programs and 3 implementations of Typed Racket.
PDF · DOI · pldb

Gradual Type Theory new_licata_ahmed_2019

Gradually typed languages are designed to support both dynamically typed and statically typed programming styles while preserving the benefits of each. While existing gradual type soundness theorems for these languages aim to show that type-based reasoning is preserved when moving from the fully static setting to a gradual one, these theorems do not imply that correctness of type-based refactorings and optimizations is preserved. Establishing correctness of program transformations is technically difficult, because it requires reasoning about program equivalence, and is often neglected in the metatheory of gradual languages.

In this paper, we propose an axiomatic account of program equivalence in a gradual cast calculus, which we formalize in a logic we call gradual type theory (GTT). Based on Levy’s call-by-push-value, GTT gives an axiomatic account of both call-by-value and call-by-name gradual languages. Based on our axiomatic account we prove many theorems that justify optimizations and refactorings in gradually typed languages. For example, uniqueness principles for gradual type connectives show that if the βη laws hold for a connective, then casts between that connective must be equivalent to the so-called “lazy” cast semantics. Contrapositively, this shows that “eager” cast semantics violates the extensionality of function types. As another example, we show that gradual upcasts are pure functions and, dually, gradual downcasts are strict functions. We show the consistency and applicability of our axiomatic theory by proving that a contract-based implementation using the lazy cast semantics gives a logical relations model of our type theory, where equivalence in GTT implies contextual equivalence of the programs. Since GTT also axiomatizes the dynamic gradual guarantee, our model also establishes this central theorem of gradual typing. The model is parametrized by the implementation of the dynamic types, and so gives a family of implementations that validate type-based optimization and the gradual guarantee.

PDF · DOI · pldb

Graduality from Embedding-Projection Pairs new_ahmed_2018

Gradually typed languages allow statically typed and dynamically typed code to interact while maintaining benefits of both styles. The key to reasoning about these mixed programs is Siek-Vitousek-Cimini-Boyland’s (dynamic) gradual guarantee, which says that giving components of a program more precise types only adds runtime type checking, and does not otherwise change behavior. In this paper, we give a semantic reformulation of the gradual guarantee called graduality. We change the name to promote the analogy that graduality is to gradual typing what parametricity is to polymorphism. Each gives a local-to-global, syntactic-to-semantic reasoning principle that is formulated in terms of a kind of observational approximation.

Utilizing the analogy, we develop a novel logical relation for proving graduality. We show that embedding-projection pairs (ep pairs) are to graduality what relations are to parametricity. We argue that casts between two types where one is “more dynamic” (less precise) than the other necessarily form an ep pair, and we use this to cleanly prove the graduality cases for casts from the ep-pair property. To construct ep pairs, we give an analysis of the type dynamism relation—also known as type precision or naïve subtyping—that interprets the rules for type dynamism as compositional constructions on ep pairs, analogous to the coercion interpretation of subtyping.

PDF · DOI · pldb

Call-by-name Gradual Type Theory new_licata_2018_fscd

We present gradual type theory, a logic and type theory for call-by-name gradual typing. We define the central constructions of gradual typing (the dynamic type, type casts and type error) in a novel way, by universal properties relative to new judgments for gradual type and term dynamism. These dynamism judgements build on prior work in blame calculi and on the “gradual guarantee” theorem of gradual typing. Combined with the ordinary extensionality (eta) principles that type theory provides, we show that most of the standard operational behavior of casts is uniquely determined by the gradual guarantee. This provides a semantic justification for the definitions of casts, and shows that non-standard definitions of casts must violate these principles. Our type theory is the internal language of a certain class of preorder categories called equipments. We give a general construction of an equipment interpreting gradual type theory from a 2-category representing non-gradual types and programs, which is a semantic analogue of the interpretation of gradual typing using contracts, and use it to build some concrete domain-theoretic models of gradual typing.
DOI

Do be do be do lindley-2017-do

PDF · DOI · arXiv · pldb

Is Sound Gradual Typing Dead? takikawa_etal_2016

Programmers have come to embrace dynamically-typed languages for prototyping and delivering large and complex systems. When it comes to maintaining and evolving these systems, the lack of explicit static typing becomes a bottleneck. In response, researchers have explored the idea of gradually-typed programming languages which allow the incremental addition of type annotations to software written in one of these untyped languages. Some of these new, hybrid languages insert run-time checks at the boundary between typed and untyped code to establish type soundness for the overall system. With sound gradual typing, programmers can rely on the language implementation to provide meaningful error messages when type invariants are violated. While most research on sound gradual typing remains theoretical, the few emerging implementations suffer from performance overheads due to these checks. None of the publications on this topic comes with a comprehensive performance evaluation. Worse, a few report disastrous numbers. In response, this paper proposes a method for evaluating the performance of gradually-typed programming languages. The method hinges on exploring the space of partial conversions from untyped to typed. For each benchmark, the performance of the different versions is reported in a synthetic metric that associates runtime overhead to conversion effort. The paper reports on the results of applying the method to Typed Racket, a mature implementation of sound gradual typing, using a suite of real-world programs of various sizes and complexities. Based on these results the paper concludes that, given the current state of implementation technologies, sound gradual typing faces significant challenges. Conversely, it raises the question of how implementations could reduce the overheads associated with soundness and how tools could be used to steer programmers clear from pathological cases.
PDF · Web · pldb

Models of a Non-associative Composition munchmaccagnoni-2014-models

DOI

Call-By-Push-Value: A Functional/Imperative Synthesis levy-2003-callbypushvalue

DOI
External (76)
  • Reconciling Noninterference and Gradual Typing (2020)
  • The Fire Triangle: How to Mix Substitution, Dependent Elimination, and Effects (2020)
  • Approximate Normalization for Dependent Gradual Types (2019)
  • Complete Monitors for Gradual Types (2019)
  • Typed Racket Reference (2019)
  • Gradual Parametricity, Revisited (2019)
  • Foundations of dependent interoperability (2018)
  • A Spectrum of Type Soundness and Performance (2018)
  • Type-Driven Gradual Security with References (2018)
  • Consistent Subtyping for All (2018)
  • Theorems for Free for Free: Parametricity, With and Without Types (2017)
  • Gradual Typing with Union and Intersection Types (2017)
  • Automatically Generating the Dynamic Semantics of Gradually Typed Languages (2017)
  • Correctness of compiling polymorphism to dynamic typing (2017)
  • Gradual Session Types (2017)
  • On Polymorphic Gradual Typing (2017)
  • Gradual Refinement Types (2017)
  • Big Types in Little Runtime: Open-world Soundness and Collaborative Blame for Gradual Type Systems (2017)
  • Dependent Types and Fibred Computational Effects (2016)
  • The Gradualizer: A Methodology and Algorithm for Generating Gradual Type Systems (2016)
  • Partial Type Equivalences for Verified Dependent Interoperability (2016)
  • Abstracting Gradual Typing (2016)
  • The recursive union of some gradual types (2016)
  • Principal Type Schemes for Gradual Programs (2015)
  • Space-Efficient Manifest Contracts (2015)
  • Polarized Substructural Session Types (invited talk) (2015)
  • Refined Criteria for Gradual Typing (2015)
  • The Problem of Structural Type Tests in a Gradually-Typed Language (2014)
  • A Theory of Gradual Effect Systems (2014)
  • An Effect System for Algebraic Effects and Handlers (2013)
  • Gradual Security Typing with References (2013)
  • Facebook: Analyzing PHP statically (2013)
  • The interaction of contracts and laziness (2012)
  • Gradual Ownership Types (2012)
  • Chaperones and Impersonators: Run-time Support for Reasonable Interposition (2012)
  • Gradual typing for first-class classes (2012)
  • Blame for All (2011)
  • Gradual Information Flow Typing (2011)
  • Dynamic Languages are Static Languages (2011)
  • Gradual typing for generics (2011)
  • Contracts Made Manifest (2010)
  • Space-efficient gradual typing (2010)
  • Threesomes, with and Without Blame (2010)
  • Threesomes, with and without blame (2010)
  • State-Dependent Representation Independence (2009)
  • Non-Parametric Parametricity (2009)
  • Exploring the Design Space of Higher-Order Casts (2009)
  • Well-typed programs can’t be blamed (2009)
  • Static Contract Checking for Haskell (2009)
  • The Logical Basis of Evaluation Order and Pattern-Matching (2009)
  • The Design and Implementation of Typed Scheme (2008)
  • Operational Semantics for Multi-Language Programs (2007)
  • Gradual Typing for Objects (2007)
  • Step-Indexed Syntactic Logical Relations for Recursive and Quantified Types (2006)
  • Contracts as Pairs of Projections (2006)
  • Typed Contracts for Functional Programming (2006)
  • Gradual Typing for Functional Languages (2006)
  • Interlanguage Migration: From Scripts to Programs (2006)
  • Semantic Casts: Contracts and Structural Subtyping in a Nominal World (2004)
  • A Bisimulation for Dynamic Sealing (2004)
  • Parametricity As a Notion of Uniformity in Reflexive Graphs (2002)
  • Contracts for higher-order functions (2002)
  • Locus Solum: From the rules of logic to the logic of rules (2001)
  • A modality for recursion (2000)
  • Direct models of the computational lambda-calculus (1999)
  • Dynamic Typing: Syntax and Proof Theory (1994)
  • A logic for parametric polymorphism (1993)
  • Logic programming with focusing proofs in linear logic (1992)
  • Reasoning about Programs in Continuation-Passing Style (1992)
  • Types, Abstractions, and Parametric Polymorphism, Part 2 (1991)
  • Notions of computation and monads (1991)
  • On the expressive power of programming languages (1990)
  • Quasi-static typing (1990)
  • Abstract types have existential type (1985)
  • Types, Abstraction and Parametric Polymorphism (1983)
  • Types Are Not Sets (1973)
new_dissertation_2020 reference entries/refs/new_dissertation_2020/new_dissertation_2020.hel