Skip to content

Commit 2187bf5

Browse files
authored
Merge pull request github#9419 from github/revert-9373-cfg-for-key-paths
Revert "Swift: Control-flow for key paths"
2 parents 8b1605a + c9d109d commit 2187bf5

File tree

7 files changed

+16
-435
lines changed

7 files changed

+16
-435
lines changed

swift/ql/lib/codeql/swift/controlflow/BasicBlocks.qll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@ private module JoinBlockPredecessors {
207207
isPropertySetterElement(n, _, result)
208208
or
209209
isPropertyObserverElement(n, _, result)
210-
or
211-
result = n.(KeyPathElement).getAst()
212-
or
213-
result = n.(FuncDeclElement).getAst()
214210
}
215211

216212
int getId(JoinBlockPredecessor jbp) {

swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowElements.qll

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ newtype TControlFlowElement =
1010
} or
1111
TPropertyObserverElement(AccessorDecl observer, AssignExpr assign) {
1212
isPropertyObserverElement(observer, assign)
13-
} or
14-
TKeyPathElement(KeyPathExpr expr)
13+
}
1514

1615
predicate isLValue(Expr e) { any(AssignExpr assign).getDest() = e }
1716

@@ -172,18 +171,4 @@ class FuncDeclElement extends ControlFlowElement, TFuncDeclElement {
172171
override string toString() { result = func.toString() }
173172

174173
override Location getLocation() { result = func.getLocation() }
175-
176-
AbstractFunctionDecl getAst() { result = func }
177-
}
178-
179-
class KeyPathElement extends ControlFlowElement, TKeyPathElement {
180-
KeyPathExpr expr;
181-
182-
KeyPathElement() { this = TKeyPathElement(expr) }
183-
184-
override Location getLocation() { result = expr.getLocation() }
185-
186-
KeyPathExpr getAst() { result = expr }
187-
188-
override string toString() { result = expr.toString() }
189174
}

swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,19 @@ module CfgScope {
4747
}
4848

4949
private class BodyStmtCallableScope extends Range_ instanceof AbstractFunctionDecl {
50-
Decls::FuncDeclTree tree;
51-
52-
BodyStmtCallableScope() { tree.getAst() = this }
53-
54-
final override predicate entry(ControlFlowElement first) { first(tree, first) }
55-
56-
final override predicate exit(ControlFlowElement last, Completion c) { last(tree, last, c) }
57-
}
58-
59-
private class KeyPathScope extends Range_ instanceof KeyPathExpr {
60-
AstControlFlowTree tree;
61-
62-
KeyPathScope() { tree.getAst() = this.getParsedRoot().getFullyConverted() }
63-
64-
final override predicate entry(ControlFlowElement first) { first(tree, first) }
50+
final override predicate entry(ControlFlowElement first) {
51+
exists(Decls::FuncDeclTree tree |
52+
tree.getAst() = this and
53+
first = tree
54+
)
55+
}
6556

66-
final override predicate exit(ControlFlowElement last, Completion c) { last(tree, last, c) }
57+
final override predicate exit(ControlFlowElement last, Completion c) {
58+
exists(Decls::FuncDeclTree tree |
59+
tree.getAst() = this and
60+
tree.last(last, c)
61+
)
62+
}
6763
}
6864
}
6965

@@ -1116,20 +1112,6 @@ module Exprs {
11161112
}
11171113
}
11181114

1119-
class KeyPathTree extends AstLeafTree {
1120-
override KeyPathExpr ast;
1121-
}
1122-
1123-
class KeyPathApplicationTree extends AstStandardPostOrderTree {
1124-
override KeyPathApplicationExpr ast;
1125-
1126-
final override ControlFlowElement getChildElement(int i) {
1127-
i = 0 and result.asAstNode() = ast.getBase().getFullyConverted()
1128-
or
1129-
i = 1 and result.asAstNode() = ast.getKeyPath().getFullyConverted()
1130-
}
1131-
}
1132-
11331115
private class InOutTree extends AstStandardPostOrderTree {
11341116
override InOutExpr ast;
11351117

@@ -1666,9 +1648,7 @@ private module Cached {
16661648
result = scopeOfAst(n.asAstNode()) or
16671649
result = scopeOfAst(n.(PropertyGetterElement).getRef()) or
16681650
result = scopeOfAst(n.(PropertySetterElement).getAssignExpr()) or
1669-
result = scopeOfAst(n.(PropertyObserverElement).getAssignExpr()) or
1670-
result = n.(FuncDeclElement).getAst() or
1671-
result = n.(KeyPathElement).getAst()
1651+
result = scopeOfAst(n.(PropertyObserverElement).getAssignExpr())
16721652
}
16731653

16741654
cached

swift/ql/lib/codeql/swift/controlflow/internal/Scope.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ private import swift
22
private import codeql.swift.generated.GetImmediateParent
33

44
module CallableBase {
5-
class TypeRange = @abstract_function_decl or @key_path_expr;
5+
class TypeRange = @abstract_function_decl;
66

77
class Range extends Scope::Range, TypeRange { }
88
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
private import swift
22
private import DataFlowPrivate
33
private import DataFlowPublic
4-
private import codeql.swift.controlflow.ControlFlowGraph
54

65
newtype TReturnKind = TNormalReturnKind()
76

@@ -54,7 +53,7 @@ class DataFlowCall extends ExprNode {
5453
cached
5554
private module Cached {
5655
cached
57-
newtype TDataFlowCallable = TDataFlowFunc(CfgScope scope)
56+
newtype TDataFlowCallable = TDataFlowFunc(FuncDecl func)
5857

5958
/** Gets a viable run-time target for the call `call`. */
6059
cached

0 commit comments

Comments
 (0)