Constraining Delimited Control with Contracts
Asumu Takikawa
- T. Stephen Strickland*
Sam Tobin-Hochstadt Northeastern University University of Maryland, College Park*
1
Constraining Delimited Control with Contracts Asumu Takikawa T. - - PowerPoint PPT Presentation
Constraining Delimited Control with Contracts Asumu Takikawa T. Stephen Strickland* Sam Tobin-Hochstadt Northeastern University University of Maryland, College Park* 1 Experienced programmers divide up all significant programs into separate
1
2
web server
request? (-> request? response?)
servlet
3
web server
request? (-> request? response?)
servlet Import/export is a communication channel between components Executable specifications can protect these channels
4
5
web server servlet
6
web server servlet
7
web server servlet Control establishes a new communication channel No mechanism exists to protect these channels
8
9
10
∅ Types Contracts Gradual typing wcm ccm call/comp abort prompt
11
∅ Types Contracts Gradual typing wcm ccm call/comp abort prompt
12
∅ Types Contracts Gradual typing wcm ccm call/comp abort prompt
talk
13
14
15
[Findler & Felleisen ICFP 2002]
16
"2a00:1450:400a:804::1012"
17
"2a00:1450:400a:804::1012"
18
19
Elements of delimited control [Dybvig et. al JFP 2007]
(1) make a delimiter (2) delimit a continuation (3) capture a continuation (4) abort a continuation (5) install a continuation
(1) create a tag (2) mark stack segment with tag (3) store segment in a variable (4) delete part of stack (5) append segments onto stack Continuation marks [Clements et al. ESOP 2001] (6) store data in continuation (6) store data in stack
20
Elements of delimited control [Dybvig et. al JFP 2007]
(1) make a delimiter (2) delimit a continuation (3) capture a continuation (4) abort a continuation (5) install a continuation
(1) create a tag (2) mark stack segment with tag (3) store segment in a variable (4) delete part of stack (5) append segments onto stack Continuation marks [Clements et al. ESOP 2001] (6) store data in continuation (6) store data in stack
21
22
23
24
25
26
27
28
A correct contract system should:
along channels between components
it affects the flow of values [Dimoulas Dissertation 2012] [Dimouas et al. ESOP 2012]
29
component A component B prime? protected channel
Contracts checked on boundary crossings
30
component A component B
% ☆ h
unprotected channel prime?
abort ☆ 4
abort bypasses usual protection by jumping Same mechanism does not work
31
along channels between components
32
along channels between components
33
★ = (contract ☆ (prompt-tag/c prime?) B A) component A component B
% ★ h
abort ☆ 4
34
★ = (contract ☆ (prompt-tag/c prime?) B A) component A component B
% ★ h
abort ☆ 4
35
★ = (contract ☆ (prompt-tag/c prime?) B A) Blame B component A component B
% ★ h
abort ☆ 4
prompt has positive party as B
36
★ = (contract ☆ (prompt-tag/c prime?) B A) Blame B component A component B
% ★ h
abort ☆ 4
prompt has positive party as B
37
★ = (contract ☆ (prompt-tag/c prime?) A B) component A component B
% ☆ h
abort ★ 4
38
★ = (contract ☆ (prompt-tag/c prime?) A B) component A component B
% ☆ h
abort ★ 4
39
★ = (contract ☆ (prompt-tag/c prime?) A B) Blame B component A component B
% ☆ h
abort ★ 4
abort swaps positive, negative parties
40
★ = (contract ☆ (prompt-tag/c prime?) A B) Blame B component A component B
% ☆ h
abort ★ 4
abort swaps positive, negative parties
it affects the flow of values
41
h = (λ (f) (f 4)) f = (λ (x) (prime-after x))
★ = (contract ☆ (prompt-tag/c (-> prime? prime?)) A B) component A component B
% ☆ h
abort ★ f
42
h = (λ (f) (f 4)) f = (λ (x) (prime-after x))
★ = (contract ☆ (prompt-tag/c (-> prime? prime?)) A B) component A component B
% ☆ h
abort ★ f
43
h = (λ (f) (f 4)) f = (λ (x) (prime-after x))
★ = (contract ☆ (prompt-tag/c (-> prime? prime?)) A B) Blame A component A component B
% ☆ h
abort ★ f
Delayed contract means blame raised at prompt
44
ctc = (-> prime? prime?)
45
ctc = (-> prime? prime?)
56
ctc = (-> prime? prime?)
67
ctc = (-> prime? prime?)
78
Blame A
ctc = (-> prime? prime?)
89
h = (λ (f) (f 7)) f = (λ (x) 4)
★ = (contract ☆ (prompt-tag/c (-> prime? prime?)) C A,B) component A component B
% ★ h
C C
abort ★ f
Contract triggered from both sides
100
h = (λ (f) (f 7)) f = (λ (x) 4)
★ = (contract ☆ (prompt-tag/c (-> prime? prime?)) C A,B) component A component B
% ★ h
C C
abort ★ f
Contract triggered from both sides
101
h = (λ (f) (f 7)) f = (λ (x) 4)
★ = (contract ☆ (prompt-tag/c (-> prime? prime?)) C A,B) Blame B component A component B
% ★ h
C C
abort ★ f
Contract triggered from both sides
102
ctc = (-> prime? prime?)
103
ctc = (-> prime? prime?)
114
ctc = (-> prime? prime?)
125
ctc = (-> prime? prime?)
136
ctc = (-> prime? prime?)
147
ctc = (-> prime? prime?)
158
Blame B
ctc = (-> prime? prime?)
169
A correct contract system should:
along channels between components
it affects the flow of values
180
181
∅ Types Contracts Gradual typing wcm ccm call/comp abort prompt
talk
182
∅ Types Contracts Gradual typing wcm ccm call/comp abort prompt
183
[Tobin-Hochstadt & Felleisen DLS 2006] [Siek & Taha, Scheme 2006] Gradual typing = Type system + Dynamic checking
typed untyped
contract check
τ → contract
184
☆ : (Prompt Integer Float) typed untyped
% ☆ h
abort ★ "a"
★ = (contract ☆ (prompt-tag/c int?) typed untyped)
185
☆ : (Prompt Integer Float) Blame untyped typed untyped
% ☆ h
abort ★ "a"
★ = (contract ☆ (prompt-tag/c int?) typed untyped)
186
187
188
189