@@ -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.
@@ -3634,7 +3641,10 @@ class DeclDeserializer {
3634
3641
if (declOrOffset.isComplete ())
3635
3642
return declOrOffset;
3636
3643
3637
- const auto resultType = MF.getType (resultInterfaceTypeID);
3644
+ auto resultTypeOrError = MF.getTypeChecked (resultInterfaceTypeID);
3645
+ if (!resultTypeOrError)
3646
+ return resultTypeOrError.takeError ();
3647
+ const auto resultType = resultTypeOrError.get ();
3638
3648
if (declOrOffset.isComplete ())
3639
3649
return declOrOffset;
3640
3650
@@ -3707,9 +3717,13 @@ class DeclDeserializer {
3707
3717
std::move (needsNewVTableEntry));
3708
3718
3709
3719
if (opaqueReturnTypeID) {
3720
+ auto declOrError = MF.getDeclChecked (opaqueReturnTypeID);
3721
+ if (!declOrError)
3722
+ return declOrError.takeError ();
3723
+
3710
3724
ctx.evaluator .cacheOutput (
3711
3725
OpaqueResultTypeRequest{fn},
3712
- cast<OpaqueTypeDecl>(MF. getDecl (opaqueReturnTypeID )));
3726
+ cast<OpaqueTypeDecl>(declOrError. get ( )));
3713
3727
}
3714
3728
3715
3729
if (!isAccessor)
@@ -3850,26 +3864,31 @@ class DeclDeserializer {
3850
3864
opaqueDecl->setGenericSignature (GenericSignature ());
3851
3865
if (underlyingTypeSubsID) {
3852
3866
auto subMapOrError = MF.getSubstitutionMapChecked (underlyingTypeSubsID);
3853
- if (!subMapOrError)
3854
- return subMapOrError.takeError ();
3855
-
3856
- // Check whether there are any conditionally available substitutions.
3857
- // If there are, it means that "unique" we just read is a universally
3858
- // available substitution.
3859
- SmallVector<OpaqueTypeDecl::ConditionallyAvailableSubstitutions *>
3860
- limitedAvailability;
3867
+ if (!subMapOrError) {
3868
+ // If the underlying type references internal details, ignore it.
3869
+ auto unconsumedError =
3870
+ consumeErrorIfXRefNonLoadedModule (subMapOrError.takeError ());
3871
+ if (unconsumedError)
3872
+ return std::move (unconsumedError);
3873
+ } else {
3874
+ // Check whether there are any conditionally available substitutions.
3875
+ // If there are, it means that "unique" we just read is a universally
3876
+ // available substitution.
3877
+ SmallVector<OpaqueTypeDecl::ConditionallyAvailableSubstitutions *>
3878
+ limitedAvailability;
3861
3879
3862
- deserializeConditionalSubstitutions (limitedAvailability);
3880
+ deserializeConditionalSubstitutions (limitedAvailability);
3863
3881
3864
- if (limitedAvailability.empty ()) {
3865
- opaqueDecl->setUniqueUnderlyingTypeSubstitutions (subMapOrError.get ());
3866
- } else {
3867
- limitedAvailability.push_back (
3868
- OpaqueTypeDecl::ConditionallyAvailableSubstitutions::get (
3869
- ctx, {{VersionRange::empty (), /* unavailability=*/ false }},
3870
- subMapOrError.get ()));
3882
+ if (limitedAvailability.empty ()) {
3883
+ opaqueDecl->setUniqueUnderlyingTypeSubstitutions (subMapOrError.get ());
3884
+ } else {
3885
+ limitedAvailability.push_back (
3886
+ OpaqueTypeDecl::ConditionallyAvailableSubstitutions::get (
3887
+ ctx, {{VersionRange::empty (), /* unavailability=*/ false }},
3888
+ subMapOrError.get ()));
3871
3889
3872
- opaqueDecl->setConditionallyAvailableSubstitutions (limitedAvailability);
3890
+ opaqueDecl->setConditionallyAvailableSubstitutions (limitedAvailability);
3891
+ }
3873
3892
}
3874
3893
}
3875
3894
return opaqueDecl;
0 commit comments