Skip to content

Commit c4065fb

Browse files
committed
wip4
1 parent cf5f60f commit c4065fb

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,9 +2421,9 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
24212421
private import Input3
24222422

24232423
private predicate closureStep(AstNode pattern, TypePath path1, Closure c, TypePath path2) {
2424-
exists(int index, Parameter p |
2424+
exists(Parameter p |
24252425
pattern = p.getPattern() and
2426-
p = c.getParameter(index) and
2426+
p = c.getParameter(_) and
24272427
path1.isEmpty() and
24282428
path2 = getClosureParameterTypePath(p)
24292429
)
@@ -3157,26 +3157,24 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
31573157
CachedStage::ref() and
31583158
result = inferTypeCertain(n, path)
31593159
or
3160+
result = inferType0(n, path) and
31603161
// Don't propagate type information into a node which conflicts with certain
31613162
// type information.
3162-
result = inferType0(n, path) and
31633163
forall(TypePath prefix |
31643164
Certain::hasInferredCertainType(n, prefix) and
31653165
prefix.isPrefixOf(path)
31663166
|
31673167
not Certain::certainTypeConflict(n, prefix, path, result)
31683168
or
3169-
// propagate closure parameter pseudo types even when there is certain information,
3170-
// but prevent those types from escaping from the closure
3171-
exists(Parameter p |
3172-
result.(ClosureParameterPseudoType).getParameter() = p and
3173-
not p = n.(Closure).getParameter(_)
3174-
)
3175-
)
3169+
// propagate closure parameter pseudo types even when there is certain information
3170+
result instanceof ClosureParameterPseudoType
3171+
) and
3172+
// prevent closure parameter pseudo types from escaping from the closure
3173+
not result.(ClosureParameterPseudoType).getParameter() = n.(Closure).getParameter(_)
31763174
or
31773175
// If `n` has an explicitly unknown type at `prefix` and at the same time a certain
31783176
// type at `prefix.suffix`, then extend the unknown type information to any path
3179-
// extending `prefix.suffix` where there is no certain type information
3177+
// extending `prefix.suffix` where there is not also certain type information
31803178
exists(TypePath prefix, TypePath suffix, Type certain, TypeParameter tp |
31813179
inferType0(n, prefix) instanceof UnknownType and
31823180
certain = inferTypeCertain(n, prefix.appendInverse(suffix)) and
@@ -3189,6 +3187,10 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
31893187
infersTypeAt(n, path, result.getATypeParameter())
31903188
}
31913189

3190+
/**
3191+
* Holds if `n` has type information at the type path `prefix.tp`. This entails
3192+
* that the type at `prefix` must be the type that declares `tp`.
3193+
*/
31923194
pragma[nomagic]
31933195
private predicate infersTypeAt(AstNode n, TypePath prefix, TypeParameter tp) {
31943196
exists(TypePath path |
@@ -3201,6 +3203,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
32013203
/**
32023204
* Gets the inferred root type of `n`, if any.
32033205
*/
3206+
pragma[nomagic]
32043207
Type inferType(AstNode n) { result = inferType(n, TypePath::nil()) }
32053208

32063209
/**
@@ -3238,7 +3241,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
32383241
}
32393242

32403243
/**
3241-
* Checks that `Input3::inferType` is an alias for `inferType`.
3244+
* Checks that `Input3::inferTypeForDefaults` is an alias for `inferType`.
32423245
*/
32433246
query predicate inferTypeMismatch(AstNode n, TypePath path, Type t) {
32443247
inferType(n, path) = t and
@@ -3251,6 +3254,10 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
32513254

32523255
/** Provides various debugging predicates. */
32533256
module Debug {
3257+
/**
3258+
* Holds if `n` has reached the type path limit. This is usually indicative
3259+
* of an unintended type inference explosion.
3260+
*/
32543261
pragma[nomagic]
32553262
predicate atLimit(AstNode n) {
32563263
exists(TypePath path0 |

0 commit comments

Comments
 (0)