@@ -4274,16 +4274,13 @@ Type ModuleFile::getType(TypeID TID) {
4274
4274
}
4275
4275
4276
4276
class swift ::TypeDeserializer {
4277
- template <typename T>
4278
- using Serialized = ModuleFile::Serialized<T>;
4279
4277
using TypeID = serialization::TypeID;
4280
4278
4281
4279
ModuleFile &MF;
4282
4280
ASTContext &ctx;
4283
- Serialized<Type> &typeOrOffset;
4284
4281
public:
4285
- TypeDeserializer (ModuleFile &MF, Serialized<Type> &typeOrOffset )
4286
- : MF(MF), ctx(MF.getContext()), typeOrOffset(typeOrOffset) {}
4282
+ explicit TypeDeserializer (ModuleFile &MF)
4283
+ : MF(MF), ctx(MF.getContext()) {}
4287
4284
4288
4285
Expected<Type> getTypeCheckedImpl ();
4289
4286
};
@@ -4300,7 +4297,24 @@ Expected<Type> ModuleFile::getTypeChecked(TypeID TID) {
4300
4297
4301
4298
BCOffsetRAII restoreOffset (DeclTypeCursor);
4302
4299
DeclTypeCursor.JumpToBit (typeOrOffset);
4303
- return TypeDeserializer (*this , typeOrOffset).getTypeCheckedImpl ();
4300
+
4301
+ auto result = TypeDeserializer (*this ).getTypeCheckedImpl ();
4302
+ if (!result)
4303
+ return result;
4304
+ typeOrOffset = result.get ();
4305
+
4306
+ #ifndef NDEBUG
4307
+ PrettyStackTraceType trace (getContext (), " deserializing" , typeOrOffset.get ());
4308
+ if (typeOrOffset.get ()->hasError ()) {
4309
+ typeOrOffset.get ()->dump ();
4310
+ llvm_unreachable (" deserialization produced an invalid type "
4311
+ " (rdar://problem/30382791)" );
4312
+ }
4313
+ #endif
4314
+
4315
+ // Invoke the callback on the deserialized type.
4316
+ DeserializedTypeCallback (typeOrOffset.get ());
4317
+ return typeOrOffset.get ();
4304
4318
}
4305
4319
4306
4320
Expected<Type> TypeDeserializer::getTypeCheckedImpl () {
@@ -4319,6 +4333,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4319
4333
StringRef blobData;
4320
4334
unsigned recordID = MF.DeclTypeCursor .readRecord (entry.ID , scratch,
4321
4335
&blobData);
4336
+ Type result;
4322
4337
4323
4338
switch (recordID) {
4324
4339
case decls_block::BUILTIN_ALIAS_TYPE: {
@@ -4339,7 +4354,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4339
4354
if (!alias ||
4340
4355
!alias->getDeclaredInterfaceType ()->isEqual (expectedType.get ())) {
4341
4356
// Fall back to the canonical type.
4342
- typeOrOffset = expectedType.get ();
4357
+ result = expectedType.get ();
4343
4358
break ;
4344
4359
}
4345
4360
}
@@ -4348,11 +4363,11 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4348
4363
// Look through compatibility aliases that are now unavailable.
4349
4364
if (alias->getAttrs ().isUnavailable (ctx) &&
4350
4365
alias->isCompatibilityAlias ()) {
4351
- typeOrOffset = alias->getUnderlyingTypeLoc ().getType ();
4366
+ result = alias->getUnderlyingTypeLoc ().getType ();
4352
4367
break ;
4353
4368
}
4354
4369
4355
- typeOrOffset = alias->getDeclaredInterfaceType ();
4370
+ result = alias->getDeclaredInterfaceType ();
4356
4371
break ;
4357
4372
}
4358
4373
@@ -4404,7 +4419,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4404
4419
4405
4420
auto parentTypeOrError = MF.getTypeChecked (parentTypeID);
4406
4421
if (!parentTypeOrError) {
4407
- typeOrOffset = underlyingType;
4422
+ result = underlyingType;
4408
4423
break ;
4409
4424
}
4410
4425
@@ -4414,17 +4429,17 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4414
4429
alias->isCompatibilityAlias ()) {
4415
4430
underlyingType = alias->getUnderlyingTypeLoc ().getType ().subst (subMap);
4416
4431
assert (underlyingType);
4417
- typeOrOffset = underlyingType;
4432
+ result = underlyingType;
4418
4433
break ;
4419
4434
}
4420
4435
4421
4436
if (!formSugaredType) {
4422
- typeOrOffset = underlyingType;
4437
+ result = underlyingType;
4423
4438
break ;
4424
4439
}
4425
4440
4426
4441
auto parentType = parentTypeOrError.get ();
4427
- typeOrOffset = TypeAliasType::get (alias, parentType, subMap,
4442
+ result = TypeAliasType::get (alias, parentType, subMap,
4428
4443
substitutedType);
4429
4444
break ;
4430
4445
}
@@ -4474,9 +4489,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4474
4489
return llvm::make_error<XRefError>(" declaration is not a nominal type" ,
4475
4490
tinyTrace, fullName);
4476
4491
}
4477
- typeOrOffset = NominalType::get (nominal, parentTy.get (), ctx);
4478
-
4479
- assert (typeOrOffset.isComplete ());
4492
+ result = NominalType::get (nominal, parentTy.get (), ctx);
4480
4493
break ;
4481
4494
}
4482
4495
@@ -4488,7 +4501,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4488
4501
if (!underlyingTy)
4489
4502
return underlyingTy.takeError ();
4490
4503
4491
- typeOrOffset = ParenType::get (ctx, underlyingTy.get ());
4504
+ result = ParenType::get (ctx, underlyingTy.get ());
4492
4505
break ;
4493
4506
}
4494
4507
@@ -4517,7 +4530,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4517
4530
elements.emplace_back (elementTy.get (), MF.getIdentifier (nameID));
4518
4531
}
4519
4532
4520
- typeOrOffset = TupleType::get (elements, ctx);
4533
+ result = TupleType::get (elements, ctx);
4521
4534
break ;
4522
4535
}
4523
4536
@@ -4594,10 +4607,10 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4594
4607
4595
4608
if (recordID == decls_block::FUNCTION_TYPE) {
4596
4609
assert (genericSig == nullptr );
4597
- typeOrOffset = FunctionType::get (params, resultTy.get (), info);
4610
+ result = FunctionType::get (params, resultTy.get (), info);
4598
4611
} else {
4599
4612
assert (genericSig != nullptr );
4600
- typeOrOffset = GenericFunctionType::get (genericSig,
4613
+ result = GenericFunctionType::get (genericSig,
4601
4614
params, resultTy.get (), info);
4602
4615
}
4603
4616
@@ -4615,20 +4628,20 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4615
4628
4616
4629
switch (repr) {
4617
4630
case serialization::MetatypeRepresentation::MR_None:
4618
- typeOrOffset = ExistentialMetatypeType::get (instanceType.get ());
4631
+ result = ExistentialMetatypeType::get (instanceType.get ());
4619
4632
break ;
4620
4633
4621
4634
case serialization::MetatypeRepresentation::MR_Thin:
4622
4635
MF.error ();
4623
4636
break ;
4624
4637
4625
4638
case serialization::MetatypeRepresentation::MR_Thick:
4626
- typeOrOffset = ExistentialMetatypeType::get (instanceType.get (),
4639
+ result = ExistentialMetatypeType::get (instanceType.get (),
4627
4640
MetatypeRepresentation::Thick);
4628
4641
break ;
4629
4642
4630
4643
case serialization::MetatypeRepresentation::MR_ObjC:
4631
- typeOrOffset = ExistentialMetatypeType::get (instanceType.get (),
4644
+ result = ExistentialMetatypeType::get (instanceType.get (),
4632
4645
MetatypeRepresentation::ObjC);
4633
4646
break ;
4634
4647
@@ -4650,21 +4663,21 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4650
4663
4651
4664
switch (repr) {
4652
4665
case serialization::MetatypeRepresentation::MR_None:
4653
- typeOrOffset = MetatypeType::get (instanceType.get ());
4666
+ result = MetatypeType::get (instanceType.get ());
4654
4667
break ;
4655
4668
4656
4669
case serialization::MetatypeRepresentation::MR_Thin:
4657
- typeOrOffset = MetatypeType::get (instanceType.get (),
4670
+ result = MetatypeType::get (instanceType.get (),
4658
4671
MetatypeRepresentation::Thin);
4659
4672
break ;
4660
4673
4661
4674
case serialization::MetatypeRepresentation::MR_Thick:
4662
- typeOrOffset = MetatypeType::get (instanceType.get (),
4675
+ result = MetatypeType::get (instanceType.get (),
4663
4676
MetatypeRepresentation::Thick);
4664
4677
break ;
4665
4678
4666
4679
case serialization::MetatypeRepresentation::MR_ObjC:
4667
- typeOrOffset = MetatypeType::get (instanceType.get (),
4680
+ result = MetatypeType::get (instanceType.get (),
4668
4681
MetatypeRepresentation::ObjC);
4669
4682
break ;
4670
4683
@@ -4678,7 +4691,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4678
4691
case decls_block::DYNAMIC_SELF_TYPE: {
4679
4692
TypeID selfID;
4680
4693
decls_block::DynamicSelfTypeLayout::readRecord (scratch, selfID);
4681
- typeOrOffset = DynamicSelfType::get (MF.getType (selfID), ctx);
4694
+ result = DynamicSelfType::get (MF.getType (selfID), ctx);
4682
4695
break ;
4683
4696
}
4684
4697
@@ -4699,7 +4712,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4699
4712
if (!objectTy)
4700
4713
return objectTy.takeError ();
4701
4714
4702
- typeOrOffset = ReferenceStorageType::get (objectTy.get (),
4715
+ result = ReferenceStorageType::get (objectTy.get (),
4703
4716
ownership.getValue (), ctx);
4704
4717
break ;
4705
4718
}
@@ -4719,7 +4732,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4719
4732
4720
4733
Type interfaceType = GenericTypeParamType::get (depth, index, ctx);
4721
4734
Type contextType = env->mapTypeIntoContext (interfaceType);
4722
- typeOrOffset = contextType;
4735
+ result = contextType;
4723
4736
4724
4737
if (contextType->hasError ()) {
4725
4738
MF.error ();
@@ -4735,7 +4748,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4735
4748
decls_block::OpenedArchetypeTypeLayout::readRecord (scratch,
4736
4749
existentialID);
4737
4750
4738
- typeOrOffset = OpenedArchetypeType::get (MF.getType (existentialID));
4751
+ result = OpenedArchetypeType::get (MF.getType (existentialID));
4739
4752
break ;
4740
4753
}
4741
4754
@@ -4777,15 +4790,11 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4777
4790
return nullptr ;
4778
4791
}
4779
4792
4780
- // See if we triggered deserialization through our conformances.
4781
- if (typeOrOffset.isComplete ())
4782
- break ;
4783
-
4784
- typeOrOffset = genericParam->getDeclaredInterfaceType ();
4793
+ result = genericParam->getDeclaredInterfaceType ();
4785
4794
break ;
4786
4795
}
4787
4796
4788
- typeOrOffset = GenericTypeParamType::get (declIDOrDepth,indexPlusOne-1 ,ctx);
4797
+ result = GenericTypeParamType::get (declIDOrDepth,indexPlusOne-1 ,ctx);
4789
4798
break ;
4790
4799
}
4791
4800
@@ -4804,7 +4813,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4804
4813
protocols.push_back (protoTy.get ());
4805
4814
}
4806
4815
4807
- typeOrOffset = ProtocolCompositionType::get (ctx, protocols,
4816
+ result = ProtocolCompositionType::get (ctx, protocols,
4808
4817
hasExplicitAnyObject);
4809
4818
break ;
4810
4819
}
@@ -4815,7 +4824,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4815
4824
4816
4825
decls_block::DependentMemberTypeLayout::readRecord (scratch, baseID,
4817
4826
assocTypeID);
4818
- typeOrOffset = DependentMemberType::get (
4827
+ result = DependentMemberType::get (
4819
4828
MF.getType (baseID),
4820
4829
cast<AssociatedTypeDecl>(MF.getDecl (assocTypeID)));
4821
4830
break ;
@@ -4847,15 +4856,15 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4847
4856
}
4848
4857
4849
4858
auto boundTy = BoundGenericType::get (nominal, parentTy, genericArgs);
4850
- typeOrOffset = boundTy;
4859
+ result = boundTy;
4851
4860
break ;
4852
4861
}
4853
4862
4854
4863
case decls_block::SIL_BLOCK_STORAGE_TYPE: {
4855
4864
TypeID captureID;
4856
4865
4857
4866
decls_block::SILBlockStorageTypeLayout::readRecord (scratch, captureID);
4858
- typeOrOffset = SILBlockStorageType::get (MF.getType (captureID)
4867
+ result = SILBlockStorageType::get (MF.getType (captureID)
4859
4868
->getCanonicalType ());
4860
4869
break ;
4861
4870
}
@@ -4891,7 +4900,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
4891
4900
return nullptr ;
4892
4901
4893
4902
auto subMap = MF.getSubstitutionMap (subMapID);
4894
- typeOrOffset = SILBoxType::get (ctx, layout, subMap);
4903
+ result = SILBoxType::get (ctx, layout, subMap);
4895
4904
break ;
4896
4905
}
4897
4906
@@ -5046,7 +5055,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
5046
5055
5047
5056
GenericSignature *genericSig = MF.getGenericSignature (rawGenericSig);
5048
5057
5049
- typeOrOffset = SILFunctionType::get (genericSig, extInfo,
5058
+ result = SILFunctionType::get (genericSig, extInfo,
5050
5059
coroutineKind.getValue (),
5051
5060
calleeConvention.getValue (),
5052
5061
allParams, allYields, allResults,
@@ -5063,7 +5072,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
5063
5072
if (!baseTy)
5064
5073
return baseTy.takeError ();
5065
5074
5066
- typeOrOffset = ArraySliceType::get (baseTy.get ());
5075
+ result = ArraySliceType::get (baseTy.get ());
5067
5076
break ;
5068
5077
}
5069
5078
@@ -5079,7 +5088,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
5079
5088
if (!valueTy)
5080
5089
return valueTy.takeError ();
5081
5090
5082
- typeOrOffset = DictionaryType::get (keyTy.get (), valueTy.get ());
5091
+ result = DictionaryType::get (keyTy.get (), valueTy.get ());
5083
5092
break ;
5084
5093
}
5085
5094
@@ -5091,7 +5100,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
5091
5100
if (!baseTy)
5092
5101
return baseTy.takeError ();
5093
5102
5094
- typeOrOffset = OptionalType::get (baseTy.get ());
5103
+ result = OptionalType::get (baseTy.get ());
5095
5104
break ;
5096
5105
}
5097
5106
@@ -5109,7 +5118,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
5109
5118
// FIXME: Check this?
5110
5119
auto parentTy = MF.getType (parentID);
5111
5120
5112
- typeOrOffset = UnboundGenericType::get (genericDecl, parentTy, ctx);
5121
+ result = UnboundGenericType::get (genericDecl, parentTy, ctx);
5113
5122
break ;
5114
5123
}
5115
5124
@@ -5119,19 +5128,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
5119
5128
return nullptr ;
5120
5129
}
5121
5130
5122
- #ifndef NDEBUG
5123
- PrettyStackTraceType trace (ctx, " deserializing" , typeOrOffset.get ());
5124
- if (typeOrOffset.get ()->hasError ()) {
5125
- typeOrOffset.get ()->dump ();
5126
- llvm_unreachable (" deserialization produced an invalid type "
5127
- " (rdar://problem/30382791)" );
5128
- }
5129
- #endif
5130
-
5131
- // Invoke the callback on the deserialized type.
5132
- MF.DeserializedTypeCallback (typeOrOffset);
5133
-
5134
- return typeOrOffset;
5131
+ return result;
5135
5132
}
5136
5133
5137
5134
Decl *handleErrorAndSupplyMissingClassMember (ASTContext &context,
0 commit comments