Skip to content

Commit 8a43fdc

Browse files
authored
Merge pull request #1448 from xiemaisi/js/fix-access-paths-perf-regression
Approved by esben-semmle
2 parents 9135446 + b32a037 commit 8a43fdc

File tree

1 file changed

+14
-29
lines changed

1 file changed

+14
-29
lines changed

javascript/ql/src/semmle/javascript/dataflow/internal/AccessPaths.qll

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ private newtype PropertyName =
2828
}
2929

3030
/**
31-
* Gets the representation of the property name of `pacc`, if any.
31+
* Gets an access to property `name` of access path `base` in basic block `bb`.
3232
*/
33-
private PropertyName getPropertyName(PropAccess pacc) {
34-
result = StaticPropertyName(pacc.getPropertyName())
35-
or
36-
exists(SsaVariable var |
37-
pacc.getPropertyNameExpr() = var.getAUse() and
38-
result = DynamicPropertyName(var)
33+
private PropAccess namedPropAccess(AccessPath base, PropertyName name, BasicBlock bb) {
34+
result.getBase() = base.getAnInstanceIn(bb) and
35+
(
36+
name = StaticPropertyName(result.getPropertyName())
37+
or
38+
exists(SsaVariable var |
39+
result.getPropertyNameExpr() = var.getAUse() and
40+
name = DynamicPropertyName(var)
41+
)
3942
)
4043
}
4144

@@ -76,10 +79,7 @@ private newtype TAccessPath =
7679
* A property access on an access path.
7780
*/
7881
MkAccessStep(AccessPath base, PropertyName name) {
79-
exists(PropAccess pacc |
80-
pacc.getBase() = base.getAnInstance() and
81-
getPropertyName(pacc) = name
82-
)
82+
exists(namedPropAccess(base, name, _))
8383
}
8484

8585
/**
@@ -108,24 +108,9 @@ class AccessPath extends TAccessPath {
108108
this_.getBasicBlock() = bb
109109
)
110110
or
111-
exists(PropertyName name |
112-
result = getABaseInstanceIn(bb, name) and
113-
getPropertyName(result) = name
114-
)
115-
}
116-
117-
/**
118-
* Gets a property access in `bb` whose base is represented by the
119-
* base of this access path, and where `name` is bound to the last
120-
* component of this access path.
121-
*
122-
* This is an auxiliary predicate that's needed to enforce a better
123-
* join order in `getAnInstanceIn` above.
124-
*/
125-
pragma[noinline]
126-
private PropAccess getABaseInstanceIn(BasicBlock bb, PropertyName name) {
127-
exists(AccessPath base | this = MkAccessStep(base, name) |
128-
result.getBase() = base.getAnInstanceIn(bb)
111+
exists(AccessPath base, PropertyName name |
112+
this = MkAccessStep(base, name) and
113+
result = namedPropAccess(base, name, bb)
129114
)
130115
}
131116

0 commit comments

Comments
 (0)