Skip to content

Commit 62d10f9

Browse files
committed
Improve join ordering
1 parent d5f7ef0 commit 62d10f9

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

java/ql/lib/semmle/code/java/Member.qll

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,14 +397,21 @@ private predicate potentialInterfaceImplementationWithSignature(string sig, RefT
397397
not t.isAbstract()
398398
}
399399

400-
pragma[nomagic]
401-
private predicate implementsInterfaceMethod(SrcMethod impl, SrcMethod m) {
402-
exists(RefType t, Interface i, Method minst, Method implinst |
403-
m = minst.getSourceDeclaration() and
400+
pragma[noinline]
401+
private predicate isInterfaceSourceImplementation(Method minst, RefType t) {
402+
exists(Interface i |
404403
i = minst.getDeclaringType() and
405404
t.extendsOrImplements+(i) and
406-
t.isSourceDeclaration() and
405+
t.isSourceDeclaration()
406+
)
407+
}
408+
409+
pragma[nomagic]
410+
private predicate implementsInterfaceMethod(SrcMethod impl, SrcMethod m) {
411+
exists(RefType t, Method minst, Method implinst |
412+
isInterfaceSourceImplementation(minst, t) and
407413
potentialInterfaceImplementationWithSignature(minst.getSignature(), t, implinst) and
414+
m = minst.getSourceDeclaration() and
408415
impl = implinst.getSourceDeclaration()
409416
)
410417
}
@@ -542,7 +549,7 @@ class Method extends Callable, @method {
542549

543550
/** A method that is the same as its source declaration. */
544551
class SrcMethod extends Method {
545-
SrcMethod() { methods(_, _, _, _, _, this) }
552+
SrcMethod() { methods(this, _, _, _, _, this) }
546553

547554
/**
548555
* All the methods that could possibly be called when this method

java/ql/lib/semmle/code/java/dataflow/TypeFlow.qll

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,14 @@ private predicate unionTypeFlow0(TypeFlowNode n, RefType t, boolean exact) {
681681
private predicate unionTypeFlow(TypeFlowNode n, RefType t, boolean exact) {
682682
unionTypeFlow0(n, t, exact) and
683683
// filter impossible union parts:
684-
if exact = true
685-
then t.getErasure().(RefType).getASourceSupertype*() = getTypeBound(n).getErasure()
686-
else haveIntersection(getTypeBound(n), t)
684+
exists(RefType tErased, RefType boundErased |
685+
pragma[only_bind_into](tErased) = t.getErasure() and
686+
pragma[only_bind_into](boundErased) = getTypeBound(n).getErasure()
687+
|
688+
if exact = true
689+
then tErased.getASourceSupertype*() = boundErased
690+
else erasedHaveIntersection(tErased, boundErased)
691+
)
687692
}
688693

689694
/**

java/ql/lib/semmle/code/java/dispatch/internal/Unification.qll

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ module MkUnification<unificationTarget/1 targetLeft, unificationTarget/1 targetR
2222
targetRight(t2) and t2.getGenericType() = g
2323
}
2424

25+
pragma[noinline]
26+
private predicate unificationTargetsWithCommonSourceDecl(
27+
ParameterizedType pt1, ParameterizedType pt2
28+
) {
29+
exists(RefType commonSourceDecl |
30+
unificationTargets(pt1, pt2) and
31+
pragma[only_bind_out](pt1).getSourceDeclaration() = pragma[only_bind_out](commonSourceDecl) and
32+
pragma[only_bind_out](pt2).getSourceDeclaration() = commonSourceDecl
33+
)
34+
}
35+
2536
private predicate unificationTargets(Type t1, Type t2) {
2637
exists(GenericType g | unificationTargetLeft(t1, g) and unificationTargetRight(t2, g))
2738
or
@@ -32,10 +43,9 @@ module MkUnification<unificationTarget/1 targetLeft, unificationTarget/1 targetR
3243
)
3344
or
3445
exists(ParameterizedType pt1, ParameterizedType pt2, int pos |
35-
unificationTargets(pt1, pt2) and
36-
not pt1.getSourceDeclaration() != pt2.getSourceDeclaration() and
37-
t1 = pt1.getTypeArgument(pos) and
38-
t2 = pt2.getTypeArgument(pos)
46+
unificationTargetsWithCommonSourceDecl(pt1, pt2) and
47+
t1 = pt1.getTypeArgument(pragma[only_bind_into](pos)) and
48+
t2 = pt2.getTypeArgument(pragma[only_bind_into](pos))
3949
)
4050
}
4151

@@ -44,8 +54,8 @@ module MkUnification<unificationTarget/1 targetLeft, unificationTarget/1 targetR
4454
ParameterizedType t1, ParameterizedType t2, int pos, RefType arg1, RefType arg2
4555
) {
4656
unificationTargets(t1, t2) and
47-
arg1 = t1.getTypeArgument(pos) and
48-
arg2 = t2.getTypeArgument(pos)
57+
arg1 = t1.getTypeArgument(pragma[only_bind_into](pos)) and
58+
arg2 = t2.getTypeArgument(pragma[only_bind_into](pos))
4959
}
5060

5161
private RefType getUpperBound(RefType t) {

0 commit comments

Comments
 (0)