Dependent Types in Practical Programming Hongwei Xi Oregon Graduate Institute.

Slides:



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

Programming with Lists
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Static and User-Extensible Proof Checking Antonis StampoulisZhong Shao Yale University POPL 2012.
CSE Winter 2008 Introduction to Program Verification refining an interface.
Imperative Programming with Dependent Types Hongwei Xi University of Cincinnati.
PADL 041 Implementing Cut Elimination: A case study of simulating dependent types in Haskell Chiyan Chen Dengping Zhu Hongwei Xi Boston University.
1 Dependent Types for Termination Verification Hongwei Xi University of Cincinnati.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Winter 2013.
Introduction to ML – Part 1 Frances Spalding. Assignment 1 chive/fall05/cos441/assignments/a1.ht m
An Introduction to Proof-Carrying Code David Walker Princeton University (slides kindly donated by George Necula; modified by David Walker)
VeriML: Revisiting the Foundations of Proof Assistants Zhong Shao Yale University MacQueen Fest May 13, 2012 (Joint work with Antonis Stampoulis)
The Design and Implementation of a Certifying Compiler [Necula, Lee] A Certifying Compiler for Java [Necula, Lee et al] David W. Hill CSCI
1 CPS Transform for Dependent ML Hongwei Xi University of Cincinnati and Carsten Schürmann Yale University.
Research Languages on the.NET Platform Nick Benton Microsoft Research, Cambridge UK.
Extensible Verification of Untrusted Code Bor-Yuh Evan Chang, Adam Chlipala, Kun Gao, George Necula, and Robert Schneck May 14, 2004 OSQ Retreat Santa.
Introduction to ML – Part 1 Kenny Zhu. Assignment 2 chive/fall07/cos441/assignments/a2.ht m
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Dependently Typed Pattern Matching Hongwei Xi Boston University.
1 CS 312 – Lecture 28 Continuations –Probably the most confusing thing you’ve seen all semester… Course summary –Life after CS 312.
Refinement types for ML By Tim Freeman, Frank CMU Presented by: Andrey Utis.
May 1, 2003May 1, Imperative Programming with Dependent Types Hongwei Xi Boston University.
Facilitating Program Verification with Dependent Types Hongwei Xi Boston University.
Survey of Typed Assembly Language (TAL) Introduction and Motivation –Conventional untyped compiler < Typed intermediate languages –Typed intermediate language.
Extensibility, Safety and Performance in the SPIN Operating System Bershad et al Presentation by norm Slides shamelessly “borrowed” from Stefan Savage’s.
Typed Memory Management in a Calculus of Capabilities David Walker (with Karl Crary and Greg Morrisett)
1 A Dependently Typed Assembly Language Hongwei Xi University of Cincinnati and Robert Harper Carnegie Mellon University.
Good Advice for Type-directed Programming Aspect-oriented Programming and Extensible Generic Functions Geoffrey Washburn [ ] Joint.
Introduction to ML - Part 2 Kenny Zhu. What is next? ML has a rich set of structured values Tuples: (17, true, “stuff”) Records: {name = “george”, age.
Introduction to ML Last time: Basics: integers, Booleans, tuples,... simple functions introduction to data types This time, we continue writing an evaluator.
A Dependently Typed Assembly Language Robert Harper (Joint work with Robert Harper)
Tim Sheard Oregon Graduate Institute Lecture 5: Review of homework 2 CS510 Sect FSC Winter 2004 Winter 2004.
A Type System for Expressive Security Policies David Walker Cornell University.
1 Dependent Types in Practical Programming Hongwei Xi University of Cincinnati.
Facilitating Programming Verification with Dependent Types Hongwei Xi University of Cincinnati.
Presented by Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
CS 104 Introduction to Computer Science and Graphics Problems Software and Programming Language (2) Programming Languages 09/26/2008 Yang Song (Prepared.
Dependently Typed Data Structures Hongwei Xi presented by James Hook Pacific Software Research Center Oregon Graduate.
Compiling with Dependent Types Hongwei Xi University of Cincinnati.
VeriML DARPA CRASH Project Progress Report Antonis Stampoulis October 5 th, 2012 A language-based, dependently-typed, user-extensible approach to proof.
By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,
CSE 341 Programming Languages Racket Datatype Style Programming Zach Tatlock Spring 2014.
CSC 580 – Theory of Programming Languages, Spring, 2009 Week 9: Functional Languages ML and Haskell, Dr. Dale E. Parson.
Refinements to techniques for verifying shape analysis invariants in Coq Kenneth Roe GBO Presentation 9/30/2013 The Johns Hopkins University.
The Fail-Safe C to Java translator Yuhki Kamijima (Tohoku Univ.)
Chapter 8 Lecture 1 Software Testing. Program testing Testing is intended to show that a program does what it is intended to do and to discover program.
Implementing a Dependently Typed λ -Calculus Ali Assaf Abbie Desrosiers Alexandre Tomberg.
Advanced Functional Programming Tim Sheard 1 Lecture 17 Advanced Functional Programming Tim Sheard Oregon Graduate Institute of Science & Technology Lecture:
Pointers and Arrays in C and Assembly Language. Arrays Provide useful abstraction Match up to machine memory organization Array index computation –time.
Programming Languages Dan Grossman 2013 Datatype-Programming in Racket Without Structs.
Heath Carroll Bill Hanczaryk Rich Porter.  A Theory of Type Polymorphism in Programming ◦ Robin Milner (1977)  Milner credited with introducing the.
BPF+ Exploiting Global Data-flow Optimization in a Packet Filter Architecture Andrew Begel, Steven McCanne, Susan L. Graham University of California, Berkeley.
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Spring 2017.
Pointers and Arrays in C and Assembly Language
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2013.
Imperative Programming with Dependent Types
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Zach Tatlock Winter 2018.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2017.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Autumn 2018.
Advanced Functional Programming
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Zach Tatlock Winter 2018.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Spring 2019.
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2019.
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Autumn 2017.
Presentation transcript:

Dependent Types in Practical Programming Hongwei Xi Oregon Graduate Institute

Motivation: Narrowing the Huge Gap NuPrl Coq Program ExtractionProof synthesis ML with Dependent Types ML

Some Key Issues in Language Design Program error detection Program verification Large scale programming Program documentation Efficient implementation

Some key features in SML Rich programming constructs Imperative features Advanced type system Sophisticated module system

zip: dynamic safety datatype ‘a list = nil | :: ‘a * ‘a list exception UnequalLengths fun(‘a, ‘b) zip(nil, nil) = nil | zip(x :: xs, y :: ys) = (x, y) :: zip(xs, ys) | zip(x :: xs, nil) = raise UnequalLengths | zip(nil, y :: ys) = raise UnequalLengths

An Example of Dependent Types We refine the datatype ‘a list : typeref ‘a list of nat with nil <| ‘a list(0) | :: ’a list(n+1) Some explanation –nil is a list of length 0 –:: yields a list of length n+1 when given an element of type ‘a and a list of length n

zip: static safety fun(‘a, ‘b) zip(nil, nil) = nil | zip(x :: xs, y :: ys) = (x, y) :: zip(xs,ys) (* | zip(x :: xs, nil) = raise UnequalLengths | zip(nil, y :: ys) = raise UnequalLengths *) where zip ‘a * ‘b list(n)

zip: An Elaborated Version fun(‘a, ‘b) zip[0](nil, nil) = nil | zip[n+1](x :: xs, y :: ys) =(x, y) :: zip[n](xs,ys) where zip ‘a * ‘b list(n)

Array bounds Checking Array bounds checking refers to determining whether the value of an expression is within the bounds of an array when it is used to index the array. Pascal, Ada, Modula-3, SML, Java are among the programming languages which require that all bounds violations be captured. C and C++ are not. However, array bounds checking can be expensive. FoxNet (SML): up to 30% loss of throughput SPIN kernel (Modula-3): significant performance loss

Array Bounds Check Elimination Some previous approaches: –Synthesizing loop invariants (Suzuki & Ishihata): too expensive in practice to be applicable –Flow analysis (Gupta; Kolte & Wolfe): totally automatic but sensitive to program structures and not thorough A recent approach: –Safe C compiler (Necula and Lee): relatively simple language constructs A serious drawback: no or little feedback

Some Built-in Dependent Types int(i) stands for the singleton type which contains only integer i. bool(b) stands for the singleton type which contains only boolean b. ‘a array(n) stands for the type of arrays of size n whose elements are of type ‘a.

Dependent Types of Some Built-in Functions assert sub <| {size:nat}{index:nat | index < size} ‘a array(size) * int(index) -> ‘a This implies that sub can only be applied to an array of size size and an integer of value index such that 0 <= index < size holds. Other array operations such as update can be typed similarly.

Dot Product: A version in DML fun{n:nat} dotprod v1 v2 = let fun loop(i, n, result) = if i = n then result else loop(i+1, n, result+sub(v1,i)*sub(v2,i)) where loop int in loop (0, length v1, 0) end where dotprod int array(n) -> int

Dot Product: A Version in de Caml let dotprod v1 v2 = begin let result = ref 0 in for i = 0 to vect_length v1 - 1 do result := result + v1..(i) * v2..(i) done; !result end withtype {n:nat} int vect(n) -> int vect(n) -> int ;; (* for example: dotprod [|1;2;3|] [|1;2;3|] = 1*1 + 2*2 + 3*3 = 14 *)

Dependently Typed Assembly Language We aim for passing dependent types from source level to assembly level. This is inspired and/or supported by –TIL compiler (Fox project at CMU) –RML compiler (Tolmach and Oliva) –Proof-carrying code (Necula and Lee) –Typed Assembly Language (Morrisett et al)

Some Advantages of DTAL Providing invaluable support for compiler writers (Tolmach and Oliva; Morrisett et al) Producing memory safety proofs for proof- carrying code An alternative to proof-carrying code Aggressive compiler optimization

bcopy: A Version in de Caml let bcopy (src, dst) = let length = vect_length src in for n = 0 to length - 1 do dst..(n) <- src..(n) done withtype {i:nat}{j:nat | i <= j} ‘a vect(i) * ‘a vect(j) -> unit ;;

bcopy: A Version in DTAL bcopy: {i:nat}{j:nat | i<=j} [r1: int(i), r2: int array(i), r3: int array(j)] mov r4, 0 // set the count to be 0 jmp loop // start the loop loop: {i:nat}{j:nat | i<=j}{k:nat} [r1: int(i), r2: int array(i), r3: int array(j), r4: int(k)] sub r5, r4, r1 beq r5, finish // r4 = r1 and done load r5, r2(r4) // r5 <- r2(r4) store r3(r4), r5 // r3(r4) <- r5 add r4, r4, 1 // r4 <- r4 + 1 jmp loop // loop again finish:[] halt

Proof Generation for Proof-Carrying Code Code Proof Poof-Carrying Code Unpacking Verifying Executing Memory Safety Termination

A Similar Scenario NuPrl proof Proof verification Program extraction Code-carrying proof?

Significant Features of DML Exhibiting convincing signs of a practical programming language –Theoretical fundation –Prototype implementation and evaluation Enhancing both code safety and code efficiency Generating DTAL (ongoing research)

Current Status and Future Direction We have finished the following. –Theoretical development of DML –A prototype implementation of DML –A prototype implementation of DTAL We are working on the following. –Writing a DML front-end for Caml-light (de Caml) –Designing a dependently typed assembly language We intend to do the following. –Dependent types for (a subset of) Java!