Skip to content

Commit bb25702

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

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
@@ -2750,7 +2750,9 @@ Expected<DeclContext *>ModuleFile::getLocalDeclContext(LocalDeclContextID DCID)
27502750
implicit,
27512751
discriminator,
27522752
parentID);
2753-
DeclContext *parent = getDeclContext(parentID);
2753+
DeclContext *parent;
2754+
UNWRAP(getDeclContextChecked(parentID), parent);
2755+
27542756
auto type = getType(closureTypeID);
27552757

27562758
declContextOrOffset = new (ctx)
@@ -2762,7 +2764,8 @@ Expected<DeclContext *>ModuleFile::getLocalDeclContext(LocalDeclContextID DCID)
27622764
DeclContextID parentID;
27632765
decls_block::TopLevelCodeDeclContextLayout::readRecord(scratch,
27642766
parentID);
2765-
DeclContext *parent = getDeclContext(parentID);
2767+
DeclContext *parent;
2768+
UNWRAP(getDeclContextChecked(parentID), parent);
27662769

27672770
declContextOrOffset = new (ctx) SerializedTopLevelCodeDeclContext(parent);
27682771
break;
@@ -2792,7 +2795,8 @@ Expected<DeclContext *>ModuleFile::getLocalDeclContext(LocalDeclContextID DCID)
27922795
decls_block::DefaultArgumentInitializerLayout::readRecord(scratch,
27932796
parentID,
27942797
index);
2795-
DeclContext *parent = getDeclContext(parentID);
2798+
DeclContext *parent;
2799+
UNWRAP(getDeclContextChecked(parentID), parent);
27962800

27972801
declContextOrOffset = new (ctx) DefaultArgumentInitializer(parent, index);
27982802
break;
@@ -3367,7 +3371,8 @@ class DeclDeserializer {
33673371
}
33683372
}
33693373

3370-
auto DC = MF.getDeclContext(contextID);
3374+
DeclContext *DC;
3375+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
33713376

33723377
auto genericParams = MF.maybeReadGenericParams(DC);
33733378
if (declOrOffset.isComplete())
@@ -3439,7 +3444,9 @@ class DeclDeserializer {
34393444
isImplicit,
34403445
rawOverriddenIDs);
34413446

3442-
auto DC = MF.getDeclContext(contextID);
3447+
DeclContext *DC;
3448+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
3449+
34433450
if (declOrOffset.isComplete())
34443451
return declOrOffset;
34453452

@@ -3622,7 +3629,9 @@ class DeclDeserializer {
36223629
}
36233630
}
36243631

3625-
auto parent = MF.getDeclContext(contextID);
3632+
DeclContext *parent;
3633+
UNWRAP(MF.getDeclContextChecked(contextID), parent);
3634+
36263635
if (declOrOffset.isComplete())
36273636
return declOrOffset;
36283637

@@ -3786,7 +3795,9 @@ class DeclDeserializer {
37863795
}
37873796
}
37883797

3789-
auto DC = MF.getDeclContext(contextID);
3798+
DeclContext *DC;
3799+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
3800+
37903801
if (declOrOffset.isComplete())
37913802
return declOrOffset;
37923803

@@ -3942,7 +3953,9 @@ class DeclDeserializer {
39423953
auto paramName = MF.getIdentifier(paramNameID);
39433954
PrettySupplementalDeclNameTrace trace(paramName);
39443955

3945-
auto DC = MF.getDeclContext(contextID);
3956+
DeclContext *DC;
3957+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
3958+
39463959
if (declOrOffset.isComplete())
39473960
return declOrOffset;
39483961

@@ -4158,7 +4171,9 @@ class DeclDeserializer {
41584171
}
41594172
}
41604173

4161-
auto DC = MF.getDeclContext(contextID);
4174+
DeclContext *DC;
4175+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
4176+
41624177
if (declOrOffset.isComplete())
41634178
return declOrOffset;
41644179

@@ -4380,7 +4395,9 @@ class DeclDeserializer {
43804395
rawAccessLevel,
43814396
exportUnderlyingType);
43824397

4383-
auto declContext = MF.getDeclContext(contextID);
4398+
DeclContext *declContext;
4399+
UNWRAP(MF.getDeclContextChecked(contextID), declContext);
4400+
43844401
auto interfaceSigOrErr = MF.getGenericSignatureChecked(interfaceSigID);
43854402
if (!interfaceSigOrErr)
43864403
return interfaceSigOrErr.takeError();
@@ -4483,7 +4500,8 @@ class DeclDeserializer {
44834500
if (!StaticSpelling.has_value())
44844501
return MF.diagnoseFatal();
44854502

4486-
auto dc = MF.getDeclContext(contextID);
4503+
DeclContext *dc;
4504+
UNWRAP(MF.getDeclContextChecked(contextID), dc);
44874505

44884506
SmallVector<std::pair<Pattern *, DeclContextID>, 4> patterns;
44894507
for (unsigned i = 0; i != numPatterns; ++i) {
@@ -4519,8 +4537,11 @@ class DeclDeserializer {
45194537

45204538
for (unsigned i = 0; i != patterns.size(); ++i) {
45214539
binding->setPattern(i, patterns[i].first);
4522-
if (auto *context = MF.getDeclContext(patterns[i].second))
4523-
binding->setInitContext(i, cast<PatternBindingInitializer>(context));
4540+
4541+
DeclContext *dcPattern;
4542+
UNWRAP(MF.getDeclContextChecked(patterns[i].second), dcPattern);
4543+
if (dcPattern)
4544+
binding->setInitContext(i, cast<PatternBindingInitializer>(dcPattern));
45244545
}
45254546

45264547
return binding;
@@ -4553,7 +4574,9 @@ class DeclDeserializer {
45534574
}
45544575
}
45554576

4556-
auto DC = MF.getDeclContext(contextID);
4577+
DeclContext *DC;
4578+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
4579+
45574580
if (declOrOffset.isComplete())
45584581
return declOrOffset;
45594582

@@ -4624,7 +4647,8 @@ class DeclDeserializer {
46244647
Identifier name = MF.getIdentifier(nameID);
46254648
PrettySupplementalDeclNameTrace trace(name);
46264649

4627-
auto DC = MF.getDeclContext(contextID);
4650+
DeclContext *DC;
4651+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
46284652

46294653
auto result = MF.createDecl<OperatorDecl>(
46304654
DC, SourceLoc(), name, SourceLoc());
@@ -4660,7 +4684,8 @@ class DeclDeserializer {
46604684
if (!precedenceGroup)
46614685
return precedenceGroup.takeError();
46624686

4663-
auto DC = MF.getDeclContext(contextID);
4687+
DeclContext *DC;
4688+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
46644689

46654690
auto result = MF.createDecl<InfixOperatorDecl>(
46664691
DC, SourceLoc(), name, SourceLoc(), SourceLoc(), Identifier(),
@@ -4687,7 +4712,8 @@ class DeclDeserializer {
46874712
assignment, numHigherThan,
46884713
rawRelations);
46894714

4690-
auto DC = MF.getDeclContext(contextID);
4715+
DeclContext *DC;
4716+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
46914717

46924718
auto associativity = getActualAssociativity(rawAssociativity);
46934719
if (!associativity.has_value())
@@ -4770,7 +4796,9 @@ class DeclDeserializer {
47704796
}
47714797
}
47724798

4773-
auto DC = MF.getDeclContext(contextID);
4799+
DeclContext *DC;
4800+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
4801+
47744802
if (declOrOffset.isComplete())
47754803
return declOrOffset;
47764804

@@ -4931,7 +4959,9 @@ class DeclDeserializer {
49314959
}
49324960
}
49334961

4934-
DeclContext *DC = MF.getDeclContext(contextID);
4962+
DeclContext *DC;
4963+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
4964+
49354965
if (declOrOffset.isComplete())
49364966
return declOrOffset;
49374967

@@ -5038,7 +5068,9 @@ class DeclDeserializer {
50385068
}
50395069
}
50405070

5041-
auto parent = MF.getDeclContext(contextID);
5071+
DeclContext *parent;
5072+
UNWRAP(MF.getDeclContextChecked(contextID), parent);
5073+
50425074
if (declOrOffset.isComplete())
50435075
return declOrOffset;
50445076

@@ -5113,7 +5145,8 @@ class DeclDeserializer {
51135145
numConformances, numInherited,
51145146
data);
51155147

5116-
auto DC = MF.getDeclContext(contextID);
5148+
DeclContext *DC;
5149+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
51175150

51185151
auto conformanceIDs = data.slice(0, numConformances);
51195152
data = data.slice(numConformances);
@@ -5200,7 +5233,9 @@ class DeclDeserializer {
52005233
isImplicit, isObjC,
52015234
genericSigID);
52025235

5203-
DeclContext *DC = MF.getDeclContext(contextID);
5236+
DeclContext *DC;
5237+
UNWRAP(MF.getDeclContextChecked(contextID), DC);
5238+
52045239
if (declOrOffset.isComplete())
52055240
return declOrOffset;
52065241

@@ -5275,7 +5310,9 @@ class DeclDeserializer {
52755310
}
52765311
}
52775312

5278-
auto parent = MF.getDeclContext(contextID);
5313+
DeclContext *parent;
5314+
UNWRAP(MF.getDeclContextChecked(contextID), parent);
5315+
52795316
if (declOrOffset.isComplete())
52805317
return declOrOffset;
52815318

0 commit comments

Comments
 (0)