X-Git-Url: http://plrg.eecs.uci.edu/git/?p=repair.git;a=blobdiff_plain;f=Repair%2FRepairCompiler%2FMCC%2FIR%2FGraphAnalysis.java;h=3fdbe6e87a63ae9a6fb93443069b66bb979a1dd0;hp=6b6a7153c9a79ad12019b4ddcd1df321806febde;hb=87862c69c1cb47c83a858f0b6e52d9c0bc25913f;hpb=1865e2c81c6c387dcc48114a33921e26fc0211b1 diff --git a/Repair/RepairCompiler/MCC/IR/GraphAnalysis.java b/Repair/RepairCompiler/MCC/IR/GraphAnalysis.java index 6b6a715..3fdbe6e 100755 --- a/Repair/RepairCompiler/MCC/IR/GraphAnalysis.java +++ b/Repair/RepairCompiler/MCC/IR/GraphAnalysis.java @@ -20,52 +20,93 @@ public class GraphAnalysis { Stack workset=new Stack(); HashSet closureset=new HashSet(); boolean needcyclecheck=false; - HashSet cantremovetrans=new HashSet(); + HashSet dependent=new HashSet(); + + /* Compute dependent set */ + workset.push(gn); + while(!workset.empty()) { + GraphNode gn2=(GraphNode)workset.pop(); + for(Iterator edgeit=gn2.edges();edgeit.hasNext();) { + GraphNode gn3=((GraphNode.Edge)edgeit.next()).getTarget(); + if (removed.contains(gn3)) + continue; + if (!termination.conjunctions.contains(gn3)&&!dependent.contains(gn3)) { + dependent.add(gn3); + workset.push(gn3); + } + } + } + + /* Compute the closure set */ workset.push(gn); while(!workset.empty()) { GraphNode gn2=(GraphNode)workset.pop(); if (!closureset.contains(gn2)) { closureset.add(gn2); - boolean goodoption=false; for(Iterator edgeit=gn2.edges();edgeit.hasNext();) { GraphNode gn3=((GraphNode.Edge)edgeit.next()).getTarget(); if (removed.contains(gn3)) continue; - if (((cantremove.contains(gn2)||!couldremove.contains(gn2)) - &&termination.conjunctions.contains(gn2))|| - cantremovetrans.contains(gn2)) - cantremovetrans.add(gn3); - - if (termination.abstractrepair.contains(gn3)|| - termination.conjunctions.contains(gn3)|| - termination.updatenodes.contains(gn3)) { - /** Check for cycles if the graphnode can't - * be removed (we know we aren't introducing - * new things to repair). */ - if ((!termination.abstractrepair.contains(gn3)&& - cantremove.contains(gn3))|| - cantremovetrans.contains(gn3)) { - needcyclecheck=true; - } else return false; - } - if ((!couldremove.contains(gn3))||cantremove.contains(gn3)) - goodoption=true; workset.push(gn3); } - if (!goodoption) { - if (termination.scopenodes.contains(gn2)) - return false; - } } } - if (needcyclecheck) { - Set cycles=GraphNode.findcycles(closureset); - for(Iterator it=cycles.iterator();it.hasNext();) { - GraphNode gn2=(GraphNode)it.next(); - if (termination.abstractrepair.contains(gn2)|| - termination.conjunctions.contains(gn2)|| - termination.updatenodes.contains(gn2)) - return false; + + /* Check for harmful cycles through gn */ + Set cycles=GraphNode.findcycles(closureset); + if (cycles.contains(gn)) + return false; + + /* Check for harmful cycles being introduced in dependent nodes */ + cycles=GraphNode.findcycles(dependent); + for(Iterator it=cycles.iterator();it.hasNext();) { + GraphNode gn2=(GraphNode)it.next(); + if (termination.abstractrepair.contains(gn2)|| + termination.conjunctions.contains(gn2)|| + termination.updatenodes.contains(gn2)) + return false; + } + + /* Make sure all abstractrepairs/consequence nodes in the dependent nodes + are well formed. */ + outerloop: + for(Iterator it=dependent.iterator();it.hasNext();) { + GraphNode gn2=(GraphNode)it.next(); + if (termination.abstractrepair.contains(gn2)|| + termination.scopenodes.contains(gn2)) { + boolean ismodify=false; + int numadd=0; + int numremove=0; + + if (termination.abstractrepair.contains(gn2)&& + ((TermNode)gn2.getOwner()).getAbstract().getType()==AbstractRepair.MODIFYRELATION) + ismodify=true; + + innerloop: + for(Iterator edgeit=gn2.edges();edgeit.hasNext();) { + GraphNode gn3=((GraphNode.Edge)edgeit.next()).getTarget(); + if (removed.contains(gn3)) + continue innerloop; + if (cantremove.contains(gn3)|| + !couldremove.contains(gn3)) { + if (ismodify) { + TermNode tn3=(TermNode)gn3.getOwner(); + MultUpdateNode mun=tn3.getUpdate(); + if (mun.getType()==MultUpdateNode.ADD) + numadd++; + if (mun.getType()==MultUpdateNode.REMOVE) + numremove++; + if (mun.getType()==MultUpdateNode.MODIFY) + continue outerloop; + if ((numadd>0)&&(numremove>0||!((TermNode)gn2.getOwner()).getAbstract().needsRemoves(termination.state))) + continue outerloop; + } else + if (termination.consequence.contains(gn3)|| + termination.updatenodes.contains(gn3)) + continue outerloop; + } + } + return false; } } return true; @@ -97,7 +138,7 @@ public class GraphAnalysis { for(Iterator it=termination.consequencenodes.iterator();it.hasNext();) { GraphNode gn=(GraphNode) it.next(); if (safetransclosure(gn, mustremove,cantremove, couldremove)) { - couldremove.remove(gn); + couldremove.remove(gn); } } @@ -105,8 +146,8 @@ public class GraphAnalysis { for(Iterator it=termination.updatenodes.iterator();it.hasNext();) { GraphNode gn=(GraphNode) it.next(); - if (safetransclosure(gn, mustremove,cantremove, cantremove)) { - couldremove.remove(gn); + if (safetransclosure(gn, mustremove,cantremove, couldremove)) { + couldremove.remove(gn); } } @@ -116,6 +157,8 @@ public class GraphAnalysis { GraphNode gn=(GraphNode) it.next(); if (mustremove.contains(gn)||cantremove.contains(gn)) continue; + if (!safetransclosure(gn, mustremove,cantremove, couldremove)) + continue; boolean allgood=true; for(Iterator edgeit=gn.edges();edgeit.hasNext();) { @@ -124,7 +167,7 @@ public class GraphAnalysis { assert tn2.getType()==TermNode.ABSTRACT; boolean foundupdate=false; for(Iterator edgeit2=gn2.edges();edgeit2.hasNext();) { - GraphNode gn3=((GraphNode.Edge)edgeit2.next()).getTarget(); + GraphNode gn3=((GraphNode.Edge)edgeit2.next()).getTarget(); if (!couldremove.contains(gn3)&&!mustremove.contains(gn3)) { TermNode tn3=(TermNode)gn3.getOwner(); if (tn3.getType()==TermNode.UPDATE) @@ -134,13 +177,26 @@ public class GraphAnalysis { if (!foundupdate) allgood=false; } - if (allgood) + if (allgood) { couldremove.remove(gn); + if (Compiler.PRUNEQUANTIFIERS) { + TermNode tn=(TermNode)gn.getOwner(); + Constraint constr=tn.getConstraint(); + for(Iterator consit=((Set)termination.conjunctionmap.get(constr)).iterator();consit.hasNext();) { + GraphNode gn4=(GraphNode)consit.next(); + TermNode tn4=(TermNode)gn4.getOwner(); + if (tn4.getquantifiernode()) { + mustremove.add(gn4); /* This node is history */ + System.out.println("Eliminating: "+gn4.getTextLabel()); + } + } + } + } } /* Look for constraints which can only be satisfied one way */ - + Vector constraints=termination.state.vConstraints; for(int i=0;i