Skip to content

Commit 1f04b2f

Browse files
committed
[Serialization] Wire up the generic parameter of a protocol early.
When we deserialize a protocol declaration, we had a bunch of intervening code before it would deserialize and wire up its generic parameter (Self), including configuring the generic environment. If any of that code referenced an AssociatedTypeDecl of that protocol, the deserialization of the AssociatedTypeDecl could end up computing an erroneous type. This might be the source of the nondeterministic deserialization failure that seems to afflict AssociatedTypeDecls in rdar://problem/30382791.
1 parent 8af3196 commit 1f04b2f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,6 +2576,10 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
25762576
declOrOffset = assocType;
25772577

25782578
assocType->computeType();
2579+
2580+
assert(!assocType->getDeclaredInterfaceType()->hasError() &&
2581+
"erroneous associated type");
2582+
25792583
Accessibility parentAccess = cast<ProtocolDecl>(DC)->getFormalAccess();
25802584
assocType->setAccessibility(std::max(parentAccess,Accessibility::Internal));
25812585
if (isImplicit)
@@ -3031,8 +3035,6 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
30313035
getIdentifier(nameID), None);
30323036
declOrOffset = proto;
30333037

3034-
configureGenericEnvironment(proto, genericEnvID);
3035-
30363038
proto->setRequiresClass(isClassBounded);
30373039

30383040
if (auto accessLevel = getActualAccessibility(rawAccessLevel)) {
@@ -3042,6 +3044,10 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
30423044
return nullptr;
30433045
}
30443046

3047+
auto genericParams = maybeReadGenericParams(DC);
3048+
assert(genericParams && "protocol with no generic parameters?");
3049+
proto->setGenericParams(genericParams);
3050+
30453051
auto protocols = ctx.Allocate<ProtocolDecl *>(numProtocols);
30463052
for_each(protocols, rawProtocolAndInheritedIDs.slice(0, numProtocols),
30473053
[this](ProtocolDecl *&p, uint64_t rawID) {
@@ -3051,9 +3057,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
30513057

30523058
handleInherited(proto, rawProtocolAndInheritedIDs.slice(numProtocols));
30533059

3054-
auto genericParams = maybeReadGenericParams(DC);
3055-
assert(genericParams && "protocol with no generic parameters?");
3056-
proto->setGenericParams(genericParams);
3060+
configureGenericEnvironment(proto, genericEnvID);
30573061

30583062
SmallVector<Requirement, 4> requirements;
30593063
readGenericRequirements(requirements, DeclTypeCursor);

0 commit comments

Comments
 (0)