Skip to content

Commit 47f6734

Browse files
committed
Rust: Fix bad join
Before ``` Pipeline standard for TypeInference::MethodCallMatching::AccessConstraint::RelevantAccess.getTypeAt/1#dispred#e8abf748@ada3a07w was evaluated in 801 iterations totaling 31ms (delta sizes total: 182871). 50151 ~1% {4} r1 = SCAN TypeInference::MethodCallMatching::AccessConstraint::MkRelevantAccess#7a01048b#prev_delta OUTPUT In.0, In.2, In.3, In.4 39574 ~0% {5} | JOIN WITH `TypeInference::MethodCallMatchingInput::Access.getInferredNonSelfType/2#dispred#b181cb0a#prev` ON FIRST 2 OUTPUT Lhs.3, Rhs.3, _, Lhs.2, Rhs.2 {3} | REWRITE WITH Tmp.2 := "", Out.2 := InverseAppend(In.3,Tmp.2,In.4) KEEPING 3 36996 ~0% {3} | SCAN OUTPUT In.0, In.2, In.1 36102333 ~0% {4} r2 = SCAN TypeInference::MethodCallMatching::AccessConstraint::MkRelevantAccess#7a01048b#prev OUTPUT In.0, In.2, In.3, In.4 90175 ~1% {5} | JOIN WITH `TypeInference::MethodCallMatchingInput::Access.getInferredNonSelfType/2#dispred#b181cb0a#prev_delta` ON FIRST 2 OUTPUT Lhs.3, Rhs.3, _, Lhs.2, Rhs.2 {3} | REWRITE WITH Tmp.2 := "", Out.2 := InverseAppend(In.3,Tmp.2,In.4) KEEPING 3 65014 ~1% {3} | SCAN OUTPUT In.0, In.2, In.1 50151 ~1% {5} r3 = SCAN TypeInference::MethodCallMatching::AccessConstraint::MkRelevantAccess#7a01048b#prev_delta OUTPUT In.2, In.0, In.1, In.3, In.4 24208 ~1% {4} | JOIN WITH `FunctionType::FunctionPosition.isSelf/0#dispred#9e84d302` ON FIRST 1 OUTPUT Lhs.1, Lhs.2, Lhs.3, Lhs.4 95022 ~0% {9} | JOIN WITH `TypeInference::MethodCallMatchingInput::Access.getInferredSelfType/3#dispred#45b2f893#prev` ON FIRST 1 OUTPUT Lhs.2, Lhs.3, Rhs.2, Rhs.3, Rhs.4, _, Rhs.1, Lhs.1, _ {6} | REWRITE WITH Tmp.5 := ";", Tmp.5 := (In.6 ++ Tmp.5), Tmp.8 := "", Out.5 := InverseAppend(Tmp.5,Tmp.8,In.7) KEEPING 6 93919 ~1% {7} | SCAN OUTPUT In.0, In.1, In.2, In.3, In.4, In.5, _ {6} | REWRITE WITH NOT [NOT [Tmp.6 := "borrow", TEST InOut.5 = Tmp.6, Tmp.6 := true, TEST InOut.2 = Tmp.6], NOT [Tmp.6 := "", TEST InOut.5 = Tmp.6, Tmp.6 := true, TEST InOut.2 != Tmp.6]] KEEPING 6 81298 ~1% {5} | SCAN OUTPUT In.1, In.4, _, In.0, In.3 {3} | REWRITE WITH Tmp.2 := "", Out.2 := InverseAppend(In.3,Tmp.2,In.4) KEEPING 3 64110 ~1% {3} | SCAN OUTPUT In.0, In.2, In.1 36102333 ~0% {5} r4 = SCAN TypeInference::MethodCallMatching::AccessConstraint::MkRelevantAccess#7a01048b#prev OUTPUT In.2, In.0, In.1, In.3, In.4 17473531 ~0% {4} | JOIN WITH `FunctionType::FunctionPosition.isSelf/0#dispred#9e84d302` ON FIRST 1 OUTPUT Lhs.1, Lhs.2, Lhs.3, Lhs.4 47409 ~1% {9} | JOIN WITH `TypeInference::MethodCallMatchingInput::Access.getInferredSelfType/3#dispred#45b2f893#prev_delta` ON FIRST 1 OUTPUT Lhs.2, Lhs.3, Rhs.2, Rhs.3, Rhs.4, _, Rhs.1, Lhs.1, _ {6} | REWRITE WITH Tmp.5 := ";", Tmp.5 := (In.6 ++ Tmp.5), Tmp.8 := "", Out.5 := InverseAppend(Tmp.5,Tmp.8,In.7) KEEPING 6 29885 ~0% {7} | SCAN OUTPUT In.0, In.1, In.2, In.3, In.4, In.5, _ {6} | REWRITE WITH NOT [NOT [Tmp.6 := "borrow", TEST InOut.5 = Tmp.6, Tmp.6 := true, TEST InOut.2 = Tmp.6], NOT [Tmp.6 := "", TEST InOut.5 = Tmp.6, Tmp.6 := true, TEST InOut.2 != Tmp.6]] KEEPING 6 16952 ~1% {5} | SCAN OUTPUT In.1, In.4, _, In.0, In.3 {3} | REWRITE WITH Tmp.2 := "", Out.2 := InverseAppend(In.3,Tmp.2,In.4) KEEPING 3 16829 ~0% {3} | SCAN OUTPUT In.0, In.2, In.1 182949 ~1% {3} r5 = r1 UNION r2 UNION r3 UNION r4 182949 ~1% {3} | AND NOT `TypeInference::MethodCallMatching::AccessConstraint::RelevantAccess.getTypeAt/1#dispred#e8abf748#prev`(FIRST 3) return r5 ``` After ``` Pipeline standard for TypeInference::MethodCallMatching::AccessConstraint::RelevantAccess.getTypeAt/1#dispred#e8abf748@31ee547w was evaluated in 801 iterations totaling 19ms (delta sizes total: 182946). 81298 ~0% {5} r1 = JOIN TypeInference::MethodCallMatching::AccessConstraint::MkRelevantAccess#7a01048b#prev_delta WITH `TypeInference::MethodCallMatchingInput::Access.getInferredSelfType/3#dispred#45b2f893#prev` ON FIRST 3 OUTPUT Lhs.4, Rhs.4, _, Lhs.3, Rhs.3 {3} | REWRITE WITH Tmp.2 := "", Out.2 := InverseAppend(In.3,Tmp.2,In.4) KEEPING 3 64110 ~1% {3} | SCAN OUTPUT In.0, In.2, In.1 39574 ~0% {5} r2 = JOIN TypeInference::MethodCallMatching::AccessConstraint::MkRelevantAccess#7a01048b#prev_delta WITH `TypeInference::MethodCallMatchingInput::Access.getInferredNonSelfType/2#dispred#b181cb0a#prev` ON FIRST 2 OUTPUT Lhs.4, Rhs.3, _, Lhs.3, Rhs.2 {3} | REWRITE WITH Tmp.2 := "", Out.2 := InverseAppend(In.3,Tmp.2,In.4) KEEPING 3 36996 ~0% {3} | SCAN OUTPUT In.0, In.2, In.1 16952 ~0% {5} r3 = JOIN TypeInference::MethodCallMatching::AccessConstraint::MkRelevantAccess#7a01048b#prev WITH `TypeInference::MethodCallMatchingInput::Access.getInferredSelfType/3#dispred#45b2f893#prev_delta` ON FIRST 3 OUTPUT Lhs.4, Rhs.4, _, Lhs.3, Rhs.3 {3} | REWRITE WITH Tmp.2 := "", Out.2 := InverseAppend(In.3,Tmp.2,In.4) KEEPING 3 16829 ~0% {3} | SCAN OUTPUT In.0, In.2, In.1 90175 ~0% {5} r4 = JOIN TypeInference::MethodCallMatching::AccessConstraint::MkRelevantAccess#7a01048b#prev WITH `TypeInference::MethodCallMatchingInput::Access.getInferredNonSelfType/2#dispred#b181cb0a#prev_delta` ON FIRST 2 OUTPUT Lhs.4, Rhs.3, _, Lhs.3, Rhs.2 {3} | REWRITE WITH Tmp.2 := "", Out.2 := InverseAppend(In.3,Tmp.2,In.4) KEEPING 3 65014 ~0% {3} | SCAN OUTPUT In.0, In.2, In.1 182949 ~1% {3} r5 = r1 UNION r2 UNION r3 UNION r4 182949 ~1% {3} | AND NOT `TypeInference::MethodCallMatching::AccessConstraint::RelevantAccess.getTypeAt/1#dispred#e8abf748#prev`(FIRST 3) return r5 ```
1 parent d4b55c7 commit 47f6734

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

rust/ql/lib/codeql/rust/internal/TypeInference.qll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,8 +2014,12 @@ private module MethodCallMatchingInput implements MatchingWithEnvironmentInputSi
20142014
}
20152015

20162016
pragma[nomagic]
2017-
private Type getInferredSelfType(string derefChain, boolean borrow, TypePath path) {
2018-
result = this.getACandidateReceiverTypeAt(derefChain, borrow, path)
2017+
private Type getInferredSelfType(AccessPosition apos, string derefChainBorrow, TypePath path) {
2018+
exists(string derefChain, boolean borrow |
2019+
result = this.getACandidateReceiverTypeAt(derefChain, borrow, path) and
2020+
derefChainBorrow = encodeDerefChainBorrow(derefChain, borrow) and
2021+
apos.isSelf()
2022+
)
20192023
}
20202024

20212025
pragma[nomagic]
@@ -2041,11 +2045,7 @@ private module MethodCallMatchingInput implements MatchingWithEnvironmentInputSi
20412045

20422046
bindingset[derefChainBorrow]
20432047
Type getInferredType(string derefChainBorrow, AccessPosition apos, TypePath path) {
2044-
exists(string derefChain, boolean borrow |
2045-
derefChainBorrow = encodeDerefChainBorrow(derefChain, borrow) and
2046-
apos.isSelf() and
2047-
result = this.getInferredSelfType(derefChain, borrow, path)
2048-
)
2048+
result = this.getInferredSelfType(apos, derefChainBorrow, path)
20492049
or
20502050
result = this.getInferredNonSelfType(apos, path)
20512051
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
13321332
}
13331333

13341334
private newtype TRelevantAccess =
1335-
MkRelevantAccess(Access a, AccessEnvironment e, AccessPosition apos, TypePath path) {
1335+
MkRelevantAccess(Access a, AccessPosition apos, AccessEnvironment e, TypePath path) {
13361336
relevantAccessConstraint(a, e, _, apos, path, _)
13371337
}
13381338

@@ -1342,11 +1342,11 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
13421342
*/
13431343
private class RelevantAccess extends MkRelevantAccess {
13441344
Access a;
1345-
AccessEnvironment e;
13461345
AccessPosition apos;
1346+
AccessEnvironment e;
13471347
TypePath path;
13481348

1349-
RelevantAccess() { this = MkRelevantAccess(a, e, apos, path) }
1349+
RelevantAccess() { this = MkRelevantAccess(a, apos, e, path) }
13501350

13511351
Type getTypeAt(TypePath suffix) {
13521352
result = a.getInferredType(e, apos, path.appendInverse(suffix))
@@ -1377,7 +1377,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
13771377
Type constraint, TypePath path, Type t
13781378
) {
13791379
exists(RelevantAccess ra |
1380-
ra = MkRelevantAccess(a, e, apos, prefix) and
1380+
ra = MkRelevantAccess(a, apos, e, prefix) and
13811381
SatisfiesConstraint<RelevantAccess, SatisfiesConstraintInput>::satisfiesConstraintType(ra,
13821382
constraint, path, t) and
13831383
constraint = ra.getConstraint(target)

0 commit comments

Comments
 (0)