Skip to content

Commit 104ba0e

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 727bdde commit 104ba0e

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
@@ -1812,8 +1812,12 @@ private module MethodCallMatchingInput implements MatchingWithEnvironmentInputSi
18121812
}
18131813

18141814
pragma[nomagic]
1815-
private Type getInferredSelfType(string derefChain, boolean borrow, TypePath path) {
1816-
result = this.getACandidateReceiverTypeAt(derefChain, borrow, path)
1815+
private Type getInferredSelfType(AccessPosition apos, string derefChainBorrow, TypePath path) {
1816+
exists(string derefChain, boolean borrow |
1817+
result = this.getACandidateReceiverTypeAt(derefChain, borrow, path) and
1818+
derefChainBorrow = encodeDerefChainBorrow(derefChain, borrow) and
1819+
apos.isSelf()
1820+
)
18171821
}
18181822

18191823
pragma[nomagic]
@@ -1839,11 +1843,7 @@ private module MethodCallMatchingInput implements MatchingWithEnvironmentInputSi
18391843

18401844
bindingset[derefChainBorrow]
18411845
Type getInferredType(string derefChainBorrow, AccessPosition apos, TypePath path) {
1842-
exists(string derefChain, boolean borrow |
1843-
derefChainBorrow = encodeDerefChainBorrow(derefChain, borrow) and
1844-
apos.isSelf() and
1845-
result = this.getInferredSelfType(derefChain, borrow, path)
1846-
)
1846+
result = this.getInferredSelfType(apos, derefChainBorrow, path)
18471847
or
18481848
result = this.getInferredNonSelfType(apos, path)
18491849
}

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

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

12711271
private newtype TRelevantAccess =
1272-
MkRelevantAccess(Access a, AccessEnvironment e, AccessPosition apos, TypePath path) {
1272+
MkRelevantAccess(Access a, AccessPosition apos, AccessEnvironment e, TypePath path) {
12731273
relevantAccessConstraint(a, e, _, apos, path, _)
12741274
}
12751275

@@ -1279,11 +1279,11 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
12791279
*/
12801280
private class RelevantAccess extends MkRelevantAccess {
12811281
Access a;
1282-
AccessEnvironment e;
12831282
AccessPosition apos;
1283+
AccessEnvironment e;
12841284
TypePath path;
12851285

1286-
RelevantAccess() { this = MkRelevantAccess(a, e, apos, path) }
1286+
RelevantAccess() { this = MkRelevantAccess(a, apos, e, path) }
12871287

12881288
Type getTypeAt(TypePath suffix) {
12891289
result = a.getInferredType(e, apos, path.appendInverse(suffix))
@@ -1314,7 +1314,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
13141314
Type constraint, TypePath path, Type t
13151315
) {
13161316
exists(RelevantAccess ra |
1317-
ra = MkRelevantAccess(a, e, apos, prefix) and
1317+
ra = MkRelevantAccess(a, apos, e, prefix) and
13181318
SatisfiesConstraint<RelevantAccess, SatisfiesConstraintInput>::satisfiesConstraintType(ra,
13191319
constraint, path, t) and
13201320
constraint = ra.getConstraint(target)

0 commit comments

Comments
 (0)