Skip to content

[ParseableInterface] Don't bother computing default witness tables #20437

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
Nov 9, 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
10 changes: 6 additions & 4 deletions lib/SILGen/SILGenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,11 +823,13 @@ class SILGenType : public TypeMemberVisitor<SILGenType> {
genVTable.emitVTable();
}

// Build a default witness table if this is a protocol.
// Build a default witness table if this is a protocol that needs one.
if (auto protocol = dyn_cast<ProtocolDecl>(theType)) {
if (!protocol->isObjC() &&
protocol->isResilient())
SGM.emitDefaultWitnessTable(protocol);
if (!protocol->isObjC() && protocol->isResilient()) {
auto *SF = protocol->getParentSourceFile();
if (!SF || SF->Kind != SourceFileKind::Interface)
SGM.emitDefaultWitnessTable(protocol);
}
return;
}

Expand Down
6 changes: 4 additions & 2 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3155,14 +3155,15 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
if (!PD->hasValidSignature())
return;

auto *SF = PD->getParentSourceFile();
{
// Check for circular inheritance within the protocol.
SmallVector<ProtocolDecl *, 8> path;
path.push_back(PD);
checkCircularity(TC, PD, diag::circular_protocol_def,
DescriptiveDeclKind::Protocol, path);

if (auto *SF = PD->getParentSourceFile()) {
if (SF) {
if (auto *tracker = SF->getReferencedNameTracker()) {
bool isNonPrivate =
(PD->getFormalAccess() > AccessLevel::FilePrivate);
Expand All @@ -3184,7 +3185,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {

TC.checkDeclCircularity(PD);
if (PD->isResilient())
TC.inferDefaultWitnesses(PD);
if (!SF || SF->Kind != SourceFileKind::Interface)
TC.inferDefaultWitnesses(PD);

if (TC.Context.LangOpts.DebugGenericSignatures) {
auto requirementsSig =
Expand Down
16 changes: 14 additions & 2 deletions test/ParseableInterface/Conformances.swiftinterface
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// swift-module-flags:

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -enable-resilience -o %t/Conformances.swiftmodule %s
// RUN: %target-swift-frontend -emit-module-path %t/Conformances.swiftmodule -enable-resilience -emit-sil -o %t/Conformances.sil %s
// RUN: %FileCheck -check-prefix CHECK-MODULE %s < %t/Conformances.sil
// RUN: %FileCheck -check-prefix NEGATIVE-MODULE %s < %t/Conformances.sil
// RUN: %target-swift-frontend -emit-sil -I %t %S/Inputs/ConformancesUser.swift -O | %FileCheck %s

public protocol MyProto {
Expand All @@ -11,6 +13,15 @@ public protocol MyProto {
var prop: Int { get set }
subscript(index: Int) -> Int { get set }
}
extension MyProto {
public func method() {}
}

// Make sure there's no default witness table. (But also make sure we printed at
// least some regular witness tables, or we'll have to change the test.)
// CHECK-MODULE: sil_witness_table{{.+}}: MyProto module Conformances
// NEGATIVE-MODULE-NOT: sil_default_witness_table{{.+}}MyProto


@_fixed_layout // allow conformance devirtualization
public struct FullStructImpl: MyProto {
Expand All @@ -31,7 +42,8 @@ public struct OpaqueStructImpl: MyProto {}

// CHECK-LABEL: sil @$s16ConformancesUser10testOpaqueSiyF
// CHECK: function_ref @$s12Conformances7MyProtoPxycfC
// CHECK: function_ref @$s12Conformances7MyProtoP6methodyyF
// Note the default implementation is filled in here.
// CHECK: function_ref @$s12Conformances7MyProtoPAAE6methodyyF
// CHECK: function_ref @$s12Conformances7MyProtoP4propSivs
// CHECK: function_ref @$s12Conformances7MyProtoPyS2icig
// CHECK: end sil function '$s16ConformancesUser10testOpaqueSiyF'