@@ -1458,40 +1458,49 @@ static Type formProtocolRelativeType(ProtocolDecl *proto,
1458
1458
1459
1459
const RequirementSource *FloatingRequirementSource::getSource (
1460
1460
GenericSignatureBuilder &builder,
1461
- Type type) const {
1461
+ ResolvedType type) const {
1462
1462
switch (kind) {
1463
1463
case Resolved:
1464
1464
return storage.get <const RequirementSource *>();
1465
1465
1466
- case Explicit:
1466
+ case Explicit: {
1467
+ auto depType = type.getDependentType (builder);
1468
+
1467
1469
if (auto requirementRepr = storage.dyn_cast <const RequirementRepr *>())
1468
- return RequirementSource::forExplicit (builder, type , requirementRepr);
1470
+ return RequirementSource::forExplicit (builder, depType , requirementRepr);
1469
1471
if (auto typeRepr = storage.dyn_cast <const TypeRepr *>())
1470
- return RequirementSource::forExplicit (builder, type, typeRepr);
1471
- return RequirementSource::forAbstract (builder, type);
1472
+ return RequirementSource::forExplicit (builder, depType, typeRepr);
1473
+ return RequirementSource::forAbstract (builder, depType);
1474
+ }
1472
1475
1473
- case Inferred:
1474
- return RequirementSource::forInferred (builder, type,
1476
+ case Inferred: {
1477
+ auto depType = type.getDependentType (builder);
1478
+ return RequirementSource::forInferred (builder, depType,
1475
1479
storage.get <const TypeRepr *>());
1480
+ }
1476
1481
1477
1482
case AbstractProtocol: {
1483
+ auto depType = type.getDependentType ();
1484
+
1478
1485
// Derive the dependent type on which this requirement was written. It is
1479
1486
// the path from the requirement source on which this requirement is based
1480
1487
// to the potential archetype on which the requirement is being placed.
1481
1488
auto baseSource = storage.get <const RequirementSource *>();
1482
1489
auto baseSourceType = baseSource->getAffectedType ();
1483
1490
1484
1491
auto dependentType =
1485
- formProtocolRelativeType (protocolReq.protocol , baseSourceType, type );
1492
+ formProtocolRelativeType (protocolReq.protocol , baseSourceType, depType );
1486
1493
1487
1494
return storage.get <const RequirementSource *>()
1488
1495
->viaProtocolRequirement (builder, dependentType,
1489
1496
protocolReq.protocol , protocolReq.inferred ,
1490
1497
protocolReq.written );
1491
1498
}
1492
1499
1493
- case NestedTypeNameMatch:
1494
- return RequirementSource::forNestedTypeNameMatch (builder, type);
1500
+ case NestedTypeNameMatch: {
1501
+ auto depType = type.getDependentType (builder);
1502
+ return RequirementSource::forNestedTypeNameMatch (builder, depType);
1503
+ }
1495
1504
}
1496
1505
1497
1506
llvm_unreachable (" Unhandled FloatingPointRequirementSourceKind in switch." );
@@ -1712,8 +1721,7 @@ bool EquivalenceClass::recordConformanceConstraint(
1712
1721
1713
1722
// Record this conformance source.
1714
1723
known->second .push_back ({type.getUnresolvedType (), proto,
1715
- source.getSource (builder,
1716
- type.getDependentType (builder))});
1724
+ source.getSource (builder, type)});
1717
1725
++NumConformanceConstraints;
1718
1726
1719
1727
return inserted;
@@ -4131,8 +4139,7 @@ ConstraintResult GenericSignatureBuilder::addConformanceRequirement(
4131
4139
if (!equivClass->recordConformanceConstraint (*this , type, proto, source))
4132
4140
return ConstraintResult::Resolved;
4133
4141
4134
- auto resolvedSource = source.getSource (*this ,
4135
- type.getDependentType (*this ));
4142
+ auto resolvedSource = source.getSource (*this , type);
4136
4143
return expandConformanceRequirement (type, proto, resolvedSource,
4137
4144
/* onlySameTypeRequirements=*/ false );
4138
4145
}
@@ -4159,7 +4166,7 @@ ConstraintResult GenericSignatureBuilder::addLayoutRequirementDirect(
4159
4166
4160
4167
// Record this layout constraint.
4161
4168
equivClass->layoutConstraints .push_back ({type.getUnresolvedType (),
4162
- layout, source.getSource (*this , type. getDependentType (* this ) )});
4169
+ layout, source.getSource (*this , type)});
4163
4170
equivClass->modified (*this );
4164
4171
++NumLayoutConstraints;
4165
4172
if (!anyChanges) ++NumLayoutConstraintsExtra;
@@ -4236,8 +4243,7 @@ bool GenericSignatureBuilder::updateSuperclass(
4236
4243
// Presence of a superclass constraint implies a _Class layout
4237
4244
// constraint.
4238
4245
auto layoutReqSource =
4239
- source.getSource (*this ,
4240
- type.getDependentType (*this ))->viaDerived (*this );
4246
+ source.getSource (*this , type)->viaDerived (*this );
4241
4247
addLayoutRequirementDirect (type,
4242
4248
LayoutConstraint::getLayoutConstraint (
4243
4249
superclass->getClassOrBoundGenericClass ()->isObjC ()
@@ -4275,8 +4281,7 @@ ConstraintResult GenericSignatureBuilder::addSuperclassRequirementDirect(
4275
4281
ResolvedType type,
4276
4282
Type superclass,
4277
4283
FloatingRequirementSource source) {
4278
- auto resolvedSource =
4279
- source.getSource (*this , type.getDependentType (*this ));
4284
+ auto resolvedSource = source.getSource (*this , type);
4280
4285
4281
4286
// Record the constraint.
4282
4287
auto equivClass = type.getEquivalenceClass (*this );
@@ -4322,37 +4327,6 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement(
4322
4327
assert (constraintType && " No type to express resolved constraint?" );
4323
4328
}
4324
4329
4325
- // Check whether we have a reasonable constraint type at all.
4326
- if (!constraintType->isExistentialType () &&
4327
- !constraintType->getClassOrBoundGenericClass ()) {
4328
- if (source.getLoc ().isValid () && !constraintType->hasError ()) {
4329
- auto subjectType = subject.dyn_cast <Type>();
4330
- if (!subjectType)
4331
- subjectType = subject.get <PotentialArchetype *>()
4332
- ->getDependentType (getGenericParams ());
4333
-
4334
- Impl->HadAnyError = true ;
4335
-
4336
- if (subjectType->is <DependentMemberType>()) {
4337
- subjectType = resolveDependentMemberTypes (*this , subjectType);
4338
- }
4339
-
4340
- if (!subjectType->is <DependentMemberType>()) {
4341
- // If we end up here, it means either the subject type was never a
4342
- // a dependent member type, or it was initially a dependent member
4343
- // type, but resolving it lead to some other type. Let's map this
4344
- // to an error type so we can emit correct diagnostics.
4345
- subjectType = ErrorType::get (subjectType);
4346
- }
4347
-
4348
- auto invalidConstraint = Constraint<Type>(
4349
- {subject, constraintType, source.getSource (*this , subjectType)});
4350
- invalidIsaConstraints.push_back (invalidConstraint);
4351
- }
4352
-
4353
- return ConstraintResult::Conflicting;
4354
- }
4355
-
4356
4330
// Resolve the subject. If we can't, delay the constraint.
4357
4331
auto resolvedSubject = resolve (subject, source);
4358
4332
if (!resolvedSubject) {
@@ -4392,7 +4366,7 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement(
4392
4366
4393
4367
// One cannot explicitly write a constraint on a concrete type.
4394
4368
if (source.isExplicit ()) {
4395
- if (source.getLoc ().isValid ()) {
4369
+ if (source.getLoc ().isValid () && !subjectType-> hasError () ) {
4396
4370
Impl->HadAnyError = true ;
4397
4371
Diags.diagnose (source.getLoc (), diag::requires_not_suitable_archetype,
4398
4372
subjectType);
@@ -4404,6 +4378,20 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement(
4404
4378
return ConstraintResult::Resolved;
4405
4379
}
4406
4380
4381
+ // Check whether we have a reasonable constraint type at all.
4382
+ if (!constraintType->isExistentialType () &&
4383
+ !constraintType->getClassOrBoundGenericClass ()) {
4384
+ if (source.getLoc ().isValid () && !constraintType->hasError ()) {
4385
+ Impl->HadAnyError = true ;
4386
+
4387
+ auto invalidConstraint = Constraint<Type>(
4388
+ {subject, constraintType, source.getSource (*this , resolvedSubject)});
4389
+ invalidIsaConstraints.push_back (invalidConstraint);
4390
+ }
4391
+
4392
+ return ConstraintResult::Conflicting;
4393
+ }
4394
+
4407
4395
// Protocol requirements.
4408
4396
if (constraintType->isExistentialType ()) {
4409
4397
bool anyErrors = false ;
@@ -4626,7 +4614,7 @@ GenericSignatureBuilder::addSameTypeRequirementBetweenTypeParameters(
4626
4614
const RequirementSource *source2;
4627
4615
if (auto existingSource2 =
4628
4616
equivClass2->findAnySuperclassConstraintAsWritten (
4629
- OrigT2->getDependentType (getGenericParams () )))
4617
+ OrigT2->getDependentType ()))
4630
4618
source2 = existingSource2->source ;
4631
4619
else
4632
4620
source2 = equivClass2->superclassConstraints .front ().source ;
@@ -4859,17 +4847,17 @@ ConstraintResult GenericSignatureBuilder::addSameTypeRequirementDirect(
4859
4847
// If one side is concrete, map the other side to that concrete type.
4860
4848
if (concreteType1) {
4861
4849
return addSameTypeRequirementToConcrete (type2, concreteType1,
4862
- source.getSource (*this , type2. getDependentType (* this ) ));
4850
+ source.getSource (*this , type2));
4863
4851
}
4864
4852
4865
4853
if (concreteType2) {
4866
4854
return addSameTypeRequirementToConcrete (type1, concreteType2,
4867
- source.getSource (*this , type1. getDependentType (* this ) ));
4855
+ source.getSource (*this , type1));
4868
4856
}
4869
4857
4870
4858
return addSameTypeRequirementBetweenTypeParameters (
4871
4859
type1, type2,
4872
- source.getSource (*this , type2. getDependentType (* this ) ));
4860
+ source.getSource (*this , type2));
4873
4861
}
4874
4862
4875
4863
ConstraintResult GenericSignatureBuilder::addInheritedRequirements (
0 commit comments