@@ -1026,7 +1026,6 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
1026
1026
1027
1027
// Initialized by the setup operation.
1028
1028
std::optional<ConstraintSystem> cs;
1029
- ConstraintLocator *locator = nullptr ;
1030
1029
ConstraintLocator *reqLocator = nullptr ;
1031
1030
ConstraintLocator *witnessLocator = nullptr ;
1032
1031
Type witnessType, openWitnessType;
@@ -1115,8 +1114,8 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
1115
1114
selfTy = syntheticEnv->mapTypeIntoContext (selfTy);
1116
1115
1117
1116
// Open up the type of the requirement.
1118
- reqLocator = cs-> getConstraintLocator (
1119
- static_cast <Expr *>( nullptr ), LocatorPathElt ::ProtocolRequirement(req) );
1117
+ reqLocator =
1118
+ cs-> getConstraintLocator (req, ConstraintLocator ::ProtocolRequirement);
1120
1119
OpenedTypeMap reqReplacements;
1121
1120
reqType = cs->getTypeOfMemberReference (selfTy, req, dc,
1122
1121
/* isDynamicResult=*/ false ,
@@ -1151,10 +1150,8 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
1151
1150
1152
1151
// Open up the witness type.
1153
1152
witnessType = witness->getInterfaceType ();
1154
- // FIXME: witness as a base locator?
1155
- locator = cs->getConstraintLocator ({});
1156
- witnessLocator = cs->getConstraintLocator ({},
1157
- LocatorPathElt::Witness (witness));
1153
+ witnessLocator =
1154
+ cs->getConstraintLocator (req, LocatorPathElt::Witness (witness));
1158
1155
if (witness->getDeclContext ()->isTypeContext ()) {
1159
1156
openWitnessType = cs->getTypeOfMemberReference (
1160
1157
selfTy, witness, dc, /* isDynamicResult=*/ false ,
@@ -1174,44 +1171,8 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
1174
1171
// Match a type in the requirement to a type in the witness.
1175
1172
auto matchTypes = [&](Type reqType,
1176
1173
Type witnessType) -> std::optional<RequirementMatch> {
1177
- // `swift_attr` attributes in the type context were ignored before,
1178
- // which means that we need to maintain status quo to avoid breaking
1179
- // witness matching by stripping everything concurrency related from
1180
- // inner types.
1181
- auto shouldStripConcurrency = [&]() {
1182
- if (!req->isObjC ())
1183
- return false ;
1184
-
1185
- auto &ctx = dc->getASTContext ();
1186
- return !(ctx.isSwiftVersionAtLeast (6 ) ||
1187
- ctx.LangOpts .StrictConcurrencyLevel ==
1188
- StrictConcurrency::Complete);
1189
- };
1190
-
1191
- if (shouldStripConcurrency ()) {
1192
- if (reqType->is <FunctionType>()) {
1193
- auto *fnTy = reqType->castTo <FunctionType>();
1194
- SmallVector<AnyFunctionType::Param, 4 > params;
1195
- llvm::transform (fnTy->getParams (), std::back_inserter (params),
1196
- [&](const AnyFunctionType::Param ¶m) {
1197
- return param.withType (
1198
- param.getPlainType ()->stripConcurrency (
1199
- /* recursive=*/ true ,
1200
- /* dropGlobalActor=*/ true ));
1201
- });
1202
-
1203
- auto resultTy =
1204
- fnTy->getResult ()->stripConcurrency (/* recursive=*/ true ,
1205
- /* dropGlobalActor=*/ true );
1206
-
1207
- reqType = FunctionType::get (params, resultTy, fnTy->getExtInfo ());
1208
- } else {
1209
- reqType = reqType->stripConcurrency (/* recursive=*/ true ,
1210
- /* dropGlobalActor=*/ true );
1211
- }
1212
- }
1213
-
1214
- cs->addConstraint (ConstraintKind::Bind, reqType, witnessType, locator);
1174
+ cs->addConstraint (ConstraintKind::Bind, reqType, witnessType,
1175
+ witnessLocator);
1215
1176
// FIXME: Check whether this has already failed.
1216
1177
return std::nullopt ;
1217
1178
};
@@ -1235,14 +1196,31 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
1235
1196
return *result;
1236
1197
}
1237
1198
}
1238
- bool requiresNonSendable = false ;
1239
- if (!solution || solution->Fixes .size ()) {
1240
- // / If the *only* problems are that `@Sendable` attributes are missing,
1241
- // / allow the match in some circumstances.
1242
- requiresNonSendable = solution
1243
- && llvm::all_of (solution->Fixes , [](constraints::ConstraintFix *fix) {
1244
- return fix->getKind () == constraints::FixKind::AddSendableAttribute;
1245
- });
1199
+
1200
+ bool requiresNonSendable = [&]() {
1201
+ if (!solution)
1202
+ return false ;
1203
+
1204
+ // If the *only* problems are that `@Sendable` attributes are missing,
1205
+ // allow the match in some circumstances.
1206
+ if (!solution->Fixes .empty ()) {
1207
+ return llvm::all_of (solution->Fixes ,
1208
+ [](constraints::ConstraintFix *fix) {
1209
+ return fix->getKind () ==
1210
+ constraints::FixKind::AddSendableAttribute;
1211
+ });
1212
+ }
1213
+
1214
+ // If there are no other issues, let's check whether this are
1215
+ // missing Sendable conformances when matching ObjC requirements.
1216
+ // This is not an error until Swift 6 because `swift_attr` wasn't
1217
+ // allowed in type contexts initially.
1218
+ return req->isObjC () &&
1219
+ solution->getFixedScore ()
1220
+ .Data [SK_MissingSynthesizableConformance] > 0 ;
1221
+ }();
1222
+
1223
+ if (!solution || !solution->Fixes .empty ()) {
1246
1224
if (!requiresNonSendable)
1247
1225
return RequirementMatch (witness, MatchKind::TypeConflict,
1248
1226
witnessType);
0 commit comments