Skip to content

Commit 6da8c05

Browse files
authored
Merge pull request #18101 from DougGregor/finalize-type-force-layout
[Type checker] Move forcing of overridden/@objc/dynamic into finalizeType().
2 parents 5980c4c + 926e9c2 commit 6da8c05

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
@@ -2982,11 +2982,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
29822982

29832983
TC.checkDeclCircularity(CD);
29842984
TC.ConformanceContexts.push_back(CD);
2985-
2986-
for (auto Member : CD->getMembers()) {
2987-
if (auto VD = dyn_cast<ValueDecl>(Member))
2988-
TC.requestMemberLayout(VD);
2989-
}
29902985
}
29912986

29922987
void visitProtocolDecl(ProtocolDecl *PD) {
@@ -4599,13 +4594,6 @@ void TypeChecker::requestMemberLayout(ValueDecl *member) {
45994594
if (auto *protocolDecl = dyn_cast<ProtocolDecl>(dc))
46004595
requestNominalLayout(protocolDecl);
46014596

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

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

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

46564655
TC.validateDecl(VD);
46574656

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

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

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

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

0 commit comments

Comments
 (0)