Skip to content

Commit ae988a5

Browse files
committed
Shared: Generalize SatisfiesConstraint module
1 parent 16613d1 commit ae988a5

File tree

4 files changed

+129
-94
lines changed

4 files changed

+129
-94
lines changed

rust/ql/lib/codeql/rust/internal/typeinference/BlanketImplementation.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ module SatisfiesBlanketConstraint<
103103
}
104104

105105
private module SatisfiesBlanketConstraintInput implements
106-
SatisfiesConstraintInputSig<ArgumentTypeAndBlanketOffset>
106+
SatisfiesTypeInputSig<ArgumentTypeAndBlanketOffset>
107107
{
108108
pragma[nomagic]
109109
additional predicate relevantConstraint(
@@ -123,7 +123,7 @@ module SatisfiesBlanketConstraint<
123123
}
124124

125125
private module SatisfiesBlanketConstraint =
126-
SatisfiesConstraint<ArgumentTypeAndBlanketOffset, SatisfiesBlanketConstraintInput>;
126+
SatisfiesType<ArgumentTypeAndBlanketOffset, SatisfiesBlanketConstraintInput>;
127127

128128
/**
129129
* Holds if the argument type `at` satisfies the first non-trivial blanket

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,8 +2544,7 @@ private module AssocFunctionResolution {
25442544
Location getLocation() { result = afc.getLocation() }
25452545
}
25462546

2547-
private module CallSatisfiesDerefConstraintInput implements
2548-
SatisfiesConstraintInputSig<CallDerefCand>
2547+
private module CallSatisfiesDerefConstraintInput implements SatisfiesTypeInputSig<CallDerefCand>
25492548
{
25502549
pragma[nomagic]
25512550
predicate relevantConstraint(CallDerefCand mc, Type constraint) {
@@ -2555,7 +2554,7 @@ private module AssocFunctionResolution {
25552554
}
25562555

25572556
private module CallSatisfiesDerefConstraint =
2558-
SatisfiesConstraint<CallDerefCand, CallSatisfiesDerefConstraintInput>;
2557+
SatisfiesType<CallDerefCand, CallSatisfiesDerefConstraintInput>;
25592558

25602559
pragma[nomagic]
25612560
private AssociatedTypeTypeParameter getDerefTargetTypeParameter() {
@@ -3586,21 +3585,20 @@ final private class AwaitTarget extends Expr {
35863585
Type getTypeAt(TypePath path) { result = inferType(this, path) }
35873586
}
35883587

3589-
private module AwaitSatisfiesConstraintInput implements SatisfiesConstraintInputSig<AwaitTarget> {
3588+
private module AwaitSatisfiesTypeInput implements SatisfiesTypeInputSig<AwaitTarget> {
35903589
pragma[nomagic]
35913590
predicate relevantConstraint(AwaitTarget term, Type constraint) {
35923591
exists(term) and
35933592
constraint.(TraitType).getTrait() instanceof FutureTrait
35943593
}
35953594
}
35963595

3597-
private module AwaitSatisfiesConstraint =
3598-
SatisfiesConstraint<AwaitTarget, AwaitSatisfiesConstraintInput>;
3596+
private module AwaitSatisfiesType = SatisfiesType<AwaitTarget, AwaitSatisfiesTypeInput>;
35993597

36003598
pragma[nomagic]
36013599
private Type inferAwaitExprType(AstNode n, TypePath path) {
36023600
exists(TypePath exprPath |
3603-
AwaitSatisfiesConstraint::satisfiesConstraintType(n.(AwaitExpr).getExpr(), _, exprPath, result) and
3601+
AwaitSatisfiesType::satisfiesConstraintType(n.(AwaitExpr).getExpr(), _, exprPath, result) and
36043602
exprPath.isCons(getFutureOutputTypeParameter(), path)
36053603
)
36063604
}
@@ -3779,9 +3777,7 @@ final private class ForIterableExpr extends Expr {
37793777
Type getTypeAt(TypePath path) { result = inferType(this, path) }
37803778
}
37813779

3782-
private module ForIterableSatisfiesConstraintInput implements
3783-
SatisfiesConstraintInputSig<ForIterableExpr>
3784-
{
3780+
private module ForIterableSatisfiesTypeInput implements SatisfiesTypeInputSig<ForIterableExpr> {
37853781
predicate relevantConstraint(ForIterableExpr term, Type constraint) {
37863782
exists(term) and
37873783
exists(Trait t | t = constraint.(TraitType).getTrait() |
@@ -3802,15 +3798,15 @@ private AssociatedTypeTypeParameter getIntoIteratorItemTypeParameter() {
38023798
result = getAssociatedTypeTypeParameter(any(IntoIteratorTrait t).getItemType())
38033799
}
38043800

3805-
private module ForIterableSatisfiesConstraint =
3806-
SatisfiesConstraint<ForIterableExpr, ForIterableSatisfiesConstraintInput>;
3801+
private module ForIterableSatisfiesType =
3802+
SatisfiesType<ForIterableExpr, ForIterableSatisfiesTypeInput>;
38073803

38083804
pragma[nomagic]
38093805
private Type inferForLoopExprType(AstNode n, TypePath path) {
38103806
// type of iterable -> type of pattern (loop variable)
38113807
exists(ForExpr fe, TypePath exprPath, AssociatedTypeTypeParameter tp |
38123808
n = fe.getPat() and
3813-
ForIterableSatisfiesConstraint::satisfiesConstraintType(fe.getIterable(), _, exprPath, result) and
3809+
ForIterableSatisfiesType::satisfiesConstraintType(fe.getIterable(), _, exprPath, result) and
38143810
exprPath.isCons(tp, path)
38153811
|
38163812
tp = getIntoIteratorItemTypeParameter()
@@ -3836,21 +3832,20 @@ final private class InvokedClosureExpr extends Expr {
38363832
CallExpr getCall() { result = call }
38373833
}
38383834

3839-
private module InvokedClosureSatisfiesConstraintInput implements
3840-
SatisfiesConstraintInputSig<InvokedClosureExpr>
3835+
private module InvokedClosureSatisfiesTypeInput implements SatisfiesTypeInputSig<InvokedClosureExpr>
38413836
{
38423837
predicate relevantConstraint(InvokedClosureExpr term, Type constraint) {
38433838
exists(term) and
38443839
constraint.(TraitType).getTrait() instanceof FnOnceTrait
38453840
}
38463841
}
38473842

3848-
private module InvokedClosureSatisfiesConstraint =
3849-
SatisfiesConstraint<InvokedClosureExpr, InvokedClosureSatisfiesConstraintInput>;
3843+
private module InvokedClosureSatisfiesType =
3844+
SatisfiesType<InvokedClosureExpr, InvokedClosureSatisfiesTypeInput>;
38503845

38513846
/** Gets the type of `ce` when viewed as an implementation of `FnOnce`. */
38523847
private Type invokedClosureFnTypeAt(InvokedClosureExpr ce, TypePath path) {
3853-
InvokedClosureSatisfiesConstraint::satisfiesConstraintType(ce, _, path, result)
3848+
InvokedClosureSatisfiesType::satisfiesConstraintType(ce, _, path, result)
38543849
}
38553850

38563851
/**

rust/ql/lib/codeql/rust/internal/typeinference/TypeMention.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,14 +730,14 @@ private predicate pathConcreteTypeAssocType(
730730
)
731731
}
732732

733-
private module PathSatisfiesConstraintInput implements SatisfiesConstraintInputSig<PreTypeMention> {
733+
private module PathSatisfiesConstraintInput implements SatisfiesTypeInputSig<PreTypeMention> {
734734
predicate relevantConstraint(PreTypeMention tm, Type constraint) {
735735
pathConcreteTypeAssocType(_, tm, constraint.(TraitType).getTrait(), _, _)
736736
}
737737
}
738738

739739
private module PathSatisfiesConstraint =
740-
SatisfiesConstraint<PreTypeMention, PathSatisfiesConstraintInput>;
740+
SatisfiesType<PreTypeMention, PathSatisfiesConstraintInput>;
741741

742742
/**
743743
* Gets the type of `path` at `typePath` when `path` accesses an associated type

0 commit comments

Comments
 (0)