Skip to content

Commit 3419c00

Browse files
committed
Rust: Use ToIndex instead of FromIndex in ranked forex predicates
`ToIndex` makes more sense, since we start the recursion from `0`.
1 parent c0ebc17 commit 3419c00

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ module ArgsAreInstantiationsOf<ArgsAreInstantiationsOfInputSig Input> {
351351
|
352352
rnk = 0
353353
or
354-
argsAreInstantiationsOfFromIndex(call, abs, f, rnk - 1)
354+
argsAreInstantiationsOfToIndex(call, abs, f, rnk - 1)
355355
)
356356
}
357357

@@ -360,15 +360,15 @@ module ArgsAreInstantiationsOf<ArgsAreInstantiationsOfInputSig Input> {
360360
}
361361
}
362362

363-
private module ArgIsInstantiationOfFromIndex =
363+
private module ArgIsInstantiationOfToIndex =
364364
ArgIsInstantiationOf<CallAndPos, ArgIsInstantiationOfInput>;
365365

366366
pragma[nomagic]
367-
private predicate argsAreInstantiationsOfFromIndex(
367+
private predicate argsAreInstantiationsOfToIndex(
368368
Input::Call call, ImplOrTraitItemNode i, Function f, int rnk
369369
) {
370370
exists(FunctionPosition pos |
371-
ArgIsInstantiationOfFromIndex::argIsInstantiationOf(MkCallAndPos(call, pos), i, _) and
371+
ArgIsInstantiationOfToIndex::argIsInstantiationOf(MkCallAndPos(call, pos), i, _) and
372372
call.hasTargetCand(i, f) and
373373
toCheckRanked(i, f, pos, rnk)
374374
)
@@ -381,7 +381,7 @@ module ArgsAreInstantiationsOf<ArgsAreInstantiationsOfInputSig Input> {
381381
pragma[nomagic]
382382
predicate argsAreInstantiationsOf(Input::Call call, ImplOrTraitItemNode i, Function f) {
383383
exists(int rnk |
384-
argsAreInstantiationsOfFromIndex(call, i, f, rnk) and
384+
argsAreInstantiationsOfToIndex(call, i, f, rnk) and
385385
rnk = max(int r | toCheckRanked(i, f, _, r))
386386
)
387387
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -578,21 +578,21 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
578578
}
579579

580580
pragma[nomagic]
581-
private predicate satisfiesConcreteTypesFromIndex(
581+
private predicate satisfiesConcreteTypesToIndex(
582582
App app, TypeAbstraction abs, Constraint constraint, int i
583583
) {
584584
exists(Type t, TypePath path |
585585
t = resolveNthTypeAt(app, abs, constraint, i, path) and
586586
if t = abs.getATypeParameter() then any() else app.getTypeAt(path) = t
587587
) and
588588
// Recurse unless we are at the first path
589-
if i = 0 then any() else satisfiesConcreteTypesFromIndex(app, abs, constraint, i - 1)
589+
if i = 0 then any() else satisfiesConcreteTypesToIndex(app, abs, constraint, i - 1)
590590
}
591591

592592
/** Holds if all the concrete types in `constraint` also occur in `app`. */
593593
pragma[nomagic]
594594
private predicate satisfiesConcreteTypes(App app, TypeAbstraction abs, Constraint constraint) {
595-
satisfiesConcreteTypesFromIndex(app, abs, constraint,
595+
satisfiesConcreteTypesToIndex(app, abs, constraint,
596596
max(int i | exists(getNthPath(constraint, i))))
597597
}
598598

@@ -620,7 +620,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
620620
}
621621

622622
pragma[nomagic]
623-
private predicate typeParametersEqualFromIndexBase(
623+
private predicate typeParametersEqualToIndexBase(
624624
App app, TypeAbstraction abs, Constraint constraint, TypeParameter tp, TypePath path
625625
) {
626626
path = getNthTypeParameterPath(constraint, tp, 0) and
@@ -630,15 +630,15 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
630630
}
631631

632632
pragma[nomagic]
633-
private predicate typeParametersEqualFromIndex(
633+
private predicate typeParametersEqualToIndex(
634634
App app, TypeAbstraction abs, Constraint constraint, TypeParameter tp, Type t, int i
635635
) {
636636
exists(TypePath path |
637637
t = app.getTypeAt(path) and
638638
if i = 0
639-
then typeParametersEqualFromIndexBase(app, abs, constraint, tp, path)
639+
then typeParametersEqualToIndexBase(app, abs, constraint, tp, path)
640640
else (
641-
typeParametersEqualFromIndex(app, abs, constraint, tp, t, i - 1) and
641+
typeParametersEqualToIndex(app, abs, constraint, tp, t, i - 1) and
642642
path = getNthTypeParameterPath(constraint, tp, i)
643643
)
644644
)
@@ -655,19 +655,19 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
655655
exists(int n | n = max(int i | exists(getNthTypeParameterPath(constraint, tp, i))) |
656656
// If the largest index is 0, then there are no equalities to check as
657657
// the type parameter only occurs once.
658-
if n = 0 then any() else typeParametersEqualFromIndex(app, abs, constraint, tp, _, n)
658+
if n = 0 then any() else typeParametersEqualToIndex(app, abs, constraint, tp, _, n)
659659
)
660660
)
661661
}
662662

663-
private predicate typeParametersHaveEqualInstantiationFromIndex(
663+
private predicate typeParametersHaveEqualInstantiationToIndex(
664664
App app, TypeAbstraction abs, Constraint constraint, int i
665665
) {
666666
exists(TypeParameter tp | tp = getNthTypeParameter(abs, i) |
667667
typeParametersEqual(app, abs, constraint, tp) and
668668
if i = 0
669669
then any()
670-
else typeParametersHaveEqualInstantiationFromIndex(app, abs, constraint, i - 1)
670+
else typeParametersHaveEqualInstantiationToIndex(app, abs, constraint, i - 1)
671671
)
672672
}
673673

@@ -697,7 +697,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
697697
not exists(getNthTypeParameter(abs, _))
698698
or
699699
exists(int n | n = max(int i | exists(getNthTypeParameter(abs, i))) |
700-
typeParametersHaveEqualInstantiationFromIndex(app, abs, constraint, n)
700+
typeParametersHaveEqualInstantiationToIndex(app, abs, constraint, n)
701701
)
702702
)
703703
}

0 commit comments

Comments
 (0)