Skip to content

[TBDGen] The non-deallocating destructor applies to some @objc classes. #16837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions lib/TBDGen/TBDGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
#include "swift/IRGen/Linking.h"
#include "swift/SIL/FormalLinkage.h"
#include "swift/SIL/SILDeclRef.h"
#include "swift/SIL/SILWitnessTable.h"
#include "swift/SIL/SILModule.h"
#include "swift/SIL/SILVTableVisitor.h"
#include "swift/SIL/SILWitnessTable.h"
#include "swift/SIL/TypeLowering.h"
#include "llvm/ADT/StringSet.h"

Expand Down Expand Up @@ -233,13 +234,6 @@ void TBDGenVisitor::visitClassDecl(ClassDecl *CD) {
auto hasFieldOffset = var && var->hasStorage() && !var->isStatic();
if (hasFieldOffset)
addSymbol(LinkEntity::forFieldOffset(var));

// The non-allocating forms of the destructors.
if (auto dtor = dyn_cast<DestructorDecl>(value)) {
// ObjC classes don't have a symbol for their destructor.
if (!isObjC)
addSymbol(SILDeclRef(dtor, SILDeclRef::Kind::Destroyer));
}
}

visitNominalTypeDecl(CD);
Expand Down Expand Up @@ -300,6 +294,19 @@ void TBDGenVisitor::visitConstructorDecl(ConstructorDecl *CD) {
visitAbstractFunctionDecl(CD);
}

void TBDGenVisitor::visitDestructorDecl(DestructorDecl *DD) {
// Class destructors come in two forms (deallocating and non-deallocating),
// like constructors above. This is the deallocating one:
visitAbstractFunctionDecl(DD);

auto parentClass = DD->getParent()->getAsClassOrClassExtensionContext();

// But the non-deallocating one doesn't apply to some @objc classes.
if (!Lowering::usesObjCAllocator(parentClass)) {
addSymbol(SILDeclRef(DD, SILDeclRef::Kind::Destroyer));
}
}

void TBDGenVisitor::visitExtensionDecl(ExtensionDecl *ED) {
if (!ED->getExtendedType()->isExistentialType()) {
addConformances(ED);
Expand Down
2 changes: 2 additions & 0 deletions lib/TBDGen/TBDGenVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {

void visitConstructorDecl(ConstructorDecl *CD);

void visitDestructorDecl(DestructorDecl *DD);

void visitExtensionDecl(ExtensionDecl *ED);

void visitProtocolDecl(ProtocolDecl *PD);
Expand Down
30 changes: 0 additions & 30 deletions test/TBD/class_objc.swift

This file was deleted.

37 changes: 37 additions & 0 deletions test/TBD/class_objc.swift.gyb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// RUN: %empty-directory(%t)
// RUN: %gyb %s > %t/main.swift

// RUN: %target-swift-frontend -emit-ir -o- -parse-as-library -module-name test -import-objc-header %S/Inputs/objc_class_header.h -validate-tbd-against-ir=all %t/main.swift -disable-objc-attr-requires-foundation-module

// RUN: %target-swift-frontend -enable-resilience -emit-ir -o- -parse-as-library -module-name test -import-objc-header %S/Inputs/objc_class_header.h -validate-tbd-against-ir=all %t/main.swift -disable-objc-attr-requires-foundation-module

// REQUIRES: objc_interop

import Foundation

% names = ["Public", "Internal", "Private"]

% for i, name in enumerate(names):
% access = name.lower()

// a class by itself
${access} class ${name}Empty: NSObject {}

// subclasses of that
% for subname in names[i:]:
% subaccess = subname.lower()
${subaccess} class ${subname}Sub${name}Empty: ${name}Empty {}
%end

${access} class ${name}InheritObjCProtocol: NSObject, ObjCProtocol {}

// some bugs were revealed when there's @objc without inheriting from
// NSObject.
@objc ${access} class ${name}ObjCOnly {}

%end

@usableFromInline
@objc
internal class InternalObjCOnlyUsableFromInline {}