@@ -127,6 +127,18 @@ const char XRefError::ID = '\0';
127
127
void XRefError::anchor () {}
128
128
const char OverrideError::ID = ' \0 ' ;
129
129
void OverrideError::anchor () {}
130
+ const char TypeError::ID = ' \0 ' ;
131
+ void TypeError::anchor () {}
132
+
133
+ LLVM_NODISCARD
134
+ static std::unique_ptr<llvm::ErrorInfoBase> takeErrorInfo (llvm::Error error) {
135
+ std::unique_ptr<llvm::ErrorInfoBase> result;
136
+ llvm::handleAllErrors (std::move (error),
137
+ [&](std::unique_ptr<llvm::ErrorInfoBase> info) {
138
+ result = std::move (info);
139
+ });
140
+ return result;
141
+ }
130
142
131
143
132
144
// / Skips a single record in the bitstream.
@@ -2492,7 +2504,7 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {
2492
2504
bool isImplicit, isObjC, hasStubImplementation, throws;
2493
2505
GenericEnvironmentID genericEnvID;
2494
2506
uint8_t storedInitKind, rawAccessLevel;
2495
- TypeID interfaceID;
2507
+ TypeID interfaceID, canonicalTypeID ;
2496
2508
DeclID overriddenID;
2497
2509
ArrayRef<uint64_t > argNameIDs;
2498
2510
@@ -2501,8 +2513,8 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {
2501
2513
isObjC, hasStubImplementation,
2502
2514
throws, storedInitKind,
2503
2515
genericEnvID, interfaceID,
2504
- overriddenID, rawAccessLevel ,
2505
- argNameIDs);
2516
+ canonicalTypeID, overriddenID ,
2517
+ rawAccessLevel, argNameIDs);
2506
2518
2507
2519
// Resolve the name ids.
2508
2520
SmallVector<Identifier, 2 > argNames;
@@ -2595,15 +2607,15 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {
2595
2607
DeclContextID contextID;
2596
2608
bool isImplicit, isObjC, isStatic, isLet, hasNonPatternBindingInit;
2597
2609
uint8_t storageKind, rawAccessLevel, rawSetterAccessLevel;
2598
- TypeID interfaceTypeID;
2610
+ TypeID interfaceTypeID, canonicalTypeID ;
2599
2611
DeclID getterID, setterID, materializeForSetID, willSetID, didSetID;
2600
2612
DeclID addressorID, mutableAddressorID, overriddenID;
2601
2613
2602
2614
decls_block::VarLayout::readRecord (scratch, nameID, contextID,
2603
2615
isImplicit, isObjC, isStatic, isLet,
2604
2616
hasNonPatternBindingInit, storageKind,
2605
- interfaceTypeID, getterID ,
2606
- setterID, materializeForSetID,
2617
+ interfaceTypeID, canonicalTypeID ,
2618
+ getterID, setterID, materializeForSetID,
2607
2619
addressorID, mutableAddressorID,
2608
2620
willSetID, didSetID, overriddenID,
2609
2621
rawAccessLevel, rawSetterAccessLevel);
@@ -2616,6 +2628,10 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {
2616
2628
return llvm::make_error<OverrideError>(name);
2617
2629
}
2618
2630
2631
+ auto canonicalType = getTypeChecked (canonicalTypeID);
2632
+ if (!canonicalType)
2633
+ return llvm::make_error<TypeError>(name, takeErrorInfo (canonicalType.takeError ()));
2634
+
2619
2635
auto DC = ForcedContext ? *ForcedContext : getDeclContext (contextID);
2620
2636
if (declOrOffset.isComplete ())
2621
2637
return declOrOffset;
@@ -2703,7 +2719,7 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {
2703
2719
bool isObjC, isMutating, hasDynamicSelf, throws;
2704
2720
unsigned numParamPatterns;
2705
2721
GenericEnvironmentID genericEnvID;
2706
- TypeID interfaceTypeID;
2722
+ TypeID interfaceTypeID, canonicalTypeID ;
2707
2723
DeclID associatedDeclID;
2708
2724
DeclID overriddenID;
2709
2725
DeclID accessorStorageDeclID;
@@ -2714,10 +2730,11 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {
2714
2730
isStatic, rawStaticSpelling, isObjC,
2715
2731
isMutating, hasDynamicSelf, throws,
2716
2732
numParamPatterns, genericEnvID,
2717
- interfaceTypeID, associatedDeclID,
2718
- overriddenID, accessorStorageDeclID,
2719
- hasCompoundName, rawAddressorKind,
2720
- rawAccessLevel, nameIDs);
2733
+ interfaceTypeID, canonicalTypeID,
2734
+ associatedDeclID, overriddenID,
2735
+ accessorStorageDeclID, hasCompoundName,
2736
+ rawAddressorKind, rawAccessLevel,
2737
+ nameIDs);
2721
2738
2722
2739
// Resolve the name ids.
2723
2740
SmallVector<Identifier, 2 > names;
@@ -3237,7 +3254,7 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {
3237
3254
DeclContextID contextID;
3238
3255
bool isImplicit, isObjC;
3239
3256
GenericEnvironmentID genericEnvID;
3240
- TypeID interfaceTypeID;
3257
+ TypeID interfaceTypeID, canonicalTypeID ;
3241
3258
DeclID getterID, setterID, materializeForSetID;
3242
3259
DeclID addressorID, mutableAddressorID, willSetID, didSetID;
3243
3260
DeclID overriddenID;
@@ -3248,7 +3265,7 @@ ModuleFile::getDeclChecked(DeclID DID, Optional<DeclContext *> ForcedContext) {
3248
3265
decls_block::SubscriptLayout::readRecord (scratch, contextID,
3249
3266
isImplicit, isObjC, rawStorageKind,
3250
3267
genericEnvID,
3251
- interfaceTypeID,
3268
+ interfaceTypeID, canonicalTypeID,
3252
3269
getterID, setterID,
3253
3270
materializeForSetID,
3254
3271
addressorID, mutableAddressorID,
@@ -3587,17 +3604,20 @@ Expected<Type> ModuleFile::getTypeChecked(TypeID TID) {
3587
3604
TypeID canonicalTypeID;
3588
3605
decls_block::NameAliasTypeLayout::readRecord (scratch, underlyingID,
3589
3606
canonicalTypeID);
3590
- auto alias = dyn_cast_or_null<TypeAliasDecl>(getDecl (underlyingID));
3591
- if (!alias) {
3592
- error ();
3593
- return nullptr ;
3594
- }
3607
+ auto aliasOrError = getDeclChecked (underlyingID);
3608
+ if (!aliasOrError)
3609
+ return aliasOrError.takeError ();
3610
+ auto alias = dyn_cast<TypeAliasDecl>(aliasOrError.get ());
3595
3611
3596
3612
if (ctx.LangOpts .EnableDeserializationRecovery ) {
3597
- if (Type expectedType = getType (canonicalTypeID)) {
3598
- if (!alias->getDeclaredInterfaceType ()->isEqual (expectedType)) {
3613
+ Expected<Type> expectedType = getTypeChecked (canonicalTypeID);
3614
+ if (!expectedType)
3615
+ return expectedType.takeError ();
3616
+ if (expectedType.get ()) {
3617
+ if (!alias ||
3618
+ !alias->getDeclaredInterfaceType ()->isEqual (expectedType.get ())) {
3599
3619
// Fall back to the canonical type.
3600
- typeOrOffset = expectedType;
3620
+ typeOrOffset = expectedType. get () ;
3601
3621
break ;
3602
3622
}
3603
3623
}
@@ -3619,12 +3639,22 @@ Expected<Type> ModuleFile::getTypeChecked(TypeID TID) {
3619
3639
TypeID parentID;
3620
3640
decls_block::NominalTypeLayout::readRecord (scratch, declID, parentID);
3621
3641
3622
- Type parentTy = getType (parentID);
3642
+ Expected<Type> parentTy = getTypeChecked (parentID);
3643
+ if (!parentTy)
3644
+ return parentTy.takeError ();
3623
3645
3624
- // Record the type as soon as possible. Members of a nominal type often
3625
- // try to refer back to the type.
3626
- auto nominal = cast<NominalTypeDecl>(getDecl (declID));
3627
- typeOrOffset = NominalType::get (nominal, parentTy, ctx);
3646
+ auto nominalOrError = getDeclChecked (declID);
3647
+ if (!nominalOrError)
3648
+ return nominalOrError.takeError ();
3649
+
3650
+ auto nominal = dyn_cast<NominalTypeDecl>(nominalOrError.get ());
3651
+ if (!nominal) {
3652
+ XRefTracePath tinyTrace{*nominalOrError.get ()->getModuleContext ()};
3653
+ tinyTrace.addValue (cast<ValueDecl>(nominalOrError.get ())->getName ());
3654
+ return llvm::make_error<XRefError>(" declaration is not a nominal type" ,
3655
+ tinyTrace);
3656
+ }
3657
+ typeOrOffset = NominalType::get (nominal, parentTy.get (), ctx);
3628
3658
3629
3659
assert (typeOrOffset.isComplete ());
3630
3660
break ;
0 commit comments