From fc810e12058b27efab4600caeae93d81a82320b9 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 9 Feb 2020 00:36:58 -0500 Subject: [PATCH] SILGen: Relax assertion about missing vtable entries in a class Since resilient class metadata is built at runtime, we don't actually care if there are missing vtable entries. The restriction was relaxed in Sema in 9117c5728a10a829fd492026a62231717d0efe86, but SILGen still had an assertion here. Add a test and relax the assertion. Fixes . --- lib/SILGen/SILGenType.cpp | 10 ++++-- test/SILGen/vtable_implementation_only.swift | 36 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 test/SILGen/vtable_implementation_only.swift diff --git a/lib/SILGen/SILGenType.cpp b/lib/SILGen/SILGenType.cpp index 0486b0080fc09..d0d5157dc3e38 100644 --- a/lib/SILGen/SILGenType.cpp +++ b/lib/SILGen/SILGenType.cpp @@ -311,8 +311,14 @@ class SILGenVTable : public SILVTableVisitor { } void addPlaceholder(MissingMemberDecl *m) { - assert(m->getNumberOfVTableEntries() == 0 - && "Should not be emitting class with missing members"); +#ifndef NDEBUG + auto *classDecl = cast(m->getDeclContext()); + bool isResilient = + classDecl->isResilient(SGM.M.getSwiftModule(), + ResilienceExpansion::Maximal); + assert(isResilient || m->getNumberOfVTableEntries() == 0 && + "Should not be emitting fragile class with missing members"); +#endif } }; diff --git a/test/SILGen/vtable_implementation_only.swift b/test/SILGen/vtable_implementation_only.swift new file mode 100644 index 0000000000000..a298c7e08bb13 --- /dev/null +++ b/test/SILGen/vtable_implementation_only.swift @@ -0,0 +1,36 @@ +// RUN: %empty-directory(%t) + +// For convenience, this file includes the three different "files" used in this +// test. It selects one with -DCoreDishwasher, -DDishwasherKit, or neither. + +// RUN: %target-swift-frontend -emit-module %s -DCoreDishwasher -module-name CoreDishwasher -o %t/CoreDishwasher -emit-module-path %t/CoreDishwasher.swiftmodule -I %t +// RUN: %target-swift-frontend -emit-module %s -DDishwasherKit -module-name DishwasherKit -o %t/DishwasherKit -emit-module-path %t/DishwasherKit.swiftmodule -enable-library-evolution -I %t +// RUN: %target-swift-frontend -emit-silgen -I %t %s + +#if CoreDishwasher + + public struct SpimsterWicket { + public init() {} + } + +#elseif DishwasherKit + + @_implementationOnly import CoreDishwasher + + open class Dishwasher { + public init() {} + + var wicket = SpimsterWicket() + + open var modelName: String { "Dishwasher" } + } + +#else + + import DishwasherKit + + open class FancyDishwasher: Dishwasher { + open override var modelName: String { "Fancy \(super.modelName)" } + } + +#endif