@@ -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
@@ -124,10 +124,28 @@ private module Input implements InputSig1<Location>, InputSig2<PreTypeMention> {
124124 }
125125
126126 int getTypePathLimit ( ) { result = 10 }
127+ }
127128
128- PreTypeMention getABaseTypeMention ( Type t ) { none ( ) }
129+ private import Input1
129130
130- PreTypeMention getATypeParameterConstraint ( TypeParameter tp ) {
131+ private module M1 = Make1< Location , Input1 > ;
132+
133+ import M1
134+
135+ predicate getTypePathLimit = Input1:: getTypePathLimit / 0 ;
136+
137+ predicate getTypeParameterId = Input1:: getTypeParameterId / 1 ;
138+
139+ class TypePath = M1:: TypePath ;
140+
141+ module TypePath = M1:: TypePath;
142+
143+ /**
144+ * Provides shared logic for implementing `InputSig2<PreTypeMention>` and
145+ * `InputSig2<TypeMention>`.
146+ */
147+ private module Input2Common {
148+ AstNode getATypeParameterConstraint ( TypeParameter tp ) {
131149 result = tp .( TypeParamTypeParameter ) .getTypeParam ( ) .getATypeBound ( ) .getTypeRepr ( ) or
132150 result = tp .( SelfTypeParameter ) .getTrait ( ) or
133151 result =
@@ -146,7 +164,7 @@ private module Input implements InputSig1<Location>, InputSig2<PreTypeMention> {
146164 * inference module for more information.
147165 */
148166 predicate conditionSatisfiesConstraint (
149- TypeAbstraction abs , PreTypeMention condition , PreTypeMention constraint , boolean transitive
167+ TypeAbstraction abs , AstNode condition , AstNode constraint , boolean transitive
150168 ) {
151169 // `impl` blocks implementing traits
152170 transitive = false and
@@ -194,23 +212,64 @@ private module Input implements InputSig1<Location>, InputSig2<PreTypeMention> {
194212 )
195213 )
196214 }
215+
216+ predicate typeParameterIsFunctionallyDetermined ( TypeParameter tp ) {
217+ tp instanceof AssociatedTypeTypeParameter
218+ }
197219}
198220
199- private import Input
221+ private module PreInput2 implements InputSig2< PreTypeMention > {
222+ PreTypeMention getABaseTypeMention ( Type t ) { none ( ) }
200223
201- private module M1 = Make1< Location , Input > ;
224+ PreTypeMention getATypeParameterConstraint ( TypeParameter tp ) {
225+ result = Input2Common:: getATypeParameterConstraint ( tp )
226+ }
202227
203- import M1
228+ predicate conditionSatisfiesConstraint (
229+ TypeAbstraction abs , PreTypeMention condition , PreTypeMention constraint , boolean transitive
230+ ) {
231+ Input2Common:: conditionSatisfiesConstraint ( abs , condition , constraint , transitive )
232+ }
204233
205- predicate getTypePathLimit = Input:: getTypePathLimit / 0 ;
234+ predicate typeAbstractionHasAmbiguousConstraintAt (
235+ TypeAbstraction abs , Type constraint , TypePath path
236+ ) {
237+ FunctionOverloading:: preImplHasAmbiguousSiblingAt ( abs , constraint .( TraitType ) .getTrait ( ) , path )
238+ }
206239
207- predicate getTypeParameterId = Input:: getTypeParameterId / 1 ;
240+ predicate typeParameterIsFunctionallyDetermined =
241+ Input2Common:: typeParameterIsFunctionallyDetermined / 1 ;
242+ }
208243
209- class TypePath = M1:: TypePath ;
244+ /** Provides an instantiation of the shared type inference library for `PreTypeMention`s. */
245+ module PreM2 = Make2< PreTypeMention , PreInput2 > ;
210246
211- module TypePath = M1:: TypePath;
247+ private module Input2 implements InputSig2< TypeMention > {
248+ TypeMention getABaseTypeMention ( Type t ) { none ( ) }
212249
213- private module M2 = Make2< PreTypeMention , Input > ;
250+ TypeMention getATypeParameterConstraint ( TypeParameter tp ) {
251+ result = Input2Common:: getATypeParameterConstraint ( tp )
252+ }
253+
254+ predicate conditionSatisfiesConstraint (
255+ TypeAbstraction abs , TypeMention condition , TypeMention constraint , boolean transitive
256+ ) {
257+ Input2Common:: conditionSatisfiesConstraint ( abs , condition , constraint , transitive )
258+ }
259+
260+ predicate typeAbstractionHasAmbiguousConstraintAt (
261+ TypeAbstraction abs , Type constraint , TypePath path
262+ ) {
263+ FunctionOverloading:: implHasAmbiguousSiblingAt ( abs , constraint .( TraitType ) .getTrait ( ) , path )
264+ }
265+
266+ predicate typeParameterIsFunctionallyDetermined =
267+ Input2Common:: typeParameterIsFunctionallyDetermined / 1 ;
268+ }
269+
270+ private import Input2
271+
272+ private module M2 = Make2< TypeMention , Input2 > ;
214273
215274import M2
216275
@@ -1070,25 +1129,18 @@ private module ContextTyping {
10701129 AstNode n , FunctionPosition pos , boolean hasReceiver , TypePath path
10711130 ) {
10721131 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
10811132 hasUnknownType ( n ) and
1082- prefix = path . getAPrefix ( )
1133+ not pos . isReturn ( )
10831134 }
10841135
10851136 pragma [ nomagic]
10861137 Type check ( AstNode n , TypePath path ) {
10871138 result = inferCallType ( n , any ( FunctionPosition pos | pos .isReturn ( ) ) , _, path )
10881139 or
10891140 exists ( FunctionPosition pos , boolean hasReceiver , TypePath prefix |
1090- result = inferCallNonReturnType ( n , pos , hasReceiver , prefix , path ) and
1091- hasUnknownTypeAt ( n , prefix )
1141+ result = inferCallNonReturnType ( n , pos , hasReceiver , path ) and
1142+ hasUnknownTypeAt ( n , prefix ) and
1143+ prefix .isPrefixOf ( path )
10921144 |
10931145 // Never propagate type information directly into the receiver, since its type
10941146 // must already have been known in order to resolve the call
@@ -3970,7 +4022,7 @@ private module Debug {
39704022 TypeAbstraction abs , TypeMention condition , TypeMention constraint , boolean transitive
39714023 ) {
39724024 abs = getRelevantLocatable ( ) and
3973- Input :: conditionSatisfiesConstraint ( abs , condition , constraint , transitive )
4025+ Input2 :: conditionSatisfiesConstraint ( abs , condition , constraint , transitive )
39744026 }
39754027
39764028 predicate debugInferShorthandSelfType ( ShorthandSelfParameterMention self , TypePath path , Type t ) {
0 commit comments