ON THE COST OF TYPE-TAG SOUNDNESS Ben Greenman Zeina Migeed ON - - PowerPoint PPT Presentation

on the cost of type tag soundness
SMART_READER_LITE
LIVE PREVIEW

ON THE COST OF TYPE-TAG SOUNDNESS Ben Greenman Zeina Migeed ON - - PowerPoint PPT Presentation

ON THE COST OF TYPE-TAG SOUNDNESS Ben Greenman Zeina Migeed ON THE COST OF TYPE-TAG SOUNDNESS 1. Tag soundness 2. Performance cost of soundness 3. Evaluation method 4. Conclusions TYPE-TAG SOUNDNESS Type Soundness e : If


slide-1
SLIDE 1

ON THE COST OF TYPE-TAG SOUNDNESS

Zeina Migeed Ben Greenman

slide-2
SLIDE 2

ON THE COST OF TYPE-TAG SOUNDNESS

  • 1. Tag soundness
  • 2. Performance cost of soundness
  • 3. Evaluation method
  • 4. Conclusions
slide-3
SLIDE 3

TYPE-TAG SOUNDNESS

slide-4
SLIDE 4

Type Soundness

No undefined behavior Type-based reasoning If then either:

  • and
  • diverges
  • (division by zero, etc.)

⊢ e : τ ⊢ v : τ e v * e Error * e

slide-5
SLIDE 5

If then either:

  • and
  • diverges
  • (division by zero, etc.)

Type Soundness

⊢ e : τ e v * e Error * e ⊢ v : τ

slide-6
SLIDE 6

If then either:

  • and
  • diverges
  • (division by zero, etc.)

Tag Soundness

⊢ e : τ e v * e Error * e ⊢ v : ⌊τ⌋

slide-7
SLIDE 7

If then either:

  • and
  • diverges
  • (division by zero, etc.)

Tag Soundness

⊢ e : τ e v * e Error * e ⊢ v : ⌊τ⌋ ⌊Int⌋ = Int ⌊τ × τ'⌋ = Pair ⌊τ → τ'⌋ = Fun ... ⌊τ⌋ = K

slide-8
SLIDE 8

Tag Soundness

No undefined behavior Tag-based reasoning

⌊Int⌋ = Int ⌊τ × τ'⌋ = Pair ⌊τ → τ'⌋ = Fun ... ⌊τ⌋ = K

If then either:

  • and
  • diverges
  • ⊢ e : τ

⊢ v : ⌊τ⌋ e v * e Error * e

slide-9
SLIDE 9

Types vs. Tags

If and then might be:

⊢ e : Int × Int e v *

Type Soundness Tag Soundness

(0, 0) (3, 2) (-7, 9) (0, 0) (3, 2) (-7, 9) ("A", 0) (0, (1, 2)) v

slide-10
SLIDE 10

Types vs. Tags

If and then might be:

⊢ e : Int × Int

Type Soundness Tag Soundness

(0, 0) (3, 2) (-7, 9) (0, 0) (3, 2) (-7, 9) ("A", 0) (0, (1, 2)) v e v *

slide-11
SLIDE 11

* fast * slow

slide-12
SLIDE 12

Type Sound? Tag Sound?

* fast * slow

slide-13
SLIDE 13

PERFORMANCE COST OF SOUNDNESS

slide-14
SLIDE 14

e e e ?

Problem: Safe Interaction

τ τ τ

slide-15
SLIDE 15

e e e

Gradual Typing

τ τ τ

λ

slide-16
SLIDE 16

read()

Enter a value: >

User Input

e *

τ τ τ

slide-17
SLIDE 17

unzip()

Deserialization

e *

τ τ τ

0110 1110 1011

slide-18
SLIDE 18

v + v E[v,v] ... v'

Primitive Operations ( δ )

e *

Int Int Int

slide-19
SLIDE 19

Unreliable Source

e

Enter a value: >

0110 1110 1011

E[•] ?

τ

λ

slide-20
SLIDE 20

e v ?

Option 1: Trust

τ τ

slide-21
SLIDE 21

e ?

Option 2: Check

τ

vτ ... vτ

slide-22
SLIDE 22

e ?

Option 2: Check

τ

vτ ...

COST OF SOUNDNESS

slide-23
SLIDE 23

?

Cost of Types ( )

Int × Int

(6,1)

Int × Int

(6,1)

Int × Int

(6,1)

Int × Int

(6,1) * slow

slide-24
SLIDE 24

?

Cost of Tags ( )

Int × Int

(6,1)

Int × Int

(6,1) * fast

slide-25
SLIDE 25

COST OF SOUNDNESS IN RETICULATED

slide-26
SLIDE 26

e e e

Retic vs. Python

τ τ τ

slide-27
SLIDE 27

Reticulated

def dist(pt : Tuple(Int,Int)) -> Int: x = pt[0] y = pt[1] return abs(x + y)

slide-28
SLIDE 28

Reticulated

def dist(pt : Tuple(Int,Int)) -> Int: x = pt[0] y = pt[1] return abs(x + y) dist((0, 0)) *

slide-29
SLIDE 29

Reticulated

def dist(pt : Tuple(Int,Int)) -> Int: x = pt[0] y = pt[1] return abs(x + y) dist("NaN") Expected Tuple *

slide-30
SLIDE 30

Reticulated

def dist(pt : Tuple(Int,Int)) -> Int: x = pt[0] y = pt[1] return abs(x + y) dist((0, "NaN")) Expected Int *

slide-31
SLIDE 31

Evaluation Method

slide-32
SLIDE 32
  • 1. Fully-Typed
slide-33
SLIDE 33
  • 2. Configurations
slide-34
SLIDE 34

7s 11s 5s 4s 9s 2s 5s 24s 9s 14s 5s 21s 9s 6s 9s 8s

  • 3. Measure
slide-35
SLIDE 35

7s 11s 5s 4s 9s 2s 5s 24s 9s 14s 5s 21s 9s 6s 9s 8s

What % have at most Dx overhead? D = 4, vs.

slide-36
SLIDE 36

What % have at most Dx overhead? D = 4, vs.

slide-37
SLIDE 37

Evaluation Method

O(2)

2

2

  • r
slide-38
SLIDE 38

EXPERIMENT & RESULTS

slide-39
SLIDE 39

Benchmarks

DLS 2014 POPL 2017 PEPM 2018 futen call_method espionage http2 call_simple pythonflow slowSHA chaos take5 aespython fannkuch sample_fsm stats go meteor nbody nqueens pidigits pystone spectralnorm

slide-40
SLIDE 40

# Typed Components

DLS 2014 POPL 2017 PEPM 2018 15 7 12 4 6 12 17 15 16 34 * 1 19 * 79 * 7 8 5 2 5 14 5

slide-41
SLIDE 41

Exhaustive Results

What % of configurations have at most 4x overhead?

100% 50%

4x

slide-42
SLIDE 42

Exhaustive Results

What % of configurations have at most Dx overhead?

100% 50%

4x 2x 6x 8x 1x

slide-43
SLIDE 43

Exhaustive Results

What % of configurations have at most Dx overhead?

100% 50%

4x 2x 6x 8x 1x

slide-44
SLIDE 44

Approximate Results

What % of configurations have at most 4x overhead, based on R samples of S configurations each?

100% 50%

4x

slide-45
SLIDE 45

Approximate Results

What % of configurations have at most Dx overhead, based on R samples of S configurations each?

100% 50%

4x 2x 6x 8x 1x

slide-46
SLIDE 46

Approximate Results

What % of configurations have at most Dx overhead, based on R samples of S configurations each?

100% 50%

4x 2x 6x 8x 1x

slide-47
SLIDE 47

100% 50%

4x 2x 6x 8x

100% 50%

4x 2x 6x 8x

espionage 4,096 configurations aespython 10 samples


  • f 340 configurations

1x 1x

slide-48
SLIDE 48
slide-49
SLIDE 49

Cost of Tag Soundness

  • Worst-case overhead: under 10x
slide-50
SLIDE 50

Type Soundness Tag Soundness 1x 1x 1x 1x 1x 1x 2x 2x 2x 3x 3x 3x 3x 5x 7x 8x 7x 7x 6x 6x 2x 43x 27x 1527x 233x 292x 1x 1x 10x 1x 29x 5x 32x 1x 34x 47x 5x 2x 139x 4x This is an APPLES to ORANGES comparison!

slide-51
SLIDE 51

Cost of Tag Soundness

  • Worst-case overhead: under 10x
  • Best-case overhead: 1x -- 4x
  • adding types never* improves performance
  • Slowest configuration: fully-typed
  • Overhead number of type annotations

slide-52
SLIDE 52
slide-53
SLIDE 53
slide-54
SLIDE 54

Runtime vs. # Types

slide-55
SLIDE 55

Runtime vs. # Types

slide-56
SLIDE 56

Speedup?

  • Unsound optimization for

read-only values (tuples)

  • Double-checks method

calls

slide-57
SLIDE 57

Runtime vs. # Types

slide-58
SLIDE 58

Experiment

  • granularity: functions & class-fields
  • 10 samples of [10 * (F + C)] configurations
  • Karst at Indiana University cluster (32GB RAM, 250GB other)
  • Reticulated, master branch, commit e478343
  • Python 3.4.3
  • 40 iterations per configuration, report average
  • 200 values of D on x-axis
slide-59
SLIDE 59

POPL 2017

slide-60
SLIDE 60
slide-61
SLIDE 61

References

  • Vitousek, Swords, Siek. Big Types in Little

Runtime: Open-World Soundness and Collaborative Blame for Gradual Type Systems. POPL 2017

  • Takikawa, Feltey, Greenman, New, Vitek, Felleisen.

Is Sound Gradual Typing Dead? POPL 2016.

slide-62
SLIDE 62

UNUSED SLIDES

slide-63
SLIDE 63

⊢ e : τ ⊢ e' : τ' ???

slide-64
SLIDE 64

Takikawa Method

  • granularity
  • experimental modules, fixed modules
  • configurations
  • baseline
  • performance ratio