Skip to content

Commit 11194e5

Browse files
committed
Swift: Get rid of the unnecessary parameter/argument position for the closure. Instead, we can just reuse the 'this' parameter and argument.
1 parent 951b6be commit 11194e5

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
lines changed

swift/ql/lib/codeql/swift/dataflow/internal/DataFlowDispatch.qll

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,12 @@ private module Cached {
293293
newtype TArgumentPosition =
294294
TThisArgument() or
295295
// we rely on default exprs generated in the caller for ordering
296-
TPositionalArgument(int n) { n = any(Argument arg).getIndex() } or
297-
TClosureSelfArgument()
296+
TPositionalArgument(int n) { n = any(Argument arg).getIndex() }
298297

299298
cached
300299
newtype TParameterPosition =
301300
TThisParameter() or
302-
TPositionalParameter(int n) { n = any(Argument arg).getIndex() } or
303-
TClosureSelfParameter()
301+
TPositionalParameter(int n) { n = any(Argument arg).getIndex() }
304302
}
305303

306304
import Cached
@@ -333,10 +331,6 @@ class ThisParameterPosition extends ParameterPosition, TThisParameter {
333331
override string toString() { result = "this" }
334332
}
335333

336-
class ClosureSelfParameter extends ParameterPosition, TClosureSelfParameter {
337-
override string toString() { result = "{ ... }" }
338-
}
339-
340334
/** An argument position. */
341335
class ArgumentPosition extends TArgumentPosition {
342336
/** Gets a textual representation of this position. */
@@ -353,18 +347,11 @@ class ThisArgumentPosition extends ArgumentPosition, TThisArgument {
353347
override string toString() { result = "this" }
354348
}
355349

356-
class ClosureSelfArgument extends ArgumentPosition, TClosureSelfArgument {
357-
override string toString() { result = "{ ... }" }
358-
}
359-
360350
/** Holds if arguments at position `apos` match parameters at position `ppos`. */
361351
pragma[inline]
362352
predicate parameterMatch(ParameterPosition ppos, ArgumentPosition apos) {
363353
ppos instanceof TThisParameter and
364354
apos instanceof TThisArgument
365355
or
366356
ppos.(PositionalParameterPosition).getIndex() = apos.(PositionalArgumentPosition).getIndex()
367-
or
368-
ppos instanceof TClosureSelfParameter and
369-
apos instanceof TClosureSelfArgument
370357
}

swift/ql/lib/codeql/swift/dataflow/internal/DataFlowPrivate.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ private module ParameterNodes {
422422
class ClosureSelfParameterNode extends ParameterNodeImpl, ClosureSelfReferenceNode {
423423
override predicate isParameterOf(DataFlowCallable c, ParameterPosition pos) {
424424
c.asSourceCallable() = this.getClosure() and
425-
pos instanceof ClosureSelfParameter
425+
pos instanceof TThisParameter
426426
}
427427
}
428428

@@ -649,7 +649,7 @@ private module ArgumentNodes {
649649
override predicate argumentOf(DataFlowCall call, ArgumentPosition pos) {
650650
apply = call.asCall() and
651651
not exists(apply.getStaticTarget()) and
652-
pos instanceof ClosureSelfArgument
652+
pos instanceof ThisArgumentPosition
653653
}
654654
}
655655
}

0 commit comments

Comments
 (0)