COMPLETE MONITORS FOR GRADUAL TYPES Ben Greenman Matthias - - PowerPoint PPT Presentation

complete monitors for gradual types
SMART_READER_LITE
LIVE PREVIEW

COMPLETE MONITORS FOR GRADUAL TYPES Ben Greenman Matthias - - PowerPoint PPT Presentation

Ben Greenman Matthias Felleisen Christos Dimoulas at at at COMPLETE MONITORS FOR GRADUAL TYPES Ben Greenman Matthias Felleisen Christos Dimoulas at at at COMPLETE MONITORS FOR GRADUAL TYPES a careful analysis of the mixed-typed


slide-1
SLIDE 1

COMPLETE MONITORS FOR GRADUAL TYPES

Ben Greenman Matthias Felleisen Christos Dimoulas

at at at

slide-2
SLIDE 2

COMPLETE MONITORS FOR GRADUAL TYPES

Ben Greenman Matthias Felleisen Christos Dimoulas

at at at

a careful analysis

  • f the mixed-typed

design space

slide-3
SLIDE 3

Type soundness is not enough Complete monitoring is crucial for meaningful gradual types "Incomplete" monitoring provides a way to measure the quality of blame errors *from ESOP 2012 *

slide-4
SLIDE 4

Mixed-Typed Language

slide-5
SLIDE 5

Mixed-Typed Language

U T U U T

Untyped/Typed mix

U

= untyped code

T

= simply-typed (no 'Dynamic' type) code

slide-6
SLIDE 6

A Few Motivations

U T U U T

slide-7
SLIDE 7

A Few Motivations

U T U U T

Prototyping

slide-8
SLIDE 8

A Few Motivations

U T U U T

Prototyping write untyped code, rely on types

slide-9
SLIDE 9

A Few Motivations

U T U U T

Prototyping write untyped code, rely on types Re-Use

slide-10
SLIDE 10

A Few Motivations

U T U U T

Prototyping write untyped code, rely on types Re-Use write typed code, use old libraries

slide-11
SLIDE 11

Many Implementations ...

JavaScript Flow + Racket Typed Racket + Python Reticulated + Python Mypy + PHP Hack + JavaScript TypeScript +

slide-12
SLIDE 12

Many Implementations ...

JavaScript Flow + Racket Typed Racket + Python Reticulated + Python Mypy + PHP Hack + JavaScript TypeScript +

... diffcult to compare

UTU U T

slide-13
SLIDE 13

Many Models, too

GTLC AGT λH λ*

UTU U T

slide-14
SLIDE 14

Goal: Characterize the Landscape

slide-15
SLIDE 15

Non-Goal: Restrict Landscape

slide-16
SLIDE 16
slide-17
SLIDE 17

Warmup: Optional Typing / Erasure

slide-18
SLIDE 18

Example: Optional Typing

function f (x : [N,N]) { ... fst x ... }

T

slide-19
SLIDE 19

Example: Optional Typing

function f (x : [N,N]) { ... fst x ... }

T

f(9)

U

slide-20
SLIDE 20

Example: Optional Typing

function f (x : [N,N]) { ... fst x ... }

T

f(9)

U

Error: 9 is not a pair

slide-21
SLIDE 21

Example: Optional Typing

function f (x : [N,N]) { ... fst x ... }

T

f(9)

U

Error: 9 is not a pair types are meaningless at run-time cannot help debug a faulty program

slide-22
SLIDE 22

= Does Not Preserve Types

Uni sound

slide-23
SLIDE 23

= Does Not Preserve Types

Uni sound

"type" sound

slide-24
SLIDE 24

ICFP '18

slide-25
SLIDE 25

ICFP '18 : Three Semantics, Soundnesses

slide-26
SLIDE 26

ICFP '18 : Three Semantics, Soundnesses

Erasure semantics

  • types predict nothing
slide-27
SLIDE 27

ICFP '18 : Three Semantics, Soundnesses

Erasure semantics

  • types predict nothing

Transient semantics

  • types predict the top-level shape of values
  • enforced by tag checks
slide-28
SLIDE 28

ICFP '18 : Three Semantics, Soundnesses

Erasure semantics

  • types predict nothing

Transient semantics

  • types predict the top-level shape of values
  • enforced by tag checks

Natural semantics

  • types predict the full behavior of values
  • enforced by higher-order wrappers
slide-29
SLIDE 29

ICFP '18 : Three Semantics, Soundnesses

Erasure semantics

  • types predict nothing

Transient semantics

  • types predict the top-level shape of values
  • enforced by tag checks

Natural semantics

  • types predict the full behavior of values
  • enforced by higher-order wrappers

Uni sound ⌊T⌋ sound T sound

Erasure semantics

  • types predict nothing

Transient semantics

  • types predict the top-level shape of values
  • enforced by tag checks

Natural semantics

  • types predict the full behavior of values
  • enforced by higher-order wrappers
slide-30
SLIDE 30

ICFP '18: A Spectrum of Type Soundness

Uni sound

slide-31
SLIDE 31

ICFP '18: A Spectrum of Type Soundness

Uni sound ⌊T⌋ sound Uni sound T sound Erasure Natural Transient

slide-32
SLIDE 32

⌊T⌋ sound T sound Natural Transient

slide-33
SLIDE 33

⌊T⌋ sound T sound Natural Transient

Transient semantics

  • types predict the top-level shape of values
  • enforced by tag checks

Natural semantics

  • types predict the full behavior of values
  • enforced by higher-order wrappers

⌊T⌋ sound T sound

Transient semantics

  • types predict the top-level shape of values
  • enforced by tag checks

Natural semantics

  • types predict the full behavior of values
  • enforced by higher-order wrappers
slide-34
SLIDE 34

⌊T⌋ sound T sound Natural Transient

slide-35
SLIDE 35

⌊T⌋ sound T sound Natural Transient Amnesic

Amnesic semantics

  • enforce tag checks ⌊T⌋

with higher-order wrappers

  • same behavior as Transient
  • same type soundness as Natural

OOPSLA '19

Greenberg POPL '15 Castagna, Lanvin ICFP '17

slide-36
SLIDE 36

Type Soundness is NOT ENOUGH

⌊T⌋ sound Uni sound T sound ??? Erasure Natural Transient Amnesic

slide-37
SLIDE 37

Example: Transient/Amnesic vs. Natural

slide-38
SLIDE 38

Example: Transient/Amnesic vs. Natural

Prototyping

slide-39
SLIDE 39

Example: Transient/Amnesic vs. Natural

Prototyping Library Re-Use

slide-40
SLIDE 40

Example: Transient/Amnesic vs. Natural

Prototyping Library Re-Use Combine: untyped script + typed API + untyped library via a higher-order value

slide-41
SLIDE 41

Example: Transient/Amnesic vs. Natural

  • 1. plot data
  • 2. listen for a click
  • 3. draw an image

Clickable Plot

1

slide-42
SLIDE 42

Example: Transient/Amnesic vs. Natural

  • 1. plot data
  • 2. listen for a click
  • 3. draw an image

Clickable Plot

2

slide-43
SLIDE 43

Example: Transient/Amnesic vs. Natural

  • 1. plot data
  • 2. listen for a click
  • 3. draw an image

Clickable Plot

3

slide-44
SLIDE 44

Example: interactive plot

Client

U

Library

U

API

T

slide-45
SLIDE 45

Example: interactive plot

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

Library

U

API

T

slide-46
SLIDE 46

Example: interactive plot

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

API

T

slide-47
SLIDE 47

Example: interactive plot

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

slide-48
SLIDE 48

Example: interactive plot

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

slide-49
SLIDE 49

Example: interactive plot

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

Promises a pair of numbers

slide-50
SLIDE 50

Example: interactive plot

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

Promises a pair of numbers

slide-51
SLIDE 51

Example: interactive plot

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

Promises a pair of numbers Expects a pair of numbers

slide-52
SLIDE 52

Example: interactive plot

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

slide-53
SLIDE 53

Example: interactive plot

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

slide-54
SLIDE 54

Example: interactive plot

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

Sends MouseEvt value

slide-55
SLIDE 55

Example: interactive plot

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

Sends MouseEvt value

[N,N] != MouseEvt

slide-56
SLIDE 56

Example: interactive plot

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

Sends MouseEvt value

[N,N] != MouseEvt

  • Q. Does h receive

bad input?

slide-57
SLIDE 57

Example: interactive plot

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

  • Q. Does h receive

bad input?

slide-58
SLIDE 58

Example: interactive plot

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

  • Q. Does h receive

bad input?

  • A. Yes, Trans/Amns
  • A. No, Natural
slide-59
SLIDE 59

U T U

slide-60
SLIDE 60

U T U

h

slide-61
SLIDE 61

U T U

h

slide-62
SLIDE 62

U T U

h(evt)

  • Q. Do types guard the callback channel?
slide-63
SLIDE 63

U T U

h(evt)

  • Q. Do types guard the callback channel?

Transient/Amnesic: no, because the channel is between two untyped components Natural: yes, because the channel was created via typed code

slide-64
SLIDE 64

U T U

h(evt)

  • Q. Do types guard the callback channel?

Type Soundness ⇒ yes Complete Monitoring ⇒ yes

slide-65
SLIDE 65

⌊T⌋ sound Uni sound T sound Complete monitoring Erasure Natural Transient Amnesic

slide-66
SLIDE 66

Natural Transient Amnesic type soundness

T ⌊T⌋ T

complete monitoring Natural Transient Amnesic type soundness

T ⌊T⌋ T

complete monitoring

slide-67
SLIDE 67

Natural Transient Amnesic type soundness

T ⌊T⌋ T

complete monitoring Natural Transient Amnesic type soundness

T ⌊T⌋ T

complete monitoring BLAME

slide-68
SLIDE 68

Natural, Blame

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

slide-69
SLIDE 69

Natural, Blame

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

Error: MouseEvt is not a pair

slide-70
SLIDE 70

Natural, Blame

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

Error: expected [N,N] got MouseEvt blaming Library assuming the API types are correct

slide-71
SLIDE 71

Transient/Amnesic, Blame

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

slide-72
SLIDE 72

Transient/Amnesic, Blame

class ClickPlot { constructor(

  • nClick){...}

mouseHandler(evt){ i = onClick(evt) // draw i } show(){...} } Library

U

type ClickPlot { constructor( ([N,N]) => Image) mouseHandler : (MouseEvt) => Void show : () => Void } API

T

function h(x) { if (0 < fst x): pumpkin else: fish } p = ClickPlot(h) p.show() // click Client

U

Error: <obj> is not a pair blaming: Client / API API / Library

slide-73
SLIDE 73

U T U U T

v

Blame Properties

  • 1. blame only

responsible edges

  • 2. blame all

responsible edges

  • 3. blame exactly the responsible edges
slide-74
SLIDE 74

U T U U T

v

Blame Properties

  • 1. blame only

responsible edges

  • 2. blame all

responsible edges

  • 3. blame exactly the responsible edges

Blame Soundness Blame Completeness

  • B. Soundness + B. Completeness
slide-75
SLIDE 75

Natural Transient Amnesic type soundness

T ⌊T⌋ T

complete monitoring blame soundness blame completeness Natural Transient Amnesic type soundness

T ⌊T⌋ T

complete monitoring blame soundness blame completeness

slide-76
SLIDE 76

Natural Transient Amnesic type soundness

T ⌊T⌋ T

complete monitoring blame soundness blame completeness Natural Transient Amnesic type soundness

T ⌊T⌋ T

complete monitoring blame soundness blame completeness

slide-77
SLIDE 77

Every Typed Language is Mixed-Typed

Many typed languages trust untyped code

slide-78
SLIDE 78

Every Typed Language is Mixed-Typed

Many typed languages trust untyped code Gradual typing makes these boundaries visible ...

U T

slide-79
SLIDE 79

Every Typed Language is Mixed-Typed

Many typed languages trust untyped code Gradual typing makes these boundaries visible ...

U T

... and challenges our notions of types and what types mean

slide-80
SLIDE 80

Complete monitoring strengthens type soundness for programs that compose typed and untyped and enables precise statements about the quality of blame

slide-81
SLIDE 81

github.com/nuprl/gfd-oopsla-2019

Code + Proofs:

slide-82
SLIDE 82

Natural Transient Amnesic type soundness

T ⌊T⌋ T

complete monitoring* blame soundness* blame completeness* Natural Transient Amnesic type soundness

T ⌊T⌋ T

complete monitoring* blame soundness* blame completeness*

slide-83
SLIDE 83

⌊T⌋ sound Uni sound T sound Complete monitoring Erasure Natural Transient Amnesic