Skip to content

Commit 926e9c2

Browse files
committed
[Type checker] Move forcing of overridden/@objc/dynamic into finalizeType().
As part of factoring overridden decls/@objc/dynamic computation into requests for the request-evaluator, I forced computation of this information as part of requestMemberLayout. This is incorrect: requestMemberLayout() is meant only to trigger finalization of the enclosing class, which is responsible for making sure the type can be properly laid out. Move the newly-introduced forcing logic into finalizeType() where it belongs. Thanks to @slavapestov for describing the intent here.
1 parent 91c1b55 commit 926e9c2

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,11 +2979,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
29792979

29802980
TC.checkDeclCircularity(CD);
29812981
TC.ConformanceContexts.push_back(CD);
2982-
2983-
for (auto Member : CD->getMembers()) {
2984-
if (auto VD = dyn_cast<ValueDecl>(Member))
2985-
TC.requestMemberLayout(VD);
2986-
}
29872982
}
29882983

29892984
void visitProtocolDecl(ProtocolDecl *PD) {
@@ -4598,13 +4593,6 @@ void TypeChecker::requestMemberLayout(ValueDecl *member) {
45984593
if (auto *protocolDecl = dyn_cast<ProtocolDecl>(dc))
45994594
requestNominalLayout(protocolDecl);
46004595

4601-
// Compute overrides.
4602-
(void)member->getOverriddenDecls();
4603-
4604-
// Check whether the member is @objc or dynamic.
4605-
(void)member->isObjC();
4606-
(void)member->isDynamic();
4607-
46084596
// If this represents (abstract) storage, form the appropriate accessors.
46094597
if (auto storage = dyn_cast<AbstractStorageDecl>(member)) {
46104598
validateAbstractStorageDecl(*this, storage);
@@ -4640,10 +4628,21 @@ void TypeChecker::requestSuperclassLayout(ClassDecl *classDecl) {
46404628
}
46414629
}
46424630

4631+
/// "Finalize" the type so that SILGen can make copies of it, call
4632+
/// methods on it, etc. This requires forcing enough computation so
4633+
/// that (for example) a class can layout its vtable or a struct can
4634+
/// be laid out in memory.
46434635
static void finalizeType(TypeChecker &TC, NominalTypeDecl *nominal) {
46444636
assert(!nominal->hasClangNode());
46454637
assert(isa<SourceFile>(nominal->getModuleScopeContext()));
46464638

4639+
if (auto *CD = dyn_cast<ClassDecl>(nominal)) {
4640+
// We need to add implicit initializers and dtors because it
4641+
// affects vtable layout.
4642+
TC.addImplicitConstructors(CD);
4643+
CD->addImplicitDestructor();
4644+
}
4645+
46474646
for (auto *D : nominal->getMembers()) {
46484647
auto VD = dyn_cast<ValueDecl>(D);
46494648
if (!VD)
@@ -4654,7 +4653,12 @@ static void finalizeType(TypeChecker &TC, NominalTypeDecl *nominal) {
46544653

46554654
TC.validateDecl(VD);
46564655

4657-
TC.requestMemberLayout(VD);
4656+
// Compute overrides.
4657+
(void)VD->getOverriddenDecls();
4658+
4659+
// Check whether the member is @objc or dynamic.
4660+
(void)VD->isObjC();
4661+
(void)VD->isDynamic();
46584662

46594663
// The only thing left to do is synthesize storage for lazy variables.
46604664
auto *prop = dyn_cast<VarDecl>(D);
@@ -4669,11 +4673,6 @@ static void finalizeType(TypeChecker &TC, NominalTypeDecl *nominal) {
46694673
}
46704674

46714675
if (auto *CD = dyn_cast<ClassDecl>(nominal)) {
4672-
// We need to add implicit initializers and dtors because it
4673-
// affects vtable layout.
4674-
TC.addImplicitConstructors(CD);
4675-
CD->addImplicitDestructor();
4676-
46774676
// We need the superclass vtable layout as well.
46784677
TC.requestSuperclassLayout(CD);
46794678

@@ -5534,9 +5533,6 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
55345533
*this, classDecl, superclassCtor, kind)) {
55355534
Context.addSynthesizedDecl(ctor);
55365535
classDecl->addMember(ctor);
5537-
5538-
if (classDecl->hasValidatedLayout())
5539-
requestMemberLayout(ctor);
55405536
}
55415537
}
55425538

0 commit comments

Comments
 (0)