@@ -158,6 +158,8 @@ void InvalidRecordKindError::anchor() {}
158
158
const char UnsafeDeserializationError::ID = ' \0 ' ;
159
159
void UnsafeDeserializationError::anchor () {}
160
160
161
+ static llvm::Error consumeErrorIfXRefNonLoadedModule (llvm::Error &&error);
162
+
161
163
// / Skips a single record in the bitstream.
162
164
// /
163
165
// / Destroys the stream position if the next entry is not a record.
@@ -1360,7 +1362,12 @@ ModuleFile::getSubstitutionMapChecked(serialization::SubstitutionMapID id) {
1360
1362
SmallVector<Type, 4 > replacementTypes;
1361
1363
replacementTypes.reserve (replacementTypeIDs.size ());
1362
1364
for (auto typeID : replacementTypeIDs) {
1363
- replacementTypes.push_back (getType (typeID));
1365
+ auto typeOrError = getTypeChecked (typeID);
1366
+ if (!typeOrError) {
1367
+ consumeError (typeOrError.takeError ());
1368
+ continue ;
1369
+ }
1370
+ replacementTypes.push_back (typeOrError.get ());
1364
1371
}
1365
1372
1366
1373
// Read the conformances.
@@ -3601,7 +3608,10 @@ class DeclDeserializer {
3601
3608
if (declOrOffset.isComplete ())
3602
3609
return declOrOffset;
3603
3610
3604
- const auto resultType = MF.getType (resultInterfaceTypeID);
3611
+ auto resultTypeOrError = MF.getTypeChecked (resultInterfaceTypeID);
3612
+ if (!resultTypeOrError)
3613
+ return resultTypeOrError.takeError ();
3614
+ const auto resultType = resultTypeOrError.get ();
3605
3615
if (declOrOffset.isComplete ())
3606
3616
return declOrOffset;
3607
3617
@@ -3674,9 +3684,13 @@ class DeclDeserializer {
3674
3684
std::move (needsNewVTableEntry));
3675
3685
3676
3686
if (opaqueReturnTypeID) {
3687
+ auto declOrError = MF.getDeclChecked (opaqueReturnTypeID);
3688
+ if (!declOrError)
3689
+ return declOrError.takeError ();
3690
+
3677
3691
ctx.evaluator .cacheOutput (
3678
3692
OpaqueResultTypeRequest{fn},
3679
- cast<OpaqueTypeDecl>(MF. getDecl (opaqueReturnTypeID )));
3693
+ cast<OpaqueTypeDecl>(declOrError. get ( )));
3680
3694
}
3681
3695
3682
3696
if (!isAccessor)
@@ -3817,26 +3831,31 @@ class DeclDeserializer {
3817
3831
opaqueDecl->setGenericSignature (GenericSignature ());
3818
3832
if (underlyingTypeSubsID) {
3819
3833
auto subMapOrError = MF.getSubstitutionMapChecked (underlyingTypeSubsID);
3820
- if (!subMapOrError)
3821
- return subMapOrError.takeError ();
3822
-
3823
- // Check whether there are any conditionally available substitutions.
3824
- // If there are, it means that "unique" we just read is a universally
3825
- // available substitution.
3826
- SmallVector<OpaqueTypeDecl::ConditionallyAvailableSubstitutions *>
3827
- limitedAvailability;
3834
+ if (!subMapOrError) {
3835
+ // If the underlying type references internal details, ignore it.
3836
+ auto unconsumedError =
3837
+ consumeErrorIfXRefNonLoadedModule (subMapOrError.takeError ());
3838
+ if (unconsumedError)
3839
+ return unconsumedError;
3840
+ } else {
3841
+ // Check whether there are any conditionally available substitutions.
3842
+ // If there are, it means that "unique" we just read is a universally
3843
+ // available substitution.
3844
+ SmallVector<OpaqueTypeDecl::ConditionallyAvailableSubstitutions *>
3845
+ limitedAvailability;
3828
3846
3829
- deserializeConditionalSubstitutions (limitedAvailability);
3847
+ deserializeConditionalSubstitutions (limitedAvailability);
3830
3848
3831
- if (limitedAvailability.empty ()) {
3832
- opaqueDecl->setUniqueUnderlyingTypeSubstitutions (subMapOrError.get ());
3833
- } else {
3834
- limitedAvailability.push_back (
3835
- OpaqueTypeDecl::ConditionallyAvailableSubstitutions::get (
3836
- ctx, {{VersionRange::empty (), /* unavailability=*/ false }},
3837
- subMapOrError.get ()));
3849
+ if (limitedAvailability.empty ()) {
3850
+ opaqueDecl->setUniqueUnderlyingTypeSubstitutions (subMapOrError.get ());
3851
+ } else {
3852
+ limitedAvailability.push_back (
3853
+ OpaqueTypeDecl::ConditionallyAvailableSubstitutions::get (
3854
+ ctx, {{VersionRange::empty (), /* unavailability=*/ false }},
3855
+ subMapOrError.get ()));
3838
3856
3839
- opaqueDecl->setConditionallyAvailableSubstitutions (limitedAvailability);
3857
+ opaqueDecl->setConditionallyAvailableSubstitutions (limitedAvailability);
3858
+ }
3840
3859
}
3841
3860
}
3842
3861
return opaqueDecl;
0 commit comments