Skip to content

Commit 75e2f36

Browse files
committed
embedded stdlib: make the ManagedBuffer initializer public in the embedded stdlib
Otherwise derived classes cannot be specialized. Fixes a compile time error when using ManagedBuffer in embedded mode. rdar://122414669
1 parent 0dc7dd5 commit 75e2f36

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

stdlib/public/core/ManagedBuffer.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,21 @@ open class ManagedBuffer<Header, Element> {
4444
/// reading the `header` property during `ManagedBuffer.create` is undefined.
4545
public final var header: Header
4646

47+
#if $Embedded
48+
// In embedded mode this initializer has to be public, otherwise derived
49+
// classes cannot be specialized.
50+
public init(_doNotCallMe: ()) {
51+
_internalInvariantFailure("Only initialize these by calling create")
52+
}
53+
#else
4754
// This is really unfortunate. In Swift 5.0, the method descriptor for this
4855
// initializer was public and subclasses would "inherit" it, referencing its
4956
// method descriptor from their class override table.
5057
@usableFromInline
5158
internal init(_doNotCallMe: ()) {
5259
_internalInvariantFailure("Only initialize these by calling create")
5360
}
61+
#endif
5462

5563
@inlinable
5664
deinit {}

test/embedded/managed-buffer.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-emit-ir %s -module-name=main -enable-experimental-feature Embedded | %FileCheck %s
2+
3+
// REQUIRES: swift_in_compiler
4+
// REQUIRES: OS=macosx || OS=linux-gnu
5+
6+
// CHECK: @"$s4main8MyBufferCN" = {{.*global.*}} <{ ptr @"$ss13ManagedBufferCySis5UInt8VGN", ptr @"$s4main8MyBufferCfD", ptr @"$s4main8MyBufferC12_doNotCallMeACyt_tcfC" }>
7+
// CHECK: @"$ss13ManagedBufferCySis5UInt8VGN" = {{.*global.*}} <{ ptr null, ptr @"$ss13ManagedBufferCfDSi_s5UInt8VTg5", ptr @"$ss13ManagedBufferC12_doNotCallMeAByxq_Gyt_tcfCSi_s5UInt8VTg5" }>
8+
final public class MyBuffer: ManagedBuffer<Int, UInt8> {
9+
}
10+

0 commit comments

Comments
 (0)