Address review comments

This commit is contained in:
Tom Hvitved
2025-05-21 14:01:48 +02:00
parent 3fa4ea4da3
commit 13861b81a8
2 changed files with 25 additions and 29 deletions

View File

@@ -240,7 +240,7 @@ private predicate typeEqualityLeft(AstNode n1, TypePath path1, AstNode n2, TypeP
any(PrefixExpr pe |
pe.getOperatorName() = "*" and
pe.getExpr() = n1 and
path1 = TypePath::consInverse(TRefTypeParameter(), path2)
path1.isCons(TRefTypeParameter(), path2)
)
}
@@ -926,7 +926,7 @@ private Type inferRefExprType(Expr e, TypePath path) {
e = re.getExpr() and
exists(TypePath exprPath, TypePath refPath, Type exprType |
result = inferType(re, exprPath) and
exprPath = TypePath::consInverse(TRefTypeParameter(), refPath) and
exprPath.isCons(TRefTypeParameter(), refPath) and
exprType = inferType(e)
|
if exprType = TRefType()
@@ -940,8 +940,9 @@ private Type inferRefExprType(Expr e, TypePath path) {
pragma[nomagic]
private Type inferTryExprType(TryExpr te, TypePath path) {
exists(TypeParam tp |
result = inferType(te.getExpr(), TypePath::consInverse(TTypeParamTypeParameter(tp), path))
exists(TypeParam tp, TypePath path0 |
result = inferType(te.getExpr(), path0) and
path0.isCons(TTypeParamTypeParameter(tp), path)
|
tp = any(ResultEnum r).getGenericParamList().getGenericParam(0)
or
@@ -1017,7 +1018,7 @@ private module Cached {
pragma[nomagic]
Type getTypeAt(TypePath path) {
exists(TypePath path0 | result = inferType(this, path0) |
path0 = TypePath::consInverse(TRefTypeParameter(), path)
path0.isCons(TRefTypeParameter(), path)
or
not path0.isCons(TRefTypeParameter(), _) and
not (path0.isEmpty() and result = TRefType()) and

View File

@@ -184,7 +184,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
/** Gets the length of this path, assuming the length is at least 2. */
bindingset[this]
pragma[inline_late]
private int length2() {
private int lengthAtLeast2() {
// Same as
// `result = strictcount(this.indexOf(".")) + 1`
// but performs better because it doesn't use an aggregate
@@ -200,7 +200,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
else
if exists(TypeParameter::decode(this))
then result = 1
else result = this.length2()
else result = this.lengthAtLeast2()
}
/** Gets the path obtained by appending `suffix` onto this path. */
@@ -216,7 +216,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
(
not exists(getTypePathLimit())
or
result.length2() <= getTypePathLimit()
result.lengthAtLeast2() <= getTypePathLimit()
)
)
}
@@ -228,22 +228,26 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
* so there is no need to check the length of `result`.
*/
bindingset[this, result]
TypePath appendInverse(TypePath suffix) {
if result.isEmpty()
then this.isEmpty() and suffix.isEmpty()
else
if this.isEmpty()
then suffix = result
else (
result = this and suffix.isEmpty()
or
result = this + "." + suffix
)
TypePath appendInverse(TypePath suffix) { suffix = result.stripPrefix(this) }
/** Gets the path obtained by removing `prefix` from this path. */
bindingset[this, prefix]
TypePath stripPrefix(TypePath prefix) {
if prefix.isEmpty()
then result = this
else (
this = prefix and
result.isEmpty()
or
this = prefix + "." + result
)
}
/** Holds if this path starts with `tp`, followed by `suffix`. */
bindingset[this]
predicate isCons(TypeParameter tp, TypePath suffix) { this = TypePath::consInverse(tp, suffix) }
predicate isCons(TypeParameter tp, TypePath suffix) {
suffix = this.stripPrefix(TypePath::singleton(tp))
}
}
/** Provides predicates for constructing `TypePath`s. */
@@ -260,15 +264,6 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
*/
bindingset[suffix]
TypePath cons(TypeParameter tp, TypePath suffix) { result = singleton(tp).append(suffix) }
/**
* Gets the type path obtained by appending the singleton type path `tp`
* onto `suffix`.
*/
bindingset[result]
TypePath consInverse(TypeParameter tp, TypePath suffix) {
result = singleton(tp).appendInverse(suffix)
}
}
/**