@@ -512,15 +512,28 @@ CanType IRGenModule::getRuntimeReifiedType(CanType type) {
512
512
}));
513
513
}
514
514
515
+ static bool containsPrivateType (CanType ty) {
516
+ return ty.findIf ([](Type t) -> bool {
517
+ if (auto *nominal = t->getAnyNominal ()) {
518
+ if (nominal->getEffectiveAccess () <= AccessLevel::FilePrivate)
519
+ return true ;
520
+ }
521
+ return false ;
522
+ });
523
+ }
524
+
515
525
CanType IRGenModule::substOpaqueTypesWithUnderlyingTypes (CanType type) {
516
526
// Substitute away opaque types whose underlying types we're allowed to
517
527
// assume are constant.
518
528
if (type->hasOpaqueArchetype ()) {
519
529
ReplaceOpaqueTypesWithUnderlyingTypes replacer (getSwiftModule (),
520
530
ResilienceExpansion::Maximal);
521
- type = type.subst (replacer, replacer,
522
- SubstFlags::SubstituteOpaqueArchetypes)
523
- ->getCanonicalType ();
531
+ auto underlyingTy =
532
+ type.subst (replacer, replacer, SubstFlags::SubstituteOpaqueArchetypes)
533
+ ->getCanonicalType ();
534
+ // The underlying type could contain a private type from a different TU.
535
+ if (!containsPrivateType (underlyingTy))
536
+ return underlyingTy;
524
537
}
525
538
526
539
return type;
@@ -533,8 +546,12 @@ SILType IRGenModule::substOpaqueTypesWithUnderlyingTypes(
533
546
if (type.getASTType ()->hasOpaqueArchetype ()) {
534
547
ReplaceOpaqueTypesWithUnderlyingTypes replacer (getSwiftModule (),
535
548
ResilienceExpansion::Maximal);
536
- type = type.subst (getSILModule (), replacer, replacer, genericSig,
537
- /* substitute opaque*/ true );
549
+ auto underlyingTy =
550
+ type.subst (getSILModule (), replacer, replacer, genericSig,
551
+ /* substitute opaque*/ true );
552
+ // The underlying type could contain a private type from a different TU.
553
+ if (!containsPrivateType (underlyingTy.getASTType ()))
554
+ return underlyingTy;
538
555
}
539
556
540
557
return type;
@@ -548,11 +565,14 @@ IRGenModule::substOpaqueTypesWithUnderlyingTypes(CanType type,
548
565
if (type->hasOpaqueArchetype ()) {
549
566
ReplaceOpaqueTypesWithUnderlyingTypes replacer (getSwiftModule (),
550
567
ResilienceExpansion::Maximal);
551
- conformance = conformance.subst (type, replacer, replacer,
552
- SubstFlags::SubstituteOpaqueArchetypes);
553
- type = type.subst (replacer, replacer,
554
- SubstFlags::SubstituteOpaqueArchetypes)
555
- ->getCanonicalType ();
568
+ auto substConformance = conformance.subst (
569
+ type, replacer, replacer, SubstFlags::SubstituteOpaqueArchetypes);
570
+ auto underlyingTy =
571
+ type.subst (replacer, replacer, SubstFlags::SubstituteOpaqueArchetypes)
572
+ ->getCanonicalType ();
573
+ // The underlying type could contain a private type from a different TU.
574
+ if (!containsPrivateType (underlyingTy))
575
+ return std::make_pair (underlyingTy, substConformance);
556
576
}
557
577
558
578
return std::make_pair (type, conformance);
0 commit comments