Skip to content

Commit 66d7a3a

Browse files
authored
Merge pull request #13288 from slavapestov/class-resilience-part-1
Class resilience part 1
2 parents fec040d + d299403 commit 66d7a3a

File tree

9 files changed

+218
-282
lines changed

9 files changed

+218
-282
lines changed

include/swift/Runtime/Metadata.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ struct TargetClassMetadata : public TargetHeapMetadata<Runtime> {
12751275
ConstTargetMetadataPointer<Runtime, swift::TargetClassMetadata> superClass,
12761276
StoredPointer data,
12771277
ClassFlags flags,
1278-
ClassIVarDestroyer ivarDestroyer,
1278+
StoredPointer ivarDestroyer,
12791279
StoredPointer size, StoredPointer addressPoint,
12801280
StoredPointer alignMask,
12811281
StoredPointer classSize, StoredPointer classAddressPoint)
@@ -1362,7 +1362,7 @@ struct TargetClassMetadata : public TargetHeapMetadata<Runtime> {
13621362

13631363
/// A function for destroying instance variables, used to clean up
13641364
/// after an early return from a constructor.
1365-
ClassIVarDestroyer IVarDestroyer; // TODO: Make target-agnostic size
1365+
StoredPointer IVarDestroyer;
13661366

13671367
// After this come the class members, laid out as follows:
13681368
// - class members for the superclass (recursively)
@@ -1383,9 +1383,10 @@ struct TargetClassMetadata : public TargetHeapMetadata<Runtime> {
13831383
Description = description;
13841384
}
13851385

1386+
/// Only valid if the target is in-process.
13861387
ClassIVarDestroyer getIVarDestroyer() const {
13871388
assert(isTypeMetadata());
1388-
return IVarDestroyer;
1389+
return reinterpret_cast<ClassIVarDestroyer>(IVarDestroyer);
13891390
}
13901391

13911392
/// Is this class an artificial subclass, such as one dynamically

lib/IRGen/GenClass.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ namespace {
258258
auto superclass = superclassType.getClassOrBoundGenericClass();
259259
assert(superclass);
260260

261+
// If the superclass came from another module, we may have dropped
262+
// stored properties due to the Swift language version availability of
263+
// their types. In these cases we can't precisely lay out the ivars in
264+
// the class object at compile time so we need to do runtime layout.
265+
if (classHasIncompleteLayout(IGM, superclass)) {
266+
ClassMetadataRequiresDynamicInitialization = true;
267+
}
268+
261269
if (superclass->hasClangNode()) {
262270
// If the superclass was imported from Objective-C, its size is
263271
// not known at compile time. However, since the field offset

lib/IRGen/GenKeyPath.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,16 @@ IRGenModule::getAddrOfKeyPathPattern(KeyPathPattern *pattern,
908908
auto declaringClass =
909909
cast<ClassDecl>(overridden.getDecl()->getDeclContext());
910910
auto &metadataLayout = getMetadataLayout(declaringClass);
911+
// FIXME: Resilience. We don't want vtable layout to be ABI, so this
912+
// should be encoded as a reference to the method dispatch thunk
913+
// instead.
911914
auto offset = metadataLayout.getStaticMethodOffset(overridden);
912915
idValue = llvm::ConstantInt::get(SizeTy, offset.getValue());
913916
idResolved = true;
914917
} else if (auto methodProto = dyn_cast<ProtocolDecl>(dc)) {
918+
// FIXME: Resilience. We don't want witness table layout to be ABI,
919+
// so this should be encoded as a reference to the method dispatch
920+
// thunk instead.
915921
auto &protoInfo = getProtocolInfo(methodProto);
916922
auto index = protoInfo.getFunctionIndex(
917923
cast<AbstractFunctionDecl>(declRef.getDecl()));

0 commit comments

Comments
 (0)