Skip to content

SILGen: Relax assertion about missing vtable entries in a class #29726

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
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: 8 additions & 2 deletions lib/SILGen/SILGenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,14 @@ class SILGenVTable : public SILVTableVisitor<SILGenVTable> {
}

void addPlaceholder(MissingMemberDecl *m) {
assert(m->getNumberOfVTableEntries() == 0
&& "Should not be emitting class with missing members");
#ifndef NDEBUG
auto *classDecl = cast<ClassDecl>(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
}
};

Expand Down
36 changes: 36 additions & 0 deletions test/SILGen/vtable_implementation_only.swift
Original file line number Diff line number Diff line change
@@ -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