Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Polymorphic Effect System

Polymorphic Effect System

paper presentation for the class SAV

Cédric Bastin

May 24, 2015
Tweet

More Decks by Cédric Bastin

Other Decks in Research

Transcript

  1. Polymorphic Effect System John M. Lucassen, David K.Gifford POPL 1988

    Cedric Bastin, Manos Koukoutos EPFL cedric.bastin@epfl.ch emmanouil.koukoutos@epfl.ch May 13, 2015 Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 1 / 26
  2. Overview 1 Introduction 2 Effect System 3 Inference Rules 4

    Semantics 5 Effect Masking Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 2 / 26
  3. Related Work Abstract Interpretation: conventional flow analysis Calculate local effect

    of each subroutine Transitive closure / graph flow algorithm Calling pattern between subroutines need to be known statically ⇒ cannot deal with first-class subroutines Syntactic Interference Control: Reynolds ’78 Method to compute the support set and allow concurrent evaluation when the support sets don’t overlap Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 3 / 26
  4. What does effect analysis enable? Combine advantages of functional and

    imperative programming Concurrent analysis Compiler optimization Compile for parallel environments with concurrent scheduling Masking of side effects useful for program writers, compiler writers and language designers improve design and maintenance of iterative programs Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 4 / 26
  5. Type System First order lambda calculus: λx : T.f (x)

    Second order lambda calculus = polymorphic lambda calculus Λα.λx : α.f (x) Type system: λf : T → S.λx : T.f (x) type : (T → S) → T → S Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 5 / 26
  6. Descriptions and Kinds Kinds are the “types of descriptions” kind:

    REGION | EFFECT | TYPE 3 layers: expression, descriptors, kinds description δ : kind κ ::= Region ρ : REGION | Effect : EFFECT | Type τ : TYPE The generalized subtype relation on descriptions is defined to correspond to the subset relation on the underlying sets of regions and effects. Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 6 / 26
  7. Example system F = second order lambda calculus FX =

    programming language with effect system MFX = statically scoped Lisp dialect with type and effect system twice = (PLAMBDA (t:Type, e:Effect) (LAMBDA (f:(SUBR (t) e t)) (LAMBDA (x:T) (f(f x))))) twice : (POLY (t:TYPE e:EFFECT) PURE (SUBR (SUBR:(t) e t) PURE (SUBR (t) e t))) Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 7 / 26
  8. Effects Effect = concise summary of observable side-effects Effect soundness

    = statically calculated effects are conservative approximation Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 8 / 26
  9. Regions Region = describes an abstract area of the store

    in which side effects may occur Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 9 / 26
  10. Descriptors and Kinds subroutine types incorporate a latent effect Cedric

    Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 10 / 26
  11. Effect System Effect system = approximate effects statically Concise summary

    of observable side effects A, B e : τ A, B e! Type assignment A : add: A[x ← τ] get: A(x) Kind assignment B : add: B[d ← κ] get: B(d) e = expression τ = type = effect Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 11 / 26
  12. Ordinary Abstraction Effect is encoded in the type but the

    abstraction expression itself has effect PURE Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 14 / 26
  13. Ordinary Application The encoded effect of the subroutine is “unpacked”

    upon application of the abstraction. Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 15 / 26
  14. Semantics - States Locations Loc: Memory addresses A location lρ,τ

    is tagged by the region ρ it belongs to, and the type τ of the value it contains. A region can contain an unlimited number of locations. Stores σ : Loc → Val: mappings from locations to values States e, σ pairs of expression/store Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 16 / 26
  15. Reduction rules Obvious extension of lambda calculus rules: Cedric Bastin,

    Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 17 / 26
  16. Partial orders on descriptions REGION = ⊆ EFFECT is based

    on the underlying regions, for corresponding effects with ⊥ = PURE. E.g. ALLOC(r1) (MAXEFFECT (ALLOC (UNION r1 r2)) (WRITE r1)) ALLOC(r1), WRITE(r1), (ALLOC r2) uncomparable TYPE is based on the underlying regions and effects (all form lattices) Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 18 / 26
  17. Type and effect preservation Theorem (Type and effect preservation) Reduction

    of a well-formed state preserves or decreases the type and effect descriptions of the state. Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 19 / 26
  18. Soundness Definition (Reach) A location lρ1,τ can be reached through

    a region ρ2 if FV (ρ1) ∧ FV (ρ2) = ∅ Theorem (Soundness) Reduction of a well-formed state allocates, reads, and writes only locations that can be reached through the regions specified by its effect. Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 20 / 26
  19. Effect masking Let @red be a fresh region constant. example

    allocates, reads and writes on @red: example!(MAXEFF (READ @red) (WRITE @red) (ALLOC @red)) But this is not visible outside the scope of example @red is private to the expression. Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 21 / 26
  20. Effect masking - rule Let an expression e : τ,

    e! , and ρ a region in . If ρ / ∈ FV (τ) x ∈ FV (e) → ρ / ∈ A(x) then ρ can be removed from . So in the previous slide, example!PURE Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 22 / 26
  21. Effect masking - soundness Remember that soundness states that evaluation

    of an expression e! cannot have effects not mentioned in . Masking breaks soundness: evaluation of example has effects on @red, although the masked effect is PURE. Solution: evaluate the expression down to a value, and then mask effects. Introduce a private construct, acts as a delimiter. Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 23 / 26
  22. Effect masking - reduction Source to source transformation: example becomes

    (private @red example) Like before, example!(MAXEFF . . .) private masks the effects on @red: (private @red example)!PURE Evaluation: (private @red example) → . . . → (private @red 2) → 2 Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 24 / 26
  23. Effect masking - soundness Theorem (Soundness with effect masking) Reduction

    of a well-formed state allocates, reads, and writes only locations that can be reached through the regions specified by its effect or through the private regions of the expression. Cedric Bastin, Manos Koukoutos (EPFL) Polymorphic Effect System May 13, 2015 25 / 26
  24. Thank you for your attention! Questions? Cedric Bastin, Manos Koukoutos

    (EPFL) Polymorphic Effect System May 13, 2015 26 / 26