Termination in higher-order processes L3 internship under the - - PowerPoint PPT Presentation
Termination in higher-order processes L3 internship under the - - PowerPoint PPT Presentation
Termination in higher-order processes L3 internship under the supervision of Daniel Hirschkoff Simon Castellan December, 1 st 2011 Introduction a study of termination in higher order -calculus ( -calculus where messages can be
Introduction
◮ a study of termination in higher order π-calculus (π-calculus
where messages can be (parametrized) processes)
◮ talk overview
◮ presentation of HOπω : termination and non-termination in
this calculus
◮ description of λπ : HOπω with the (simply typed) λ-calculs ◮ Soft-λπ : a subcalculus on which types give information about
the length of reductions
Contents
HOπω :Higher order π-calculus λπ : higher order π-calculs with full λ-calculus Soft-λπ : toward a bound on the length of reductions
HOπω
◮ π-calculus where processes may exchange (parametrised
processes)
◮ the grammar for this language is
(names) a, b (processes) P, Q ::= 0 null | (P || Q) parallel | a(x). P reception | aV message | (νa)P name restriction | V W functional application (values) V , W ::= x variables = names | λx. P function | ⋆ base value
◮ communication rule : a(x). P || aV → P[V /x]
Non termination in HOπω
◮ reduction in HOπω :
◮ a(x). P || aV → P[V /x] ◮ (λx.P)V → P[V /x]
◮ “concurrent auto-application” :
◮ δ ≡ a(f ). (f ⋆ || af ) ◮ Ω ≡ δ || aλx.δ → Ω
Non termination in HOπω
◮ reduction in HOπω :
◮ a(x). P || aV → P[V /x] ◮ (λx.P)V → P[V /x]
◮ “concurrent auto-application” :
◮ δ ≡ a(f ). (f ⋆ || af ) ◮ Ω ≡ δ || aλx.δ → Ω
◮ the similar process : δ′ ≡ a(f ). (f ⋆ || b(x). (cx || af ))
waits for a message on b at each iteration : “spawning” (in [LMS10], Dal Lago, Martini and Sangiorgi)
Typing in HOπω for termination
◮ two strategies developed in [LMS10] and [DHS10] to make a
type system that guarantees termination
◮ in this talk, I use a strategy based on [DS06].
the idea is to stratify channels : to each channel, we associate an integer representing the level of the channel Γ ⊢ t : k Γ ⊢ t′ : k′ Γ ⊢ t || t′ : max(k, k′) Γ ⊢ t : τ Γ(a) = ♯kτ Γ ⊢ at : k
Typing in HOπω for termination
◮ two strategies developed in [LMS10] and [DHS10] to make a
type system that guarantees termination
◮ in this talk, I use a strategy based on [DS06].
the idea is to stratify channels : to each channel, we associate an integer representing the level of the channel Γ ⊢ t : k Γ ⊢ t′ : k′ Γ ⊢ t || t′ : max(k, k′) Γ ⊢ t : τ Γ(a) = ♯kτ Γ ⊢ at : k
◮ controlling inputs :
Γ, x : τ ⊢ P : n < k Γ(a) = ♯k(τ) Γ ⊢ a(x).P : 0
Typing example
Γ ⊢ t : k Γ ⊢ t′ : k′ Γ ⊢ t || t′ : max(k, k′) Γ ⊢ t : τ Γ(a) = ♯kτ Γ ⊢ at : k Γ, x : τ ⊢ P : n < k Γ(a) = ♯k(τ) Γ ⊢ a(x).P : 0
◮ a(x). ax is rejected ◮ a(x). (bx || cx) is accepted iff b and c are < a. ◮ a(x). b(x).ax may be accepted (the output on a is hidden
by the reception on a)
Typing example
Γ ⊢ t : k Γ ⊢ t′ : k′ Γ ⊢ t || t′ : max(k, k′) Γ ⊢ t : τ Γ(a) = ♯kτ Γ ⊢ at : k Γ, x : τ ⊢ P : n < k Γ(a) = ♯k(τ) Γ ⊢ a(x).P : 0
◮ a(x). ax is rejected ◮ a(x). (bx || cx) is accepted iff b and c are < a. ◮ a(x). b(x).ax may be accepted (the output on a is hidden
by the reception on a)
◮ functions :
◮ if x : τ ⊢ P : n, then ⊢ λ x. P : τ →n+1 ⋄ ◮ application: the term V W has level n iff V has type τ →n ⋄
Termination proof
Theorem
Every well-typed term of HOπω is strongly normalizing.
Proof.
◮ attach to P, m(P) the multiset of outputs (akV ) at
top-level in P and levels of applications ((λnx.P) V )
◮ m(bx || cx || a(x). dx) = {lvl(b), lvl(c)} ◮ show that P → P′ implies m(P) > m(P′) for multiset
- rdering.
◮ P ≡ a(x). P0 || aV → P′ ≡ P0[V /x] ◮ P ≡ (λx. P0)V → P′ ≡ P0[V /x]
Contents
HOπω :Higher order π-calculus λπ : higher order π-calculs with full λ-calculus Soft-λπ : toward a bound on the length of reductions
λπ : syntax and semantics
◮ λπ is an extension in HOπω where all functions are available. ◮ grammar where processes and functions coexist :
t, u ::= 0 null | (t || u) parallel | a(x). t reception | at message | (νa)t name restriction | x variable | λx. t abstraction | t u application
◮ channels are not first-class values (but π can be encoded)
λπ : syntax and semantics
◮ λπ is an extension in HOπω where all functions are available. ◮ grammar where processes and functions coexist :
t, u ::= 0 null | (t || u) parallel | a(x). t reception | at message | (νa)t name restriction | x variable | λx. t abstraction | t u application
◮ channels are not first-class values (but π can be encoded) ◮ reduction : same two primitve rules as in HOπω. ◮ strategy : weak reduction for the λ-calculus (although we
could reduce under abstraction and inputs), in particular reduction inside messages
A few examples
◮ contains spawning and classic idioms of HOπω. ◮ messages as localities:
◮ P → P′ implies aP → aP′ ◮ aP (P not a normal form) can be read “P running at a” ◮ passivation: a(X).bX takes whatever process running at a
and transfers it to b
A few examples
◮ contains spawning and classic idioms of HOπω. ◮ messages as localities:
◮ P → P′ implies aP → aP′ ◮ aP (P not a normal form) can be read “P running at a” ◮ passivation: a(X).bX takes whatever process running at a
and transfers it to b
◮ channels as first-class values :
◮ given a, the couple (λx. ax), (λ f .a(x). f x) represents
channel a
Typing in λπ
◮ type grammar :
σ, τ ::= ⋆ base type σ → τ function type k (∈ N) type of processes at level k α ::=♯k(τ) channel types carrying values of type τ
◮ for the λ part : simple types ◮ for the concurrent part : tracking receptions’ body for
incorrect outputs (as before)
◮ type of a process = maximum of the levels of the channels
carrying top-level messages
◮ in particular, spawning is typable
Typing rules
Γ(x) = τ Γ ⊢ x : τ Γ, x : τ ⊢ t : σ Γ ⊢ λx.t : τ → σ Γ ⊢ t : σ → τ Γ ⊢ u : σ Γ ⊢ t u : τ
Γ ⊢ t : τ Γ(a) = ♯kτ Γ ⊢ at : k Γ(a) = ♯kτ Γ, x : τ ⊢ t : p < k Γ ⊢ a(x).t : 0 Γ, a : ♯kτ ⊢ t : τ Γ ⊢ (νa)t : τ Γ ⊢ t : k Γ ⊢ t′ : k′ Γ ⊢ t || t′ : max(k, k′) Γ ⊢ 0 : 0
Typing rules
Γ(x) = τ Γ ⊢ x : τ Γ, x : τ ⊢ t : σ Γ ⊢ λx.t : τ → σ Γ ⊢ t : σ → τ Γ ⊢ u : σ Γ ⊢ t u : τ
Γ ⊢ t : τ Γ(a) = ♯kτ Γ ⊢ at : k Γ(a) = ♯kτ Γ, x : τ ⊢ t : p < k Γ ⊢ a(x).t : 0 Γ, a : ♯kτ ⊢ t : τ Γ ⊢ (νa)t : τ Γ ⊢ t : k Γ ⊢ t′ : k′ Γ ⊢ t || t′ : max(k, k′) Γ ⊢ 0 : 0
Typing rules
Γ(x) = τ Γ ⊢ x : τ Γ, x : τ ⊢ t : σ Γ ⊢ λx.t : τ → σ Γ ⊢ t : σ → τ Γ ⊢ u : σ Γ ⊢ t u : τ
Γ ⊢ t : τ Γ(a) = ♯kτ Γ ⊢ at : k Γ(a) = ♯kτ Γ, x : τ ⊢ t : p < k Γ ⊢ a(x).t : 0 Γ, a : ♯kτ ⊢ t : τ Γ ⊢ (νa)t : τ Γ ⊢ t : k Γ ⊢ t′ : k′ Γ ⊢ t || t′ : max(k, k′) Γ ⊢ 0 : 0
Subtyping
◮ there are two (related) problems with the previous rules :
◮ f (a(x). 0 || a⋆) → f 0, does f have the type level(a) → ..
- r 0 → ... (subject reduction) ?
◮ if we have a process of level k why can’t we pass it to a
function expecting a process of level k′ > k (polymorphism) ?
◮ one way to resolve that problem is to introduce subtyping.
◮ k ⊑ k′ iff k ≤ k′ (types of processes) ◮ σ → τ ⊑ σ′ → τ ′ iff σ′ ⊑ σ and τ ⊑ τ ′
◮ then we add the subsumption rule
Γ ⊢ t : σ σ ⊑ τ Γ ⊢ t : τ
Termination in λπ
Theorem
Every well-typed term of λπ is strongly normalizing.
Proof.
◮ proof by reducibility candidates. ◮ [[k]] = {t, Γ ⊢ t : k and t is strongly normalizing} ◮ for the λ part, everything goes as usual ◮ for the concurrent part, we need a lemma :
◮ if P || Q reduces to R with a communication between P and
Q, then w(R) < w(P||Q)
◮ same argument as in HOπω.
Comparison with the λ-calculus with regions ([Ama09])
◮ the λ-calculus with regions is a calculus that abstracts
references, channels into the the concept of regions
◮ two primitive operations
◮ get(r) to read from a store (receive) ◮ write(r, v) to write a value to a store (send)
◮ difference in operational semantics :
◮ listen (in λπ) : blocking, erases the value ◮ get (in [Ama09]) : non-blocking, leaves the value
Comparison with the λ-calculus with regions ([Ama09])
◮ the λ-calculus with regions is a calculus that abstracts
references, channels into the the concept of regions
◮ two primitive operations
◮ get(r) to read from a store (receive) ◮ write(r, v) to write a value to a store (send)
◮ difference in operational semantics :
◮ listen (in λπ) : blocking, erases the value ◮ get (in [Ama09]) : non-blocking, leaves the value
◮ spawning example :
◮ t1 ≡ (λk. λy.set(a, k); k ⋆)(get a)(get b) ◮ then t1, (a ⇐ (λ .t1)) is ill-typed and loops
◮ difference between type systems
◮ in λπ we watch inputs ◮ in [Ama09] we watch the type of the regions
Contents
HOπω :Higher order π-calculus λπ : higher order π-calculs with full λ-calculus Soft-λπ : toward a bound on the length of reductions
Soft-λπ
◮ as in soft-lambda calculus, we add two syntaxic constructions
λ!x. t and !t
◮ goal : if ⊢ t : τ then t does at most f (t, τ) reductions before
reducing to a normal form
◮ for HOπω, such a system has been built in [LMS10] ◮ we treat processes and λ-calculs separately ◮ but we could have extended [LMS10] to λπ (no difficulty a
priori)
Typing rules
Γ, x : τ; ∆ ⊢ t : σ Γ; ∆ ⊢ λ!x.t :!τ → σ Γ; ∆, x : τ ⊢ t : σ Γ; ∆ ⊢ λx.t : τ → σ Γ; ∆1 ⊢ t : τ → σ Γ; ∆2 ⊢ u : τ Γ; ∆1, ∆2 ⊢ t u : σ Γ ∪ ∆(x) = τ Γ; ∆ ⊢ x : τ ∅; ∆ ⊢ t : τ Γ; !∆, ∆′ ⊢!t :!τ Γ; ∆1 ⊢ t : e Γ; ∆2 ⊢ u : e′ Γ; ∆1, ∆2 ⊢ t || u : max(e, e′) Γ, a : ♯k(τ); ∆ ⊢ t : σ Γ; ∆ ⊢ (νa)t : σ Γ; ∆ ⊢ t : τ Γ(a) = ♯k(τ) Γ; ∆ ⊢ at : k Γ; ∆ ⊢ 0 : 0 Γ, x : τ; ∆ ⊢ t : e Γ(a) = ♯k(τ) e < k Γ; ∆ ⊢ a(x).t : 0 Γ ⊢ t : τ τ ≤ σ Γ ⊢ t : σ
A bound
Theorem
Every well-typed term t of Soft-λπ normalizes in at most O(dn+k) steps, where
◮ d is the number of occurences of the variable (or name) that
appears the most in t (duplicability factor)
◮ n is the number of channels used in t ; ◮ k is the box depth of t (maximum nesting of bangs appearing
in t’s typing derivation)
◮ to ease reasoning we consider a derivation of t where channels
are assigned different levels
◮ use of two measure : one for the concurrent aspects and one
for the sequential aspects
◮ the “concurrent” bound is reached :
◮ pn ≡ (a0(x).a1x || x) || . . . || (an−1(x).anx || x) ◮ pn||a1P||an(x).x reduces to P || . . . || P
- 2ntimes
Conclusion
To go further :
◮ see if the proof can be extended to more complex type
systems for λ (eg. System F)
◮ some ideas for type inference in λπ ◮ improve the bound (perhaps dn+k where is n the highest level
- f names bound in t)
π-calculus encoding into λπ
◮ two features needed : first-class channels and replication ◮ first-class channels : ok (cf. example) ◮ replication : through spawning,
[[!a(x).P]] = (νb)S ||bλx. S, S = a(f ). b(x). ([[P]] || af || f ())
λπ versus the rest of the world
λπ versus :
◮ [LMS10] :
◮ in λπ : a(k).(k||ak) – different levels for x ◮ in [LMS10] : a(x).ax – reception body too large
◮ [DHS10] :
◮ in λπ : aax – nesting output ◮ in [DHS10] : a(x).ax – reception body too large
Roberto M. Amadio. On stratified regions. CoRR, abs/0904.2076, 2009.
- R. Demangeon, D. Hirschkoff, and D. Sangiorgi.
Termination in higher-order concurrent calculi. Journal of Logic and Algebraic Programming, 2010.
- Y. Deng and D. Sangiorgi.