Skip to content

Commit 06f0c11

Browse files
committed
Shared: Generalize SatisfiesConstraint module
1 parent 082dc61 commit 06f0c11

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
@@ -2362,8 +2362,7 @@ private module AssocFunctionResolution {
23622362
Location getLocation() { result = afc.getLocation() }
23632363
}
23642364

2365-
private module CallSatisfiesDerefConstraintInput implements
2366-
SatisfiesConstraintInputSig<CallDerefCand>
2365+
private module CallSatisfiesDerefConstraintInput implements SatisfiesTypeInputSig<CallDerefCand>
23672366
{
23682367
pragma[nomagic]
23692368
predicate relevantConstraint(CallDerefCand mc, Type constraint) {
@@ -2373,7 +2372,7 @@ private module AssocFunctionResolution {
23732372
}
23742373

23752374
private module CallSatisfiesDerefConstraint =
2376-
SatisfiesConstraint<CallDerefCand, CallSatisfiesDerefConstraintInput>;
2375+
SatisfiesType<CallDerefCand, CallSatisfiesDerefConstraintInput>;
23772376

23782377
pragma[nomagic]
23792378
private AssociatedTypeTypeParameter getDerefTargetTypeParameter() {
@@ -3466,21 +3465,20 @@ final private class AwaitTarget extends Expr {
34663465
Type getTypeAt(TypePath path) { result = inferType(this, path) }
34673466
}
34683467

3469-
private module AwaitSatisfiesConstraintInput implements SatisfiesConstraintInputSig<AwaitTarget> {
3468+
private module AwaitSatisfiesTypeInput implements SatisfiesTypeInputSig<AwaitTarget> {
34703469
pragma[nomagic]
34713470
predicate relevantConstraint(AwaitTarget term, Type constraint) {
34723471
exists(term) and
34733472
constraint.(TraitType).getTrait() instanceof FutureTrait
34743473
}
34753474
}
34763475

3477-
private module AwaitSatisfiesConstraint =
3478-
SatisfiesConstraint<AwaitTarget, AwaitSatisfiesConstraintInput>;
3476+
private module AwaitSatisfiesType = SatisfiesType<AwaitTarget, AwaitSatisfiesTypeInput>;
34793477

34803478
pragma[nomagic]
34813479
private Type inferAwaitExprType(AstNode n, TypePath path) {
34823480
exists(TypePath exprPath |
3483-
AwaitSatisfiesConstraint::satisfiesConstraintType(n.(AwaitExpr).getExpr(), _, exprPath, result) and
3481+
AwaitSatisfiesType::satisfiesConstraintType(n.(AwaitExpr).getExpr(), _, exprPath, result) and
34843482
exprPath.isCons(getFutureOutputTypeParameter(), path)
34853483
)
34863484
}
@@ -3616,9 +3614,7 @@ final private class ForIterableExpr extends Expr {
36163614
Type getTypeAt(TypePath path) { result = inferType(this, path) }
36173615
}
36183616

3619-
private module ForIterableSatisfiesConstraintInput implements
3620-
SatisfiesConstraintInputSig<ForIterableExpr>
3621-
{
3617+
private module ForIterableSatisfiesTypeInput implements SatisfiesTypeInputSig<ForIterableExpr> {
36223618
predicate relevantConstraint(ForIterableExpr term, Type constraint) {
36233619
exists(term) and
36243620
exists(Trait t | t = constraint.(TraitType).getTrait() |
@@ -3639,15 +3635,15 @@ private AssociatedTypeTypeParameter getIntoIteratorItemTypeParameter() {
36393635
result = getAssociatedTypeTypeParameter(any(IntoIteratorTrait t).getItemType())
36403636
}
36413637

3642-
private module ForIterableSatisfiesConstraint =
3643-
SatisfiesConstraint<ForIterableExpr, ForIterableSatisfiesConstraintInput>;
3638+
private module ForIterableSatisfiesType =
3639+
SatisfiesType<ForIterableExpr, ForIterableSatisfiesTypeInput>;
36443640

36453641
pragma[nomagic]
36463642
private Type inferForLoopExprType(AstNode n, TypePath path) {
36473643
// type of iterable -> type of pattern (loop variable)
36483644
exists(ForExpr fe, TypePath exprPath, AssociatedTypeTypeParameter tp |
36493645
n = fe.getPat() and
3650-
ForIterableSatisfiesConstraint::satisfiesConstraintType(fe.getIterable(), _, exprPath, result) and
3646+
ForIterableSatisfiesType::satisfiesConstraintType(fe.getIterable(), _, exprPath, result) and
36513647
exprPath.isCons(tp, path)
36523648
|
36533649
tp = getIntoIteratorItemTypeParameter()
@@ -3673,21 +3669,20 @@ final private class InvokedClosureExpr extends Expr {
36733669
CallExpr getCall() { result = call }
36743670
}
36753671

3676-
private module InvokedClosureSatisfiesConstraintInput implements
3677-
SatisfiesConstraintInputSig<InvokedClosureExpr>
3672+
private module InvokedClosureSatisfiesTypeInput implements SatisfiesTypeInputSig<InvokedClosureExpr>
36783673
{
36793674
predicate relevantConstraint(InvokedClosureExpr term, Type constraint) {
36803675
exists(term) and
36813676
constraint.(TraitType).getTrait() instanceof FnOnceTrait
36823677
}
36833678
}
36843679

3685-
private module InvokedClosureSatisfiesConstraint =
3686-
SatisfiesConstraint<InvokedClosureExpr, InvokedClosureSatisfiesConstraintInput>;
3680+
private module InvokedClosureSatisfiesType =
3681+
SatisfiesType<InvokedClosureExpr, InvokedClosureSatisfiesTypeInput>;
36873682

36883683
/** Gets the type of `ce` when viewed as an implementation of `FnOnce`. */
36893684
private Type invokedClosureFnTypeAt(InvokedClosureExpr ce, TypePath path) {
3690-
InvokedClosureSatisfiesConstraint::satisfiesConstraintType(ce, _, path, result)
3685+
InvokedClosureSatisfiesType::satisfiesConstraintType(ce, _, path, result)
36913686
}
36923687

36933688
/**

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)