Skip to content

Commit ede3b9f

Browse files
committed
Improve join order by making a separate predicate
1 parent e335737 commit ede3b9f

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -306,27 +306,35 @@ module SourceSinkInterpretationInput implements
306306
or
307307
// `syntacticQualBaseType`'s underlying type might be a struct type and `sse`
308308
// might be a promoted method or field in it.
309-
exists(StructType st, Field field1, Field field2, int depth1, int depth2, Type t2 |
310-
st = syntacticQualBaseType.getUnderlyingType() and
311-
field1 = st.getFieldAtDepth(_, depth1) and
312-
field2 = st.getFieldAtDepth(_, depth2) and
313-
targetType = lookThroughPointerType(field1.getType()) and
314-
t2 = lookThroughPointerType(field2.getType()) and
315-
(
316-
field1 = field2
317-
or
318-
field2 =
319-
targetType.getUnderlyingType().(StructType).getFieldAtDepth(_, depth2 - depth1 - 1)
320-
)
321-
|
322-
sse.asEntity().(Method).getReceiverBaseType() = t2
323-
or
324-
sse.asEntity().(Field).getDeclaringType() = t2.getUnderlyingType()
325-
)
309+
targetType =
310+
getIntermediateEmbeddedType(sse.asEntity(), syntacticQualBaseType.getUnderlyingType())
326311
)
327312
)
328313
}
329314

315+
/**
316+
* Gets the type of an embedded field of `st` which is on the path to `e`,
317+
* which is a promoted method or field of `st`, or its base type if it's a
318+
* pointer type.
319+
*/
320+
private Type getIntermediateEmbeddedType(Entity e, StructType st) {
321+
exists(Field field1, Field field2, int depth1, int depth2, Type t2 |
322+
field1 = st.getFieldAtDepth(_, depth1) and
323+
field2 = st.getFieldAtDepth(_, depth2) and
324+
result = lookThroughPointerType(field1.getType()) and
325+
t2 = lookThroughPointerType(field2.getType()) and
326+
(
327+
field1 = field2
328+
or
329+
field2 = result.getUnderlyingType().(StructType).getFieldAtDepth(_, depth2 - depth1 - 1)
330+
)
331+
|
332+
e.(Method).getReceiverBaseType() = t2
333+
or
334+
e.(Field).getDeclaringType() = t2.getUnderlyingType()
335+
)
336+
}
337+
330338
/**
331339
* Gets `underlying`, where `n` if of the form `implicitDeref?(underlying.implicitFieldRead1.implicitFieldRead2...)`
332340
*

0 commit comments

Comments
 (0)