1 / 37

Continuation Marks

Continuation Marks. A john clements talk. What are Continuation Marks?. What are Continuation Marks?. What are Continuations?. What are Continuation Marks?. What are Continuations?. Continuations. Paren-hackers. Contexts. Stacks. Compiler-writers. Semanticists. Contexts. Stacks.

henriette
Download Presentation

Continuation Marks

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Continuation Marks A john clements talk

  2. What are Continuation Marks?

  3. What are Continuation Marks? What are Continuations?

  4. What are Continuation Marks? What are Continuations? Continuations Paren-hackers Contexts Stacks Compiler-writers Semanticists

  5. Contexts Stacks Compiler-writers Semanticists (let*-2vals ([kept-vars (cond [(eq? tail-bound 'all) free-vars] [else (filter (lambda (varref) (ormap (lambda (binding) (bound-identifier=? binding varref)) tail-bound)) free-vars)])] [var-clauses (map (lambda (x) (list x (d->so `(quote-syntax ,x)))) kept-vars)] [let-bindings (filter (lambda (var) (case (syntax-property var 'stepper-binding-type) ((let-bound) #t) ((lambda-bound stepper-temp top-level) #f) (else (error 'make-debug-info "varref ~a's binding-type info \ was not recognized: ~a" (syntax-e var) (syntax-property var 'stepper-binding-type))))) kept-vars)] [lifter-syms (map get-lifted-var let-bindings)] [quoted-lifter-syms (map (lambda (b) (d->so `(quote-syntax ,b))) lifter-syms)] [let-clauses (map list lifter-syms quoted-lifter-syms)]) (make-full-mark source label (append var-clauses (if lifting? let-clauses null))))

  6. Contexts Stacks Compiler-writers Semanticists (let*-2vals ([kept-vars (cond [(eq? tail-bound 'all) free-vars] [else (filter (lambda (varref) (ormap (lambda (binding) (bound-identifier=? binding varref)) tail-bound)) free-vars)])] [var-clauses (map (lambda (x) (list x (d->so `(quote-syntax ,x)))) kept-vars)] [let-bindings (filter (lambda (var) (case (syntax-property var 'stepper-binding-type) ((let-bound) #t) ((lambda-bound stepper-temp top-level) #f) (else (error 'make-debug-info "varref ~a's binding-type info \ was not recognized: ~a" (syntax-e var) (syntax-property var 'stepper-binding-type))))) kept-vars)] [lifter-syms (map get-lifted-var let-bindings)] [quoted-lifter-syms (map (lambda (b) (d->so `(quote-syntax ,b))) lifter-syms)] [let-clauses (map list lifter-syms quoted-lifter-syms)]) (make-full-mark source label (append var-clauses (if lifting? let-clauses null)))) mark mark mark

  7. Closing the Loop Programming Language Marks

  8. Closing the Loop Programming Language with marks

  9. Closing the Loop oops! Programming Language with marks

  10. Closing the Loop Programming Language with marks

  11. Contexts Stacks Compiler-writers Semanticists (let*-2vals ([kept-vars (cond [(eq? tail-bound 'all) free-vars] [else (filter (lambda (varref) (ormap (lambda (binding) (bound-identifier=? binding varref)) tail-bound)) free-vars)])] [var-clauses (map (lambda (x) (list x (d->so `(quote-syntax ,x)))) kept-vars)] [let-bindings (filter (lambda (var) (case (syntax-property var 'stepper-binding-type) ((let-bound) #t) ((lambda-bound stepper-temp top-level) #f) (else (error 'make-debug-info "varref ~a's binding-type info \ was not recognized: ~a" (syntax-e var) (syntax-property var 'stepper-binding-type))))) kept-vars)] [lifter-syms (map get-lifted-var let-bindings)] [quoted-lifter-syms (map (lambda (b) (d->so `(quote-syntax ,b))) lifter-syms)] [let-clauses (map list lifter-syms quoted-lifter-syms)]) (make-full-mark source label (append var-clauses (if lifting? let-clauses null)))) mark mark mark

  12. Contexts Stacks Compiler-writers Semanticists (let*-2vals ([kept-vars (cond [(eq? tail-bound 'all) free-vars] [else (filter (lambda (varref) (ormap (lambda (binding) (bound-identifier=? binding varref)) tail-bound)) free-vars)])] [var-clauses (map (lambda (x) (list x (d->so `(quote-syntax ,x)))) kept-vars)] [let-bindings (filter (lambda (var) (case (syntax-property var 'stepper-binding-type) ((let-bound) #t) ((lambda-bound stepper-temp top-level) #f) (else (error 'make-debug-info "varref ~a's binding-type info \ was not recognized: ~a" (syntax-e var) (syntax-property var 'stepper-binding-type))))) kept-vars)] [lifter-syms (map get-lifted-var let-bindings)] [quoted-lifter-syms (map (lambda (b) (d->so `(quote-syntax ,b))) lifter-syms)] [let-clauses (map list lifter-syms quoted-lifter-syms)]) (make-full-mark source label (append var-clauses (if lifting? let-clauses null))))

  13. New Language Forms

  14. New Language Forms • Introducing marks: • Observing marks: (with-continuation-mark M M) mark value body (current-continuation-marks)

  15. New Language Forms Synopsis of Reduction Semantics: New Contexts: E = [] | (E M) | (V E) | … | (w-c-m V E) * *With restrictions on successive w-c-m’s New Reductions: E[(w-c-m V V)] -> E[V] E[(w-c-m V (w-c-m M M))] -> E[(w-c-m M M)] E[(c-c-m)] -> E[X(E)]

  16. New Language Forms (define (loop x) (w-c-m x (loop (+ x 1)))) (loop 0) -> (w-c-m 0 (loop (+ 0 1))) -> (w-c-m 0 (loop 1)) -> (w-c-m 0 (w-c-m 1 (loop (+ 1 1)))) -> (w-c-m 1 (loop (+ 1 1))) -> (w-c-m 1 (loop 2)) -> (w-c-m 1 (w-c-m 2 (loop (+ 2 1)))) -> ...

  17. New Language Forms (define (f x) (w-c-m x (+ (f x) 1))) (loop 0) -> (w-c-m 0 (+ (f 0) 1)) -> (w-c-m 0 (+ (w-c-m 0 (+ (f 0) 1)) 1)) -> (w-c-m 0 (+ (w-c-m 0 (+ (w-c-m 0 (+ (f 0) 1)) 1)) 1)) -> (w-c-m 0 (+ (w-c-m 0 (+ (w-c-m 0 (+ (w-c-m 0 (+ (f 0) 1)) 1)) 1)) 1)) -> ...

  18. Expressiveness • Conjecture: cannot be expressed in a “tail-call preserving way” by state, continuations, etc. • Difficult to state claim clearly

  19. Using Continuation Marks (to build a stepper)

  20. Building a Stepper (using continuation marks)

  21. Building a Stepper • Why a Stepper? • A stepper is a sound debugger • A stepper is a complete debugger • … with a suitable proof • How to build a stepper? • Annotation with continuation marks • Non-invasive (well-defined) implementation

  22. Building a Stepper • Annotation: • Marks must contain: • Source position • Values of free variables • Breakpoints • Where? Everywhere. • No, even more than that.

  23. Building a Stepper Pragmatics

  24. Pragmatics • Orthogonality of annotations • Add a ‘key’ to each mark: • Marks with different keys are orthogonal (with-continuation-mark M M M) key mark body (current-continuation-marks M)

  25. Macro Reversal (cond [a b] [c d]) ?? R? R (if c d (error)) (if a b (if c d (error)))

  26. “Needed” variables • Variables stored in each mark • Avoid duplication • Store all variables which are not guaranteed to occur in an enclosing mark.

  27. “Needed” variables Variable “a” is not needed in these contexts (letrec ([a 13] [b (+ a 14)] [c (lambda () a)]) (g a) Variable “a” is needed in these contexts

  28. Opaque Values • Closures: procedures, classes • Structures, Units • Put them in a table

  29. Before & After Steps (+ 1 (if true 3 4)) -> (+ 1 3) Requires additional breakpoints for: • tail-position expressions • results of primitive applications

  30. Unannotated Code • Libraries • Partial Annotation • Complete Reconstruction not possible • Detection necessary

  31. Lifting & Renaming • Newly created closures go to top level • Names must be assigned at runtime • Extra binding created

  32. Lightweight Inspection (what else can we do with continuation marks?)

  33. Stack Inspection • Widely used security measure • Associate privileges with ‘principals’ • Inspect the stack to make guarantees about execution • Implemented in a variety of ways: • Stack Inspection • “Security-passing style” ...

  34. Stack Inspection • … or using continuation marks • Preserves tail-call optimization • Place marks on the “bad” code T T G G OLD NEW

  35. Aspect-Oriented Programming • Allows textual separation of program aspects. • May be implemented by a static annotation • … with certain run-time decisions • “cflow” rules in AspectJ • But what about tail-call optimization? • May be recovered with continuation marks

  36. Lightweight Inspection • Other uses waiting to be found…

  37. Lightweight Inspection • Other uses waiting to be found… • Tell me yours!

More Related