Skip to content

Commit 45449f6

Browse files
committed
Rust: Move TypeAbstraction into separate file
1 parent 7f273c7 commit 45449f6

File tree

5 files changed

+62
-70
lines changed

5 files changed

+62
-70
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
private import rust
99
private import codeql.rust.internal.PathResolution
1010
private import Type
11+
private import TypeAbstraction
1112
private import TypeMention
1213
private import TypeInference
1314
private import FunctionType

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
private import rust
22
private import codeql.rust.internal.PathResolution
3-
private import TypeInference
43
private import Type
4+
private import TypeAbstraction
55
private import TypeMention
6+
private import TypeInference
67

78
private newtype TFunctionPosition =
89
TArgumentFunctionPosition(ArgumentPosition pos) or

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

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -569,74 +569,6 @@ class ImplTraitTypeTypeParameter extends ImplTraitType, TypeParameter {
569569
override TypeParameter getPositionalTypeParameter(int i) { none() }
570570
}
571571

572-
/**
573-
* A type abstraction. I.e., a place in the program where type variables are
574-
* introduced.
575-
*
576-
* Example:
577-
* ```rust
578-
* impl<A, B> Foo<A, B> { }
579-
* // ^^^^^^ a type abstraction
580-
* ```
581-
*/
582-
abstract class TypeAbstraction extends AstNode {
583-
abstract TypeParameter getATypeParameter();
584-
}
585-
586-
final class ImplTypeAbstraction extends TypeAbstraction, Impl {
587-
override TypeParamTypeParameter getATypeParameter() {
588-
result.getTypeParam() = this.getGenericParamList().getATypeParam()
589-
}
590-
}
591-
592-
private predicate idDynTraitTypeRepr(@dyn_trait_type_repr x, @dyn_trait_type_repr y) { x = y }
593-
594-
private predicate idOfDynTraitTypeRepr(@dyn_trait_type_repr x, int y) =
595-
equivalenceRelation(idDynTraitTypeRepr/2)(x, y)
596-
597-
private int idOfDynTraitTypeRepr(DynTraitTypeRepr node) {
598-
idOfDynTraitTypeRepr(Synth::convertAstNodeToRaw(node), result)
599-
}
600-
601-
/** Holds if `dt` is the canonical dyn trait type abstraction for `trait`. */
602-
private predicate canonicalDynTraitTypeAbstraction(DynTraitTypeRepr dt, Trait trait) {
603-
dt = min(DynTraitTypeRepr d | d.getTrait() = trait | d order by idOfDynTraitTypeRepr(d))
604-
}
605-
606-
final class DynTypeAbstraction extends TypeAbstraction, DynTraitTypeRepr {
607-
DynTypeAbstraction() { canonicalDynTraitTypeAbstraction(this, this.getTrait()) }
608-
609-
override TypeParameter getATypeParameter() {
610-
result = any(DynTraitTypeParameter tp | tp.getTrait() = this.getTrait()).getTraitTypeParameter()
611-
}
612-
}
613-
614-
final class TraitTypeAbstraction extends TypeAbstraction, Trait {
615-
override TypeParameter getATypeParameter() {
616-
result.(TypeParamTypeParameter).getTypeParam() = this.getGenericParamList().getATypeParam()
617-
or
618-
result.(AssociatedTypeTypeParameter).getTrait() = this
619-
or
620-
result.(SelfTypeParameter).getTrait() = this
621-
}
622-
}
623-
624-
final class TypeBoundTypeAbstraction extends TypeAbstraction, TypeBound {
625-
override TypeParameter getATypeParameter() { none() }
626-
}
627-
628-
final class SelfTypeBoundTypeAbstraction extends TypeAbstraction, Name {
629-
SelfTypeBoundTypeAbstraction() { any(TraitTypeAbstraction trait).getName() = this }
630-
631-
override TypeParameter getATypeParameter() { none() }
632-
}
633-
634-
final class ImplTraitTypeReprAbstraction extends TypeAbstraction, ImplTraitTypeRepr {
635-
override TypeParameter getATypeParameter() {
636-
implTraitTypeParam(this, _, result.(TypeParamTypeParameter).getTypeParam())
637-
}
638-
}
639-
640572
/**
641573
* Holds if `t` is a valid complex [`self` root type][1].
642574
*
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
private import rust
2+
private import codeql.rust.elements.internal.generated.Raw
3+
private import codeql.rust.elements.internal.generated.Synth
4+
private import Type
5+
6+
/**
7+
* A type abstraction. I.e., a place in the program where type variables are
8+
* introduced.
9+
*
10+
* Example:
11+
* ```rust
12+
* impl<A, B> Foo<A, B> { }
13+
* // ^^^^^^ a type abstraction
14+
* ```
15+
*/
16+
abstract class TypeAbstraction extends AstNode {
17+
abstract TypeParameter getATypeParameter();
18+
}
19+
20+
final class ImplTypeAbstraction extends TypeAbstraction, Impl {
21+
override TypeParamTypeParameter getATypeParameter() {
22+
result.getTypeParam() = this.getGenericParamList().getATypeParam()
23+
}
24+
}
25+
26+
final class DynTypeAbstraction extends TypeAbstraction, DynTraitTypeRepr {
27+
override TypeParameter getATypeParameter() {
28+
result = any(DynTraitTypeParameter tp | tp.getTrait() = this.getTrait()).getTraitTypeParameter()
29+
}
30+
}
31+
32+
final class TraitTypeAbstraction extends TypeAbstraction, Trait {
33+
override TypeParameter getATypeParameter() {
34+
result.(TypeParamTypeParameter).getTypeParam() = this.getGenericParamList().getATypeParam()
35+
or
36+
result.(AssociatedTypeTypeParameter).getTrait() = this
37+
or
38+
result.(SelfTypeParameter).getTrait() = this
39+
}
40+
}
41+
42+
final class TypeBoundTypeAbstraction extends TypeAbstraction, TypeBound {
43+
override TypeParameter getATypeParameter() { none() }
44+
}
45+
46+
final class SelfTypeBoundTypeAbstraction extends TypeAbstraction, Name {
47+
SelfTypeBoundTypeAbstraction() { any(TraitTypeAbstraction trait).getName() = this }
48+
49+
override TypeParameter getATypeParameter() { none() }
50+
}
51+
52+
final class ImplTraitTypeReprAbstraction extends TypeAbstraction, ImplTraitTypeRepr {
53+
override TypeParamTypeParameter getATypeParameter() {
54+
exists(TImplTraitTypeParameter(this, result.getTypeParam()))
55+
}
56+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ private import codeql.util.Option
55
private import rust
66
private import codeql.rust.internal.PathResolution
77
private import Type
8+
private import TypeAbstraction
9+
private import TypeAbstraction as TA
810
private import Type as T
911
private import TypeMention
1012
private import codeql.rust.internal.typeinference.DerefChain
@@ -37,7 +39,7 @@ private module Input1 implements InputSig1<Location> {
3739

3840
class TypeParameter = T::TypeParameter;
3941

40-
class TypeAbstraction = T::TypeAbstraction;
42+
class TypeAbstraction = TA::TypeAbstraction;
4143

4244
class TypeArgumentPosition extends TTypeArgumentPosition {
4345
int asMethodTypeArgumentPosition() { this = TMethodTypeArgumentPosition(result) }

0 commit comments

Comments
 (0)