Skip to content

[Serialization] Drop inherited conformances on classes #23347

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 13, 2019
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
2 changes: 2 additions & 0 deletions include/swift/AST/DeclContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ enum class ConformanceLookupKind : unsigned {
All,
/// Only the explicit conformance.
OnlyExplicit,
/// All conformances except for inherited ones.
NonInherited,
};

/// Describes a diagnostic for a conflict between two protocol
Expand Down
28 changes: 24 additions & 4 deletions lib/AST/ConformanceLookupTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,10 +989,30 @@ void ConformanceLookupTable::lookupConformances(
return true;

// If we are to filter out this result, do so now.
if (lookupKind == ConformanceLookupKind::OnlyExplicit &&
entry->getKind() != ConformanceEntryKind::Explicit &&
entry->getKind() != ConformanceEntryKind::Synthesized)
return false;
switch (lookupKind) {
case ConformanceLookupKind::OnlyExplicit:
switch (entry->getKind()) {
case ConformanceEntryKind::Explicit:
case ConformanceEntryKind::Synthesized:
break;
case ConformanceEntryKind::Implied:
case ConformanceEntryKind::Inherited:
return false;
}
break;
case ConformanceLookupKind::NonInherited:
switch (entry->getKind()) {
case ConformanceEntryKind::Explicit:
case ConformanceEntryKind::Synthesized:
case ConformanceEntryKind::Implied:
break;
case ConformanceEntryKind::Inherited:
return false;
}
break;
case ConformanceLookupKind::All:
break;
}

// Record the protocol.
if (protocols)
Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ void SILGenModule::emitExternalDefinition(Decl *d) {
case DeclKind::Class: {
// Emit witness tables.
auto nom = cast<NominalTypeDecl>(d);
for (auto c : nom->getLocalConformances(ConformanceLookupKind::All,
for (auto c : nom->getLocalConformances(ConformanceLookupKind::NonInherited,
nullptr)) {
auto *proto = c->getProtocol();
if (Lowering::TypeConverter::protocolRequiresWitnessTable(proto) &&
Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ class SILGenType : public TypeMemberVisitor<SILGenType> {
// Emit witness tables for conformances of concrete types. Protocol types
// are existential and do not have witness tables.
for (auto *conformance : theType->getLocalConformances(
ConformanceLookupKind::All, nullptr)) {
ConformanceLookupKind::NonInherited, nullptr)) {
if (conformance->isComplete()) {
if (auto *normal = dyn_cast<NormalProtocolConformance>(conformance))
SGM.getWitnessTable(normal);
Expand Down
2 changes: 1 addition & 1 deletion lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3217,7 +3217,7 @@ void Serializer::writeDecl(const Decl *D) {
auto contextID = addDeclContextRef(theClass->getDeclContext());

auto conformances = theClass->getLocalConformances(
ConformanceLookupKind::All, nullptr);
ConformanceLookupKind::NonInherited, nullptr);

SmallVector<TypeID, 4> inheritedTypes;
for (auto inherited : theClass->getInherited()) {
Expand Down
3 changes: 2 additions & 1 deletion lib/TBDGen/TBDGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ void TBDGenVisitor::addBaseConformanceDescriptor(
}

void TBDGenVisitor::addConformances(DeclContext *DC) {
for (auto conformance : DC->getLocalConformances()) {
for (auto conformance : DC->getLocalConformances(
ConformanceLookupKind::NonInherited)) {
auto protocol = conformance->getProtocol();
auto needsWTable =
Lowering::TypeConverter::protocolRequiresWitnessTable(protocol);
Expand Down
6 changes: 3 additions & 3 deletions validation-test/Serialization/conformance-removed.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -emit-sil -emit-module-path %t/SwiftLib.swiftmodule -I %S/Inputs/conformance-removed/ %S/Inputs/conformance-removed/SwiftLib.swift -Xcc -DUSE_PROTO
// RUN: not --crash %target-build-swift -typecheck -I %t -I %S/Inputs/custom-modules/ %s 2>&1 | %FileCheck %s
// RUN: %target-build-swift -emit-module -emit-module-path %t/SwiftLib.swiftmodule -I %S/Inputs/conformance-removed/ %S/Inputs/conformance-removed/SwiftLib.swift -Xcc -DUSE_PROTO
// RUN: not grep SomeProto %t/SwiftLib.swiftmodule
// RUN: %target-build-swift -typecheck -I %t -I %S/Inputs/custom-modules/ %s

// REQUIRES: objc_interop

import SwiftLib
class Rdar28282310: Sub {}
// CHECK: If you're seeing a crash here, check that your SDK and dependencies are at least as new as the versions used to build 'SwiftLib'