1 From Stack Traces to Lazy Rewriting Sequences Stephen Chang , Eli - - PowerPoint PPT Presentation

1 from stack traces to lazy rewriting sequences
SMART_READER_LITE
LIVE PREVIEW

1 From Stack Traces to Lazy Rewriting Sequences Stephen Chang , Eli - - PowerPoint PPT Presentation

1 From Stack Traces to Lazy Rewriting Sequences Stephen Chang , Eli Barzilay, John Clements*, Matthias Felleisen Northeastern University *California Polytechnic State University 10/5/2011 2 Debugging lazy programs is hard. 3 Freja (Nilsson


slide-1
SLIDE 1

1

slide-2
SLIDE 2

From Stack Traces to Lazy Rewriting Sequences

Stephen Chang, Eli Barzilay, John Clements*, Matthias Felleisen Northeastern University *California Polytechnic State University

10/5/2011

2

slide-3
SLIDE 3

Debugging lazy programs is hard.

3

slide-4
SLIDE 4

Freja (Nilsson and Fritzson 1992) Hat (Sparud and Runciman, 1997) Buddha (Pope, 1998) HOOD (Gill, 2000) New Hat (Wallace et al., 2001) HsDebug (Ennals and Peyton Jones, 2003) Rectus (Murk and Kolmoldin, 2006) GHCi debugger (Marlow et al., 2007) StackTrace (Allwood et al., 2009)

4

slide-5
SLIDE 5

Freja (Nilsson and Fritzson 1992) Hat (Sparud and Runciman, 1997) Buddha (Pope, 1998) HOOD (Gill, 2000) New Hat (Wallace et al., 2001) HsDebug (Ennals and Peyton Jones, 2003) Rectus (Murk and Kolmoldin, 2006) GHCi debugger (Marlow et al., 2007) StackTrace (Allwood et al., 2009)

What do you think is Haskell's most glaring weakness / blind spot / problem? [Tibell, Knowlson 2011]

Inadequate Tools (50%)

5

slide-6
SLIDE 6

[State of Haskell Survey 2011]

6

slide-7
SLIDE 7

[State of Haskell Survey 2011]

"A debugger adjusted to the complexity of debugging lazily evaluated structures." (weeks)

7

slide-8
SLIDE 8

[State of Haskell Survey 2011]

"A debugger adjusted to the complexity of debugging lazily evaluated structures." (weeks) "Laziness is hard to come to grips with. It's powerful and good, but it also causes strange problems that a beginner often cannot diagnose." (months)

8

slide-9
SLIDE 9

[State of Haskell Survey 2011]

"A debugger adjusted to the complexity of debugging lazily evaluated structures." (weeks) "Laziness is hard to come to grips with. It's powerful and good, but it also causes strange problems that a beginner often cannot diagnose." (months) "I think that a good debugger that lets me step through a program /quickly and comfortably/ would be a great help." (1yr)

9

slide-10
SLIDE 10

[State of Haskell Survey 2011]

"A debugger adjusted to the complexity of debugging lazily evaluated structures." (weeks) "Laziness is hard to come to grips with. It's powerful and good, but it also causes strange problems that a beginner often cannot diagnose." (months) "I think that a good debugger that lets me step through a program /quickly and comfortably/ would be a great help." (1yr) "I'd love to see some debugging (~step by step evaluation/run tracing) support." (2yrs)

10

slide-11
SLIDE 11

[State of Haskell Survey 2011]

"A debugger adjusted to the complexity of debugging lazily evaluated structures." (weeks) "Laziness is hard to come to grips with. It's powerful and good, but it also causes strange problems that a beginner often cannot diagnose." (months) "I think that a good debugger that lets me step through a program /quickly and comfortably/ would be a great help." (1yr) "I'd love to see some debugging (~step by step evaluation/run tracing) support." (2yrs) "Debugging lazy code" (4 yrs)

11

slide-12
SLIDE 12

[State of Haskell Survey 2011]

"A debugger adjusted to the complexity of debugging lazily evaluated structures." (weeks) "Laziness is hard to come to grips with. It's powerful and good, but it also causes strange problems that a beginner often cannot diagnose." (months) "I think that a good debugger that lets me step through a program /quickly and comfortably/ would be a great help." (1yr) "I'd love to see some debugging (~step by step evaluation/run tracing) support." (2yrs) "Debugging lazy code" (4 yrs)

Better lazy step-based tools are needed.

12

slide-13
SLIDE 13

What's a "step"?

13

slide-14
SLIDE 14

HsDebug

[Ennals and Peyton Jones 2003]

14

slide-15
SLIDE 15

HsDebug

[Ennals and Peyton Jones 2003]

  • Evaluate expressions optimistically.

15

slide-16
SLIDE 16

HsDebug

[Ennals and Peyton Jones 2003]

  • Evaluate expressions optimistically.
  • To preserve lazy behavior, handle special cases:

non-termination errors

16

slide-17
SLIDE 17

HsDebug

[Ennals and Peyton Jones 2003]

  • Evaluate expressions optimistically.
  • To preserve lazy behavior, handle special cases:

non-termination errors

  • Too difficult to implement.

17

slide-18
SLIDE 18

Idea #1:

Debugger shouldn't change the program evaluation model.

18

slide-19
SLIDE 19

GHCi Debugger

[Marlow et al. 2007]

19

slide-20
SLIDE 20

GHCi Debugger

[Marlow et al. 2007]

  • Shows the effects of laziness.

20

slide-21
SLIDE 21

GHCi Debugger

[Marlow et al. 2007]

  • Shows the effects of laziness.
  • "having execution jump around can be distracting and confusing"

21

slide-22
SLIDE 22

GHCi Debugger

[Marlow et al. 2007]

  • Shows the effects of laziness.
  • "having execution jump around can be distracting and confusing"

test1 x y = (test2 y) + x test2 x = x * 2 test3 x = x + 1 main = print $ test1 (1 + 2) (test3 (3 + 4))

22

slide-23
SLIDE 23

GHCi Debugger

[Marlow et al. 2007]

  • Shows the effects of laziness.
  • "having execution jump around can be distracting and confusing"

test1 x y = (test2 y) + x test2 x = x * 2 test3 x = x + 1 main = print $ test1 (1 + 2) (test3 (3 + 4))

23

slide-24
SLIDE 24

GHCi Debugger

[Marlow et al. 2007]

  • Shows the effects of laziness.
  • "having execution jump around can be distracting and confusing"

test1 x y = (test2 y) + x test2 x = x * 2 test3 x = x + 1 main = print $ test1 (1 + 2) (test3 (3 + 4))

24

slide-25
SLIDE 25

GHCi Debugger

[Marlow et al. 2007]

  • Shows the effects of laziness.
  • "having execution jump around can be distracting and confusing"

test1 x y = (test2 y) + x test2 x = x * 2 test3 x = x + 1 main = print $ test1 (1 + 2) (test3 (3 + 4))

25

slide-26
SLIDE 26

GHCi Debugger

[Marlow et al. 2007]

  • Shows the effects of laziness.
  • "having execution jump around can be distracting and confusing"

test1 x y = (test2 y) + x test2 x = x * 2 test3 x = x + 1 main = print $ test1 (1 + 2) (test3 (3 + 4))

26

slide-27
SLIDE 27

GHCi Debugger

[Marlow et al. 2007]

  • Shows the effects of laziness.
  • "having execution jump around can be distracting and confusing"

test1 x y = (test2 y) + x test2 x = x * 2 test3 x = x + 1 main = print $ test1 (1 + 2) (test3 (3 + 4))

27

slide-28
SLIDE 28

GHCi Debugger

[Marlow et al. 2007]

  • Shows the effects of laziness.
  • "having execution jump around can be distracting and confusing"

test1 x y = (test2 y) + x test2 x = x * 2 test3 x = x + 1 main = print $ test1 (1 + 2) (test3 (3 + 4))

28

slide-29
SLIDE 29

GHCi Debugger

[Marlow et al. 2007]

  • Shows the effects of laziness.
  • "having execution jump around can be distracting and confusing"

test1 x y = (test2 y) + x test2 x = x * 2 test3 x = x + 1 main = print $ test1 (1 + 2) (test3 (3 + 4))

29

slide-30
SLIDE 30

GHCi Debugger

[Marlow et al. 2007]

  • Shows the effects of laziness.
  • "having execution jump around can be distracting and confusing"

test1 x y = (test2 y) + x test2 x = x * 2 test3 x = x + 1 main = print $ test1 (1 + 2) (test3 (3 + 4))

30

slide-31
SLIDE 31

GHCi Debugger

[Marlow et al. 2007]

  • Shows the effects of laziness.
  • "having execution jump around can be distracting and confusing"

test1 x y = (test2 y) + x test2 x = x * 2 test3 x = x + 1 main = print $ test1 (1 + 2) (test3 (3 + 4))

31

slide-32
SLIDE 32

GHCi Debugger

[Marlow et al. 2007]

  • Shows the effects of laziness.
  • "having execution jump around can be distracting and confusing"

test1 x y = (test2 y) + x test2 x = x * 2 test3 x = x + 1 main = print $ test1 (1 + 2) (test3 (3 + 4))

32

slide-33
SLIDE 33

GHCi Debugger

[Marlow et al. 2007]

  • Shows the effects of laziness.
  • "having execution jump around can be distracting and confusing"

test1 x y = (test2 y) + x test2 x = x * 2 test3 x = x + 1 main = print $ test1 (1 + 2) (test3 (3 + 4))

33

slide-34
SLIDE 34

GHCi Debugger

[Marlow et al. 2007]

  • Shows the effects of laziness.
  • "having execution jump around can be distracting and confusing"

test1 x y = (test2 y) + x test2 x = x * 2 test3 x = x + 1 main = print $ test1 (1 + 2) (test3 (3 + 4))

34

slide-35
SLIDE 35

GHCi Debugger

[Marlow et al. 2007]

  • Shows the effects of laziness.
  • "having execution jump around can be distracting and confusing"

test1 x y = (test2 y) + x test2 x = x * 2 test3 x = x + 1 main = print $ test1 (1 + 2) (test3 (3 + 4))

  • Step semantics correspond to low-level implementation
  • - unfamiliar to programmers.

35

slide-36
SLIDE 36

Idea #2:

Debugger should use a high-level semantics familiar to programmers.

36

slide-37
SLIDE 37

A reduction semantics-based tool

[Gibbons and Wansbrough 1996, Ariola et al. 1995]

37

slide-38
SLIDE 38

A reduction semantics-based tool

[Gibbons and Wansbrough 1996, Ariola et al. 1995]

  • Persistent arguments clutter reductions.

38

slide-39
SLIDE 39

A reduction semantics-based tool

[Gibbons and Wansbrough 1996, Ariola et al. 1995]

  • Persistent arguments clutter reductions.

39

slide-40
SLIDE 40

A reduction semantics-based tool

[Gibbons and Wansbrough 1996, Ariola et al. 1995]

  • Persistent arguments clutter reductions.

40

slide-41
SLIDE 41

A reduction semantics-based tool

[Gibbons and Wansbrough 1996, Ariola et al. 1995]

  • Persistent arguments clutter reductions.

41

slide-42
SLIDE 42

A reduction semantics-based tool

[Gibbons and Wansbrough 1996, Ariola et al. 1995]

  • Persistent arguments clutter reductions.
  • Extraneous reductions.

42

slide-43
SLIDE 43

A reduction semantics-based tool

[Gibbons and Wansbrough 1996, Ariola et al. 1995]

  • Persistent arguments clutter reductions.
  • Extraneous reductions.

43

slide-44
SLIDE 44

A reduction semantics-based tool

[Gibbons and Wansbrough 1996, Ariola et al. 1995]

  • Persistent arguments clutter reductions.
  • Extraneous reductions.

44

slide-45
SLIDE 45

A reduction semantics-based tool

[Gibbons and Wansbrough 1996, Ariola et al. 1995]

  • Persistent arguments clutter reductions.
  • Extraneous reductions.

45

slide-46
SLIDE 46

A reduction semantics-based tool

[Gibbons and Wansbrough 1996, Ariola et al. 1995]

  • Persistent arguments clutter reductions.
  • Extraneous reductions.

46

slide-47
SLIDE 47

Idea #3: A more "intuitive" lazy semantics is needed.

47

slide-48
SLIDE 48

Our Work

48

slide-49
SLIDE 49

Our Work

A step-based lazy debugging tool, based on a high-level "intuitive" lazy semantics.

49

slide-50
SLIDE 50

Our Work

  • An algebraic stepper tool for Lazy Racket.

50

slide-51
SLIDE 51

Our Work

  • An algebraic stepper tool for Lazy Racket.
  • A new, "intuitive" semantics for lazy languages,

51

slide-52
SLIDE 52

Our Work

  • An algebraic stepper tool for Lazy Racket.
  • A new, "intuitive" semantics for lazy languages,
  • Theory:

corresponds to existing lazy semantics.

52

slide-53
SLIDE 53

Our Work

  • An algebraic stepper tool for Lazy Racket.
  • A new, "intuitive" semantics for lazy languages,
  • Theory:

corresponds to existing lazy semantics. Tool is correct with respect to

53

slide-54
SLIDE 54

"intuitive"

54

slide-55
SLIDE 55

"intuitive" = syntactic

55

slide-56
SLIDE 56

"intuitive" = syntactic + substitution-based

56

slide-57
SLIDE 57

Demo!

57

slide-58
SLIDE 58

Semantics

58

slide-59
SLIDE 59

: Syntax

59

slide-60
SLIDE 60

: Two-phase Steps

60

slide-61
SLIDE 61

: Two-phase Steps 1) Reduce next redex.

61

slide-62
SLIDE 62

: Two-phase Steps 1) Reduce next redex.

fresh

62

slide-63
SLIDE 63

: Two-phase Steps 1) Reduce next redex.

fresh

2) If redex is under a label, update all other identically labeled expressions to match.

63

slide-64
SLIDE 64

: Two-phase Steps, Pictorially

64

slide-65
SLIDE 65

: Two-phase Steps, Pictorially

65

slide-66
SLIDE 66

: Two-phase Steps, Pictorially

66

slide-67
SLIDE 67

: Two-phase Steps, Pictorially

67

slide-68
SLIDE 68

: Two-phase Steps, Pictorially

68

slide-69
SLIDE 69

Implementation

69

slide-70
SLIDE 70

Continuation Marks

Mechanism for lightweight stack access. [Clements 2001]

70

slide-71
SLIDE 71

Continuation Marks

Mechanism for lightweight stack access. [Clements 2001] Continuation marks used in Racket implementation of:

71

slide-72
SLIDE 72

Continuation Marks

Mechanism for lightweight stack access. [Clements 2001] Continuation marks used in Racket implementation of: stack tracer, stepper, debugger, profiler, exception handling, dynamic binding, delimited continuations, web server

72

slide-73
SLIDE 73

Stepper Architecture

73

slide-74
SLIDE 74

Continuation marks are easily added to any language.

74

slide-75
SLIDE 75

Continuation marks are easily added to any language.

["Implementing continuation marks in JavaScript" (Clements et al., 2008)]

75

slide-76
SLIDE 76

Continuation marks are easily added to any language.

["Implementing continuation marks in JavaScript" (Clements et al., 2008)] ["Finding the needle: stack traces for GHC" (Allwood et al., 2009)]

76

slide-77
SLIDE 77

: Correctness Correspondence exists between and:

77

slide-78
SLIDE 78

: Correctness Correspondence exists between and:

  • Low-level semantics (i.e., Launchbury)

78

slide-79
SLIDE 79

: Correctness Correspondence exists between and:

  • Low-level semantics (i.e., Launchbury)
  • Reduction semantics (i.e., Ariola et al.)

79

slide-80
SLIDE 80

To Do

80

slide-81
SLIDE 81

To Do

  • Advanced navigation features, breakpointing

81

slide-82
SLIDE 82

To Do

  • Advanced navigation features, breakpointing
  • Additional inspection of program state

82

slide-83
SLIDE 83

To Do

  • Advanced navigation features, breakpointing
  • Additional inspection of program state
  • Scaling to large programs

83

slide-84
SLIDE 84

Summary

  • New semantics for lazy evaluation:

Easy to understand and suitable for use in a debugger. Equivalent to existing lazy semantics.

  • Algebraic stepper for Lazy Racket, based on

Proven correct. Easily ported to any lazy language via continuation marks.

84

slide-85
SLIDE 85

Summary

  • New semantics for lazy evaluation:

Easy to understand and suitable for use in a debugger. Equivalent to existing lazy semantics.

  • Algebraic stepper for Lazy Racket, based on

Proven correct. Easily ported to any lazy language via continuation marks.

Thanks!

http://racket-lang.org/

85