THE SEQUENTIAL SEMANTICS OF PRODUCER EFFECT SYSTEMS Ross Tate THE SEQUENTIAL SEMANTICS OF PRODUCER EFFECT SYSTEMS Ross Tate.
Download ReportTranscript THE SEQUENTIAL SEMANTICS OF PRODUCER EFFECT SYSTEMS Ross Tate THE SEQUENTIAL SEMANTICS OF PRODUCER EFFECT SYSTEMS Ross Tate.
THE SEQUENTIAL SEMANTICS OF PRODUCER EFFECT SYSTEMS Ross Tate THE SEQUENTIAL SEMANTICS OF PRODUCER EFFECT SYSTEMS Ross Tate WHAT IS AN EFFECT? Ignores Inputs Leaks Information Types Outputs Inputs Computation Throws Exception THE SEQUENTIAL SEMANTICS OF PRODUCER EFFECT SYSTEMS Ross Tate EFFECT SYSTEM FOR LOCKING locking locking acquire acquire entrant locking critical unlocking acquire get release WHAT IS AN EFFECT SYSTEM? ↓ ; → lockless locking unlocking critical lockless lockless locking unlocking critical locking locking entrant locking unlocking unlocking critical critical critical unlocking critical entrant entrant locking entrant entrant unlocking entrant EFFECTS FOR PURE CODE “May” Properties critical lockless entrant ÷2 locking unlocking “Must” Properties WHAT IS AN EFFECT SYSTEM? ↓ ; → lockless locking unlocking critical lockless lockless locking unlocking critical locking locking entrant locking unlocking unlocking critical critical critical unlocking critical entrant entrant locking entrant entrant unlocking lockless critical, entrant ↦ lockless, critical, entrant Cannot be formalized semantically by any preexisting framework entrant WHAT IS AN EFFECT SYSTEM? ↓ ; → lockless lockless lockless ↦ lockless, critical, entrant Monad WHAT IS AN EFFECT SYSTEM? ↓ ; → lockless lockless lockless entrant entrant entrant entrant entrant lockless critical, entrant ↦ lockless, critical, entrant Indexed Monad WHAT IS AN EFFECT SYSTEM? ↓ ; → lockless lockless lockless critical entrant critical entrant Monads cannot be used for “must” properties. critical critical entrant entrant critical lockless critical, entrant ↦ lockless, critical, entrant Layered Monads in Action entrant WHAT IS AN EFFECT SYSTEM? ↓;→ locking unlocking critical entrant locking unlocking entrant critical entrant locking critical unlocking unlocking critical locking ↦ lockless, critical, entrant Parameterized Monad entrant WHAT IS AN EFFECT SYSTEM? ↓ ; → lockless locking unlocking critical lockless lockless locking unlocking critical locking locking entrant locking unlocking unlocking critical critical critical unlocking critical entrant entrant locking lockless critical, entrant ↦ lockless, critical, entrant Productoid entrant entrant unlocking entrant THE SEQUENTIAL SEMANTICS OF PRODUCER EFFECT SYSTEMS Ross Tate WHAT IS A PRODUCER EFFECT? τ τ’ Maybe τ partial ε Pε τ’ LOCKING-EFFECT PRODUCTIONS Plockless(τ) = P (τ) Abstract Types Plocking(τ) = L ⊸ P (C ⨂ τ) Punlocking(τ) = C ⊸ P (L ⨂ τ) Pcritical(τ) = C ⊸ P (C ⨂ τ) Pentrant(τ) = L ⊸ P (L ⨂ τ) THE SEQUENTIAL SEMANTICS OF PRODUCER EFFECT SYSTEMS Ross Tate critical SEQUENCING EFFECTFUL WITH PURE critical 1 ℤ get Expects an ℤ ÷2 ℝ map ℤ C⊸C⊗ 1 C⊸C⊗ Produces a C⊸C⊗ℤ ℝ ε'' SEQUCENCING EFFECTFUL TOGETHER ℝ ε ℤ ε' ℤ Pε ℤ ℕ Pε’ ℕ map ℝ ε ε’ ↦ ε’’ Monad needs ε=ε’=ε’’ Pε Pε’ ℕ join Pε’’ ℕ WHAT IS A PRODUCTOID? Propagate effects For each ε: Pε τ’ τ τ’ map Pε τ For each ε ε’ ↦ ε’’: Sequence effects Pε Pε’ τ join Pε’’ τ Convert effects For each ε ≤ ε’: Pε τ coerce Pε’ τ Impurify into effects For each ↦ ε: τ unit Pε τ GENERALITY The sequential semantics of any producer effect system forms a productor. Any effectful language that can thunk computations into pure values has only producer effects. PRODUCTORS BUILT FROM … a single effect a join semi-lattice of effects are indexed monads [Wadler & Thiemann] a partial join semi-lattice of effects are monads [Moggi] are layered monads in action [Filinski] a state-transition effect system are parameterized monads [Atkey] These are all if and only ifs. APPLYING PRODUCTORS Abstract Operations: acquire : L ⊸ C release : C ⊸ L get : C ⊸ C ⨂ ℤ set : C ⨂ ℤ ⊸ C locking unlocking critical critical Productor using linear type theory ensures: shared memory accessed only in critical regions no deadlocks possible LOCKLESS EFFECTS Linear Strength α ⨂ P (τ) ⊸ P (α ⨂ τ) lockless cannot include exceptions WHAT IS A PRODUCTOID? For each ε: τ τ’ map Pε τ For each ε ε’ ↦ ε’’: Pε Pε’ τ join Pε’’ τ For each ε ≤ ε’: Pε τ coerce Pε’ τ For each ↦ ε: τ unit Pε τ Pε τ’ WHAT IS A PRODUCTOR? For each ε1 … εn ↦ ε: P1 … Pn τ join For each ε ε’ ↦ ε’’: Pε Pε’ τ join For each ε ≤ ε’: Pε τ coerce For each ↦ ε: τ unit Pε τ Pε’’ τ Pε’ τ Pε τ WHAT IS A PRODUCTOR? τ Pε join P ε … Pε … join P𝜀 … … 1 i P ε … Pε τ m join P𝜀 n τ join Pε τ CONCLUSION Formalized sequential structure of Effects: Semantics: effectors productors Proved generality/applicability of productors All producer effect systems Thunking guarantees producer effects Opportunities for future research Consumer effects: how are inputs used? Consumptors: dualize productors