• No results found

Type Disciplines for Well-Threadedness (1) Given a well-typed, strongly connected annotated interaction, its well-threadedness can be compositionally checked using a typing system.

In document note pdf (Page 84-86)

We first present the typing system which checks(G1–G3). Then we refine it so that it can validate (L). Henceforth letS,S0, . . .range over the finite sets of session channels.

Θ ::= Θ·τ:S | Θ,X:Θ | /0

We assumeΘdefines a function (with its domain the threads and term variables). Θ1,Θ2indicates their union s.t. dom(Θ1)∩dom(Θ2) =/0. We sayΘis well-formediff each session channel is assigned to at most two threads, i.e. iff wheneverτ:S∈Θsuch thatsS, there is at most oneτ06=τ

such thatτ0:S0Θsuch thatsS0.

The typing judgement has the formΘ`

A

, whereΘrecords free session channels used in each thread in

A

and is (inductively) well-formed.

DEFINITION17 (Type Discipline for Well-Threadedness). For an annotated strongly connected

(hence well-typed) interaction

A

,Θ`

A

is derived by the rules in Figure 24, where for convenience we annotate each inaction0with a thread, writing0τ. The notationtopT(

A

)returns the active thread of

A

for

A

which should be a non-extended annotated interaction in the sense of Definition 12 with0annotated as above (for which we settopT(0τ) =τ).

In the typing, well-formedness is inductively guaranteed so that, for well-threaded interactions, the required shape of the typing in the premise of(WT-INIT) and(WT-COMM)is always satisfied. In(WT-INIT), we placeτ2:/0so that no further threads can use τ2. The two rules for parallel composition,(WT-PAR)and(WT-PAR-EXT), are in precise correspondence with the grammar of annotated interactions (cf. Definition 12: note however we shall still be writing

A

etc. from now on for extended annotated interactions). Only in(WT-PAR)we demand the initial active threads of the two components to be identical. The hiding(WT-PAR-EXT)is also only for extended annotated

interactions. A basic property of the typing system follows.

THEOREM4 (Soundness of WT-typing). An extended annotated strongly connected interaction

A

is well-threaded ifΘ`

A

for someΘ.

Remark.Below and henceforth (IH) stands for induction hypothesis.

Proof. We prove the following stronger result, where we say a thread in

A

iscompleteif it occurs as a passive thread in session initialisation. It isincompleteif not.

Claim.IfΘ`

A

then (1)Θis well-formed; (2)

A

is consistent and each incomplete threadτin

A

usessiffτ:sis inΘ; and (3) for each complete thread, sayτ,Θcontainsτ:/0.

For(WT-INIT), (1) and (2) are direct from (IH). (3) is by (IH) and the shape of the rule, notingτ2got completed. For(WT-COMM), (1) and (3) are direct from (IH). (2) is ensured by (IH) and the con- dition in the premise. For each of(WT-ASSIGN),(WT-IFTHENELSE),(WT-SUM),(WT-PAR),

(WT-EXT-PAR) and(WT-EXT-RES), all of (1..3) are direct from (IH) and, for(G3)of (2), by

the corresponding condition in the premise. Finally(WT-VAR)and(WT-ZERO)are obvious. For

(WT-REC), (1) is direct, (2) is by (IH) with(G3)being obvious, and (3) is again by (IH). Below we define

A

A

0,(σ,A)→(σ0,A0)etc. exactly following the corresponding relations

on unannotated interactions (cf. §11.3, Figure 21, page 57), except we demand top-level parallel compositions (i.e. those which are not under prefixes) are not annotated and, when a reduction creates a new top level parallel composition, its label should be taken off.

THEOREM5 (Subject Reduction: Well-Threadedness). Below

A

, . . .include extended anno-

tated interactions.

(1) IfΘ`

A

and

A

A

0thenΘ`

E

.

(2) If II0and I has a consistent annotation then I0also has a consistent annotation.

(3) IfΘ`

A

and(σ,

A

)→(σ0,

A

0)thenΘ`

A

0.

Proof. (1) is easy rule induction (on the generation rules for≡). (2) is by (1), noting ifII0

and

A

is a consistent annotation ofIthen the same derivation witnessingII0leads to

A

0such that

A

A

0. (3) is by rule induction on reduction rules. All are easy except we use, for induction for the reduction of recursion: Θ`recX.IimpliesΘ`I[(recX.I)/X][because: ifΘ`recX.I, then Θ,X:Θ`I, hence by using induction onIand thinning we are done]. To capture local consistency directly in the typing system, we refine the type discipline given in Figure 24. The refined system also offers a simple, inductive justification of Proposition 10. We first augment the typingΘas follows:

Θ ::= Θ·τ:(↑,S) | Θ·τ:(↓,S) | Θ,X:Θ | /0

Above we add, for each thread, the direction of the latest action in that thread. The judgement has the same form except we use this refined typing. The operationΘ1Θ2now combines the information on the direction, so that it is defined iff the directions coincide for each common thread: if this fails

for any thread, the composition is undefined. We then replace (WT-Init) and (WT-Comm) as follows: (WT-INIT)Θ,τ1:(↓,S]S 0}) 2:(↑,S0)`

A

topT(

A

) =τ2 S0⊆ {s˜} Θ,τ1:(↑,S)`Aτ1Bτ2:ch(s)˜ .A (WT-COMM) Θ,τ1:(↓,S1),τ2:(↑,S2)`

A

i topT(

A

i) =τ2 J6=/0 Θ,τ1:(↑,S1∪ {s}),τ2:(↓,S2∪ {s})`Aτ1Bτ2:shop,e,xi.A

In both, the condition on the direction atτ2is non-trivial. After giving activity to another thread, when it comes back inside

A, the thread

τ2always starts as an input. The remaining rules stay in the same shape (except we use the refined typings).

It is easy to check that the typability in this refined system directly entails (not only global con- sistency, by Theorem 4, but also) local consistency, by guaranteeing strict alternation in the direction of interactions for each thread. We can further show inductively that this refined system type checks precisely the same terms as the original system, establishing Proposition 10.

14.7. Type Disciplines for Well-Threadedness (2). We next consider the existence of “rep-

In document note pdf (Page 84-86)

Related documents