@@ -133,10 +133,11 @@ namespace {
133
133
};
134
134
} // end anonymous namespace
135
135
136
- static std::tuple<Type, Type, OptionalAdjustmentKind>
137
- getTypesToCompare (ValueDecl *reqt, Type reqtType, bool reqtTypeIsIUO,
138
- Type witnessType, bool witnessTypeIsIUO,
139
- VarianceKind variance) {
136
+ static std::tuple<Type,Type, OptionalAdjustmentKind>
137
+ getTypesToCompare (ValueDecl *reqt,
138
+ Type reqtType,
139
+ Type witnessType,
140
+ VarianceKind variance) {
140
141
// For @objc protocols, deal with differences in the optionality.
141
142
// FIXME: It probably makes sense to extend this to non-@objc
142
143
// protocols as well, but this requires more testing.
@@ -159,11 +160,6 @@ getTypesToCompare(ValueDecl *reqt, Type reqtType, bool reqtTypeIsIUO,
159
160
break ;
160
161
161
162
case OTK_Optional:
162
- if (witnessTypeIsIUO) {
163
- optAdjustment = OptionalAdjustmentKind::RemoveIUO;
164
- break ;
165
- }
166
-
167
163
switch (variance) {
168
164
case VarianceKind::None:
169
165
case VarianceKind::Covariant:
@@ -183,17 +179,6 @@ getTypesToCompare(ValueDecl *reqt, Type reqtType, bool reqtTypeIsIUO,
183
179
break ;
184
180
185
181
case OTK_Optional:
186
- // When the requirement is an IUO, all is permitted, because we
187
- // assume that the user knows more about the signature than we
188
- // have information in the protocol.
189
- if (reqtTypeIsIUO)
190
- break ;
191
-
192
- if (witnessTypeIsIUO) {
193
- optAdjustment = OptionalAdjustmentKind::IUOToOptional;
194
- break ;
195
- }
196
-
197
182
switch (witnessOptKind) {
198
183
case OTK_None:
199
184
switch (variance) {
@@ -224,15 +209,6 @@ getTypesToCompare(ValueDecl *reqt, Type reqtType, bool reqtTypeIsIUO,
224
209
// have information in the protocol.
225
210
break ;
226
211
}
227
- } else {
228
- // FIXME: Until IUOs are removed from the type system, make
229
- // sure we turn these both into optionals for the purpose of
230
- // comparing types since we could be producing IUOs in some
231
- // places and optionals in others.
232
- if (auto objTy = reqtType->getImplicitlyUnwrappedOptionalObjectType ())
233
- reqtType = OptionalType::get (objTy);
234
- if (auto objTy = witnessType->getImplicitlyUnwrappedOptionalObjectType ())
235
- witnessType = OptionalType::get (objTy);
236
212
}
237
213
238
214
return std::make_tuple (reqtType, witnessType, optAdjustment);
@@ -368,14 +344,6 @@ static bool checkObjCWitnessSelector(TypeChecker &tc, ValueDecl *req,
368
344
return false ;
369
345
}
370
346
371
- static ParameterList *getParameterList (ValueDecl *value) {
372
- if (auto func = dyn_cast<AbstractFunctionDecl>(value))
373
- return func->getParameterList (func->getDeclContext ()->isTypeContext ());
374
-
375
- auto subscript = cast<SubscriptDecl>(value);
376
- return subscript->getIndices ();
377
- }
378
-
379
347
RequirementMatch
380
348
swift::matchWitness (
381
349
TypeChecker &tc,
@@ -523,24 +491,18 @@ swift::matchWitness(
523
491
// Result types must match.
524
492
// FIXME: Could allow (trivial?) subtyping here.
525
493
if (!ignoreReturnType) {
526
- auto reqTypeIsIUO =
527
- req->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
528
- auto witnessTypeIsIUO =
529
- witness->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
530
- auto types =
531
- getTypesToCompare (req, reqResultType, reqTypeIsIUO, witnessResultType,
532
- witnessTypeIsIUO, VarianceKind::Covariant);
494
+ auto types = getTypesToCompare (req, reqResultType,
495
+ witnessResultType,
496
+ VarianceKind::Covariant);
533
497
534
498
// Record optional adjustment, if any.
535
499
if (std::get<2 >(types) != OptionalAdjustmentKind::None) {
536
500
optionalAdjustments.push_back (
537
501
OptionalAdjustment (std::get<2 >(types)));
538
502
}
539
503
540
- if (!req->isObjC () && reqTypeIsIUO != witnessTypeIsIUO)
541
- return RequirementMatch (witness, MatchKind::TypeConflict, witnessType);
542
-
543
- if (auto result = matchTypes (std::get<0 >(types), std::get<1 >(types))) {
504
+ if (auto result = matchTypes (std::get<0 >(types),
505
+ std::get<1 >(types))) {
544
506
return std::move (result.getValue ());
545
507
}
546
508
}
@@ -556,12 +518,6 @@ swift::matchWitness(
556
518
return RequirementMatch (witness, MatchKind::TypeConflict,
557
519
witnessType);
558
520
559
- ParameterList *witnessParamList = getParameterList (witness);
560
- assert (witnessParamList->size () == witnessParams.size ());
561
-
562
- ParameterList *reqParamList = getParameterList (req);
563
- assert (reqParamList->size () == reqParams.size ());
564
-
565
521
// Match each of the parameters.
566
522
for (unsigned i = 0 , n = reqParams.size (); i != n; ++i) {
567
523
// Variadic bits must match.
@@ -575,33 +531,21 @@ swift::matchWitness(
575
531
if (reqParams[i].isInOut () != witnessParams[i].isInOut ())
576
532
return RequirementMatch (witness, MatchKind::TypeConflict, witnessType);
577
533
578
- auto reqParamDecl = reqParamList->get (i);
579
- auto witnessParamDecl = witnessParamList->get (i);
580
-
581
- auto reqParamTypeIsIUO =
582
- reqParamDecl->getAttrs ()
583
- .hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
584
- auto witnessParamTypeIsIUO =
585
- witnessParamDecl->getAttrs ()
586
- .hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
587
-
588
534
// Gross hack: strip a level of unchecked-optionality off both
589
535
// sides when matching against a protocol imported from Objective-C.
590
- auto types =
591
- getTypesToCompare (req, reqParams[i].getType (), reqParamTypeIsIUO,
592
- witnessParams[i].getType (), witnessParamTypeIsIUO,
593
- VarianceKind::Contravariant);
536
+ auto types = getTypesToCompare (req, reqParams[i].getType (),
537
+ witnessParams[i].getType (),
538
+ VarianceKind::Contravariant);
594
539
595
540
// Record any optional adjustment that occurred.
596
541
if (std::get<2 >(types) != OptionalAdjustmentKind::None) {
597
542
optionalAdjustments.push_back (
598
543
OptionalAdjustment (std::get<2 >(types), i));
599
544
}
600
545
601
- if (!req->isObjC () && reqParamTypeIsIUO != witnessParamTypeIsIUO)
602
- return RequirementMatch (witness, MatchKind::TypeConflict, witnessType);
603
-
604
- if (auto result = matchTypes (std::get<0 >(types), std::get<1 >(types))) {
546
+ // Check whether the parameter types match.
547
+ if (auto result = matchTypes (std::get<0 >(types),
548
+ std::get<1 >(types))) {
605
549
return std::move (result.getValue ());
606
550
}
607
551
}
@@ -613,22 +557,16 @@ swift::matchWitness(
613
557
}
614
558
615
559
} else {
616
- auto reqTypeIsIUO =
617
- req->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
618
- auto witnessTypeIsIUO =
619
- witness->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
620
- auto types = getTypesToCompare (req, reqType, reqTypeIsIUO, witnessType,
621
- witnessTypeIsIUO, VarianceKind::None);
560
+ // Simple case: add the constraint.
561
+ auto types = getTypesToCompare (req, reqType, witnessType,
562
+ VarianceKind::None);
622
563
623
564
// Record optional adjustment, if any.
624
565
if (std::get<2 >(types) != OptionalAdjustmentKind::None) {
625
566
optionalAdjustments.push_back (
626
567
OptionalAdjustment (std::get<2 >(types)));
627
568
}
628
569
629
- if (!req->isObjC () && reqTypeIsIUO != witnessTypeIsIUO)
630
- return RequirementMatch (witness, MatchKind::TypeConflict, witnessType);
631
-
632
570
if (auto result = matchTypes (std::get<0 >(types), std::get<1 >(types))) {
633
571
return std::move (result.getValue ());
634
572
}
@@ -786,8 +724,8 @@ RequirementMatch swift::matchWitness(TypeChecker &tc,
786
724
};
787
725
788
726
// Match a type in the requirement to a type in the witness.
789
- auto matchTypes = [&](Type reqType,
790
- Type witnessType) -> Optional<RequirementMatch> {
727
+ auto matchTypes = [&](Type reqType, Type witnessType)
728
+ -> Optional<RequirementMatch> {
791
729
cs->addConstraint (ConstraintKind::Equal, reqType, witnessType, locator);
792
730
// FIXME: Check whether this has already failed.
793
731
return None;
0 commit comments