Skip to content

Commit 2bcddb0

Browse files
committed
Shared: Simplify type inference predicates
1 parent 7a367c9 commit 2bcddb0

1 file changed

Lines changed: 4 additions & 23 deletions

File tree

shared/typeinference/codeql/typeinference/internal/TypeInference.qll

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3162,43 +3162,25 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
31623162
p = inferTypeCand(n, path).(ClosureParameterPseudoType).getParameter()
31633163
}
31643164

3165-
pragma[nomagic]
3166-
private predicate hasClosureParameterPseudoType(AstNode n) {
3167-
hasClosureParameterPseudoType(n, _, _)
3168-
}
3169-
3170-
pragma[nomagic]
3171-
private predicate hasTypeAtPrefix(AstNode n, TypePath prefix, TypePath path) {
3172-
hasInferredType(n, path) and
3173-
hasClosureParameterPseudoType(n) and
3174-
prefix = path.getAPrefix()
3175-
}
3176-
31773165
/**
31783166
* Holds if `n` has a closure parameter pseudo type for the parameter
31793167
* with pattern `pattern` at `prefix`, where `path = prefix.suffix`.
31803168
*
31813169
* This means that the parameter pattern can be inferred to have type
3182-
* `t` at `suffix` when `n` also has inferred type `t` at `path`.
3170+
* `type` at `suffix` when `n` also has inferred type `type` at `path`.
31833171
*/
31843172
pragma[nomagic]
31853173
private predicate hasClosureParameterPseudoTypeAtPrefix(
3186-
AstNode n, TypePath path, AstNode pattern, TypePath suffix
3174+
AstNode n, TypePath path, Type type, AstNode pattern, TypePath suffix
31873175
) {
31883176
exists(Parameter p, TypePath prefix |
31893177
hasClosureParameterPseudoType(n, prefix, p) and
3190-
hasTypeAtPrefix(n, prefix, path) and
3178+
type = inferType(n, path) and
31913179
path = prefix.appendInverse(suffix) and
31923180
pattern = p.getPattern()
31933181
)
31943182
}
31953183

3196-
pragma[nomagic]
3197-
private Type inferClosureParameterTypeCand(AstNode n, TypePath path) {
3198-
result = inferType(n, path) and
3199-
hasClosureParameterPseudoType(n)
3200-
}
3201-
32023184
private Type inferClosureParameterPseudoType(AstNode n, TypePath path) {
32033185
// The `step X` comments below refer to the steps for 'Case B' in the
32043186
// QL doc for `ClosureParameterPseudoType`.
@@ -3216,8 +3198,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
32163198
or
32173199
// step 6
32183200
exists(AstNode n0, TypePath path0 |
3219-
hasClosureParameterPseudoTypeAtPrefix(n0, path0, n, path) and
3220-
result = inferClosureParameterTypeCand(n0, path0) and
3201+
hasClosureParameterPseudoTypeAtPrefix(n0, path0, result, n, path) and
32213202
not (path.isEmpty() and result instanceof UnknownType)
32223203
)
32233204
}

0 commit comments

Comments
 (0)