59
59
// Unwrap an Expected<> variable following the typical deserialization pattern:
60
60
// - On a value, assign it to Output.
61
61
// - On an error, return it to bubble it up to the caller.
62
- #define UNWRAP ( Input, Output ) { \
62
+ #define SET_OR_RETURN_ERROR ( Output, Input ) { \
63
63
auto ValueOrError = Input; \
64
64
if (!ValueOrError) \
65
65
return ValueOrError.takeError (); \
@@ -550,7 +550,7 @@ Expected<ParameterList *> ModuleFile::readParameterList() {
550
550
SmallVector<ParamDecl *, 8 > params;
551
551
for (DeclID paramID : rawMemberIDs) {
552
552
Decl *param;
553
- UNWRAP ( getDeclChecked (paramID), param );
553
+ SET_OR_RETURN_ERROR (param, getDeclChecked (paramID));
554
554
params.push_back (cast<ParamDecl>(param));
555
555
}
556
556
@@ -596,7 +596,7 @@ Expected<Pattern *> ModuleFile::readPattern(DeclContext *owningDC) {
596
596
switch (kind) {
597
597
case decls_block::PAREN_PATTERN: {
598
598
Pattern *subPattern;
599
- UNWRAP ( readPattern (owningDC), subPattern );
599
+ SET_OR_RETURN_ERROR (subPattern, readPattern (owningDC));
600
600
601
601
auto result = ParenPattern::createImplicit (getContext (), subPattern);
602
602
@@ -629,13 +629,13 @@ Expected<Pattern *> ModuleFile::readPattern(DeclContext *owningDC) {
629
629
Identifier label = getIdentifier (labelID);
630
630
631
631
Pattern *subPattern;
632
- UNWRAP ( readPattern (owningDC), subPattern );
632
+ SET_OR_RETURN_ERROR (subPattern, readPattern (owningDC));
633
633
elements.push_back (TuplePatternElt (label, SourceLoc (), subPattern));
634
634
}
635
635
636
636
auto result = TuplePattern::createImplicit (getContext (), elements);
637
637
Type tupleType;
638
- UNWRAP ( getTypeChecked (tupleTypeID), tupleType );
638
+ SET_OR_RETURN_ERROR (tupleType, getTypeChecked (tupleTypeID));
639
639
recordPatternType (result, tupleType);
640
640
restoreOffset.reset ();
641
641
return result;
@@ -696,7 +696,7 @@ Expected<Pattern *> ModuleFile::readPattern(DeclContext *owningDC) {
696
696
BindingPatternLayout::readRecord (scratch, rawIntroducer);
697
697
698
698
Pattern *subPattern;
699
- UNWRAP ( readPattern (owningDC), subPattern );
699
+ SET_OR_RETURN_ERROR (subPattern, readPattern (owningDC));
700
700
701
701
auto introducer = getActualVarDeclIntroducer (
702
702
(serialization::VarDeclIntroducer) rawIntroducer);
@@ -1261,7 +1261,7 @@ ModuleFile::maybeReadGenericParams(DeclContext *DC) {
1261
1261
GenericParamListLayout::readRecord (scratch, paramIDs);
1262
1262
for (DeclID nextParamID : paramIDs) {
1263
1263
Decl *nextParam;
1264
- UNWRAP ( getDeclChecked (nextParamID), nextParam );
1264
+ SET_OR_RETURN_ERROR (nextParam, getDeclChecked (nextParamID));
1265
1265
1266
1266
auto genericParam = cast<GenericTypeParamDecl>(nextParam);
1267
1267
params.push_back (genericParam);
@@ -2865,7 +2865,7 @@ Expected<DeclContext *>ModuleFile::getLocalDeclContext(LocalDeclContextID DCID)
2865
2865
discriminator,
2866
2866
parentID);
2867
2867
DeclContext *parent;
2868
- UNWRAP ( getDeclContextChecked (parentID), parent );
2868
+ SET_OR_RETURN_ERROR (parent, getDeclContextChecked (parentID));
2869
2869
2870
2870
auto type = getType (closureTypeID);
2871
2871
@@ -2879,7 +2879,7 @@ Expected<DeclContext *>ModuleFile::getLocalDeclContext(LocalDeclContextID DCID)
2879
2879
decls_block::TopLevelCodeDeclContextLayout::readRecord (scratch,
2880
2880
parentID);
2881
2881
DeclContext *parent;
2882
- UNWRAP ( getDeclContextChecked (parentID), parent );
2882
+ SET_OR_RETURN_ERROR (parent, getDeclContextChecked (parentID));
2883
2883
2884
2884
declContextOrOffset = new (ctx) SerializedTopLevelCodeDeclContext (parent);
2885
2885
break ;
@@ -2910,7 +2910,7 @@ Expected<DeclContext *>ModuleFile::getLocalDeclContext(LocalDeclContextID DCID)
2910
2910
parentID,
2911
2911
index);
2912
2912
DeclContext *parent;
2913
- UNWRAP ( getDeclContextChecked (parentID), parent );
2913
+ SET_OR_RETURN_ERROR (parent, getDeclContextChecked (parentID));
2914
2914
2915
2915
declContextOrOffset = DefaultArgumentInitializer::create (parent, index);
2916
2916
break ;
@@ -3466,10 +3466,10 @@ class DeclDeserializer {
3466
3466
}
3467
3467
3468
3468
DeclContext *DC;
3469
- UNWRAP ( MF.getDeclContextChecked (contextID), DC );
3469
+ SET_OR_RETURN_ERROR (DC, MF.getDeclContextChecked (contextID));
3470
3470
3471
3471
GenericParamList *genericParams;
3472
- UNWRAP ( MF.maybeReadGenericParams (DC), genericParams );
3472
+ SET_OR_RETURN_ERROR (genericParams, MF.maybeReadGenericParams (DC));
3473
3473
if (declOrOffset.isComplete ())
3474
3474
return declOrOffset;
3475
3475
@@ -3552,7 +3552,7 @@ class DeclDeserializer {
3552
3552
rawOverriddenIDs);
3553
3553
3554
3554
DeclContext *DC;
3555
- UNWRAP ( MF.getDeclContextChecked (contextID), DC );
3555
+ SET_OR_RETURN_ERROR (DC, MF.getDeclContextChecked (contextID));
3556
3556
3557
3557
if (declOrOffset.isComplete ())
3558
3558
return declOrOffset;
@@ -3629,7 +3629,7 @@ class DeclDeserializer {
3629
3629
return declOrOffset;
3630
3630
3631
3631
GenericParamList *genericParams;
3632
- UNWRAP ( MF.maybeReadGenericParams (DC), genericParams );
3632
+ SET_OR_RETURN_ERROR (genericParams, MF.maybeReadGenericParams (DC));
3633
3633
if (declOrOffset.isComplete ())
3634
3634
return declOrOffset;
3635
3635
@@ -3738,13 +3738,13 @@ class DeclDeserializer {
3738
3738
}
3739
3739
3740
3740
DeclContext *parent;
3741
- UNWRAP ( MF.getDeclContextChecked (contextID), parent );
3741
+ SET_OR_RETURN_ERROR (parent, MF.getDeclContextChecked (contextID));
3742
3742
3743
3743
if (declOrOffset.isComplete ())
3744
3744
return declOrOffset;
3745
3745
3746
3746
GenericParamList *genericParams;
3747
- UNWRAP ( MF.maybeReadGenericParams (parent), genericParams );
3747
+ SET_OR_RETURN_ERROR (genericParams, MF.maybeReadGenericParams (parent));
3748
3748
if (declOrOffset.isComplete ())
3749
3749
return declOrOffset;
3750
3750
@@ -3772,7 +3772,7 @@ class DeclDeserializer {
3772
3772
return MF.diagnoseFatal ();
3773
3773
3774
3774
ParameterList *bodyParams;
3775
- UNWRAP ( MF.readParameterList (), bodyParams );
3775
+ SET_OR_RETURN_ERROR (bodyParams, MF.readParameterList ());
3776
3776
assert (bodyParams && " missing parameters for constructor" );
3777
3777
ctor->setParameters (bodyParams);
3778
3778
@@ -3907,7 +3907,7 @@ class DeclDeserializer {
3907
3907
}
3908
3908
3909
3909
DeclContext *DC;
3910
- UNWRAP ( MF.getDeclContextChecked (contextID), DC );
3910
+ SET_OR_RETURN_ERROR (DC, MF.getDeclContextChecked (contextID));
3911
3911
3912
3912
if (declOrOffset.isComplete ())
3913
3913
return declOrOffset;
@@ -4068,7 +4068,7 @@ class DeclDeserializer {
4068
4068
PrettySupplementalDeclNameTrace trace (paramName);
4069
4069
4070
4070
DeclContext *DC;
4071
- UNWRAP ( MF.getDeclContextChecked (contextID), DC );
4071
+ SET_OR_RETURN_ERROR (DC, MF.getDeclContextChecked (contextID));
4072
4072
4073
4073
if (declOrOffset.isComplete ())
4074
4074
return declOrOffset;
@@ -4290,7 +4290,7 @@ class DeclDeserializer {
4290
4290
}
4291
4291
4292
4292
DeclContext *DC;
4293
- UNWRAP ( MF.getDeclContextChecked (contextID), DC );
4293
+ SET_OR_RETURN_ERROR (DC, MF.getDeclContextChecked (contextID));
4294
4294
4295
4295
if (declOrOffset.isComplete ())
4296
4296
return declOrOffset;
@@ -4299,7 +4299,7 @@ class DeclDeserializer {
4299
4299
// reference generic parameters, and we want them to have a dummy
4300
4300
// DeclContext for now.
4301
4301
GenericParamList *genericParams;
4302
- UNWRAP ( MF.maybeReadGenericParams (DC), genericParams );
4302
+ SET_OR_RETURN_ERROR (genericParams, MF.maybeReadGenericParams (DC));
4303
4303
4304
4304
auto staticSpelling = getActualStaticSpellingKind (rawStaticSpelling);
4305
4305
if (!staticSpelling.has_value ())
@@ -4367,7 +4367,7 @@ class DeclDeserializer {
4367
4367
fn->setImplicitlyUnwrappedOptional (isIUO);
4368
4368
4369
4369
ParameterList *paramList;
4370
- UNWRAP ( MF.readParameterList (), paramList );
4370
+ SET_OR_RETURN_ERROR (paramList, MF.readParameterList ());
4371
4371
fn->setParameters (paramList);
4372
4372
auto numParams =
4373
4373
fn->hasImplicitSelfDecl () ? paramList->size () + 1 : paramList->size ();
@@ -4523,7 +4523,7 @@ class DeclDeserializer {
4523
4523
exportUnderlyingType);
4524
4524
4525
4525
DeclContext *declContext;
4526
- UNWRAP ( MF.getDeclContextChecked (contextID), declContext );
4526
+ SET_OR_RETURN_ERROR (declContext, MF.getDeclContextChecked (contextID));
4527
4527
4528
4528
auto interfaceSigOrErr = MF.getGenericSignatureChecked (interfaceSigID);
4529
4529
if (!interfaceSigOrErr)
@@ -4534,7 +4534,7 @@ class DeclDeserializer {
4534
4534
return cast<OpaqueTypeDecl>(declOrOffset.get ());
4535
4535
4536
4536
GenericParamList *genericParams;
4537
- UNWRAP ( MF.maybeReadGenericParams (declContext), genericParams );
4537
+ SET_OR_RETURN_ERROR (genericParams, MF.maybeReadGenericParams (declContext));
4538
4538
4539
4539
// Create the decl.
4540
4540
auto opaqueDecl = OpaqueTypeDecl::get (
@@ -4629,7 +4629,7 @@ class DeclDeserializer {
4629
4629
return MF.diagnoseFatal ();
4630
4630
4631
4631
DeclContext *dc;
4632
- UNWRAP ( MF.getDeclContextChecked (contextID), dc );
4632
+ SET_OR_RETURN_ERROR (dc, MF.getDeclContextChecked (contextID));
4633
4633
4634
4634
SmallVector<std::pair<Pattern *, DeclContextID>, 4 > patterns;
4635
4635
for (unsigned i = 0 ; i != numPatterns; ++i) {
@@ -4667,7 +4667,7 @@ class DeclDeserializer {
4667
4667
binding->setPattern (i, patterns[i].first );
4668
4668
4669
4669
DeclContext *dcPattern;
4670
- UNWRAP ( MF.getDeclContextChecked (patterns[i].second ), dcPattern );
4670
+ SET_OR_RETURN_ERROR (dcPattern, MF.getDeclContextChecked (patterns[i].second ));
4671
4671
if (dcPattern)
4672
4672
binding->setInitContext (i, cast<PatternBindingInitializer>(dcPattern));
4673
4673
}
@@ -4703,7 +4703,7 @@ class DeclDeserializer {
4703
4703
}
4704
4704
4705
4705
DeclContext *DC;
4706
- UNWRAP ( MF.getDeclContextChecked (contextID), DC );
4706
+ SET_OR_RETURN_ERROR (DC, MF.getDeclContextChecked (contextID));
4707
4707
4708
4708
if (declOrOffset.isComplete ())
4709
4709
return declOrOffset;
@@ -4736,7 +4736,7 @@ class DeclDeserializer {
4736
4736
ctx.AllocateCopy (inherited));
4737
4737
4738
4738
GenericParamList *genericParams;
4739
- UNWRAP ( MF.maybeReadGenericParams (DC), genericParams );
4739
+ SET_OR_RETURN_ERROR (genericParams, MF.maybeReadGenericParams (DC));
4740
4740
assert (genericParams && " protocol with no generic parameters?" );
4741
4741
ctx.evaluator .cacheOutput (GenericParamListRequest{proto},
4742
4742
std::move (genericParams));
@@ -4777,7 +4777,7 @@ class DeclDeserializer {
4777
4777
PrettySupplementalDeclNameTrace trace (name);
4778
4778
4779
4779
DeclContext *DC;
4780
- UNWRAP ( MF.getDeclContextChecked (contextID), DC );
4780
+ SET_OR_RETURN_ERROR (DC, MF.getDeclContextChecked (contextID));
4781
4781
4782
4782
auto result = MF.createDecl <OperatorDecl>(
4783
4783
DC, SourceLoc (), name, SourceLoc ());
@@ -4814,7 +4814,7 @@ class DeclDeserializer {
4814
4814
return precedenceGroup.takeError ();
4815
4815
4816
4816
DeclContext *DC;
4817
- UNWRAP ( MF.getDeclContextChecked (contextID), DC );
4817
+ SET_OR_RETURN_ERROR (DC, MF.getDeclContextChecked (contextID));
4818
4818
4819
4819
auto result = MF.createDecl <InfixOperatorDecl>(
4820
4820
DC, SourceLoc (), name, SourceLoc (), SourceLoc (), Identifier (),
@@ -4842,7 +4842,7 @@ class DeclDeserializer {
4842
4842
rawRelations);
4843
4843
4844
4844
DeclContext *DC;
4845
- UNWRAP ( MF.getDeclContextChecked (contextID), DC );
4845
+ SET_OR_RETURN_ERROR (DC, MF.getDeclContextChecked (contextID));
4846
4846
4847
4847
auto associativity = getActualAssociativity (rawAssociativity);
4848
4848
if (!associativity.has_value ())
@@ -4926,13 +4926,13 @@ class DeclDeserializer {
4926
4926
}
4927
4927
4928
4928
DeclContext *DC;
4929
- UNWRAP ( MF.getDeclContextChecked (contextID), DC );
4929
+ SET_OR_RETURN_ERROR (DC, MF.getDeclContextChecked (contextID));
4930
4930
4931
4931
if (declOrOffset.isComplete ())
4932
4932
return declOrOffset;
4933
4933
4934
4934
GenericParamList *genericParams;
4935
- UNWRAP ( MF.maybeReadGenericParams (DC), genericParams );
4935
+ SET_OR_RETURN_ERROR (genericParams, MF.maybeReadGenericParams (DC));
4936
4936
if (declOrOffset.isComplete ())
4937
4937
return declOrOffset;
4938
4938
@@ -5011,7 +5011,7 @@ class DeclDeserializer {
5011
5011
auto DC = DCOrError.get ();
5012
5012
5013
5013
GenericParamList *genericParams;
5014
- UNWRAP ( MF.maybeReadGenericParams (DC), genericParams );
5014
+ SET_OR_RETURN_ERROR (genericParams, MF.maybeReadGenericParams (DC));
5015
5015
if (declOrOffset.isComplete ())
5016
5016
return declOrOffset;
5017
5017
@@ -5091,7 +5091,7 @@ class DeclDeserializer {
5091
5091
}
5092
5092
5093
5093
DeclContext *DC;
5094
- UNWRAP ( MF.getDeclContextChecked (contextID), DC );
5094
+ SET_OR_RETURN_ERROR (DC, MF.getDeclContextChecked (contextID));
5095
5095
5096
5096
if (declOrOffset.isComplete ())
5097
5097
return declOrOffset;
@@ -5107,7 +5107,7 @@ class DeclDeserializer {
5107
5107
// Read payload parameter list, if it exists.
5108
5108
if (hasPayload) {
5109
5109
ParameterList *paramList;
5110
- UNWRAP ( MF.readParameterList (), paramList );
5110
+ SET_OR_RETURN_ERROR (paramList, MF.readParameterList ());
5111
5111
elem->setParameterList (paramList);
5112
5112
}
5113
5113
@@ -5201,13 +5201,13 @@ class DeclDeserializer {
5201
5201
}
5202
5202
5203
5203
DeclContext *parent;
5204
- UNWRAP ( MF.getDeclContextChecked (contextID), parent );
5204
+ SET_OR_RETURN_ERROR (parent, MF.getDeclContextChecked (contextID));
5205
5205
5206
5206
if (declOrOffset.isComplete ())
5207
5207
return declOrOffset;
5208
5208
5209
5209
GenericParamList *genericParams;
5210
- UNWRAP ( MF.maybeReadGenericParams (parent), genericParams );
5210
+ SET_OR_RETURN_ERROR (genericParams, MF.maybeReadGenericParams (parent));
5211
5211
if (declOrOffset.isComplete ())
5212
5212
return declOrOffset;
5213
5213
@@ -5228,7 +5228,7 @@ class DeclDeserializer {
5228
5228
subscript->setGenericSignature (MF.getGenericSignature (genericSigID));
5229
5229
5230
5230
ParameterList *paramList;
5231
- UNWRAP ( MF.readParameterList (), paramList );
5231
+ SET_OR_RETURN_ERROR (paramList, MF.readParameterList ());
5232
5232
subscript->setIndices (paramList);
5233
5233
5234
5234
MF.configureStorage (subscript, opaqueReadOwnership,
@@ -5259,7 +5259,8 @@ class DeclDeserializer {
5259
5259
OpaqueTypeDecl *opaqueDecl = nullptr ;
5260
5260
if (opaqueReturnTypeID) {
5261
5261
Decl *opaqueReturnType;
5262
- UNWRAP (MF.getDeclChecked (opaqueReturnTypeID), opaqueReturnType);
5262
+ SET_OR_RETURN_ERROR (opaqueReturnType,
5263
+ MF.getDeclChecked (opaqueReturnTypeID));
5263
5264
5264
5265
opaqueDecl = cast<OpaqueTypeDecl>(opaqueReturnType);
5265
5266
}
@@ -5287,7 +5288,7 @@ class DeclDeserializer {
5287
5288
data);
5288
5289
5289
5290
DeclContext *DC;
5290
- UNWRAP ( MF.getDeclContextChecked (contextID), DC );
5291
+ SET_OR_RETURN_ERROR (DC, MF.getDeclContextChecked (contextID));
5291
5292
5292
5293
auto conformanceIDs = data.slice (0 , numConformances);
5293
5294
data = data.slice (numConformances);
@@ -5315,7 +5316,7 @@ class DeclDeserializer {
5315
5316
GenericParamList *outerParams = nullptr ;
5316
5317
while (true ) {
5317
5318
GenericParamList *genericParams;
5318
- UNWRAP ( MF.maybeReadGenericParams (DC), genericParams );
5319
+ SET_OR_RETURN_ERROR (genericParams, MF.maybeReadGenericParams (DC));
5319
5320
if (!genericParams)
5320
5321
break ;
5321
5322
@@ -5380,7 +5381,7 @@ class DeclDeserializer {
5380
5381
genericSigID);
5381
5382
5382
5383
DeclContext *DC;
5383
- UNWRAP ( MF.getDeclContextChecked (contextID), DC );
5384
+ SET_OR_RETURN_ERROR (DC, MF.getDeclContextChecked (contextID));
5384
5385
5385
5386
if (declOrOffset.isComplete ())
5386
5387
return declOrOffset;
@@ -5457,13 +5458,13 @@ class DeclDeserializer {
5457
5458
}
5458
5459
5459
5460
DeclContext *parent;
5460
- UNWRAP ( MF.getDeclContextChecked (contextID), parent );
5461
+ SET_OR_RETURN_ERROR (parent, MF.getDeclContextChecked (contextID));
5461
5462
5462
5463
if (declOrOffset.isComplete ())
5463
5464
return declOrOffset;
5464
5465
5465
5466
GenericParamList *genericParams;
5466
- UNWRAP ( MF.maybeReadGenericParams (parent), genericParams );
5467
+ SET_OR_RETURN_ERROR (genericParams, MF.maybeReadGenericParams (parent));
5467
5468
if (declOrOffset.isComplete ())
5468
5469
return declOrOffset;
5469
5470
@@ -5483,7 +5484,7 @@ class DeclDeserializer {
5483
5484
macro->resultType .setType (resultInterfaceType);
5484
5485
5485
5486
if (hasParameterList) {
5486
- UNWRAP ( MF.readParameterList (), macro-> parameterList );
5487
+ SET_OR_RETURN_ERROR (macro-> parameterList , MF.readParameterList ());
5487
5488
}
5488
5489
5489
5490
if (auto accessLevel = getActualAccessLevel (rawAccessLevel))
0 commit comments