@@ -30,7 +30,7 @@ private newtype TTypeArgumentPosition =
3030 } or
3131 TTypeParamTypeArgumentPosition ( TypeParam tp )
3232
33- private module Input implements InputSig1< Location > , InputSig2 < PreTypeMention > {
33+ private module Input1 implements InputSig1< Location > {
3434 private import Type as T
3535 private import codeql.rust.elements.internal.generated.Raw
3636 private import codeql.rust.elements.internal.generated.Synth
@@ -122,12 +122,28 @@ private module Input implements InputSig1<Location>, InputSig2<PreTypeMention> {
122122 tp0 order by kind , id1 , id2
123123 )
124124 }
125+ }
125126
126- int getTypePathLimit ( ) { result = 10 }
127+ private import Input1
127128
128- PreTypeMention getABaseTypeMention ( Type t ) { none ( ) }
129+ private module M1 = Make1 < Location , Input1 > ;
129130
130- PreTypeMention getATypeParameterConstraint ( TypeParameter tp ) {
131+ import M1
132+
133+ predicate getTypePathLimit = Input1:: getTypePathLimit / 0 ;
134+
135+ predicate getTypeParameterId = Input1:: getTypeParameterId / 1 ;
136+
137+ class TypePath = M1:: TypePath ;
138+
139+ module TypePath = M1:: TypePath;
140+
141+ /**
142+ * Provides shared logic for implementing `InputSig2<PreTypeMention>` and
143+ * `InputSig2<TypeMention>`.
144+ */
145+ private module Input2Common {
146+ AstNode getATypeParameterConstraint ( TypeParameter tp ) {
131147 result = tp .( TypeParamTypeParameter ) .getTypeParam ( ) .getATypeBound ( ) .getTypeRepr ( ) or
132148 result = tp .( SelfTypeParameter ) .getTrait ( ) or
133149 result =
@@ -146,7 +162,7 @@ private module Input implements InputSig1<Location>, InputSig2<PreTypeMention> {
146162 * inference module for more information.
147163 */
148164 predicate conditionSatisfiesConstraint (
149- TypeAbstraction abs , PreTypeMention condition , PreTypeMention constraint , boolean transitive
165+ TypeAbstraction abs , AstNode condition , AstNode constraint , boolean transitive
150166 ) {
151167 // `impl` blocks implementing traits
152168 transitive = false and
@@ -194,23 +210,64 @@ private module Input implements InputSig1<Location>, InputSig2<PreTypeMention> {
194210 )
195211 )
196212 }
213+
214+ predicate typeParameterIsFunctionallyDetermined ( TypeParameter tp ) {
215+ tp instanceof AssociatedTypeTypeParameter
216+ }
197217}
198218
199- private import Input
219+ private module PreInput2 implements InputSig2< PreTypeMention > {
220+ PreTypeMention getABaseTypeMention ( Type t ) { none ( ) }
200221
201- private module M1 = Make1< Location , Input > ;
222+ PreTypeMention getATypeParameterConstraint ( TypeParameter tp ) {
223+ result = Input2Common:: getATypeParameterConstraint ( tp )
224+ }
202225
203- import M1
226+ predicate conditionSatisfiesConstraint (
227+ TypeAbstraction abs , PreTypeMention condition , PreTypeMention constraint , boolean transitive
228+ ) {
229+ Input2Common:: conditionSatisfiesConstraint ( abs , condition , constraint , transitive )
230+ }
204231
205- predicate getTypePathLimit = Input:: getTypePathLimit / 0 ;
232+ predicate typeAbstractionHasAmbiguousConstraintAt (
233+ TypeAbstraction abs , Type constraint , TypePath path
234+ ) {
235+ FunctionOverloading:: preImplHasAmbiguousSiblingAt ( abs , constraint .( TraitType ) .getTrait ( ) , path )
236+ }
206237
207- predicate getTypeParameterId = Input:: getTypeParameterId / 1 ;
238+ predicate typeParameterIsFunctionallyDetermined =
239+ Input2Common:: typeParameterIsFunctionallyDetermined / 1 ;
240+ }
208241
209- class TypePath = M1:: TypePath ;
242+ /** Provides an instantiation of the shared type inference library for `PreTypeMention`s. */
243+ module PreM2 = Make2< PreTypeMention , PreInput2 > ;
210244
211- module TypePath = M1:: TypePath;
245+ private module Input2 implements InputSig2< TypeMention > {
246+ TypeMention getABaseTypeMention ( Type t ) { none ( ) }
247+
248+ TypeMention getATypeParameterConstraint ( TypeParameter tp ) {
249+ result = Input2Common:: getATypeParameterConstraint ( tp )
250+ }
251+
252+ predicate conditionSatisfiesConstraint (
253+ TypeAbstraction abs , TypeMention condition , TypeMention constraint , boolean transitive
254+ ) {
255+ Input2Common:: conditionSatisfiesConstraint ( abs , condition , constraint , transitive )
256+ }
257+
258+ predicate typeAbstractionHasAmbiguousConstraintAt (
259+ TypeAbstraction abs , Type constraint , TypePath path
260+ ) {
261+ FunctionOverloading:: implHasAmbiguousSiblingAt ( abs , constraint .( TraitType ) .getTrait ( ) , path )
262+ }
263+
264+ predicate typeParameterIsFunctionallyDetermined =
265+ Input2Common:: typeParameterIsFunctionallyDetermined / 1 ;
266+ }
267+
268+ private import Input2
212269
213- private module M2 = Make2< PreTypeMention , Input > ;
270+ private module M2 = Make2< TypeMention , Input2 > ;
214271
215272import M2
216273
@@ -1070,25 +1127,18 @@ private module ContextTyping {
10701127 AstNode n , FunctionPosition pos , boolean hasReceiver , TypePath path
10711128 ) {
10721129 result = inferCallType ( n , pos , hasReceiver , path ) and
1073- not pos .isReturn ( )
1074- }
1075-
1076- pragma [ nomagic]
1077- private Type inferCallNonReturnType (
1078- AstNode n , FunctionPosition pos , boolean hasReceiver , TypePath prefix , TypePath path
1079- ) {
1080- result = inferCallNonReturnType ( n , pos , hasReceiver , path ) and
10811130 hasUnknownType ( n ) and
1082- prefix = path . getAPrefix ( )
1131+ not pos . isReturn ( )
10831132 }
10841133
10851134 pragma [ nomagic]
10861135 Type check ( AstNode n , TypePath path ) {
10871136 result = inferCallType ( n , any ( FunctionPosition pos | pos .isReturn ( ) ) , _, path )
10881137 or
10891138 exists ( FunctionPosition pos , boolean hasReceiver , TypePath prefix |
1090- result = inferCallNonReturnType ( n , pos , hasReceiver , prefix , path ) and
1091- hasUnknownTypeAt ( n , prefix )
1139+ result = inferCallNonReturnType ( n , pos , hasReceiver , path ) and
1140+ hasUnknownTypeAt ( n , prefix ) and
1141+ prefix .isPrefixOf ( path )
10921142 |
10931143 // Never propagate type information directly into the receiver, since its type
10941144 // must already have been known in order to resolve the call
@@ -3970,7 +4020,7 @@ private module Debug {
39704020 TypeAbstraction abs , TypeMention condition , TypeMention constraint , boolean transitive
39714021 ) {
39724022 abs = getRelevantLocatable ( ) and
3973- Input :: conditionSatisfiesConstraint ( abs , condition , constraint , transitive )
4023+ Input2 :: conditionSatisfiesConstraint ( abs , condition , constraint , transitive )
39744024 }
39754025
39764026 predicate debugInferShorthandSelfType ( ShorthandSelfParameterMention self , TypePath path , Type t ) {
0 commit comments