@@ -15,9 +15,11 @@ module Gvn {
1515 * but only if the enclosing type is not a `GenericType`.
1616 */
1717 string getNameNested ( Type t ) {
18- if not t instanceof NestedType or t .( NestedType ) .getDeclaringType ( ) instanceof GenericType
19- then result = t .getName ( )
20- else result = getNameNested ( t .( NestedType ) .getDeclaringType ( ) ) + "+" + t .getName ( )
18+ exists ( string name | name = t .getName ( ) |
19+ if not t instanceof NestedType or t .( NestedType ) .getDeclaringType ( ) instanceof GenericType
20+ then result = name
21+ else result = getNameNested ( t .( NestedType ) .getDeclaringType ( ) ) + "+" + name
22+ )
2123 }
2224
2325 /**
@@ -47,8 +49,22 @@ module Gvn {
4749 not exists ( this .getGenericDeclaringType ( ) ) and result = 0
4850 }
4951
52+ /**
53+ * Same as `getChild`, but safe-guards against potential extractor issues where
54+ * multiple children exist at the same index, which may result in a combinatorial
55+ * explosion.
56+ */
57+ private Type getChildUnique ( int i ) {
58+ result = unique( Type t | t = this .getChild ( i ) | t )
59+ or
60+ strictcount ( this .getChild ( i ) ) > 1 and
61+ result .( UnknownType ) .isCanonical ( )
62+ }
63+
5064 /** Gets the number of arguments of this type, not taking nested types into account. */
51- int getNumberOfArgumentsSelf ( ) { result = count ( int i | exists ( this .getChild ( i ) ) and i >= 0 ) }
65+ int getNumberOfArgumentsSelf ( ) {
66+ result = count ( int i | exists ( this .getChildUnique ( i ) ) and i >= 0 )
67+ }
5268
5369 /** Gets the number of arguments of this type, taking nested types into account. */
5470 int getNumberOfArguments ( ) {
@@ -61,7 +77,7 @@ module Gvn {
6177 or
6278 exists ( int offset |
6379 offset = this .getNumberOfDeclaringArguments ( ) and
64- result = this .getChild ( i - offset ) and
80+ result = this .getChildUnique ( i - offset ) and
6581 i >= offset
6682 )
6783 }
@@ -91,13 +107,9 @@ module Gvn {
91107 int getNumberOfTypeParameters ( ) {
92108 this = TPointerTypeKind ( ) and result = 1
93109 or
94- this = TNullableTypeKind ( ) and result = 1
95- or
96110 this = TArrayTypeKind ( _, _) and result = 1
97111 or
98- exists ( GenericType t | this = TConstructedType ( t .getUnboundDeclaration ( ) ) |
99- result = t .getNumberOfArguments ( )
100- )
112+ exists ( GenericType t | this = TConstructedType ( t ) | result = t .getNumberOfArguments ( ) )
101113 }
102114
103115 /** Gets the unbound declaration type that this kind corresponds to, if any. */
@@ -106,15 +118,12 @@ module Gvn {
106118 /**
107119 * Gets a textual representation of this kind when applied to arguments `args`.
108120 *
109- * This predicate is restricted to built-in generics (pointers, nullables, and
110- * arrays).
121+ * This predicate is restricted to built-in generics (pointers and arrays).
111122 */
112123 bindingset [ args]
113124 string toStringBuiltin ( string args ) {
114125 this = TPointerTypeKind ( ) and result = args + "*"
115126 or
116- this = TNullableTypeKind ( ) and result = args + "?"
117- or
118127 exists ( int rnk | this = TArrayTypeKind ( _, rnk ) |
119128 result = args + "[" + concat ( int i | i in [ 0 .. rnk - 2 ] | "," ) + "]"
120129 )
@@ -135,8 +144,6 @@ module Gvn {
135144 CompoundTypeKind getTypeKind ( Type t ) {
136145 result = TPointerTypeKind ( ) and t instanceof PointerType
137146 or
138- result = TNullableTypeKind ( ) and t instanceof NullableType
139- or
140147 t = any ( ArrayType at | result = TArrayTypeKind ( at .getDimension ( ) , at .getRank ( ) ) )
141148 or
142149 result = TConstructedType ( t .getUnboundDeclaration ( ) )
@@ -280,6 +287,7 @@ module Gvn {
280287
281288 pragma [ noinline]
282289 private predicate toStringPart ( int i , int j ) {
290+ this .isFullyConstructed ( ) and
283291 exists ( int offset |
284292 exists ( GenericType t , int children |
285293 t = this .getConstructedGenericDeclaringTypeAt ( i ) and
@@ -449,14 +457,12 @@ module Gvn {
449457 cached
450458 newtype TCompoundTypeKind =
451459 TPointerTypeKind ( ) { Stages:: UnificationStage:: forceCachingInSameStage ( ) } or
452- TNullableTypeKind ( ) or
453460 TArrayTypeKind ( int dim , int rnk ) {
454461 exists ( ArrayType at | dim = at .getDimension ( ) and rnk = at .getRank ( ) )
455462 } or
456463 TConstructedType ( GenericType unboundDecl ) {
457464 unboundDecl = any ( GenericType t ) .getUnboundDeclaration ( ) and
458465 not unboundDecl instanceof PointerType and
459- not unboundDecl instanceof NullableType and
460466 not unboundDecl instanceof ArrayType and
461467 not unboundDecl instanceof TupleType
462468 }
0 commit comments