Skip to content

Commit 4df939a

Browse files
committed
fixed a bug with mismatching generated plans and matching frames
1 parent bb354d5 commit 4df939a

File tree

1 file changed

+33
-21
lines changed
  • plugins/hu.bme.mit.incquery.localsearch.cpp/src/hu/bme/mit/incquery/localsearch/cpp/generator/planner

1 file changed

+33
-21
lines changed

plugins/hu.bme.mit.incquery.localsearch.cpp/src/hu/bme/mit/incquery/localsearch/cpp/generator/planner/PlanCompiler.xtend

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ import com.google.common.collect.ImmutableSet
44
import com.google.common.collect.Iterables
55
import hu.bme.mit.incquery.localsearch.cpp.generator.model.PatternStub
66
import java.util.List
7+
import java.util.Set
8+
import java.util.concurrent.atomic.AtomicInteger
79
import org.apache.log4j.Logger
810
import org.eclipse.viatra.query.runtime.emf.EMFQueryMetaContext
11+
import org.eclipse.viatra.query.runtime.matchers.psystem.PBody
12+
import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation
913
import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference
1014
import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PDisjunction
1115
import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter
1216
import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery
1317
import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.DefaultFlattenCallPredicate
1418
import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.PBodyNormalizer
1519
import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.PQueryFlattener
20+
import java.util.Collection
1621

1722
class PlanCompiler {
1823

@@ -32,46 +37,53 @@ class PlanCompiler {
3237

3338
def compilePlan(PQuery pQuery) {
3439
val frameRegistry = new MatchingFrameRegistry
40+
41+
val flatDisjunction = flattener.rewrite(pQuery.disjunctBodies)
42+
val normalizedDisjunction = normalizer.rewrite(flatDisjunction)
43+
44+
val normalizedBodies = normalizedDisjunction.bodies.toList
45+
3546
val bindings = pQuery.allAnnotations.filter[name == "Bind"]
3647
val boundPatternStubs = bindings.map[ binding |
37-
val boundParameters = binding.getAllValues("parameters").map [
38-
switch (it) {
39-
ParameterReference: #[it]
40-
List<ParameterReference>: it
41-
}
42-
].flatten.map[
43-
pQuery.parameters.get(pQuery.getPositionOfParameter(it.name))
44-
].toSet
48+
val boundParameters = getBoundParameters(binding, pQuery)
4549

46-
val bodies = pQuery.compile(boundParameters, false, frameRegistry)
50+
val bodies = normalizedBodies.compile(boundParameters, frameRegistry)
4751
return new PatternStub(pQuery, bodies, boundParameters)
4852
]
4953

50-
val bodies = pQuery.compile(#{}, true, frameRegistry)
54+
val bodies = if(normalizedDisjunction.sensibleWithoutBinding) {
55+
normalizedBodies.compile(#{}, frameRegistry)
56+
} else {
57+
#{}
58+
}
5159
val unboundPatternStub = new PatternStub(pQuery, bodies)
5260
// copy to prevent lazy evaluation
5361
return ImmutableSet::copyOf(Iterables::concat(#[unboundPatternStub], boundPatternStubs))
5462
}
63+
64+
private def getBoundParameters(PAnnotation binding, PQuery pQuery) {
65+
binding.getAllValues("parameters").map [
66+
switch (it) {
67+
ParameterReference: #[it]
68+
List<ParameterReference>: it
69+
}
70+
].flatten.map[
71+
pQuery.parameters.get(pQuery.getPositionOfParameter(it.name))
72+
].toSet
73+
}
5574

56-
def compile(PQuery pQuery, Iterable<PParameter> boundParameters, boolean checkSanity, MatchingFrameRegistry frameRegistry) {
57-
58-
val flatDisjunction = flattener.rewrite(pQuery.disjunctBodies)
59-
val normalizedDisjunction = normalizer.rewrite(flatDisjunction)
60-
61-
if (checkSanity && !normalizedDisjunction.sensibleWithoutBinding)
62-
return #{}
63-
64-
val normalizedBodies = normalizedDisjunction.bodies
75+
def compile(List<PBody> normalizedBodies, Iterable<PParameter> boundParameters, MatchingFrameRegistry frameRegistry) {
6576

77+
val AtomicInteger counter = new AtomicInteger(0)
6678
val patternBodyStubs = normalizedBodies.map[pBody |
6779
val boundPVariables = boundParameters.map[pBody.getVariableByNameChecked(name)]
6880
.toSet
6981

70-
val acceptor = new CPPSearchOperationAcceptor(frameRegistry)
82+
val acceptor = new CPPSearchOperationAcceptor(counter.getAndIncrement, frameRegistry)
7183
pBody.plan(Logger::getLogger(PlanCompiler), boundPVariables, EMFQueryMetaContext.INSTANCE, null, #{})
7284
.compile(pBody, boundPVariables, acceptor)
7385

74-
return acceptor.patternBodyStub
86+
return acceptor.patternBodyStub
7587
].toSet
7688

7789
return patternBodyStubs

0 commit comments

Comments
 (0)