@@ -853,6 +853,14 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
853853 signature module SatisfiesConstraintInputSig< HasTypeTreeSig Term, HasTypeTreeSig Constraint> {
854854 /** Holds if it is relevant to know if `term` satisfies `constraint`. */
855855 predicate relevantConstraint ( Term term , Constraint constraint ) ;
856+
857+ default Type foo ( Term term , TypeParameter tp , TypePath path ) { none ( ) }
858+
859+ default predicate typeAbstractionHasAmbigousConstraintAtOverride (
860+ TypeAbstraction abs , Type constraint , TypePath path
861+ ) {
862+ typeAbstractionHasAmbigousConstraintAt ( abs , constraint , path )
863+ }
856864 }
857865
858866 module SatisfiesConstraint<
@@ -978,37 +986,68 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
978986 conditionSatisfiesConstraintTypeAt ( abs , sub , constraintMention , path , t )
979987 }
980988
989+ pragma [ nomagic]
990+ private predicate satisfiesConstraintTypeMention01 (
991+ Term tt , Constraint constraint , TypeAbstraction abs , TypePath prefix , TypeParameter tp
992+ ) {
993+ exists ( Type constraintRoot |
994+ satisfiesConstraintTypeMention0 ( tt , constraint , constraintRoot , _, abs , _, _, _) and
995+ typeAbstractionHasAmbigousConstraintAtOverride ( abs , constraintRoot , _) and
996+ tp = constraint .getTypeAt ( prefix )
997+ )
998+ }
999+
1000+ bindingset [ abs, path, t]
1001+ pragma [ inline_late]
1002+ private predicate conditionSatisfiesConstraintTypeAtFilter (
1003+ TypeAbstraction abs , TypePath path , Type t
1004+ ) {
1005+ conditionSatisfiesConstraintTypeAt ( abs , _, _, path , t )
1006+ }
1007+
1008+ pragma [ nomagic]
1009+ private Type getConstraintType ( Term tt , Constraint constraint , TypePath path ) {
1010+ exists ( TypeAbstraction abs , TypePath prefix , TypeParameter tp , TypePath suffix |
1011+ satisfiesConstraintTypeMention01 ( tt , constraint , abs , prefix , tp ) and
1012+ result = foo ( tt , tp , suffix ) and
1013+ path = prefix .append ( suffix ) and
1014+ conditionSatisfiesConstraintTypeAtFilter ( abs , path , result )
1015+ )
1016+ }
1017+
9811018 pragma [ nomagic]
9821019 private predicate satisfiesConstraintTypeMention1 (
983- Term tt , Constraint constraint , Type constraintRoot , TypeAbstraction abs , TypeMention sub ,
984- TypePath path , Type t
1020+ Term tt , Constraint constraint , TypeAbstraction abs , TypeMention sub , TypePath path , Type t
9851021 ) {
986- exists ( TypeMention constraintMention |
1022+ exists ( Type constraintRoot , TypeMention constraintMention |
9871023 satisfiesConstraintTypeMention0 ( tt , constraint , constraintRoot , constraintMention , abs ,
9881024 sub , path , t )
9891025 |
990- if typeAbstractionHasAmbigousConstraintAt ( abs , constraintRoot , path .getAPrefix ( ) )
1026+ if typeAbstractionHasAmbigousConstraintAtOverride ( abs , constraintRoot , path .getAPrefix ( ) )
9911027 then
9921028 // When the constraint is not uniquely satisfied, we check that the satisfying
9931029 // abstraction is not more specific than the constraint to be satisfied. For example,
9941030 // if the constraint is `MyTrait<i32>` and there is both `impl MyTrait<i32> for ...` and
9951031 // `impl MyTrait<i64> for ...`, then the latter will be filtered away
996- not exists ( TypePath path1 , Type t1 |
1032+ forall ( TypePath path1 , Type t1 |
9971033 conditionSatisfiesConstraintTypeAt ( abs , sub , constraintMention , path1 , t1 ) and
998- not t1 instanceof TypeParameter and
999- t1 != constraint .getTypeAt ( path1 )
1034+ not t1 instanceof TypeParameter
1035+ |
1036+ not t1 != constraint .getTypeAt ( path1 )
1037+ or
1038+ t1 = getConstraintType ( tt , constraint , path1 )
10001039 )
10011040 else any ( )
10021041 )
10031042 }
10041043
10051044 pragma [ inline]
10061045 private predicate satisfiesConstraintTypeMentionInline (
1007- Term tt , Constraint constraint , Type constraintRoot , TypeAbstraction abs , TypePath path ,
1046+ Term tt , Constraint constraint , TypeAbstraction abs , TypePath path ,
10081047 TypePath pathToTypeParamInSub
10091048 ) {
10101049 exists ( TypeMention sub , TypeParameter tp |
1011- satisfiesConstraintTypeMention1 ( tt , constraint , constraintRoot , abs , sub , path , tp ) and
1050+ satisfiesConstraintTypeMention1 ( tt , constraint , abs , sub , path , tp ) and
10121051 tp = abs .getATypeParameter ( ) and
10131052 sub .getTypeAt ( pathToTypeParamInSub ) = tp
10141053 )
@@ -1018,24 +1057,22 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
10181057 private predicate satisfiesConstraintTypeMention (
10191058 Term tt , Constraint constraint , TypePath path , TypePath pathToTypeParamInSub
10201059 ) {
1021- satisfiesConstraintTypeMentionInline ( tt , constraint , _, _ , path , pathToTypeParamInSub )
1060+ satisfiesConstraintTypeMentionInline ( tt , constraint , _, path , pathToTypeParamInSub )
10221061 }
10231062
10241063 pragma [ nomagic]
10251064 private predicate satisfiesConstraintTypeMentionThrough (
1026- Term tt , TypeAbstraction abs , Constraint constraint , Type constraintRoot , TypePath path ,
1065+ Term tt , TypeAbstraction abs , Constraint constraint , TypePath path ,
10271066 TypePath pathToTypeParamInSub
10281067 ) {
1029- satisfiesConstraintTypeMentionInline ( tt , constraint , constraintRoot , abs , path ,
1030- pathToTypeParamInSub )
1068+ satisfiesConstraintTypeMentionInline ( tt , constraint , abs , path , pathToTypeParamInSub )
10311069 }
10321070
10331071 pragma [ inline]
10341072 private predicate satisfiesConstraintTypeNonTypeParamInline (
1035- Term tt , TypeAbstraction abs , Constraint constraint , Type constraintRoot , TypePath path ,
1036- Type t
1073+ Term tt , TypeAbstraction abs , Constraint constraint , TypePath path , Type t
10371074 ) {
1038- satisfiesConstraintTypeMention1 ( tt , constraint , constraintRoot , abs , _, path , t ) and
1075+ satisfiesConstraintTypeMention1 ( tt , constraint , abs , _, path , t ) and
10391076 not t = abs .getATypeParameter ( )
10401077 }
10411078
@@ -1052,7 +1089,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
10521089 */
10531090 pragma [ nomagic]
10541091 predicate satisfiesConstraintType ( Term tt , Constraint constraint , TypePath path , Type t ) {
1055- satisfiesConstraintTypeNonTypeParamInline ( tt , _, constraint , _ , path , t )
1092+ satisfiesConstraintTypeNonTypeParamInline ( tt , _, constraint , path , t )
10561093 or
10571094 exists ( TypePath prefix0 , TypePath pathToTypeParamInSub , TypePath suffix |
10581095 satisfiesConstraintTypeMention ( tt , constraint , prefix0 , pathToTypeParamInSub ) and
@@ -1072,11 +1109,10 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
10721109 predicate satisfiesConstraintTypeThrough (
10731110 Term tt , TypeAbstraction abs , Constraint constraint , TypePath path , Type t
10741111 ) {
1075- satisfiesConstraintTypeNonTypeParamInline ( tt , abs , constraint , _ , path , t )
1112+ satisfiesConstraintTypeNonTypeParamInline ( tt , abs , constraint , path , t )
10761113 or
10771114 exists ( TypePath prefix0 , TypePath pathToTypeParamInSub , TypePath suffix |
1078- satisfiesConstraintTypeMentionThrough ( tt , abs , constraint , _, prefix0 ,
1079- pathToTypeParamInSub ) and
1115+ satisfiesConstraintTypeMentionThrough ( tt , abs , constraint , prefix0 , pathToTypeParamInSub ) and
10801116 getTypeAt ( tt , pathToTypeParamInSub .appendInverse ( suffix ) ) = t and
10811117 path = prefix0 .append ( suffix )
10821118 )
@@ -1405,6 +1441,13 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
14051441 predicate relevantConstraint ( RelevantAccess at , TypeMention constraint ) {
14061442 constraint = at .getConstraint ( _)
14071443 }
1444+
1445+ Type foo ( RelevantAccess at , TypeParameter tp , TypePath path ) {
1446+ exists ( Access a , AccessEnvironment e , Declaration target |
1447+ at = MkRelevantAccess ( a , _, e , _) and
1448+ typeMatch ( a , e , target , path , result , tp )
1449+ )
1450+ }
14081451 }
14091452
14101453 predicate satisfiesConstraintType (
0 commit comments