@@ -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);
@@ -367,14 +343,6 @@ static bool checkObjCWitnessSelector(TypeChecker &tc, ValueDecl *req,
367
343
return false ;
368
344
}
369
345
370
- static ParameterList *getParameterList (ValueDecl *value) {
371
- if (auto func = dyn_cast<AbstractFunctionDecl>(value))
372
- return func->getParameterList (func->getDeclContext ()->isTypeContext ());
373
-
374
- auto subscript = cast<SubscriptDecl>(value);
375
- return subscript->getIndices ();
376
- }
377
-
378
346
RequirementMatch
379
347
swift::matchWitness (
380
348
TypeChecker &tc,
@@ -522,24 +490,18 @@ swift::matchWitness(
522
490
// Result types must match.
523
491
// FIXME: Could allow (trivial?) subtyping here.
524
492
if (!ignoreReturnType) {
525
- auto reqTypeIsIUO =
526
- req->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
527
- auto witnessTypeIsIUO =
528
- witness->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
529
- auto types =
530
- getTypesToCompare (req, reqResultType, reqTypeIsIUO, witnessResultType,
531
- witnessTypeIsIUO, VarianceKind::Covariant);
493
+ auto types = getTypesToCompare (req, reqResultType,
494
+ witnessResultType,
495
+ VarianceKind::Covariant);
532
496
533
497
// Record optional adjustment, if any.
534
498
if (std::get<2 >(types) != OptionalAdjustmentKind::None) {
535
499
optionalAdjustments.push_back (
536
500
OptionalAdjustment (std::get<2 >(types)));
537
501
}
538
502
539
- if (!req->isObjC () && reqTypeIsIUO != witnessTypeIsIUO)
540
- return RequirementMatch (witness, MatchKind::TypeConflict, witnessType);
541
-
542
- if (auto result = matchTypes (std::get<0 >(types), std::get<1 >(types))) {
503
+ if (auto result = matchTypes (std::get<0 >(types),
504
+ std::get<1 >(types))) {
543
505
return std::move (result.getValue ());
544
506
}
545
507
}
@@ -555,12 +517,6 @@ swift::matchWitness(
555
517
return RequirementMatch (witness, MatchKind::TypeConflict,
556
518
witnessType);
557
519
558
- ParameterList *witnessParamList = getParameterList (witness);
559
- assert (witnessParamList->size () == witnessParams.size ());
560
-
561
- ParameterList *reqParamList = getParameterList (req);
562
- assert (reqParamList->size () == reqParams.size ());
563
-
564
520
// Match each of the parameters.
565
521
for (unsigned i = 0 , n = reqParams.size (); i != n; ++i) {
566
522
// Variadic bits must match.
@@ -574,33 +530,21 @@ swift::matchWitness(
574
530
if (reqParams[i].isInOut () != witnessParams[i].isInOut ())
575
531
return RequirementMatch (witness, MatchKind::TypeConflict, witnessType);
576
532
577
- auto reqParamDecl = reqParamList->get (i);
578
- auto witnessParamDecl = witnessParamList->get (i);
579
-
580
- auto reqParamTypeIsIUO =
581
- reqParamDecl->getAttrs ()
582
- .hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
583
- auto witnessParamTypeIsIUO =
584
- witnessParamDecl->getAttrs ()
585
- .hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
586
-
587
533
// Gross hack: strip a level of unchecked-optionality off both
588
534
// sides when matching against a protocol imported from Objective-C.
589
- auto types =
590
- getTypesToCompare (req, reqParams[i].getType (), reqParamTypeIsIUO,
591
- witnessParams[i].getType (), witnessParamTypeIsIUO,
592
- VarianceKind::Contravariant);
535
+ auto types = getTypesToCompare (req, reqParams[i].getType (),
536
+ witnessParams[i].getType (),
537
+ VarianceKind::Contravariant);
593
538
594
539
// Record any optional adjustment that occurred.
595
540
if (std::get<2 >(types) != OptionalAdjustmentKind::None) {
596
541
optionalAdjustments.push_back (
597
542
OptionalAdjustment (std::get<2 >(types), i));
598
543
}
599
544
600
- if (!req->isObjC () && reqParamTypeIsIUO != witnessParamTypeIsIUO)
601
- return RequirementMatch (witness, MatchKind::TypeConflict, witnessType);
602
-
603
- if (auto result = matchTypes (std::get<0 >(types), std::get<1 >(types))) {
545
+ // Check whether the parameter types match.
546
+ if (auto result = matchTypes (std::get<0 >(types),
547
+ std::get<1 >(types))) {
604
548
return std::move (result.getValue ());
605
549
}
606
550
}
@@ -612,22 +556,16 @@ swift::matchWitness(
612
556
}
613
557
614
558
} else {
615
- auto reqTypeIsIUO =
616
- req->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
617
- auto witnessTypeIsIUO =
618
- witness->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
619
- auto types = getTypesToCompare (req, reqType, reqTypeIsIUO, witnessType,
620
- witnessTypeIsIUO, VarianceKind::None);
559
+ // Simple case: add the constraint.
560
+ auto types = getTypesToCompare (req, reqType, witnessType,
561
+ VarianceKind::None);
621
562
622
563
// Record optional adjustment, if any.
623
564
if (std::get<2 >(types) != OptionalAdjustmentKind::None) {
624
565
optionalAdjustments.push_back (
625
566
OptionalAdjustment (std::get<2 >(types)));
626
567
}
627
568
628
- if (!req->isObjC () && reqTypeIsIUO != witnessTypeIsIUO)
629
- return RequirementMatch (witness, MatchKind::TypeConflict, witnessType);
630
-
631
569
if (auto result = matchTypes (std::get<0 >(types), std::get<1 >(types))) {
632
570
return std::move (result.getValue ());
633
571
}
@@ -785,8 +723,8 @@ RequirementMatch swift::matchWitness(TypeChecker &tc,
785
723
};
786
724
787
725
// Match a type in the requirement to a type in the witness.
788
- auto matchTypes = [&](Type reqType,
789
- Type witnessType) -> Optional<RequirementMatch> {
726
+ auto matchTypes = [&](Type reqType, Type witnessType)
727
+ -> Optional<RequirementMatch> {
790
728
cs->addConstraint (ConstraintKind::Equal, reqType, witnessType, locator);
791
729
// FIXME: Check whether this has already failed.
792
730
return None;
0 commit comments