From b89ef78ce5be633981f7935ab3e728a578cb5120 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Thu, 28 May 2020 14:10:39 -0700 Subject: [PATCH 1/3] Adding `final` to public API is API-stable. Client code can't override or subclass a `public` declaration already, so although the ABI differs, the API is the same whether something is `final` or not. --- include/swift/AST/Attr.def | 2 +- test/api-digester/Outputs/Cake.txt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/include/swift/AST/Attr.def b/include/swift/AST/Attr.def index 8054500c3b772..95504c3477426 100644 --- a/include/swift/AST/Attr.def +++ b/include/swift/AST/Attr.def @@ -126,7 +126,7 @@ DECL_ATTR(available, Available, CONTEXTUAL_SIMPLE_DECL_ATTR(final, Final, OnClass | OnFunc | OnAccessor | OnVar | OnSubscript | DeclModifier | - ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIStableToRemove, + ABIBreakingToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove, 2) DECL_ATTR(objc, ObjC, OnAbstractFunction | OnClass | OnProtocol | OnExtension | OnVar | diff --git a/test/api-digester/Outputs/Cake.txt b/test/api-digester/Outputs/Cake.txt index 2ca2dc6739d81..a794079a71f9e 100644 --- a/test/api-digester/Outputs/Cake.txt +++ b/test/api-digester/Outputs/Cake.txt @@ -40,7 +40,6 @@ cake: TypeAlias TChangesFromIntToString.T has underlying type change from Swift. /* Decl Attribute changes */ cake: Enum IceKind is now without @frozen cake: Func C1.foo1() is now not static -cake: Func FinalFuncContainer.NewFinalFunc() is now with final cake: Func HasMutatingMethodClone.foo() has self access kind changing from Mutating to NonMutating cake: Func S1.foo1() has self access kind changing from NonMutating to Mutating cake: Func S1.foo3() is now static From be8674ea73551cfa1e91ab3a3e3f52f712c3428b Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Thu, 28 May 2020 18:19:03 -0700 Subject: [PATCH 2/3] Make an internal KeyPath helper final. And remove an unnecessary override, so that further work will allow this method not to need a vtable entry. --- stdlib/public/core/KeyPath.swift | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/stdlib/public/core/KeyPath.swift b/stdlib/public/core/KeyPath.swift index dcedf5aa4c79d..53930842b2981 100644 --- a/stdlib/public/core/KeyPath.swift +++ b/stdlib/public/core/KeyPath.swift @@ -134,6 +134,7 @@ public class AnyKeyPath: Hashable, _AppendKeyPath { // Prevent normal initialization. We use tail allocation via // allocWithTailElems(). + @available(*, unavailable) internal init() { _internalInvariantFailure("use _create(...)") } @@ -158,7 +159,7 @@ public class AnyKeyPath: Hashable, _AppendKeyPath { return result } - internal func withBuffer(_ f: (KeyPathBuffer) throws -> T) rethrows -> T { + final internal func withBuffer(_ f: (KeyPathBuffer) throws -> T) rethrows -> T { defer { _fixLifetime(self) } let base = UnsafeRawPointer(Builtin.projectTailElems(self, Int32.self)) @@ -348,14 +349,6 @@ public class ReferenceWritableKeyPath< internal final override class var kind: Kind { return .reference } - internal final override func _projectMutableAddress( - from base: UnsafePointer - ) -> (pointer: UnsafeMutablePointer, owner: AnyObject?) { - // Since we're a ReferenceWritableKeyPath, we know we don't mutate the base - // in practice. - return _projectMutableAddress(from: base.pointee) - } - @usableFromInline internal final func _projectMutableAddress(from origBase: Root) -> (pointer: UnsafeMutablePointer, owner: AnyObject?) { From 24336465c0e7f8a1f885de97fbff95b5640a925c Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Fri, 29 May 2020 14:30:02 -0700 Subject: [PATCH 3/3] Add debug output for vtable layout --- lib/IRGen/GenMeta.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/IRGen/GenMeta.cpp b/lib/IRGen/GenMeta.cpp index 7eca86628b80c..22effa95297e3 100644 --- a/lib/IRGen/GenMeta.cpp +++ b/lib/IRGen/GenMeta.cpp @@ -14,6 +14,8 @@ // //===----------------------------------------------------------------------===// +#define DEBUG_TYPE "type-metadata-layout" + #include "swift/ABI/MetadataValues.h" #include "swift/ABI/TypeIdentity.h" #include "swift/AST/ASTContext.h" @@ -1520,6 +1522,15 @@ namespace { void addVTable() { if (VTableEntries.empty()) return; + + LLVM_DEBUG( + llvm::dbgs() << "VTable entries for " << getType()->getName() << ":\n"; + for (auto entry : VTableEntries) { + llvm::dbgs() << " "; + entry.print(llvm::dbgs()); + llvm::dbgs() << '\n'; + } + ); // Only emit a method lookup function if the class is resilient // and has a non-empty vtable.