components and static analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · generic...
TRANSCRIPT
![Page 1: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/1.jpg)
Components and Static Analysis
Bruno C. d. S. Oliveira email: [email protected]
Monday, 31 August 2009
![Page 2: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/2.jpg)
This talk
• A little about me
• Overview of my research
• Datatype-Generic Programming
• Software Extensibility and Reuse
• Quickcheck and Static Analisys
Monday, 31 August 2009
![Page 3: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/3.jpg)
About me
• Just joined ROSAEC Center as a researcher.
• Worked at the University of Oxford (UK) before, where I also did my PhD.
• You can call me Bruno.
• I come from Portugal.
Monday, 31 August 2009
![Page 4: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/4.jpg)
Monday, 31 August 2009
![Page 5: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/5.jpg)
Components
• Old idea introduced by McIlroy in 1968.
• Analogy with electronics.
• Complex software built out of simpler components.
• Challange: Finding the right abstractions for componentization.
Monday, 31 August 2009
![Page 6: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/6.jpg)
Why Components?
• Understanding: software can be understood from smaller and simpler components.
• Reuse: different systems can use the same components.
• Consequences: improved maintainability, reduction of costs, increased quality.
Monday, 31 August 2009
![Page 7: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/7.jpg)
Research Areas
• Software Components, Reuse and Modularity:
• Datatype Generic Programming
• OO Design Patterns as Components
• Functional and OO Programming
• Software Extensibility and Reuse
• Aspect-Oriented Programming
• Hope to learn about Static Analisys with you!
Monday, 31 August 2009
![Page 8: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/8.jpg)
Background: Algebraic Datatypes
data List = Nil | Cons Int ListshowList :: List → StringshowList Nil = "Nil"showList (Cons x xs) = "Cons " ++ show x ++ " (" ++ showList xs ++ ")"
Nice abstraction for structuring software:
Monday, 31 August 2009
![Page 9: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/9.jpg)
Datatype-Generic Programming
Problem: Some operations are tedious to write.
data Tree = Empty | Fork Int Tree TreeshowTree :: Tree ! StringshowTree = . . .data Exp = ILit Int | BLit Bool | Add Exp Exp | If Exp Exp ExpshowExp :: Exp ! StringshowExp = . . .
Monday, 31 August 2009
![Page 10: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/10.jpg)
Datatype-Generic Programming
Solution: Write a generic function.
Note: This is Generic Haskell code.
Monday, 31 August 2009
![Page 11: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/11.jpg)
How does it work?
Algebraic datatypes as sums-of-products.
fromList :: List ! Sum Unit (Prod Int List)fromList Nil = Inl UnitfromList (Cons x xs) = Inr (x " xs)toList :: Sum Unit (Prod Int List)! ListtoList (Inl Unit) = NiltoList (Inr (x " xs)) = Cons x xs
Monday, 31 August 2009
![Page 12: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/12.jpg)
Generic TraversalsProblem: A lot of boilerplate code is often required when working with large sets of datatypes.data HsModule = HsModule SrcLoc Module (Maybe [HsExportSpec ]) [HsImportDecl ] [HsDecl ]. . .
data HsDecl = HsTypeDecl SrcLoc HsName [HsName ] HsType| HsDataDecl SrcLoc HsContext HsName [HsName ] [HsConDecl ] [HsQName ]| HsInfixDecl SrcLoc HsAssoc Int [HsOp ]| HsNewTypeDecl SrcLoc HsContext HsName [HsName ] HsConDecl [HsQName ]| HsClassDecl SrcLoc HsContext HsName [HsName ] [HsDecl ]| HsInstDecl SrcLoc HsContext HsQName [HsType ] [HsDecl ]| . . .
. . .
Rewriting:
Monday, 31 August 2009
![Page 13: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/13.jpg)
Generic TraversalsSolution: Write a generic traversal.
Note: Everywhere is a generic function from the Scrap you Boilerplate approach.
Monday, 31 August 2009
![Page 14: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/14.jpg)
Some of my work• Typecase (HW’05, with Gibbons):
• Techniques for embedding DGP in Haskell.
• “Scrap your boilerplate” reloaded (FLOPS 06, with Hinze and Loeh):
• Better understanding of the approach; alternative implementation.
• EMGM (TFP 06, with Hinze and Loeh):
• Combination of overloading and generic programming.
• Scala for Generic Programmers (WGP 08, with Gibbons):
• DGP in Scala.
Monday, 31 August 2009
![Page 15: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/15.jpg)
Static Analysis tools with DGP
• Static Analisys tools require lots of AST manipulations.
• DGP can help with AST manipulations.
• Possible Research:
• Static analysis tool as a realistic case study for DGP.
• Better DGP approach for large AST’s: Scrap your Boilerplate is too inefficient (Brown&Samson 2009).
Monday, 31 August 2009
![Page 16: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/16.jpg)
Software Extensibility
• Extensible generic functions: How to allow overriding in generic functions?
• Expression Problem: How to add new constructors to datatypes or methods to interfaces modularly?
• Expression Families Problem: How to reuse code for similar datatypes?
Monday, 31 August 2009
![Page 17: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/17.jpg)
Expression Families
data Exp1 = Num1 Int | Add1 Exp1 Exp1 | Minus1 Exp1 Exp1
eval1 :: Exp1 ! Inteval1 (Num1 x ) = xeval1 (Add1 e1 e2 ) = eval1 e1 + eval1 e2eval1 (Minus1 e1 e2 ) = eval1 e1 " eval1 e2
data Exp2 = Num2 Int | Add2 Exp2 Exp2 | Minus2 Exp2 Exp2 | Neg2 Exp2
eval2 :: Exp2 ! Inteval2 (Num2 x ) = xeval2 (Add2 e1 e2 ) = eval2 e1 + eval2 e2eval2 (Minus2 e1 e2 ) = eval2 e1 " eval2 e2eval2 (Neg2 e) = " (eval2 e)
Problem: No reuse between similar expressions
Monday, 31 August 2009
![Page 18: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/18.jpg)
Modular Visitor Components
• A solution for the Expression (Families) Problem (in ECOOP 09).
• Encoding of modularly extensible datatypes and functions.
• Works in plain Scala (no extensions needed).
• But use could be greatly simplified with a language extension.
Monday, 31 August 2009
![Page 19: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/19.jpg)
Modular Visitor Components
trait Expr [!V [ ]] {def accept [a ] (vis : V [a ]) : a
}trait num [A ] {
def num (x : Int) : A}case class Num [!V [X ] <: num [X ]] (x : Int) extends Expr [V ] {
def accept [a ] (vis : V [a ]) : a = vis.num (x )}trait add [A ] {
def add (e1 : A, e2 : A) : A}case class Add [!V [X ] <: add [X ]] (e1 : Expr [V ], e2 : Expr [V ]) extends Expr [V ] {
def accept [a ] (vis : V [a ]) : a = vis.add (e1 .accept (vis), e2 .accept (vis))}
Expressions and two variants: numbers and additions.
Monday, 31 August 2009
![Page 20: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/20.jpg)
Variants for OO Programming
variant Num (x : Int)variant Add (e1 : This, e2 : This)variant Minus (e1 : This, e2 : This)variant Neg (e : This)data Exp1 = Num with Add with Minusdata Exp2 = Num with Add with Minus with Negeval [exp in {Num,Add ,Minus }] (e : exp) : Int = e match{
case Num (x ) ! xcase Add (e1 , e2 ) ! eval (e1 ) + eval (e2 )case Minus (e1 , e2 )! eval (e1 )" eval (e2 )
}
Idea: Language extension for supporting variants.
Monday, 31 August 2009
![Page 21: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/21.jpg)
QuickCheck
• Automatic testing tool for Haskell (Claessen and Hughes, ICFP 2000).
• Tests for properties of functions.
• Also available for Erlang, where it is a commercial tool.
Monday, 31 August 2009
![Page 22: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/22.jpg)
How does it work?
• User specifies properties that functions should satisfy.
• Types of programs for generically generating inputs.
• Values for inputs generated randomly.
• Counter-examples are reported if the property is found to be invalid.
Monday, 31 August 2009
![Page 23: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/23.jpg)
ExampleProperties specified as functions:
To test simply call quickCheck:
Monday, 31 August 2009
![Page 24: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/24.jpg)
Example 2
A property that is false and a counter-example.
Monday, 31 August 2009
![Page 25: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/25.jpg)
Limitations of Quickcheck
• High-proportion of trivial inputs.
• No test adequacy criterions.
• To avoid bad distributions, good input generators must be provided manually.
Monday, 31 August 2009
![Page 26: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/26.jpg)
Static Analysis for improving Quickcheck?
• Taking into account the source code of programs to generate test data.
• Static analisys already used for contract checking (Xu&Peyton Jones&Claessen, POPL 2009).
• Static analisys also used for detecting pattern matching failures (Mitchell&Runciman, HW 2008).
Monday, 31 August 2009
![Page 27: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/27.jpg)
Conclusion
• I hope you know a little bit more about my research (and me) now!
• DGP and components for implementing Static Analysis tools.
• Static analysis for improving testing tools by smarter automated input generation.
Monday, 31 August 2009
![Page 28: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/28.jpg)
Extras
Monday, 31 August 2009
![Page 29: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/29.jpg)
Extensible Generic functions
Sometimes useful to allow overriding functionality of generic functions.
Problem: We are faced with the expression problem.
Monday, 31 August 2009
![Page 30: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/30.jpg)
Aspect-Oriented Programming
Problem: Many software concerns are tangled with other concerns.
Monday, 31 August 2009
![Page 31: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/31.jpg)
Aspect-Oriented Programming
Existing Solution: Code weaving.
Monday, 31 August 2009
![Page 32: Components and Static Analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · Generic Traversals Problem: A lot of boilerplate code is often required when working with](https://reader034.vdocuments.net/reader034/viewer/2022042206/5ea891c552cbc83efb2b0842/html5/thumbnails/32.jpg)
Better AOP
• Drawbacks of code weaving:
• Bad for program understanding and security.
• No separate compilation.
• EffectiveAdvice:
• Ongoing work (jointly with Schrijvers&Cook)
• AOP through inheritance and explicit effects.
Monday, 31 August 2009