Download - The Sequential Semantics of Producer Effect Systems

Transcript
Page 1: The Sequential Semantics  of Producer Effect Systems

THESEQUENTIAL SEMANTICS OFPRODUCER EFFECT SYSTEMS

Ross Tate

Page 2: The Sequential Semantics  of Producer Effect Systems

THESEQUENTIAL SEMANTICS OFPRODUCER EFFECT SYSTEMS

Ross Tate

Page 3: The Sequential Semantics  of Producer Effect Systems

WHAT IS AN EFFECT?Output

s

Inputs Computation

Types

IgnoresInputs

LeaksInformatio

n ThrowsException

Page 4: The Sequential Semantics  of Producer Effect Systems

THESEQUENTIAL SEMANTICS OFPRODUCER EFFECT SYSTEMS

Ross Tate

Page 5: The Sequential Semantics  of Producer Effect Systems

EFFECT SYSTEM FOR LOCKING

acquire

acquire

lockinglocking

get release

unlockingcriticalacquire

locking }entrant

Page 6: The Sequential Semantics  of Producer Effect Systems

WHAT IS AN EFFECT SYSTEM?

lockless locking unlocking critical entrant↓ ; →

lockless

lockingunlocki

ngcritical

entrant

lockless locking unlocking critical entrant

locking entrant lockingunlockin

g critical unlocking

critical unlocking critical

entrant locking entrant

Page 7: The Sequential Semantics  of Producer Effect Systems

EFFECTS FOR PURE CODE

÷ 2

locklesscritical entrant

locking unlocking

“May” Properti

es

“Must” Properti

es

Page 8: The Sequential Semantics  of Producer Effect Systems

WHAT IS AN EFFECT SYSTEM?

Cannot be formalized semantically

by any preexisting framework

e ↦ lockless, critical, entrantlockless ≤ critical, entrant

lockless locking unlocking critical entrant↓ ; →

lockless locking unlocking critical entrantlockles

slocking entrant lockinglocking

unlocking critical unlockin

gunlocki

ngcritical unlockin

g criticalcriticalentrant locking entrantentrant

Page 9: The Sequential Semantics  of Producer Effect Systems

WHAT IS AN EFFECT SYSTEM?

Monade ↦ lockless, critical, entrant

lockless↓ ; →locklesslockles

s

Page 10: The Sequential Semantics  of Producer Effect Systems

WHAT IS AN EFFECT SYSTEM?

Indexed Monade ↦ lockless, critical, entrant

lockless ≤ critical, entrant

lockless entrant↓ ; →lockless entrantlockles

s

entrant entrantentrant

Page 11: The Sequential Semantics  of Producer Effect Systems

WHAT IS AN EFFECT SYSTEM?

Layered Monads in Action

e ↦ lockless, critical, entrantlockless ≤ critical, entrant

lockless critical entrant↓ ; →lockless critical entrantlockles

s

critical criticalcriticalentrant entrantentrant

Monads cannot be used for “must”

properties.

Page 12: The Sequential Semantics  of Producer Effect Systems

WHAT IS AN EFFECT SYSTEM?

Parameterized Monade ↦ lockless, critical, entrant

locking unlocking critical entrant↓ ; →

entrant lockinglockingcritical unlockin

gunlocki

ng unlocking criticalcritical

locking entrantentrant

Page 13: The Sequential Semantics  of Producer Effect Systems

WHAT IS AN EFFECT SYSTEM?

e ↦ lockless, critical, entrantlockless ≤ critical, entrant

Productoid

lockless locking unlocking critical entrant↓ ; →

lockless locking unlocking critical entrantlockles

slocking entrant lockinglocking

unlocking critical unlockin

gunlocki

ngcritical unlockin

g criticalcriticalentrant locking entrantentrant

Page 14: The Sequential Semantics  of Producer Effect Systems

THESEQUENTIAL SEMANTICS OFPRODUCER EFFECT SYSTEMS

Ross Tate

Page 15: The Sequential Semantics  of Producer Effect Systems

WHAT IS A PRODUCER EFFECT?

τ’τ ετ’τ

⟦⟧

partial

May

be

Page 16: The Sequential Semantics  of Producer Effect Systems

LOCKING-EFFECT PRODUCTIONS Plockless(τ) = Pe(τ) Plocking(τ)= L ⊸ Pe(C ⨂ τ) Punlocking(τ) = C ⊸ Pe(L ⨂ τ) Pcritical(τ) = C ⊸ Pe(C ⨂ τ) Pentrant(τ)= L ⊸ Pe(L ⨂ τ)

Abstract Types

Page 17: The Sequential Semantics  of Producer Effect Systems

THESEQUENTIAL SEMANTICS OFPRODUCER EFFECT SYSTEMS

Ross Tate

Page 18: The Sequential Semantics  of Producer Effect Systems

}C⊸C ⊗C⊸C ⊗

SEQUENCING EFFECTFUL WITH PURE

ℤ1 getcritical ÷ 2 ℝ

ℤ1 ℝ⟦⟧ ma

p

critical

Expects an ℤProduces a C⊸C⊗ℤ

Page 19: The Sequential Semantics  of Producer Effect Systems

SEQUCENCING EFFECTFUL TOGETHER }⟦⟧⟦⟧

ε''

mapjoin

ℤ ℕℝ ℤ ℕ

Pεℝ ℤ ℕ

ε ε'

ℕPε’

Pε’’

ε ; ε’ ↦ ε’’Pε’

Monadneedsε=ε’=ε

’’

Page 20: The Sequential Semantics  of Producer Effect Systems

WHAT IS A PRODUCTOID? For each ε: For each ε ; ε’ ↦ ε’’: For each ε ≤ ε’: For each e ↦ ε:

τ τ’ τ τ’map PεPεjoin

Pε’’τ τPε’Pε

coerce Pε’τ τPε

unit Pετ τ

Propagate effects

Sequence effects

Impurify into effects

Convert effects

Page 21: The Sequential Semantics  of Producer Effect Systems

GENERALITYThe sequential semantics

of any producer effect system forms a productor.

Any effectful language that canthunk computations into pure

valueshas only producer effects.

Page 22: The Sequential Semantics  of Producer Effect Systems

PRODUCTORS BUILT FROM … a single effect

are monads [Moggi] a join semi-lattice of effects

are indexed monads [Wadler & Thiemann] a partial join semi-lattice of effects

are layered monads in action [Filinski] a state-transition effect system

are parameterized monads [Atkey]These are all if and only

ifs.

Page 23: The Sequential Semantics  of Producer Effect Systems

APPLYING PRODUCTORSAbstract Operations:

acquire : L ⊸ C release : C ⊸ L get : C ⊸ C ⨂ ℤ set : C ⨂ ℤ ⊸ C

Productor using linear type theory ensures:shared memory accessed only in critical regionsno deadlocks possible

lockingunlockingcriticalcritical

Page 24: The Sequential Semantics  of Producer Effect Systems

LOCKLESS EFFECTS Linear Strength

α ⨂ Pe(τ) ⊸ Pe(α ⨂ τ) lockless cannot include

exceptions

Page 25: The Sequential Semantics  of Producer Effect Systems

WHAT IS A PRODUCTOID? For each ε: For each ε ; ε’ ↦ ε’’: For each ε ≤ ε’: For each e ↦ ε:

τ τ’ τ τ’map PεPεjoin

Pε’’τ τPε’Pε

coerce Pε’τ τPε

unit Pετ τ

Page 26: The Sequential Semantics  of Producer Effect Systems

WHAT IS A PRODUCTOR? For each ε1 ; … ; εn ↦ ε: For each ε ; ε’ ↦ ε’’: For each ε ≤ ε’: For each e ↦ ε:

joinPε’’τ τPε’Pε

coerce Pε’τ τPε

unit Pετ τ

join Pετ τPnP1 …

Page 27: The Sequential Semantics  of Producer Effect Systems

WHAT IS A PRODUCTOR?

Pε1 Pεi Pεm Pεn… … … τjoin

join…

join…P �̂� P~𝜀 τPε τ

join

Pε τ

Page 28: The Sequential Semantics  of Producer Effect Systems

CONCLUSION Formalized sequential structure of

Effects: effectorsSemantics: productors

Proved generality/applicability of productorsAll producer effect systemsThunking guarantees producer effects

Opportunities for future researchConsumer effects: how are inputs used?Consumptors: dualize productors ?