[Serialization] Drop overridden relationship in constructors when safe

Deserialization recovery lead the compiler to drop public constructors
overridding internal constructors. This limits the logic to dropping the
overriding relationship instead of the whole constructor. This applies
when the overriden constructor fails to deserialize and only when the
overriding relationship was marked as not affecting ABI.

rdar://104704832
This commit is contained in:
Alexis Laferrière
2023-01-27 13:10:21 -08:00
parent 4665053f5b
commit 9c16b4b013
4 changed files with 37 additions and 14 deletions

View File

@@ -3535,7 +3535,8 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
// its overrides after they've been compiled: if the declaration is '@objc'
// and 'dynamic'. In that case, all accesses to the method or property will
// go through the Objective-C method tables anyway.
if (overridden->hasClangNode() || overridden->shouldUseObjCDispatch())
if (!isa<ConstructorDecl>(override) &&
(overridden->hasClangNode() || overridden->shouldUseObjCDispatch()))
return false;
// In a public-override-internal case, the override doesn't have ABI
@@ -4499,9 +4500,12 @@ public:
uint8_t rawAccessLevel = getRawStableAccessLevel(ctor->getFormalAccess());
bool firstTimeRequired = ctor->isRequired();
if (auto *overridden = ctor->getOverriddenDecl())
auto *overridden = ctor->getOverriddenDecl();
if (overridden) {
if (firstTimeRequired && overridden->isRequired())
firstTimeRequired = false;
}
bool overriddenAffectsABI = overriddenDeclAffectsABI(ctor, overridden);
unsigned abbrCode = S.DeclTypeAbbrCodes[ConstructorLayout::Code];
ConstructorLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
@@ -4517,7 +4521,8 @@ public:
ctor->getInitKind()),
S.addGenericSignatureRef(
ctor->getGenericSignature()),
S.addDeclRef(ctor->getOverriddenDecl()),
S.addDeclRef(overridden),
overriddenAffectsABI,
rawAccessLevel,
ctor->needsNewVTableEntry(),
firstTimeRequired,