150
Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of California, San Diego PLDI’16 Thursday, June 16

Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

  • Upload
    others

  • View
    23

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Refinement Typesfor

TypeScript

Panagiotis Vekris Benjamin Cosman Ranjit Jhala

University of California, San Diego

PLDI’16Thursday, June 16

Page 2: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

2

Extensible static analyses for modern scripting languages

Page 3: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

3

Extensible static analyses for modern scripting languages

Wide scale

Looks like

Compiles to

Page 4: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

3

Extensible static analyses for modern scripting languages

Higher Order Functions

Wide scale PL Interest

Object Oriented

Looks like

Compiles to

Generics

Optionally Typed

Page 5: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

4

Extensible static analyses for modern scripting languages

Verification Documentation

TSNo runtime overhead

Page 6: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

5

Extensible static analyses for modern scripting languages

Fixed type tests

Page 7: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

5

Extensible static analyses for modern scripting languages

User specified invariants

Fixed type tests

Page 8: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

5

Extensible static analyses for modern scripting languages

User specified invariants

Fixed type tests

Page 9: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

5

Extensible static analyses for modern scripting languages

User specified invariants

Fixed type tests

Page 10: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

5

Extensible static analyses for modern scripting languages

User specified invariants

Fixed type tests

Page 11: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Example

Compute the index of the minimum element of an array

6

Page 12: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

7

Page 13: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

folds over the elements of an array

7

Page 14: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

8

Page 15: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Calls with an appropriate function and initialization

8

Page 16: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Verification goal

Prove that all array accesses are within bounds

Example

Compute the index of the minimum element of an array

9

Page 17: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Array bounds analysis:

10

Page 18: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Array bounds analysis:

Constraint between two values

11

Page 19: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Constraint between two values

12

Array bounds analysis:

Page 20: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Constraint between two values

12

Array bounds analysis:

Constraint between value and closure

Page 21: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Constraint between value and closure

13

Page 22: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Constraint carries over through call to

function parameters

Constraint between value and closure

13

Page 23: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Constraint checkedon invocation

Constraint carries over through call to

function parameters

14

Page 24: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Constraint checkedon invocation

Constraint carries over through call to

function parameters

14

Problem

To check array access we must track relations between closures and values

Page 25: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

14

Problem

To check array access we must track relations between closures and values

SolutionRefinement types

Page 26: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Refinement Types

Value variable

Base type

Logical predicate

15

Page 27: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Refinement Types

“Set of values of type such that formula is true”

Value variable

Base type

Logical predicate

15

Page 28: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Refinement Types

“Set of values of type such that formula is true”

Value variable

Base type

Logical predicate

E.g.:

“Set of valid indexes for an array ”

15

Page 29: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

How can we type ?

16

Page 30: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

TypeScript type

How can we type ?

16

Page 31: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

TypeScript type

How can we type ?

Acc

Basic typing offers some guarantees

16

Page 32: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Accepts Acc

TypeScript type

How can we type ?

Acc

Basic typing offers some guarantees

16

Page 33: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Returns AccAccepts Acc

TypeScript type

How can we type ?

Acc

Basic typing offers some guarantees

16

Page 34: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

TypeScript type

How can we type ?

Does not capture: “valid index of ”

Basic typing offers some guaranteesbut not value related ones

17

Page 35: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

TypeScript type

How can we type to account for valid indexes?

Refinement type

18

Page 36: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

TypeScript type

How can we type to account for valid indexes?

Refinement type

18

Page 37: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

TypeScript type

How can we type to account for valid indexes?

Refinement type

19

Captures the relation between closure and value

Page 38: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Our contributionDesign a refinement type system for TypeScript

20

Page 39: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Challenges

Assignments

Mutability

Overloading

Annotation Overhead

21

Page 40: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Challenges Solutions we used

AssignmentsSSA Transformation

MutabilityExtend type system with immutability guarantees

OverloadingTwo-phased typing

Annotation Overhead Liquid Types

22

Page 41: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Challenges Solutions we used

AssignmentsSSA Transformation

MutabilityExtend type system with immutability guarantees

OverloadingTwo-phased typing

Annotation Overhead Liquid Types

23

Page 42: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

24

Assignments

Page 43: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

25

Page 44: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

-

-

+

+

+

+

+

25

Page 45: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

25

What is the type of ?

Page 46: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Types for

What is the type of ?

26

Page 47: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Types for

What is the type of ?

27

Page 48: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Types for

What is the type of ?

28

Page 49: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Types for

What is the type of ?

29

Page 50: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Types for

Νo single type for

30

Page 51: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Joining types of causes loss of precision

Νο single type for

31

Page 52: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Joining types of causes loss of precision

Use different versions of

Νο single type for

31

Page 53: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Use different versions of

32

Page 54: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Types for

Use different versions of

33

Page 55: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Use different versions of

Types for -

34

Page 56: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Types for -

35

Each version of has a single precise type & gets assigned once

Page 57: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Types for -

35

Static Single Assignment (SSA)

Page 58: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Types for -

35

Static Single Assignment (SSA)

How do we check these types?

Page 59: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

generates subtyping constraint

Assignment

36

Reminder

Page 60: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Subtyping Constraints

Generated constraints

37

Page 61: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Subtyping Constraints

: loop induction variable

φ( )

Generated constraints

38

Page 62: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Subtyping Constraints

: loop induction variable

φ( )

Generated constraints

38

Page 63: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Subtyping Constraints

: loop induction variable

φ( )

Generated constraints

39

Page 64: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Subtyping Constraints

: loop induction variable

φ( )

Generated constraints

Loop condition

Path Sensitivity

39

Page 65: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Subtyping Constraints

Generated constraints

Loop condition

40

Page 66: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Subtyping Constraints

Generated constraints

Safe Array Access

Loop condition

41

Page 67: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Subtyping Constraints

Generated constraints

Loop condition

Substitute

42

Page 68: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Subtyping Constraints

After substitution

43

Page 69: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Subtyping Constraints

Convert to logical implications

⇒⇒⇒⇒⇒

⇒⇒⇒

44

Page 70: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Subtyping Constraints

Convert to logical implications

Solved via SMT

⇒⇒⇒⇒⇒

⇒⇒⇒

44

Page 71: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Challenges Solutions we used

AssignmentsSSA Transformation

MutabilityExtend type system with immutability guarantees

OverloadingTwo-phased typing

Annotation Overhead Liquid Types

45

Page 72: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Mutability

46

Page 73: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Why is the access safe?

47

Page 74: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Why is the access safe?

is initialized to

47

1

Page 75: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Why is the access safe?

is initialized to

is bounded by ’s length

47

1 2

Page 76: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Why is the access safe?

is initialized to

is bounded by ’s length

increases only

47

1 2 3

Page 77: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Why is the access safe?

is initialized to

is bounded by ’s length

increases only

4. Length of does not mutate in loop47

1 2

4

3

Page 78: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

48

What if array’s length mutates in loop?

Page 79: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Silentlyupdates

48

What if array’s length mutates in loop?

Page 80: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Silentlyupdates

Check becomes stale

48

What if array’s length mutates in loop?

Page 81: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Silentlyupdates

Check becomes stale

Unsafe access!

48

What if array’s length mutates in loop?

Page 82: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Problem: stale checks break value reasoning

Silentlyupdates

49

Check becomes stale

Unsafe access!

Page 83: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Extend type system to enforce immutability constraints

50

Page 84: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

M. Tschantz and M. D. Ernst. Javari: Adding reference immutability to Java.OOPSLA, 2005.

Y. Zibin, A. Potanin, M. Ali, S. Artzi, A. Kiezun, and M. D. Ernst. Object and Reference Immutability using Java Generics. ESEC/FSE, 2007.

Y. Zibin, A. Potanin, P. Li, M. Ali, and M. D. Ernst. Ownership and Immutability in Generic Java. OOPSLA, 2010.

C. S. Gordon, M. J. Parkinson, J. Parsons, A. Bromfield, and J. Duffy. Uniqueness & Reference Immutability for Safe Parallelism. OOPSLA, 2012.

C. S. Gordon, M. D. Ernst, and D. Grossman. Rely-Guarantee References for Refinement Types over Aliased Mutable Data. PLDI, 2013.

F. Militão, J. Aldrich, and L. Caires. Rely-Guarantee Protocols. ECOOP, 2014.

Literature in Object & Reference Immutability

51

Page 85: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

M. Tschantz and M. D. Ernst. Javari: Adding reference immutability to Java.OOPSLA, 2005.

Y. Zibin, A. Potanin, M. Ali, S. Artzi, A. Kiezun, and M. D. Ernst. Object and Reference Immutability using Java Generics. ESEC/FSE, 2007.

Literature in Object & Reference Immutability

Simple extension to type system

Encoded in base types – refinements leverage immutability guarantees

52

Page 86: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Immutability Generic Java [Zibin’07]

Mutability astype parameter

53

Page 87: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Immutability Generic Java [Zibin’07]

Mutability astype parameter

This can mutate? Others can mutate?

53

Page 88: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Immutability Generic Java [Zibin’07]

Mutability astype parameter

Only immutable portions in refinement

This can mutate? Others can mutate?

53

Page 89: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Immutability Generic Java [Zibin’07]

54

Page 90: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Immutability Generic Java [Zibin’07]

Call to is flagged as an error,because may only be

applied to receivers

54

Page 91: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Challenges Solutions we used

AssignmentsSSA Transformation

MutabilityExtend type system with immutability guarantees

OverloadingTwo-phased typing

Annotation Overhead Liquid Types

55

Page 92: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Overloading

Value Based

56

Page 93: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Value Based Overloading

Function reflects upon and behaves according to types of its arguments

57

Page 94: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Value Based Overloading

Function reflects upon and behaves according to types of its arguments

#args Signature

2

3

57

Page 95: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Value Based Overloading

Function reflects upon and behaves according to types of its arguments

#args Signature

2

3

1st behavior – 3 args:is of type

57

Page 96: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Value Based Overloading

Function reflects upon and behaves according to types of its arguments

#args Signature

2

3

2nd behavior – 2 args:is of type

57

Page 97: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Q1: What makes it challenging?

Q2: How pervasive is it?

Value Based Overloading

Function reflects upon and behaves according to types of its arguments

58

Page 98: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Type Analysis(base types)

Value Analysis(refinements)

59

Q1: What makes it challenging?

Page 99: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Type Analysis(base types)

Value Analysis(refinements)

Refinements use invariants established by base typesE.g. tracking the access requires to be array

59

Q1: What makes it challenging?

Page 100: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Type Analysis(base types)

Value Analysis(refinements)

Refinements use invariants established by base typesE.g. tracking the access requires to be array

Type reasoning requires tracking logical relationshipsE.g. base type of depends on the value of

59

Q1: What makes it challenging?

Page 101: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Type Analysis(base types)

Value Analysis(refinements)

Refinements use invariants established by base typesE.g. tracking the access requires to be array

Type reasoning requires tracking logical relationshipsE.g. base type of depends on the value of

Circular dependency complicates formal reasoning & implementation

59

Q1: What makes it challenging?

Page 102: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Q2: How pervasive is it?

60

Study set:

DefinitelyTyped: The repository for high quality TypeScript type definitions

Page 103: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Q2: How pervasive is it?

60

Study set:

DefinitelyTyped: The repository for high quality TypeScript type definitions

Page 104: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

How do we check overloaded functions?

61

Two-Phased Typing [ECOOP’15]

Page 105: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

How do we check overloaded functions?

61

Two-Phased Typing [ECOOP’15]

Page 106: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

How do we check overloaded functions?

Phase 1a. Make clones of body for each overload

61

Two-Phased Typing [ECOOP’15]

Page 107: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

How do we check overloaded functions?

Phase 1a. Make clones of body for each overload

61

Two-Phased Typing [ECOOP’15]

Page 108: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

How do we check overloaded functions?

Phase 1b. Check body under clone signature

62

Two-Phased Typing [ECOOP’15]

Page 109: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

How do we check overloaded functions?

Phase 1b. Check body under clone signature

Error: expecting type , passed of type

62

Two-Phased Typing [ECOOP’15]

Value- and path-insensitive type-checking

Page 110: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

How do we check overloaded functions?

Replace errors with , trusting they are indeed dead-code

63

Two-Phased Typing [ECOOP’15]

Phase 1b. Check body under clone signature

Page 111: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

How do we check overloaded functions?

Phase 2. Refinement Type Checking

Prove dead-code with flow- and path-sensitive analysis

64

Two-Phased Typing [ECOOP’15]

Page 112: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

How do we check overloaded functions?

Phase 2. Refinement Type Checking

Prove dead-code with flow- and path-sensitive analysis

Signature implies:

Condition makes branch’s environment inconsistent

64

Two-Phased Typing [ECOOP’15]

Page 113: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

How do we check overloaded functions?

Phase 2. Refinement Type Checking

Prove dead-code with flow- and path-sensitive analysis

Signature implies:

Condition makes branch’s environment inconsistent

64

Two-Phased Typing [ECOOP’15]

Page 114: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Also in the paper…

Scaling to TypeScript

• Type featuresObject literal typesInterface typesPrimitive typesUnsound featuresUndefined & null typesCo- & Contra-variant subtypingUnchecked overloads

type

65

• Array support

• Flexible object initializationInternal: ConstructorsExternal: Unique references

Page 115: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Also in the paper…

Scaling to TypeScript

• Type featuresObject literal typesInterface typesPrimitive typesUnsound featuresUndefined & null typesCo- & Contra-variant subtypingUnchecked overloads

type

65

Formal Results

Refinement type safety for core language

• Array support

• Flexible object initializationInternal: ConstructorsExternal: Unique references

Page 116: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Experimental Evaluation

66

Page 117: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Benchmark suite

67

File LOC

366

206

304

576

588

189

293

Total 2522

Page 118: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Benchmark suite

Octane- NavierStokes: 2D fluid motion simulator- Splay: splay tree implementation- Richards: OS kernel simulator- Raytrace: ray trace renderer

68

File LOC

366

206

304

576

588

189

293

Total 2522

Page 119: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Benchmark suite

TransducersComposable algorithmic transformations

69

File LOC

366

206

304

576

588

189

293

Total 2522

Octane- NavierStokes: 2D fluid motion simulator- Splay: splay tree implementation- Richards: OS kernel simulator- Raytrace: ray trace renderer

Page 120: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Benchmark suite

D3: A JavaScript visualization library- Array operations

TransducersComposable algorithmic transformations

70

File LOC

366

206

304

576

588

189

293

Total 2522

Octane- NavierStokes: 2D fluid motion simulator- Splay: splay tree implementation- Richards: OS kernel simulator- Raytrace: ray trace renderer

Page 121: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Microsoft’s TypeScript compiler- Parts of and

Benchmark suite

71

File LOC

366

206

304

576

588

189

293

Total 2522

D3: A JavaScript visualization library- Array operations

TransducersComposable algorithmic transformations

Octane- NavierStokes: 2D fluid motion simulator- Splay: splay tree implementation- Richards: OS kernel simulator- Raytrace: ray trace renderer

Page 122: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Annotation Overhead

63%

20%

17%

TypeScript signatures

Mutability related

Refinement types

*

* Programs need to be fully typed – no type in signatures

72

File LOCAnnots(% LOC)

366 24.6

206 9.7

304 27.3

576 14.6

588 27.6

189 26.5

293 23.4

Total 2522 21.4

Page 123: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Performance

File LOCAnnots(% LOC)

Time (sec)

366 24.6 473

206 9.7 6

304 27.3 7

576 14.6 15

588 27.6 12

189 26.5 37

293 23.4 62

Total 2522 21.4

73

Page 124: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Performance

File LOCAnnots(% LOC)

Time (sec)

366 24.6 473

206 9.7 6

304 27.3 7

576 14.6 15

588 27.6 12

189 26.5 37

293 23.4 62

Total 2522 21.4

73

More than 100 static array access sites with dynamically

computed indexes

Page 125: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Properties Tested

• Property accesses

• Array bounds checks

• Overloads

• Safe Downcasts

Class based Ad hoc type hierarchies

• User specified value properties. E.g. a function:

returns a positive number accepts non-empty arrays

74

Safe Downcasts

Ad hoc type hierarchies

Page 126: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Properties Tested

74

Safe Downcasts

Ad hoc type hierarchies

Example taken from:

Page 127: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

75

Page 128: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

TypeScript interfaces are plain JavaScript objectsno type information at runtime

75

Page 129: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

TypeScript interfaces are plain JavaScript objectsno type information at runtime

Explicit field ( ) to encode type info needed for dynamic tests

76

Page 130: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

77

Invariants

Page 131: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Invariants

78

Page 132: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Invariants

79

Page 133: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

ProblemUnchecked invariants

80

Page 134: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

ProblemUnchecked invariants

80

Page 135: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

ProblemUnchecked invariants

80

Page 136: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

81

No static ordynamic error

ProblemUnchecked invariants

Page 137: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

82

SolutionEncode invariants in refinement types

No static ordynamic error

ProblemUnchecked invariants

Page 138: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Encode type information in logic

83

Page 139: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

84

Type for accounts for possible sub-interfaces

Page 140: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

85

Bitwise ANDThe containing

object

Type for accounts for possible sub-interfaces

Page 141: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

86

Λ ⇒

Type for accounts for possible sub-interfaces

Page 142: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

87

Λ ⇒

Λ ⇒

Λ

Page 143: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

87

Λ ⇒

Λ ⇒

Λ

Page 144: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Check downcast

87

Λ ⇒

Λ ⇒

Λ

Page 145: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Check downcast

88

Λ ⇒

Λ ⇒

Λ

Invariant for

Page 146: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Check downcast

89

Λ ⇒

Λ ⇒

Λ

Invariant for Path condition:Λ

Page 147: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Check downcast

90

Invariant for Path condition:Λ ⇒

Λ ⇒

Λ ⇒

Λ

Page 148: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Check downcast

91

Invariant for Path condition:Λ ⇒

Encode type information in logic

Λ ⇒

Λ ⇒

Λ

Page 149: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

Check downcast

91

Invariant for Path condition:Λ ⇒

Encode type information in logic

Λ ⇒

Λ ⇒

Λ

Page 150: Refinement Types for TypeScriptgoto.ucsd.edu/~pvekris/docs/RefScript-pldi16-talk.pdf · Refinement Types for TypeScript Panagiotis Vekris Benjamin Cosman Ranjit Jhala University of

92

Extensible static analysis for a modern scripting language

Challenges Solutions

Assignments SSA Transformation

Mutability Extend type system with immutability guarantees

Overloading Two-phased typing

Annotation Overhead Liquid Types

Fixed type tests User specified invariants

TS

Source:

Demo: Thanks!

Refinement Types for TypeScript