components and static analysisrosaec.snu.ac.kr/meet/file/20090831a.pdf · 2018-04-12 · generic...
TRANSCRIPT
Components and Static Analysis
Bruno C. d. S. Oliveira email: [email protected]
Monday, 31 August 2009
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
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
Monday, 31 August 2009
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
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
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
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
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
Datatype-Generic Programming
Solution: Write a generic function.
Note: This is Generic Haskell code.
Monday, 31 August 2009
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
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
Generic TraversalsSolution: Write a generic traversal.
Note: Everywhere is a generic function from the Scrap you Boilerplate approach.
Monday, 31 August 2009
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
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
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
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
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
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
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
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
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
ExampleProperties specified as functions:
To test simply call quickCheck:
Monday, 31 August 2009
Example 2
A property that is false and a counter-example.
Monday, 31 August 2009
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
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
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
Extras
Monday, 31 August 2009
Extensible Generic functions
Sometimes useful to allow overriding functionality of generic functions.
Problem: We are faced with the expression problem.
Monday, 31 August 2009
Aspect-Oriented Programming
Problem: Many software concerns are tangled with other concerns.
Monday, 31 August 2009
Aspect-Oriented Programming
Existing Solution: Code weaving.
Monday, 31 August 2009
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