Generative type abstraction and type-level computation (Wrestling with System FC) Stephanie Weirich, Steve Zdancewic University of Pennsylvania Dimitrios.

Slides:



Advertisements
Similar presentations
Sml2java a source to source translator Justin Koser, Haakon Larsen, Jeffrey Vaughan PLI 2003 DP-COOL.
Advertisements

Transposing F to C Transposing F to C Andrew Kennedy & Don Syme Microsoft Research Cambridge, U.K.
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Types and Programming Languages Lecture 13 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Types and Programming Languages Lecture 7 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Static Contract Checking for Haskell Dana N. Xu University of Cambridge Ph.D. Supervisor: Simon Peyton Jones Microsoft Research Cambridge.
Tom Schrijvers K.U.Leuven, Belgium with Manuel Chakravarty, Martin Sulzmann and Simon Peyton Jones.
Security of Multithreaded Programs by Compilation Tamara Rezk INDES Project, INRIA Sophia Antipolis Mediterranee Joint work with Gilles Barthe, Alejandro.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Type-based termination analysis with disjunctive invariants Dimitrios Vytiniotis, MSR Cambridge with Byron Cook (MSR Cambridge) and Ranjit Jhala (UCSD)
Reconciling OO and Haskell-Style Overloading Mark Shields Simon Peyton Jones Microsoft Research Cambridge
Type Inference David Walker COS 320. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
An Abstract Interpretation Framework for Refactoring P. Cousot, NYU, ENS, CNRS, INRIA R. Cousot, ENS, CNRS, INRIA F. Logozzo, M. Barnett, Microsoft Research.
Static and User-Extensible Proof Checking Antonis StampoulisZhong Shao Yale University POPL 2012.
Let should not be generalized Dimitrios Vytiniotis, Simon Peyton Jones Microsoft Research, Cambridge TLDI’1 0, Madrid, January 2010 Tom Schrijvers K.U.
Type Analysis and Typed Compilation Stephanie Weirich Cornell University.
Comparing Semantic and Syntactic Methods in Mechanized Proof Frameworks C.J. Bell, Robert Dockins, Aquinas Hobor, Andrew W. Appel, David Walker 1.
Extended Static Checking for Haskell (ESC/Haskell) Dana N. Xu University of Cambridge advised by Simon Peyton Jones Microsoft Research, Cambridge.
Kathleen Fisher cs242 Reading: “A history of Haskell: Being lazy with class”,A history of Haskell: Being lazy with class Section 6.4 and Section 7 “Monads.
Foundational Certified Code in a Metalogical Framework Karl Crary and Susmit Sarkar Carnegie Mellon University.
Current Techniques in Language-based Security David Walker COS 597B With slides stolen from: Steve Zdancewic University of Pennsylvania.
Current Techniques in Language-based Security David Walker COS 597B With slides stolen from: Steve Zdancewic University of Pennsylvania.
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright © Instructors.
Type inference and modern type systems Stephanie Weirich University of Pennsylvania.
Lightweight Abstraction for Mathematical Computation in Java 1 Pavel Bourdykine and Stephen M. Watt Department of Computer Science Western University London.
A Type System for Well-Founded Recursion Derek Dreyer Carnegie Mellon University POPL 2004 Venice, Italy.
System F with type equality coercions Simon Peyton Jones (Microsoft) Manuel Chakravarty (University of New South Wales) Martin Sulzmann (University of.
Code-Carrying Proofs Aytekin Vargun Rensselaer Polytechnic Institute.
Type Checking.
Modular Type Classes Derek Dreyer Robert Harper Manuel M.T. Chakravarty POPL 2007 Nice, France.
Principal Type Schemes for Modular Programs Derek Dreyer and Matthias Blume Toyota Technological Institute at Chicago ESOP 2007 Braga, Portugal.
CLF: A Concurrent Logical Framework David Walker Princeton (with I. Cervesato, F. Pfenning, K. Watkins)
Steve Zdancewic ESOP011 Secure Information Flow and CPS Steve Zdancewic Joint work with Andrew Myers Cornell University.
Survey of Typed Assembly Language (TAL) Introduction and Motivation –Conventional untyped compiler < Typed intermediate languages –Typed intermediate language.
01/17/20031 Guarded Recursive Datatype Constructors Hongwei Xi and Chiyan Chen and Gang Chen Boston University.
Software Reliability Methods Sorin Lerner. Software reliability methods: issues What are the issues?
WRT 2007 Refactoring Functional Programs Huiqing Li Simon Thompson Computing Lab Chris Brown Claus Reinke University of Kent.
A Type System for Expressive Security Policies David Walker Cornell University.
Type Inference David Walker COS 441. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
Scrap your boilerplate with class Ralf Lämmel, Simon Peyton Jones Microsoft Research.
Tim Sheard Oregon Graduate Institute Lecture 11: A Reduction Semantics for MetaML CS510 Section FSC Winter 2005 Winter 2005.
1 A Short Introduction to (Object-Oriented) Type Systems Kris De Volder.
Overview of program analysis Mooly Sagiv html://
Three Generative grammars
Generic Programming with Dependent Types Stephanie Weirich University of Pennsylvania.
Understanding PML Paulo Pinheiro da Silva. PML PML is a provenance language (a language used to encode provenance knowledge) that has been proudly derived.
Mads Torgersen, Microsoft.  Language INtegrated Query  An open multi-language query facility  Uses cool language stuff  Points into the future.
Sound Haskell Dana N. Xu University of Cambridge Joint work with Simon Peyton Jones Microsoft Research Cambridge Koen Claessen Chalmers University of Technology.
Writing Systems Software in a Functional Language An Experience Report Iavor Diatchki, Thomas Hallgren, Mark Jones, Rebekah Leslie, Andrew Tolmach.
Singleton Kinds and Singleton Types Christopher A. Stone August 2, 1999 Thesis Committee Bob Harper, chair Peter Lee John Reynolds Jon Riecke (Bell Laboratories)
CS212: Object Oriented Analysis and Design
Lecture 5 1 CSP tools for verification of Sec Prot Overview of the lecture The Casper interface Refinement checking and FDR Model checking Theorem proving.
From Hoare Logic to Matching Logic Reachability Grigore Rosu and Andrei Stefanescu University of Illinois, USA.
Types and Programming Languages Lecture 11 Simon Gay Department of Computing Science University of Glasgow 2006/07.
A Type System for Higher-Order Modules Derek Dreyer, Karl Crary, and Robert Harper Carnegie Mellon University POPL 2003.
1 Static Contract Checking for Haskell Dana N. Xu University of Cambridge Joint work with Simon Peyton Jones Microsoft Research Cambridge Koen Claessen.
Getting Started in PL Design Research Stephanie Weirich University of Pennsylvania.
Shifting the Blame A blame calculus with delimited control Taro Sekiyama* Atsushi Igarashi Soichiro Ueda Kyoto University Gradual typing.
Types and Programming Languages Lecture 3 Simon Gay Department of Computing Science University of Glasgow 2006/07.
FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University.
June 21, Reasoning about explicit strictness in a lazy language using mixed lazy/strict semantics Marko van Eekelen Maarten de Mol Nijmegen University,
The Ins and Outs of Gradual Type Inference Avik Chaudhuri Basil Hosmer Adobe Systems Aseem Rastogi Stony Brook University.
Simon Peyton Jones, Stephanie Weirich, Richard Eisenberg, Dimitrios Vytiniotis Microsoft Research University of Pennsylvania April 2016.
COMP 412, FALL Type Systems C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
An Operational Approach to Relaxed Memory Models
Names and Attributes Names are a key programming language feature
Lecture 16: Introduction to Data Types
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Microsoft Research University of Pennsylvania
Static Contract Checking for Haskell
Presentation transcript:

Generative type abstraction and type-level computation (Wrestling with System FC) Stephanie Weirich, Steve Zdancewic University of Pennsylvania Dimitrios Vytiniotis, Simon Peyton Jones Microsoft Research, Cambridge POPL 2011, Austin TX, January 2011

Type generativity is useful 1  Module implementor: module MImpl ( Tel, … ) … newtype Tel = MkTel String … module MImpl ( Tel, … ) … newtype Tel = MkTel String … Inside MImpl : Tel ~ String We can also lift this equality: List Tel ~ List String Tel -> Int ~ String -> Int etc. Inside MImpl : Tel ~ String We can also lift this equality: List Tel ~ List String Tel -> Int ~ String -> Int etc.  Module consumer: module MCons import MImpl … f :: Tel -> Tel f x = “0030” ++ x module MCons import MImpl … f :: Tel -> Tel f x = “0030” ++ x Inside MCons : Tel ≁ String Inside MCons : Tel ≁ String  Well-explored ideas found in various forms in modern languages [e.g. see papers on ML modules by Harper, Dreyer, Rossberg, Russo, …]

Type-level computation is useful 2 In the Glasgow Haskell Compiler, type-level computation involves type classes and families: module MImpl (Tel) … class LowLevel a where type R a toLowLevel :: a -> R a instance LowLevel String where type R String = ByteArray toLowLevel x = strToByteArray x instance LowLevel Tel where type R Tel = Int64 toLowLevel x = … … R is a “type function” R String ~ ByteArray R Tel ~ Int64

But there’s a problem! 3 module MImpl (Tel, …) newtype Tel = MkTel String class LowLevel a where type R a … instance LowLevel String where type R String = ByteArray … instance LowLevel Tel where type R Tel = Int64 … In the rest of the module : Tel ~ String Hence by lifting R Tel ~ R String Hence … ByteArray ~ Int64 In the rest of the module : Tel ~ String Hence by lifting R Tel ~ R String Hence … ByteArray ~ Int64

This paper 4  Type generativity and type functions are both and simultaneously useful!  But it’s easy to lose soundness [e.g. see GHC bug trac #1496]  So, what’s some good solution that combines these features? System FC2 A novel, sound, strongly-typed language with type-level equalities 1.Stages the use of the available equalities, to ensure soundness 2.Distinguishes between “codes” and “types” as in formulations of Type Theory [e.g. see papers by Dybjer] and intensional type analysis [e.g. see papers by Weirich, Crary] 3.Improves GHC’s core language [System FC, Sulzmann et al.] 4.Soundness proof w/o requiring strong normalization of types System FC2 A novel, sound, strongly-typed language with type-level equalities 1.Stages the use of the available equalities, to ensure soundness 2.Distinguishes between “codes” and “types” as in formulations of Type Theory [e.g. see papers by Dybjer] and intensional type analysis [e.g. see papers by Weirich, Crary] 3.Improves GHC’s core language [System FC, Sulzmann et al.] 4.Soundness proof w/o requiring strong normalization of types This talk. The rest is in the paper

Recap 5 newtype Tel = MkTel String -- Tel ~ String type instance R String = ByteArray -- R String ~ ByteArray type instance R Tel = Int64 -- R Tel ~ Int64 R String MUST NOT BE EQUATED TO R Tel (List String) OK TO BE EQUATED TO (List Tel)

A non-solution 6 data TR a = MkTR (R a) to :: ByteArray -> TR String to x = MkTR x from :: TR Tel -> Int64 from (MkTR x) = x TR Tel ~ TR String JUST AS BAD, BECAUSE THEN: from.to :: ByteArray -> Int64 TR Tel ~ TR String JUST AS BAD, BECAUSE THEN: from.to :: ByteArray -> Int64

Type Theory to the Rescue: Roles 7  As is common in Type Theory, distinguish between a code (a “name”) and a type (a “set of values”). newtype Tel = MkTel String Γ ˫ Tel ~ String : */TYPE Γ ˫ Tel ≁ String : */CODE YOUR TAKEAWAY #1

Code vs Type Equality 8 newtype Tel = MkTel String newtype Address = MkAddr String Γ ˫ Tel ~ Address : */TYPE Γ ˫ Tel ≁ Address : */CODE

Using the FC2 kind system to track roles 9  Key idea: Type-level computations dispatch on codes, not types  Use the kind system of FC2 to track codes type family R a type instance R String = ByteArray type instance R Tel = Int64 Fω: κ ::= * | κ → κ FC2: η ::= * | κ → η κ ::= | R : ( → *)/CODE R String ~ ByteArray : */CODE R Tel ~ Int64 : */CODE Source FC2 axioms

Look ma, no special lifting! 10

Why does that fix the problem? 11 Impossible to derive R String ~ R Tel : */TYPE … because R expects a CODE equality! Impossible to derive R String ~ R Tel : */TYPE … because R expects a CODE equality! YOUR TAKEAWAY #2

Lifting over type constructors 12 Similarly: TR : ( → *) Hence: TR Tel ≁ TR String : */TYPE Similarly: TR : ( → *) Hence: TR Tel ≁ TR String : */TYPE BUT: List : ( → *) Hence: List Tel ~ List String : */TYPE BUT: List : ( → *) Hence: List Tel ~ List String : */TYPE

FC2: The formal setup 13 Source program FC2 program Source declarations Source declarations FC2 constants and axioms Γ FC2 constants and axioms Γ Type and kind (and role) inference Type and kind (and role) inference Elaborated program contains explicit types and proof terms Easy to typecheck By elaborating to a type safe language we establish type soundness of the source and soundness of type inference and soundness of compiler transformations Elaborated program contains explicit types and proof terms Easy to typecheck By elaborating to a type safe language we establish type soundness of the source and soundness of type inference and soundness of compiler transformations

FC2 typing judgements 14 Role ρ ::= TYPE | CODE Coercions γ : Equality proof witnesses Coercion abstractions

Type-soundness via consistency 15 We know that: γ : (τ → σ) ~ (τ’ → σ’) Hence: γ1 : σ ~ σ’ Hence: γ0 : τ ~ τ’ Hence: sym γ0 : τ’ ~ τ We know that: γ : (τ → σ) ~ (τ’ → σ’) Hence: γ1 : σ ~ σ’ Hence: γ0 : τ ~ τ’ Hence: sym γ0 : τ’ ~ τ

Establishing consistency 16  Step 1  Define a role-sensitive type rewrite relation  [Novel idea: don’t require strong normalization of axioms, but require instead more determinism]  Step 2  Prove soundness and completeness of the type rewrite relation wrt the coercibility relation  Step 3:  Show that rewriting preserves head value constructors See paper and extended version for the gory details

More interesting details in the paper 17

Is this all Haskell specific? 18 No, though no other existing language demonstrates the same problem today so Haskell is a good motivation But:  Type generativity via some mechanism is useful  Type-level computation is independently useful  GHC happened to arrive at this situation early Sooner or later, as soon as both these features are in your type system you have to look for a solution

Lots of exciting future directions 19  Present a semantics that justifies the proof theory of FC2  Shed more light into coercion decomposition:  Injectivity of constructors admissible in F ω but not derivable (conj.)  Hence in need of semantic justification for the decomposition rules  Direction: Extend the kinds of F ω with roles and type functions, and encode equalities as Leibniz equalities. Can this shed any more light? What are the parametric properties of that language?  Enrich the universe of codes with term constructors  Investigate other interesting equalities (e.g. syntactic, β )  Can roles help in security and information flow type systems where different equalities may arise from different confidentiality levels?  Develop source language technology to give programmers control over the kinds of their declarations

Thank you for your attention 20 Questions?