3. Life without templates?
manual implementations
Imperative Program Transformation by Rewriting It says that an assignment x := v (where v is a variable) can x := c if the “last assignment” to v was v := c (where c is a constant). condition formalises the notion of “last assignment”, and will be the paper:
tools taking exotic specifications
n : (x := v) =⇒ x := c
if
n ⊢ A△(¬def(v) U def(v) ∧ stmt(v := c))
conlit(c)
4. But specifying templates is still hard…
code template
source code + meta-variables + matching directives
often requires multiple iterations
no required matches are missed generalization
no unwanted matches
refinement
no support for editing process
no disciplined methods for generalizing/refining templates
no automated support in the form of recommender system
5. I’m a “structural search and replace” on steroids
1/ advanced code templates in Ekeko/X
2/ formal operators for template mutation
3/ genetic search for mutation recommendations
6. 1/ advanced code templates in Ekeko/X
2/ formal operators for template mutation
3/ genetic search for mutation recommendations
template
matches
7. 1/ advanced code templates in Ekeko/X
2/ formal operators for template mutation
3/ genetic search for mutation recommendations
template
matches
8. 1/ advanced code templates in Ekeko/X
2/ formal operators for template mutation
3/ genetic search for mutation recommendations
template
matches
[<component>]@[<directive>]
9. [<component>]@[<directive>]
constraining syntax, structure,
data flow, control flow of matches
match any match is in source code,
with matching type and properties
orsimple qualified name match is any name resolving to name in template
(equals ?var) any exposes match
child, child+, child* any match is corresponding child of parent match, nested
within that child (+), or either (*)
match|set list match has at least given elements, in any order
match|regexp list match has elements described by regexp
(type ?type)
type/variable
declaration/reference
expression
match resolves to, is of, or declares the type of its
argument
(subtype ?type),
(subtype+ ?type),
(subtype* /type)
type/variable
declaration/reference
match resolves to a (transitive +, reflexive *) subtype
of the given argument
(refers-to ?var) expression match lexically refers to local, parameter or field
denoted by its argument
(invokes ?method) invocation expression match invokes given argument
grouping of templates
[public void acceptVisitor(ComponentVisitor v)…]@[(equals ?method)]
[….acceptVisitor(…)]@[(invokes ?method)]
10. 1/ advanced code templates in Ekeko/X
2/ formal operators for template mutation
3/ genetic search for mutation recommendations
? ?
?
11. 1/ advanced code templates in Ekeko/X
2/ formal operators for template mutation
3/ genetic search for mutation recommendations
introduce-variable return age; return ?v;
atomic
mutation
generalize-aliases
composite
mutation
public class Book {
private Integer count;
public Integer getCount() {
return count;
}
}
public class Book {
private Integer ?v1;
public Integer getCount() {
return [?v2]@[(refers-to ?v1)];
}
}
12. 1/ advanced code templates in Ekeko/X
2/ formal operators for template mutation
3/ genetic search for mutation recommendations
(Operator.
"remove-node"
operators/remove-node
:destructive
"Remove from template."
opscope-subject
applicability|deleteable
"Removes its selection from the template."
[])
(Operator.
constraints on their subject
"add-directive-invokes"
operators/add-directive-invokes
:refinement
"Add directive invokes."
opscope-subject
applicability|methodinvocation
"Requires matches to invoke the binding for the meta-variable."
[(make-operand "Meta-variable (e.g., ?v)" opscope-variable validity|variable)])
constraints on their operands
constraints enable checking
applicability of operator, validity of its operands
+ generating possible values!
13. 1/ advanced code templates in Ekeko/X
2/ formal operators for template mutation
3/ genetic search for mutation recommendations
given enumeration of desired matches
populate determine fitness
best
individual good
enough?
select parents crossover
& mutation
yay!
14. 1/ advanced code templates in Ekeko/X
2/ formal operators for template mutation
3/ genetic search for mutation recommendations
populate
individual = group of templates
- copies of existing group (from editor state)
- one template group per row,
consisting of a template per column in desired matches (from scratch)
15. 1/ advanced code templates in Ekeko/X
2/ formal operators for template mutation
3/ genetic search for mutation recommendations
determine fitness concurrently!
a) match each template group in population against program
b) determine precision and recall w.r.t. desired matches
c) penalize excess use of directives (KISS)
16. 1/ advanced code templates in Ekeko/X
2/ formal operators for template mutation
3/ genetic search for mutation recommendations
select parents
mutation crossover
16 2 Tree-based GP
Parents Offspring
3
x y
∗
+
y 1
+
+
/
x 2
Crossover
Point
Crossover
Point
3
+
/
x 2
(x+y)+3
(y+1)* (x/2)
(x/2)+3
GARBAGE
Figure 2.5: Example of subtree crossover. Note that the trees on the left
are actually copies of the parents. So, their genetic material can freely be
used without altering the original individuals.
[Genetic programming, a field guide]
to crossover operations frequently exchanging only very small amounts of
genetic material (i.e., small subtrees); many crossovers may in fact reduce
18. Ongoing Experiment
finetuning: very sensitive to probabilities of crossover and
mutation, quality of RNG, diversity in population, …
RQ1: how effective is the search in finding
template changes?
RQ2: do users find the recommended changes helpful?
RQ3: do composite, template-specific mutations
converge more quickly to a solution than generic code
mutations?