Skip to content

Commit f74433b

Browse files
committed
Serialization: Recover from errors in most calls to getDeclContext
rdar://126138660
1 parent cea750d commit f74433b

File tree

1 file changed

+60
-23
lines changed

1 file changed

+60
-23
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,7 +2726,9 @@ Expected<DeclContext *>ModuleFile::getLocalDeclContext(LocalDeclContextID DCID)
27262726
implicit,
27272727
discriminator,
27282728
parentID);
2729-
DeclContext *parent = getDeclContext(parentID);
2729+
DeclContext *parent;
2730+
UNWRAP(getDeclContextChecked(parentID), parent);
2731+
27302732
auto type = getType(closureTypeID);
27312733

27322734
declContextOrOffset = new (ctx)
@@ -2738,7 +2740,8 @@ Expected<DeclContext *>ModuleFile::getLocalDeclContext(LocalDeclContextID DCID)
27382740
DeclContextID parentID;
27392741
decls_block::TopLevelCodeDeclContextLayout::readRecord(scratch,
27402742
parentID);
2741-
DeclContext *parent = getDeclContext(parentID);
2743+
DeclContext *parent;
2744+
UNWRAP(getDeclContextChecked(parentID), parent);
27422745

27432746
declContextOrOffset = new (ctx) SerializedTopLevelCodeDeclContext(parent);
27442747
break;
@@ -2768,7 +2771,8 @@ Expected<DeclContext *>ModuleFile::getLocalDeclContext(LocalDeclContextID DCID)
27682771
decls_block::DefaultArgumentInitializerLayout::readRecord(scratch,
27692772
parentID,
27702773
index);
2771-
DeclContext *parent = getDeclContext(parentID);
2774+
DeclContext *parent;
2775+
UNWRAP(getDeclContextChecked(parentID), parent);
27722776

27732777
declContextOrOffset = new (ctx) DefaultArgumentInitializer(parent, index);
27742778
break;
@@ -3343,7 +3347,8 @@ class DeclDeserializer {
33433347
}
33443348
}
33453349

3346-
auto DC = MF.getDeclContext(contextID);
3350+
DeclContext *DC;
3351+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
33473352

33483353
auto genericParams = MF.maybeReadGenericParams(DC);
33493354
if (declOrOffset.isComplete())
@@ -3415,7 +3420,9 @@ class DeclDeserializer {
34153420
isImplicit,
34163421
rawOverriddenIDs);
34173422

3418-
auto DC = MF.getDeclContext(contextID);
3423+
DeclContext *DC;
3424+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
3425+
34193426
if (declOrOffset.isComplete())
34203427
return declOrOffset;
34213428

@@ -3598,7 +3605,9 @@ class DeclDeserializer {
35983605
}
35993606
}
36003607

3601-
auto parent = MF.getDeclContext(contextID);
3608+
DeclContext *parent;
3609+
UNWRAP(MF.getDeclContextChecked(contextID), parent);
3610+
36023611
if (declOrOffset.isComplete())
36033612
return declOrOffset;
36043613

@@ -3762,7 +3771,9 @@ class DeclDeserializer {
37623771
}
37633772
}
37643773

3765-
auto DC = MF.getDeclContext(contextID);
3774+
DeclContext *DC;
3775+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
3776+
37663777
if (declOrOffset.isComplete())
37673778
return declOrOffset;
37683779

@@ -3918,7 +3929,9 @@ class DeclDeserializer {
39183929
auto paramName = MF.getIdentifier(paramNameID);
39193930
PrettySupplementalDeclNameTrace trace(paramName);
39203931

3921-
auto DC = MF.getDeclContext(contextID);
3932+
DeclContext *DC;
3933+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
3934+
39223935
if (declOrOffset.isComplete())
39233936
return declOrOffset;
39243937

@@ -4134,7 +4147,9 @@ class DeclDeserializer {
41344147
}
41354148
}
41364149

4137-
auto DC = MF.getDeclContext(contextID);
4150+
DeclContext *DC;
4151+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
4152+
41384153
if (declOrOffset.isComplete())
41394154
return declOrOffset;
41404155

@@ -4356,7 +4371,9 @@ class DeclDeserializer {
43564371
rawAccessLevel,
43574372
exportUnderlyingType);
43584373

4359-
auto declContext = MF.getDeclContext(contextID);
4374+
DeclContext *declContext;
4375+
UNWRAP(MF.getDeclContextChecked(contextID), declContext);
4376+
43604377
auto interfaceSigOrErr = MF.getGenericSignatureChecked(interfaceSigID);
43614378
if (!interfaceSigOrErr)
43624379
return interfaceSigOrErr.takeError();
@@ -4459,7 +4476,8 @@ class DeclDeserializer {
44594476
if (!StaticSpelling.has_value())
44604477
return MF.diagnoseFatal();
44614478

4462-
auto dc = MF.getDeclContext(contextID);
4479+
DeclContext *dc;
4480+
UNWRAP(MF.getDeclContextChecked(contextID), dc);
44634481

44644482
SmallVector<std::pair<Pattern *, DeclContextID>, 4> patterns;
44654483
for (unsigned i = 0; i != numPatterns; ++i) {
@@ -4495,8 +4513,11 @@ class DeclDeserializer {
44954513

44964514
for (unsigned i = 0; i != patterns.size(); ++i) {
44974515
binding->setPattern(i, patterns[i].first);
4498-
if (auto *context = MF.getDeclContext(patterns[i].second))
4499-
binding->setInitContext(i, cast<PatternBindingInitializer>(context));
4516+
4517+
DeclContext *dcPattern;
4518+
UNWRAP(MF.getDeclContextChecked(patterns[i].second), dcPattern);
4519+
if (dcPattern)
4520+
binding->setInitContext(i, cast<PatternBindingInitializer>(dcPattern));
45004521
}
45014522

45024523
return binding;
@@ -4529,7 +4550,9 @@ class DeclDeserializer {
45294550
}
45304551
}
45314552

4532-
auto DC = MF.getDeclContext(contextID);
4553+
DeclContext *DC;
4554+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
4555+
45334556
if (declOrOffset.isComplete())
45344557
return declOrOffset;
45354558

@@ -4600,7 +4623,8 @@ class DeclDeserializer {
46004623
Identifier name = MF.getIdentifier(nameID);
46014624
PrettySupplementalDeclNameTrace trace(name);
46024625

4603-
auto DC = MF.getDeclContext(contextID);
4626+
DeclContext *DC;
4627+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
46044628

46054629
auto result = MF.createDecl<OperatorDecl>(
46064630
DC, SourceLoc(), name, SourceLoc());
@@ -4636,7 +4660,8 @@ class DeclDeserializer {
46364660
if (!precedenceGroup)
46374661
return precedenceGroup.takeError();
46384662

4639-
auto DC = MF.getDeclContext(contextID);
4663+
DeclContext *DC;
4664+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
46404665

46414666
auto result = MF.createDecl<InfixOperatorDecl>(
46424667
DC, SourceLoc(), name, SourceLoc(), SourceLoc(), Identifier(),
@@ -4663,7 +4688,8 @@ class DeclDeserializer {
46634688
assignment, numHigherThan,
46644689
rawRelations);
46654690

4666-
auto DC = MF.getDeclContext(contextID);
4691+
DeclContext *DC;
4692+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
46674693

46684694
auto associativity = getActualAssociativity(rawAssociativity);
46694695
if (!associativity.has_value())
@@ -4746,7 +4772,9 @@ class DeclDeserializer {
47464772
}
47474773
}
47484774

4749-
auto DC = MF.getDeclContext(contextID);
4775+
DeclContext *DC;
4776+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
4777+
47504778
if (declOrOffset.isComplete())
47514779
return declOrOffset;
47524780

@@ -4907,7 +4935,9 @@ class DeclDeserializer {
49074935
}
49084936
}
49094937

4910-
DeclContext *DC = MF.getDeclContext(contextID);
4938+
DeclContext *DC;
4939+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
4940+
49114941
if (declOrOffset.isComplete())
49124942
return declOrOffset;
49134943

@@ -5014,7 +5044,9 @@ class DeclDeserializer {
50145044
}
50155045
}
50165046

5017-
auto parent = MF.getDeclContext(contextID);
5047+
DeclContext *parent;
5048+
UNWRAP(MF.getDeclContextChecked(contextID), parent);
5049+
50185050
if (declOrOffset.isComplete())
50195051
return declOrOffset;
50205052

@@ -5089,7 +5121,8 @@ class DeclDeserializer {
50895121
numConformances, numInherited,
50905122
data);
50915123

5092-
auto DC = MF.getDeclContext(contextID);
5124+
DeclContext *DC;
5125+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
50935126

50945127
auto conformanceIDs = data.slice(0, numConformances);
50955128
data = data.slice(numConformances);
@@ -5176,7 +5209,9 @@ class DeclDeserializer {
51765209
isImplicit, isObjC,
51775210
genericSigID);
51785211

5179-
DeclContext *DC = MF.getDeclContext(contextID);
5212+
DeclContext *DC;
5213+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
5214+
51805215
if (declOrOffset.isComplete())
51815216
return declOrOffset;
51825217

@@ -5251,7 +5286,9 @@ class DeclDeserializer {
52515286
}
52525287
}
52535288

5254-
auto parent = MF.getDeclContext(contextID);
5289+
DeclContext *parent;
5290+
UNWRAP(MF.getDeclContextChecked(contextID), parent);
5291+
52555292
if (declOrOffset.isComplete())
52565293
return declOrOffset;
52575294

0 commit comments

Comments
 (0)