Fitting the Pieces Together:
A Machine-Checked Model of Safe Composition
Benjamin Delaware William Cook Don Batory University of Texas at Austin
Fitting the Pieces Together: A Machine-Checked Model of Safe - - PowerPoint PPT Presentation
Fitting the Pieces Together: A Machine-Checked Model of Safe Composition Benjamin Delaware William Cook Don Batory University of Texas at Austin Safe Composition Features Word Processor has formatting, printing, spell check,
Benjamin Delaware William Cook Don Batory University of Texas at Austin
feature Account { class Account extends Object { int balance = 0; void update(int x) { int newBal = balance + x; balance = newBal; } }}
feature InvestAccount { refines class Account extends WaMu { int 401kbalance = 0; refines void update (int x) { x = x/2; Super(); 401kbalance += x; } }} feature Account { class Account extends Object { int balance = 0; void update(int x) { int newBal = balance + x; balance = newBal; } }}
feature RetireAccount { refines class Account extends Lehman { int 401kbalance = 10000; int update (int x) { 401kbalance += x; } }} RetireAccount
feature InvestAccount { refines class Account extends WaMu { int 401kbalance = 0; refines void update (int x) { x = x/2; Super(); 401kbalance += x; } }} feature Account { class Account extends Object { int balance = 0; void update(int x) { int newBal = balance + x; balance = newBal; } }}
feature RetireAccount { refines class Account extends Lehman { int 401kbalance = 10000; int update (int x) { 401kbalance += x; } }} RetireAccount
InvestAccount
Account
RetireAccount
InvestAccount
Account
RetireAccount
InvestAccount
Account
RetireAccount
=
feature Account { class Account extends Object { int balance = 0; void update(int x) { int newBal = balance + x; balance = newBal; } }}
InvestAccount
Account
RetireAccount
=
feature Account { class Account extends Object { int balance = 0; void update(int x) { int newBal = balance + x; balance = newBal; } }}
feature InvestAccount { refines class Account extends WaMu { int 401kbalance = 0; refines void update (int x) { x = x/2; Super(); 401kbalance += x; } }}
InvestAccount
Account
RetireAccount
=
feature Account { class Account extends Object { int balance = 0; void update(int x) { int newBal = balance + x; balance = newBal; } }} WaMu int 401kbalance = 0; x = x/2; 401kbalance += x;
+
feature InvestAccount { refines class Account extends WaMu { int 401kbalance = 0; refines void update (int x) { x = x/2; Super(); 401kbalance += x; } }}
InvestAccount
Account
RetireAccount
InvestAccount
Account
RetireAccount
=
feature Account { class Account extends Object { int balance = 0; void update(int x) { int newBal = balance + x; balance = newBal; } }}
InvestAccount
Account
RetireAccount =
feature Account { class Account extends Object { int balance = 0; void update(int x) { int newBal = balance + x; balance = newBal; } }} feature RetireAccount { refines class Account extends Lehman { int 401kbalance = 10000; int update (int x) { 401kbalance += x; } }} RetireAccount
InvestAccount
Account
RetireAccount =
feature Account { class Account extends Object { int balance = 0; void update(int x) { int newBal = balance + x; balance = newBal; } }} feature RetireAccount { refines class Account extends Lehman { int 401kbalance = 10000; int update (int x) { 401kbalance += x; } }}
+
Lehman int 401kbalance = 10000; void update (int x) { 401kbalance += x; }
{Account, RetireAccount, InvestAccount}
RetireAccount ∨ InvestAccount
(RetireAccount ∨ InvestAccount) ∧ (RetireAccount ⇒ Account) ∧ (InvestAccount ⇒ Account)
InvestAccount Account RetireAccount Bailout Employer NYSE
InvestAccount Account RetireAccount Bailout Employer NYSE InvestAccount Account RetireAccount Account Account Account Bailout InvestAccount Account Bailout RetireAccount Account Bailout Account Bailout Employer InvestAccount Account Bailout Employer RetireAccount Account Bailout Employer Account Employer InvestAccount Account Employer RetireAccount Account Employer NYSE Account Bailout Employer InvestAccount Account Bailout Employer NYSE RetireAccount Account Bailout Employer NYSE Account NYSE InvestAccount Account NYSE RetireAccount Account NYSE
feature Payroll { class Employer extends Object { Account Employee1; ... Employee1.401kbalance += 10000; ... }}
Feature Table FT ::= {FD} Product specification PS ::= F Feature declaration FD ::= feature F {cld; rcld} Class refinement rcld ::= refines class dcl extending cl {fd; md; rmd} Method Refinement rmd ::= refines method ms {s; Super(); s; return y}
LJ Program LFJ Product Specification composition
type(cl) = τ ′ distinct(vark
k)
type(clk) = τk
k
→ → ⊢τ cl meth (clk vark
k) {sℓ ℓ return y; }
Γ =[ vark → τk
k][this → τ] k k
Γ ⊢ sℓ | C Γ(y) = τ ′′
(WF-Method)
⊢ | C | {τ ′′ ≺ τ ′,
′, defined clk k}
P P ⊢ P ⊢
| Cℓ
ℓ
P,
type(cl) = τ ′ distinct(vark
k)
type(clk) = τk
k
→ → ⊢τ cl meth (clk vark
k) {sℓ ℓ return y; }
Γ =[ vark → τk
k][this → τ]
Γ ⊢ sℓ Γ(y) = τ ′′
(WF-Method)
τ ′′ ≺ τ ′ defined clk
k
P P ⊢ P ⊢
ℓ
Internal Checks
P,
type(cl) = τ ′ distinct(vark
k)
type(clk) = τk
k
→ → ⊢τ cl meth (clk vark
k) {sℓ ℓ return y; }
Γ =[ vark → τk
k][this → τ] k k
Γ ⊢ sℓ | C Γ(y) = τ ′′
(WF-Method)
⊢ | C | {τ ′′ ≺ τ ′,
′, defined clk k}
P P ⊢ P ⊢
| Cℓ
ℓ
External Checks
P,
type(cl) = τ ′ distinct(vark
k)
type(clk) = τk
k
→ → ⊢ | C ⊢τ cl meth (clk vark
k) {sℓ ℓ return y; } | {τ ′′ ≺ τ ′, defined clk k} ∪ S ℓ Cℓ
Γ =[ vark → τk
k][this → τ] k k
Γ ⊢ sℓ | Cℓ
ℓ
Γ(y) = τ ′′
(WF-Method)
k
⊢ FDk | WFk ⊢{FDk } | ⋃k{InFDk⇒WFk}
k
Theorem: ⊢{FDk } | ⋃k{InFDk⇒WFk} PS ⊨ ⋃k{InFDk⇒WFk} ⊢FJ compose(PS)
Theorem: ⊢{FDk } | ⋃k{InFDk⇒WFk} PS ⊨ ⋃k{InFDk⇒WFk} ⊢FJ compose(PS)
Theorem: ⊢{FDk } | ⋃k{InFDk⇒WFk} PS ⊨ ⋃k{InFDk⇒WFk} ⊢FJ compose(PS)
PS
Product Line # of Features # of Programs Code Base Jak/Java LOC Program Jak/ Java LOC Typechecking Time JPL 70 56 34K/48K 22K/35K <30s