Skip to content

Commit 79e1af0

Browse files
committed
Rust: Fix bad join in satisfiesConstraintTypeMention
Before ``` Pipeline standard for TypeInference::CallExprBaseMatching::AccessConstraint::satisfiesConstraintTypeMention/6#69a92324@e8671rw7 was evaluated in 378 iterations totaling 313ms (delta sizes total: 168323). 462477 ~1% {7} r1 = JOIN `TypeInference::CallExprBaseMatching::AccessConstraint::hasConstraintMention/5#8730ee97#prev_delta` WITH TypeInference::CallExprBaseMatching::AccessConstraint::MkRelevantAccess#8a6252ad#reorder_3_0_1_2#prev ON FIRST 1 OUTPUT Lhs.1, Lhs.2, Lhs.4, Lhs.3, Rhs.1, Rhs.2, Rhs.3 993561 ~2% {9} | JOIN WITH `TypeInference::M2::BaseTypes::conditionSatisfiesConstraintTypeAt/5#e92dcc7a` ON FIRST 3 OUTPUT Lhs.0, Lhs.1, Lhs.2, Rhs.3, Rhs.4, Lhs.3, Lhs.4, Lhs.5, Lhs.6 993561 ~38% {7} | JOIN WITH `TypeInference::M2::BaseTypes::conditionSatisfiesConstraintTypeAt/5#e92dcc7a` ON FIRST 5 OUTPUT Lhs.0, Lhs.4, Lhs.5, Lhs.6, Lhs.7, Lhs.8, Lhs.3 {7} | AND NOT `Type::TypeAbstraction.getATypeParameter/0#dispred#030257a0`(FIRST 2) 772102 ~427% {6} | SCAN OUTPUT In.3, In.4, In.5, In.2, In.6, In.1 56885 ~1% {4} r2 = SCAN TypeInference::CallExprBaseMatching::AccessConstraint::MkRelevantAccess#8a6252ad#prev_delta OUTPUT In.3, In.0, In.1, In.2 0 ~0% {7} r3 = JOIN r2 WITH `TypeInference::CallExprBaseMatching::AccessConstraint::hasConstraintMention/5#8730ee97#prev` ON FIRST 1 OUTPUT Rhs.1, Rhs.2, Rhs.4, Lhs.1, Lhs.2, Lhs.3, Rhs.3 0 ~0% {9} | JOIN WITH `TypeInference::M2::BaseTypes::conditionSatisfiesConstraintTypeAt/5#e92dcc7a` ON FIRST 3 OUTPUT Lhs.0, Lhs.1, Lhs.2, Rhs.3, Rhs.4, Lhs.3, Lhs.4, Lhs.5, Lhs.6 0 ~0% {7} | JOIN WITH `TypeInference::M2::BaseTypes::conditionSatisfiesConstraintTypeAt/5#e92dcc7a` ON FIRST 5 OUTPUT Lhs.0, Lhs.4, Lhs.5, Lhs.6, Lhs.7, Lhs.8, Lhs.3 {7} | AND NOT `Type::TypeAbstraction.getATypeParameter/0#dispred#030257a0`(FIRST 2) 0 ~0% {6} | SCAN OUTPUT In.2, In.3, In.4, In.5, In.6, In.1 462477 ~1% {8} r4 = JOIN `TypeInference::CallExprBaseMatching::AccessConstraint::hasConstraintMention/5#8730ee97#prev_delta` WITH TypeInference::CallExprBaseMatching::AccessConstraint::MkRelevantAccess#8a6252ad#reorder_3_0_1_2#prev ON FIRST 1 OUTPUT Lhs.1, Lhs.2, Lhs.4, Lhs.0, Lhs.3, Rhs.1, Rhs.2, Rhs.3 993561 ~39% {9} | JOIN WITH `TypeInference::M2::BaseTypes::conditionSatisfiesConstraintTypeAt/5#e92dcc7a` ON FIRST 3 OUTPUT Lhs.0, Rhs.4, Lhs.3, Lhs.1, Lhs.4, Lhs.5, Lhs.6, Lhs.7, Rhs.3 23413 ~1% {8} | JOIN WITH `Type::TypeAbstraction.getATypeParameter/0#dispred#030257a0` ON FIRST 2 OUTPUT Lhs.3, Lhs.1, Lhs.2, Lhs.4, Lhs.5, Lhs.6, Lhs.7, Lhs.8 2817 ~7% {7} | JOIN WITH `TypeMention::TypeMention.resolveTypeAt/1#dispred#a125c821#bff#reorder_0_2_1` ON FIRST 2 OUTPUT Lhs.2, Lhs.3, Lhs.4, Lhs.5, Lhs.6, Lhs.7, Rhs.2 11550 ~0% {9} | JOIN WITH `TypeInference::CallExprBaseMatching::AccessConstraint::RelevantAccess.getTypeAt/1#dispred#3a89868c#prev` ON FIRST 1 OUTPUT Lhs.1, Lhs.2, Lhs.3, Lhs.4, Lhs.5, Rhs.2, _, Lhs.6, Rhs.1 {7} | REWRITE WITH Tmp.6 := "", Out.6 := InverseAppend(In.7,Tmp.6,In.8) KEEPING 7 2397 ~1% {11} | SCAN OUTPUT In.0, In.1, In.2, In.3, In.5, _, _, In.4, In.6, _, _ {7} | REWRITE WITH Out.5 := (In.7 ++ In.8), Tmp.6 := (In.7 ++ In.8), Tmp.9 := "[0-9]+", Tmp.10 := "", Out.6 := regexpReplaceAll(Tmp.6,Tmp.9,Tmp.10) KEEPING 7 2397 ~1% {9} | SCAN OUTPUT In.0, In.1, In.2, In.3, In.4, In.5, _, In.6, _ {7} | REWRITE WITH Out.6 := length(In.7), Tmp.8 := 10, TEST Out.6 <= Tmp.8 KEEPING 7 2397 ~1% {6} | SCAN OUTPUT In.1, In.2, In.3, In.0, In.5, In.4 66727 ~0% {6} r5 = JOIN `TypeInference::CallExprBaseMatching::AccessConstraint::RelevantAccess.getTypeAt/1#dispred#3a89868c#prev_delta` WITH TypeInference::CallExprBaseMatching::AccessConstraint::MkRelevantAccess#8a6252ad#reorder_3_0_1_2#prev ON FIRST 1 OUTPUT Lhs.0, Lhs.1, Lhs.2, Rhs.1, Rhs.2, Rhs.3 19305359 ~0% {9} | JOIN WITH `TypeInference::CallExprBaseMatching::AccessConstraint::hasConstraintMention/5#8730ee97#prev` ON FIRST 1 OUTPUT Rhs.1, Lhs.1, Lhs.2, Lhs.3, Lhs.4, Lhs.5, Rhs.2, Rhs.3, Rhs.4 3454881 ~1% {10} | JOIN WITH `Type::TypeAbstraction.getATypeParameter/0#dispred#030257a0` ON FIRST 1 OUTPUT Lhs.0, Lhs.6, Lhs.8, Rhs.1, Lhs.1, Lhs.2, Lhs.3, Lhs.4, Lhs.5, Lhs.7 753104 ~1% {9} | JOIN WITH `TypeInference::M2::BaseTypes::conditionSatisfiesConstraintTypeAt/5#e92dcc7a_01243#join_rhs` ON FIRST 4 OUTPUT Lhs.1, Lhs.3, Lhs.4, Lhs.5, Lhs.6, Lhs.7, Lhs.8, Lhs.9, Rhs.4 32040 ~18% {9} | JOIN WITH `TypeMention::TypeMention.resolveTypeAt/1#dispred#a125c821#bff#reorder_0_2_1` ON FIRST 2 OUTPUT Lhs.3, Lhs.4, Lhs.5, Lhs.6, Lhs.7, Lhs.8, _, Rhs.2, Lhs.2 {7} | REWRITE WITH Tmp.6 := "", Out.6 := InverseAppend(In.7,Tmp.6,In.8) KEEPING 7 13192 ~54% {11} | SCAN OUTPUT In.0, In.1, In.2, In.3, In.4, _, _, In.5, In.6, _, _ {7} | REWRITE WITH Out.5 := (In.7 ++ In.8), Tmp.6 := (In.7 ++ In.8), Tmp.9 := "[0-9]+", Tmp.10 := "", Out.6 := regexpReplaceAll(Tmp.6,Tmp.9,Tmp.10) KEEPING 7 13192 ~54% {9} | SCAN OUTPUT In.0, In.1, In.2, In.3, In.4, In.5, _, In.6, _ {7} | REWRITE WITH Out.6 := length(In.7), Tmp.8 := 10, TEST Out.6 <= Tmp.8 KEEPING 7 13192 ~55% {6} | SCAN OUTPUT In.1, In.2, In.3, In.4, In.5, In.0 0 ~0% {8} r6 = JOIN r2 WITH `TypeInference::CallExprBaseMatching::AccessConstraint::hasConstraintMention/5#8730ee97#prev` ON FIRST 1 OUTPUT Rhs.1, Rhs.2, Rhs.4, Lhs.1, Lhs.2, Lhs.3, Lhs.0, Rhs.3 0 ~0% {9} | JOIN WITH `TypeInference::M2::BaseTypes::conditionSatisfiesConstraintTypeAt/5#e92dcc7a` ON FIRST 3 OUTPUT Lhs.0, Rhs.4, Lhs.3, Lhs.4, Lhs.5, Lhs.6, Lhs.1, Lhs.7, Rhs.3 0 ~0% {8} | JOIN WITH `Type::TypeAbstraction.getATypeParameter/0#dispred#030257a0` ON FIRST 2 OUTPUT Lhs.6, Lhs.1, Lhs.2, Lhs.3, Lhs.4, Lhs.5, Lhs.7, Lhs.8 0 ~0% {7} | JOIN WITH `TypeMention::TypeMention.resolveTypeAt/1#dispred#a125c821#bff#reorder_0_2_1` ON FIRST 2 OUTPUT Lhs.5, Lhs.2, Lhs.3, Lhs.4, Lhs.6, Lhs.7, Rhs.2 0 ~0% {9} | JOIN WITH `TypeInference::CallExprBaseMatching::AccessConstraint::RelevantAccess.getTypeAt/1#dispred#3a89868c#prev` ON FIRST 1 OUTPUT Lhs.1, Lhs.2, Lhs.3, Lhs.4, Lhs.5, Rhs.2, _, Lhs.6, Rhs.1 {7} | REWRITE WITH Tmp.6 := "", Out.6 := InverseAppend(In.7,Tmp.6,In.8) KEEPING 7 0 ~0% {11} | SCAN OUTPUT In.0, In.1, In.2, In.3, In.5, _, _, In.4, In.6, _, _ {7} | REWRITE WITH Out.5 := (In.7 ++ In.8), Tmp.6 := (In.7 ++ In.8), Tmp.9 := "[0-9]+", Tmp.10 := "", Out.6 := regexpReplaceAll(Tmp.6,Tmp.9,Tmp.10) KEEPING 7 0 ~0% {9} | SCAN OUTPUT In.0, In.1, In.2, In.3, In.4, In.5, _, In.6, _ {7} | REWRITE WITH Out.6 := length(In.7), Tmp.8 := 10, TEST Out.6 <= Tmp.8 KEEPING 7 0 ~0% {6} | SCAN OUTPUT In.0, In.1, In.2, In.3, In.5, In.4 787691 ~403% {6} r7 = r1 UNION r3 UNION r4 UNION r5 UNION r6 212766 ~54% {6} | AND NOT `TypeInference::CallExprBaseMatching::AccessConstraint::satisfiesConstraintTypeMention/6#69a92324#prev`(FIRST 6) return r7 ``` After ``` Pipeline standard for TypeInference::CallExprBaseMatching::AccessConstraint::satisfiesConstraintTypeMention/6#69a92324@9c099xwn was evaluated in 380 iterations totaling 11ms (delta sizes total: 153004). 768937 ~1% {7} r1 = SCAN `TypeInference::CallExprBaseMatching::AccessConstraint::satisfiesConstraintTypeMention0/9#c82a4f76#prev_delta` OUTPUT In.5, In.8, In.1, In.2, In.3, In.4, In.7 {7} | AND NOT `Type::TypeAbstraction.getATypeParameter/0#dispred#030257a0`(FIRST 2) 745524 ~423% {6} | SCAN OUTPUT In.2, In.3, In.4, In.5, In.6, In.1 26916 ~0% {9} r2 = JOIN `TypeInference::CallExprBaseMatching::AccessConstraint::RelevantAccess.getTypeAt/1#dispred#3a89868c#prev_delta` WITH `TypeInference::CallExprBaseMatching::AccessConstraint::satisfiesConstraintTypeMention1/7#b265d17e#prev` ON FIRST 1 OUTPUT Lhs.2, Rhs.1, Rhs.2, Rhs.3, Rhs.4, Rhs.5, _, Rhs.6, Lhs.1 {7} | REWRITE WITH Tmp.6 := "", Out.6 := InverseAppend(In.7,Tmp.6,In.8) KEEPING 7 8530 ~1% {11} | SCAN OUTPUT In.0, In.1, In.2, In.3, In.4, _, _, In.5, In.6, _, _ {7} | REWRITE WITH Out.5 := (In.7 ++ In.8), Tmp.6 := (In.7 ++ In.8), Tmp.9 := "[0-9]+", Tmp.10 := "", Out.6 := regexpReplaceAll(Tmp.6,Tmp.9,Tmp.10) KEEPING 7 8530 ~1% {9} | SCAN OUTPUT In.0, In.1, In.2, In.3, In.4, In.5, _, In.6, _ {7} | REWRITE WITH Out.6 := length(In.7), Tmp.8 := 10, TEST Out.6 <= Tmp.8 KEEPING 7 8530 ~1% {6} | SCAN OUTPUT In.1, In.2, In.3, In.4, In.5, In.0 11763 ~1% {9} r3 = JOIN `TypeInference::CallExprBaseMatching::AccessConstraint::satisfiesConstraintTypeMention1/7#b265d17e#prev_delta` WITH `TypeInference::CallExprBaseMatching::AccessConstraint::RelevantAccess.getTypeAt/1#dispred#3a89868c#prev` ON FIRST 1 OUTPUT Lhs.1, Lhs.2, Lhs.3, Lhs.4, Lhs.5, Rhs.2, _, Lhs.6, Rhs.1 {7} | REWRITE WITH Tmp.6 := "", Out.6 := InverseAppend(In.7,Tmp.6,In.8) KEEPING 7 2461 ~1% {11} | SCAN OUTPUT In.0, In.1, In.2, In.3, In.5, _, _, In.4, In.6, _, _ {7} | REWRITE WITH Out.5 := (In.7 ++ In.8), Tmp.6 := (In.7 ++ In.8), Tmp.9 := "[0-9]+", Tmp.10 := "", Out.6 := regexpReplaceAll(Tmp.6,Tmp.9,Tmp.10) KEEPING 7 2461 ~1% {9} | SCAN OUTPUT In.0, In.1, In.2, In.3, In.4, In.5, _, In.6, _ {7} | REWRITE WITH Out.6 := length(In.7), Tmp.8 := 10, TEST Out.6 <= Tmp.8 KEEPING 7 2461 ~1% {6} | SCAN OUTPUT In.0, In.1, In.2, In.3, In.5, In.4 756515 ~396% {6} r4 = r1 UNION r2 UNION r3 155599 ~6% {6} | AND NOT `TypeInference::CallExprBaseMatching::AccessConstraint::satisfiesConstraintTypeMention/6#69a92324#prev`(FIRST 6) return r4 ```
1 parent f9915e6 commit 79e1af0

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

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

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
10361036
/**
10371037
* Holds if `at` satisfies `constraint` through `abs`, `sub`, and `constraintMention`.
10381038
*/
1039+
pragma[nomagic]
10391040
private predicate hasConstraintMention(
10401041
RelevantAccess at, TypeAbstraction abs, TypeMention sub, Type constraint,
10411042
TypeMention constraintMention
@@ -1059,6 +1060,30 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
10591060
)
10601061
}
10611062

1063+
pragma[nomagic]
1064+
predicate satisfiesConstraintTypeMention0(
1065+
RelevantAccess at, Access a, AccessPosition apos, TypePath prefix, Type constraint,
1066+
TypeAbstraction abs, TypeMention sub, TypePath path, Type t
1067+
) {
1068+
exists(TypeMention constraintMention |
1069+
at = MkRelevantAccess(a, apos, prefix) and
1070+
hasConstraintMention(at, abs, sub, constraint, constraintMention) and
1071+
conditionSatisfiesConstraintTypeAt(abs, sub, constraintMention, path, t)
1072+
)
1073+
}
1074+
1075+
pragma[nomagic]
1076+
predicate satisfiesConstraintTypeMention1(
1077+
RelevantAccess at, Access a, AccessPosition apos, TypePath prefix, Type constraint,
1078+
TypePath path, TypePath pathToTypeParamInSub
1079+
) {
1080+
exists(TypeAbstraction abs, TypeMention sub, TypeParameter tp |
1081+
satisfiesConstraintTypeMention0(at, a, apos, prefix, constraint, abs, sub, path, tp) and
1082+
tp = abs.getATypeParameter() and
1083+
sub.resolveTypeAt(pathToTypeParamInSub) = tp
1084+
)
1085+
}
1086+
10621087
/**
10631088
* Holds if the type at `a`, `apos`, and `path` satisfies the constraint
10641089
* `constraint` with the type `t` at `path`.
@@ -1067,22 +1092,18 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
10671092
predicate satisfiesConstraintTypeMention(
10681093
Access a, AccessPosition apos, TypePath prefix, Type constraint, TypePath path, Type t
10691094
) {
1095+
exists(TypeAbstraction abs |
1096+
satisfiesConstraintTypeMention0(_, a, apos, prefix, constraint, abs, _, path, t) and
1097+
not t = abs.getATypeParameter()
1098+
)
1099+
or
10701100
exists(
1071-
RelevantAccess at, TypeAbstraction abs, TypeMention sub, Type t0, TypePath prefix0,
1072-
TypeMention constraintMention
1101+
RelevantAccess at, TypePath prefix0, TypePath pathToTypeParamInSub, TypePath suffix
10731102
|
1074-
at = MkRelevantAccess(a, apos, prefix) and
1075-
hasConstraintMention(at, abs, sub, constraint, constraintMention) and
1076-
conditionSatisfiesConstraintTypeAt(abs, sub, constraintMention, prefix0, t0)
1077-
|
1078-
not t0 = abs.getATypeParameter() and t = t0 and path = prefix0
1079-
or
1080-
t0 = abs.getATypeParameter() and
1081-
exists(TypePath path3, TypePath suffix |
1082-
sub.resolveTypeAt(path3) = t0 and
1083-
at.getTypeAt(path3.appendInverse(suffix)) = t and
1084-
path = prefix0.append(suffix)
1085-
)
1103+
satisfiesConstraintTypeMention1(at, a, apos, prefix, constraint, prefix0,
1104+
pathToTypeParamInSub) and
1105+
at.getTypeAt(pathToTypeParamInSub.appendInverse(suffix)) = t and
1106+
path = prefix0.append(suffix)
10861107
)
10871108
}
10881109
}

0 commit comments

Comments
 (0)