fitting the pieces together
play

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,


  1. Fitting the Pieces Together: A Machine-Checked Model of Safe Composition Benjamin Delaware William Cook Don Batory University of Texas at Austin

  2. Safe Composition • Features • Word Processor has formatting, printing, spell check, tables.. • Cut across traditional modularity boundaries • Reify functionality into distinct feature modules • Software Product Line (SPL) • Multiple products from one code base • Product = subset of features • Safe Composition • Type check all products • Products are exponential in number of features • Goal • Sound type system • Foundation for efficient implementation

  3. A Feature Example

  4. A Feature Example • Features are sets of class definitions and refinements

  5. A Feature Example • Features are sets of class definitions and refinements feature Account { class Account extends Object { int balance = 0; void update(int x) { int newBal = balance + x; balance = newBal; Account } }}

  6. A Feature Example • Features are sets of class definitions and refinements feature Account { class Account extends Object { int balance = 0; void update(int x) { int newBal = balance + x; balance = newBal; Account } }} feature InvestAccount { feature RetireAccount { refines class Account extends WaMu { refines class Account extends Lehman { int 401kbalance = 0; int 401kbalance = 10000; refines void update (int x) { int update (int x) { x = x/2; 401kbalance += x; Super (); }} RetireAccount } 401kbalance += x; InvestAccount } }}

  7. Composing Features • Features are sets of class definitions and refinements feature Account { class Account extends Object { int balance = 0; void update(int x) { int newBal = balance + x; balance = newBal; Account } }} feature InvestAccount { feature RetireAccount { refines class Account extends WaMu { refines class Account extends Lehman { int 401kbalance = 0; int 401kbalance = 10000; refines void update (int x) { int update (int x) { x = x/2; 401kbalance += x; Super (); }} RetireAccount } 401kbalance += x; InvestAccount } }}

  8. Composing Features Account InvestAccount RetireAccount

  9. InvestAccount • Investor Account InvestAccount RetireAccount

  10. InvestAccount • Investor InvestAccount RetireAccount = feature Account { Account class Account extends Object { int balance = 0; void update(int x) { int newBal = balance + x; balance = newBal; Account } }}

  11. InvestAccount • Investor RetireAccount = feature Account { Account InvestAccount class Account extends Object { int balance = 0; void update(int x) { feature InvestAccount { int newBal = balance + x; refines class Account extends WaMu { balance = newBal; Account int 401kbalance = 0; } refines void update (int x) { }} x = x/2; Super (); 401kbalance += x; InvestAccount } }}

  12. InvestAccount • Investor RetireAccount feature Account { WaMu class Account extends Object { + = Account feature InvestAccount { InvestAccount int balance = 0; refines class Account extends WaMu { int 401kbalance = 0; int 401kbalance = 0; InvestAccount void update(int x) { refines void update (int x) { x = x/2; x = x/2; int newBal = balance + x; Super (); balance = newBal; 401kbalance += x; 401kbalance += x; } Account }} } }}

  13. RetireAccount • Investor Account InvestAccount RetireAccount

  14. RetireAccount • Investor InvestAccount RetireAccount = feature Account { Account class Account extends Object { int balance = 0; void update(int x) { int newBal = balance + x; balance = newBal; Account } }}

  15. RetireAccount • Investor InvestAccount RetireAccount = feature Account { Account class Account extends Object { int balance = 0; void update(int x) { int newBal = balance + x; balance = newBal; Account feature RetireAccount { } refines class Account extends Lehman { }} int 401kbalance = 10000; int update (int x) { 401kbalance += x; }} RetireAccount }

  16. RetireAccount • Investor InvestAccount feature Account { Lehman class Account extends Object { RetireAccount = + Account feature RetireAccount { int balance = 0; refines class Account extends Lehman { int 401kbalance = 10000; int 401kbalance = 10000; void update(int x) { int update (int x) { void update (int x) { int newBal = balance + x; 401kbalance += x; 401kbalance += x; RetireAccount balance = newBal; } } } }} }} Account

  17. Feature Models • A SPL has a set of available features: {Account, RetireAccount, InvestAccount} • Typically feature combinations are constrained • A feature model represents these constraints • Propositional formula is compact representation [Batory05] RetireAccount ∨ InvestAccount • Product corresponds to truth assignment • FMs should enforce implementation constraints • Safe Composition (RetireAccount ∨ InvestAccount) ∧ (RetireAccount ⇒ Account) ∧ (InvestAccount ⇒ Account)

  18. Checking Safe Composition • Could synthesize entire product line • Computationally expensive:

  19. Checking Safe Composition • Could synthesize entire product line • Computationally expensive: Account InvestAccount RetireAccount Bailout Employer NYSE

  20. Checking Safe Composition • Could synthesize entire product line • Computationally expensive: Account InvestAccount RetireAccount Bailout Employer NYSE Account Account InvestAccount Account RetireAccount Account Bailout Account Account Employer NYSE Account InvestAccount Bailout Account Account InvestAccount Employer InvestAccount NYSE Account RetireAccount Bailout Account RetireAccount Account RetireAccount Employer NYSE Account Bailout Employer Account Bailout Employer NYSE Account InvestAccount Employer Bailout Account InvestAccount Employer Bailout NYSE ... Account RetireAccount Bailout Employer Account RetireAccount Bailout Employer NYSE

  21. Difficulties • Combinatorial nature of SPLs problematic: feature Payroll { • Bailout feature needs Account class Employer extends Object { • Account needs 401kbalance Account Employee1; ... • Multiple ways to satisfy Employee1.401kbalance += 10000; • Introduction Bailout ... • }} Inheritance • Features are static • Surrounding program is not • Dependencies are resolved by a combination of features • These features have their own set of dependencies

  22. Lightweight Feature Java • Lightweight Java [ Strnisa07 ] • Minimal imperative subset of Java formalized in Coq • Lightweight Feature Java • Lightweight Java extended with features 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} • Formalized in the Coq Proof Assistant

  23. Composition in LFJ • Programs built from product specifications LFJ composition LJ Product Program Specification • compose • Refine existing classes • Apply method refinement • Introduce fields, methods • Introduce new classes • Recursively apply compose to specification

  24. LJ Type System k ) distinct ( var k k type ( cl k ) = τ k type ( cl ) = τ ′ k ][ this �→ τ ] Γ =[ var k �→ τ k ( WF-Method ) Γ ( y ) = τ ′′ k k | C ℓ ⊢ P, Γ ⊢ s ℓ | C | C ℓ | { τ ′′ ≺ τ ′ , P ⊢ k } P ⊢ ′ , defined cl k �→ �→ ℓ return y ; } k ) { s ℓ P ⊢ τ cl meth ( cl k var k • Program not available until composition

  25. LJ Type System k ) distinct ( var k k type ( cl k ) = τ k Internal Checks type ( cl ) = τ ′ k ][ this �→ τ ] Γ =[ var k �→ τ k ( WF-Method ) Γ ( y ) = τ ′′ ℓ P, Γ ⊢ s ℓ τ ′′ ≺ τ ′ P ⊢ k P ⊢ defined cl k �→ �→ ℓ return y ; } k ) { s ℓ P ⊢ τ cl meth ( cl k var k • Program not available until composition

  26. LJ Type System k ) distinct ( var k k type ( cl k ) = τ k type ( cl ) = τ ′ k ][ this �→ τ ] Γ =[ var k �→ τ k ( WF-Method ) Γ ( y ) = τ ′′ k k | C ℓ ⊢ P, Γ ⊢ s ℓ | C | C ℓ | { τ ′′ ≺ τ ′ , P ⊢ External Checks k } P ⊢ ′ , defined cl k �→ �→ ℓ return y ; } k ) { s ℓ P ⊢ τ cl meth ( cl k var k • Program not available until composition

  27. Constraint-Based Typing • External premises become constraints k ) distinct ( var k k type ( cl k ) = τ k ( WF-Method ) type ( cl ) = τ ′ k ][ this �→ τ ] Γ =[ var k �→ τ k k k ℓ Γ ⊢ s ℓ | C ℓ Γ ( y ) = τ ′′ | C �→ �→ ⊢ ℓ return y ; } | { τ ′′ ≺ τ ′ , defined cl k k ) { s ℓ k } ∪ S ⊢ τ cl meth ( cl k var k ℓ C ℓ • Compositional Constraints • Uniqueness Constraints • Structural Constraints

  28. Constraint-Based Typing • Two typing phases • Typing Feature Tables k ⊢ FD k | WF k k ⊢ {FD k } | ⋃ k { In FDk ⇒ WF k } • Well-typed product specification PS ⊨ ⋃ k { In FDk ⇒ WF k } • Feature Constraint • Compositional Constraints • Uniqueness Constraints • Structural Constraints

  29. Soundness of LFJ Type System Theorem: ⊢ {FD k } | ⋃ k { In FDk ⇒ WF k } PS ⊨ ⋃ k { In FDk ⇒ WF k } ⊢ FJ compose (PS) • Space of products Account InvestAccount RetireAccount Bailout Employer NYSE • First premise describes subset of type-safe products • Second ensures product in this space

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend