Skip to content

Commit 42d3b18

Browse files
authored
Merge pull request #4932 from slavapestov/fix-resilient-build
Fix resilient build
2 parents effcb42 + d28b8ea commit 42d3b18

37 files changed

+225
-32
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ struct TypeMetadataRecordFlags {
170170
constexpr TypeMetadataRecordFlags(int_type Data) : Data(Data) {}
171171

172172
constexpr TypeMetadataRecordKind getTypeKind() const {
173-
return TypeMetadataRecordKind((Data >> TypeKindShift) & TypeKindMask);
173+
return TypeMetadataRecordKind((Data & TypeKindMask) >> TypeKindShift);
174174
}
175175
constexpr TypeMetadataRecordFlags withTypeKind(
176176
TypeMetadataRecordKind ptk) const {
@@ -199,8 +199,8 @@ struct ProtocolConformanceFlags : public TypeMetadataRecordFlags {
199199
(Data & ~TypeKindMask) | (int_type(ptk) << TypeKindShift));
200200
}
201201
constexpr ProtocolConformanceReferenceKind getConformanceKind() const {
202-
return ProtocolConformanceReferenceKind((Data >> ConformanceKindShift)
203-
& ConformanceKindMask);
202+
return ProtocolConformanceReferenceKind((Data & ConformanceKindMask)
203+
>> ConformanceKindShift);
204204
}
205205
constexpr ProtocolConformanceFlags withConformanceKind(
206206
ProtocolConformanceReferenceKind pck) const {

include/swift/Basic/LangOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ namespace swift {
141141
/// \brief Enable experimental nested generic types feature.
142142
bool EnableExperimentalNestedGenericTypes = false;
143143

144+
/// \brief Staging flag for class resilience, which we do not want to enable
145+
/// fully until more code is in place, to allow the standard library to be
146+
/// tested with value type resilience only.
147+
bool EnableClassResilience = false;
148+
144149
/// Should we check the target OSs of serialized modules to see that they're
145150
/// new enough?
146151
bool EnableTargetOSChecking = true;

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ def enable_resilience : Flag<["-"], "enable-resilience">,
331331
HelpText<"Compile the module to export resilient interfaces for all "
332332
"public declarations by default">;
333333

334+
def enable_class_resilience : Flag<["-"], "enable-class-resilience">,
335+
HelpText<"Compile the module to export resilient interfaces for all "
336+
"public classes by default (doesn't work yet)">;
337+
334338
def group_info_path : Separate<["-"], "group-info-path">,
335339
HelpText<"The path to collect the group information of the compiled module">;
336340

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
787787
Opts.EnableExperimentalNestedGenericTypes |=
788788
Args.hasArg(OPT_enable_experimental_nested_generic_types);
789789

790+
Opts.EnableClassResilience |=
791+
Args.hasArg(OPT_enable_class_resilience);
792+
790793
Opts.DisableAvailabilityChecking |=
791794
Args.hasArg(OPT_disable_availability_checking);
792795
if (FrontendOpts.InputKind == InputFileKind::IFK_SIL)

lib/IRGen/ClassMetadataLayout.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ template <class Impl> class ClassMetadataLayout : public MetadataLayout<Impl> {
8888
// Skip superclass fields if superclass is resilient.
8989
// FIXME: Needs runtime support to ensure the field offset vector is
9090
// populated correctly.
91-
if (!IGM.isResilient(superclassDecl, ResilienceExpansion::Maximal)) {
91+
if (!IGM.Context.LangOpts.EnableClassResilience ||
92+
!IGM.isResilient(superclassDecl, ResilienceExpansion::Maximal)) {
9293
addClassMembers(superclassDecl, superclass);
9394
}
9495
}

lib/IRGen/EnumMetadataLayout.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ template <class Impl> class EnumMetadataLayout : public MetadataLayout<Impl> {
5252
// emitParentMetadataRef.
5353

5454
// Instantiation-specific.
55-
55+
56+
// Add fields for generic cases.
57+
asImpl().addGenericFields(Target, Target->getDeclaredTypeInContext());
58+
5659
// Reserve a word to cache the payload size if the type has dynamic layout.
5760
auto &strategy = getEnumImplStrategy(IGM,
5861
Target->DeclContext::getDeclaredTypeInContext()->getCanonicalType());
5962
if (strategy.needsPayloadSizeInMetadata())
6063
asImpl().addPayloadSize();
61-
62-
// Add fields for generic cases.
63-
asImpl().addGenericFields(Target, Target->getDeclaredTypeInContext());
6464
}
6565
};
6666

lib/IRGen/GenClass.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,16 @@ namespace {
242242

243243
// If the superclass is resilient to us, we cannot statically
244244
// know the layout of either its instances or its class objects.
245-
ClassHasFixedFieldCount = false;
245+
//
246+
// FIXME: We need to implement indirect field/vtable entry access
247+
// before we can enable this
248+
if (IGM.Context.LangOpts.EnableClassResilience) {
249+
ClassHasFixedFieldCount = false;
250+
} else {
251+
addFieldsForClass(superclass, superclassType);
252+
NumInherited = Elements.size();
253+
}
254+
246255
ClassHasFixedSize = false;
247256

248257
// Furthermore, if the superclass is a generic context, we have to

lib/IRGen/GenDecl.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,17 +2174,27 @@ llvm::Constant *IRGenModule::emitProtocolConformances() {
21742174
getPointerAlignment(), ProtocolDescriptorStructTy);
21752175
auto typeEntity = getTypeEntityInfo(*this,
21762176
conformance->getType()->getCanonicalType());
2177-
auto flags = typeEntity.flags
2178-
.withConformanceKind(ProtocolConformanceReferenceKind::WitnessTable);
2179-
2180-
// If the conformance is in this object's table, then the witness table
2181-
// should also be in this object file, so we can always directly reference
2182-
// it.
2183-
// TODO: Should use accessor kind for lazy conformances
2184-
// TODO: Produce a relative reference to a private generator function
2185-
// if the witness table requires lazy initialization, instantiation, or
2186-
// conditional conformance checking.
2187-
auto witnessTableVar = getAddrOfWitnessTable(conformance);
2177+
auto flags = typeEntity.flags;
2178+
2179+
llvm::Constant *witnessTableVar;
2180+
2181+
if (!isResilient(conformance->getProtocol(),
2182+
ResilienceExpansion::Maximal)) {
2183+
flags = flags.withConformanceKind(
2184+
ProtocolConformanceReferenceKind::WitnessTable);
2185+
2186+
// If the conformance is in this object's table, then the witness table
2187+
// should also be in this object file, so we can always directly reference
2188+
// it.
2189+
witnessTableVar = getAddrOfWitnessTable(conformance);
2190+
} else {
2191+
flags = flags.withConformanceKind(
2192+
ProtocolConformanceReferenceKind::WitnessTableAccessor);
2193+
2194+
witnessTableVar = getAddrOfWitnessTableAccessFunction(
2195+
conformance, ForDefinition);
2196+
}
2197+
21882198
auto witnessTableRef =
21892199
ConstantReference(witnessTableVar, ConstantReference::Direct);
21902200

lib/IRGen/GenEnum.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4656,7 +4656,7 @@ namespace {
46564656
}
46574657

46584658
bool needsPayloadSizeInMetadata() const override {
4659-
llvm_unreachable("resilient enums cannot be defined");
4659+
return false;
46604660
}
46614661

46624662
void initializeMetadata(IRGenFunction &IGF,

stdlib/public/core/ArrayBuffer.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import SwiftShims
2121
internal typealias _ArrayBridgeStorage
2222
= _BridgeStorage<_ContiguousArrayStorageBase, _NSArrayCore>
2323

24+
@_versioned
2425
@_fixed_layout
2526
internal struct _ArrayBuffer<Element> : _ArrayBufferProtocol {
2627

@@ -29,6 +30,7 @@ internal struct _ArrayBuffer<Element> : _ArrayBufferProtocol {
2930
_storage = _ArrayBridgeStorage(native: _emptyArrayStorage)
3031
}
3132

33+
@_versioned // FIXME(abi): Used from tests
3234
internal init(nsArray: _NSArrayCore) {
3335
_sanityCheck(_isClassOrObjCExistential(Element.self))
3436
_storage = _ArrayBridgeStorage(objC: nsArray)
@@ -113,6 +115,7 @@ extension _ArrayBuffer {
113115
/// Convert to an NSArray.
114116
///
115117
/// O(1) if the element type is bridged verbatim, O(*n*) otherwise.
118+
@_versioned // FIXME(abi): Used from tests
116119
internal func _asCocoaArray() -> _NSArrayCore {
117120
return _fastPath(_isNative) ? _native._asCocoaArray() : _nonNative
118121
}
@@ -273,6 +276,7 @@ extension _ArrayBuffer {
273276
/// A pointer to the first element.
274277
///
275278
/// - Precondition: The elements are known to be stored contiguously.
279+
@_versioned
276280
internal var firstElementAddress: UnsafeMutablePointer<Element> {
277281
_sanityCheck(_isNative, "must be a native buffer")
278282
return _native.firstElementAddress

stdlib/public/core/ArrayBufferProtocol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
/// The underlying buffer for an ArrayType conforms to
1414
/// `_ArrayBufferProtocol`. This buffer does not provide value semantics.
15+
@_versioned
1516
internal protocol _ArrayBufferProtocol
1617
: MutableCollection, RandomAccessCollection {
1718

stdlib/public/core/Builtin.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ public func _onFastPath() {
283283
// Declare it here instead of RuntimeShims.h, because we need to specify
284284
// the type of argument to be AnyClass. This is currently not possible
285285
// when using RuntimeShims.h
286+
@_versioned
286287
@_silgen_name("swift_objc_class_usesNativeSwiftReferenceCounting")
287288
func _usesNativeSwiftReferenceCounting(_ theClass: AnyClass) -> Bool
288289
#else
@@ -480,6 +481,7 @@ internal func _makeBridgeObject(
480481
)
481482
}
482483

484+
@_versioned
483485
@_silgen_name("_swift_class_getSuperclass")
484486
internal func _swift_class_getSuperclass(_ t: AnyClass) -> AnyClass?
485487

stdlib/public/core/ContiguousArrayBuffer.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ final class _ContiguousArrayStorage<Element> : _ContiguousArrayStorage1 {
176176
}
177177
}
178178

179+
@_versioned
179180
@_fixed_layout
180181
internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
181182

@@ -247,6 +248,7 @@ internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
247248
}
248249

249250
/// A pointer to the first element.
251+
@_versioned
250252
internal var firstElementAddress: UnsafeMutablePointer<Element> {
251253
return UnsafeMutablePointer(Builtin.projectTailElems(_storage,
252254
Element.self))
@@ -318,6 +320,7 @@ internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
318320
}
319321

320322
/// Get or set the value of the ith element.
323+
@_versioned
321324
internal subscript(i: Int) -> Element {
322325
get {
323326
return getElement(i)
@@ -434,6 +437,7 @@ internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
434437
#endif
435438

436439
/// An object that keeps the elements stored in this buffer alive.
440+
@_versioned
437441
internal var owner: AnyObject {
438442
return _storage
439443
}

stdlib/public/core/HashedCollections.swift.gyb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,7 @@ internal struct _HashedContainerStorageHeader {
25082508
/// Enough bytes are allocated to hold the bitmap for marking valid entries,
25092509
/// keys, and values. The data layout starts with the bitmap, followed by the
25102510
/// keys, followed by the values.
2511+
@_versioned
25112512
final internal class _Native${Self}StorageImpl<${TypeParameters}> {
25122513
// Note: It is intended that ${TypeParameters}
25132514
// (without : Hashable) is used here - this storage must work
@@ -3229,6 +3230,7 @@ final internal class _Native${Self}StorageKeyNSEnumerator<
32293230
/// is also a proper `NS${Self}` subclass, which is returned to Objective-C
32303231
/// during bridging. `${Self}Index` points directly to
32313232
/// `_Native${Self}Storage`.
3233+
@_versioned
32323234
final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
32333235
: _SwiftNativeNS${Self}, _NS${Self}Core {
32343236

@@ -3564,7 +3566,10 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
35643566
}
35653567

35663568
#if _runtime(_ObjC)
3569+
@_versioned
3570+
@_fixed_layout
35673571
internal struct _Cocoa${Self}Storage : _HashStorage {
3572+
@_versioned
35683573
internal var cocoa${Self}: _NS${Self}
35693574

35703575
internal typealias Index = _Cocoa${Self}Index
@@ -3695,6 +3700,8 @@ internal struct _Cocoa${Self}Storage : _HashStorage {
36953700
internal struct _Cocoa${Self}Storage {}
36963701
#endif
36973702

3703+
@_versioned
3704+
@_fixed_layout
36983705
internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorage {
36993706

37003707
internal typealias NativeStorage = _Native${Self}Storage<${TypeParameters}>
@@ -4408,6 +4415,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorage {
44084415
}
44094416
}
44104417

4418+
@_versioned
44114419
internal struct _Native${Self}Index<${TypeParametersDecl}> :
44124420
Comparable {
44134421

@@ -4418,6 +4426,8 @@ internal struct _Native${Self}Index<${TypeParametersDecl}> :
44184426
// the new model.
44194427
@_versioned
44204428
internal var nativeStorage: NativeStorage
4429+
4430+
@_versioned
44214431
internal var offset: Int
44224432

44234433
@_versioned
@@ -4799,6 +4809,7 @@ final internal class _Cocoa${Self}Iterator : IteratorProtocol {
47994809
final internal class _Cocoa${Self}Iterator {}
48004810
#endif
48014811

4812+
@_versioned
48024813
internal enum ${Self}IteratorRepresentation<${TypeParametersDecl}> {
48034814
internal typealias _Iterator = ${Self}Iterator<${TypeParameters}>
48044815
internal typealias _NativeStorageOwner =

stdlib/public/core/SipHash.swift.gyb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919
/// * Daniel J. Bernstein <[email protected]>
2020
//===----------------------------------------------------------------------===//
2121

22+
@_versioned
2223
internal enum _SipHashDetail {
24+
@_versioned
2325
@inline(__always)
2426
internal static func _rotate(_ x: UInt64, leftBy amount: Int) -> UInt64 {
2527
return (x << UInt64(amount)) | (x >> (64 - UInt64(amount)))
2628
}
2729

30+
@_versioned
2831
@inline(__always)
2932
internal static func _loadUnalignedUInt64LE(
3033
from p: UnsafeRawPointer
@@ -40,6 +43,7 @@ internal enum _SipHashDetail {
4043
(UInt64(p.load(fromByteOffset: 7, as: UInt8.self)) << 56)
4144
}
4245

46+
@_versioned
4347
@inline(__always)
4448
internal static func _loadPartialUnalignedUInt64LE(
4549
from p: UnsafeRawPointer,
@@ -57,6 +61,7 @@ internal enum _SipHashDetail {
5761
return result
5862
}
5963

64+
@_versioned
6065
@inline(__always)
6166
internal static func _sipRound(
6267
v0: inout UInt64,
@@ -87,16 +92,28 @@ internal enum _SipHashDetail {
8792
public // @testable
8893
struct ${Self} {
8994
// "somepseudorandomlygeneratedbytes"
95+
@_versioned
9096
internal var v0: UInt64 = 0x736f6d6570736575
97+
98+
@_versioned
9199
internal var v1: UInt64 = 0x646f72616e646f6d
100+
101+
@_versioned
92102
internal var v2: UInt64 = 0x6c7967656e657261
103+
104+
@_versioned
93105
internal var v3: UInt64 = 0x7465646279746573
94106

107+
@_versioned
95108
internal var hashedByteCount: UInt64 = 0
96109

110+
@_versioned
97111
internal var dataTail: UInt64 = 0
112+
113+
@_versioned
98114
internal var dataTailByteCount: Int = 0
99115

116+
@_versioned
100117
internal var finalizedHash: UInt64?
101118

102119
public init(key: (UInt64, UInt64)) {
@@ -113,6 +130,7 @@ struct ${Self} {
113130
}
114131

115132
// FIXME(ABI)#63 (UnsafeRawBufferPointer): Use UnsafeRawBufferPointer.
133+
@_versioned
116134
@inline(__always)
117135
internal mutating func _append_alwaysInline(
118136
_ data: UnsafeRawPointer,
@@ -165,6 +183,7 @@ struct ${Self} {
165183

166184
/// This function mixes in the given word directly into the state,
167185
/// ignoring `dataTail`.
186+
@_versioned
168187
@inline(__always)
169188
internal mutating func _appendDirectly(_ m: UInt64) {
170189
v3 ^= m
@@ -188,6 +207,7 @@ struct ${Self} {
188207
return _finalizeAndReturnHash_alwaysInline()
189208
}
190209

210+
@_versioned
191211
@inline(__always)
192212
internal mutating func _finalizeAndReturnHash_alwaysInline() -> UInt64 {
193213
if let finalizedHash = finalizedHash {
@@ -238,6 +258,7 @@ struct ${Self} {
238258
}
239259

240260
// FIXME(ABI)#65 (UnsafeRawBufferPointer): Use UnsafeRawBufferPointer.
261+
@_versioned
241262
@inline(__always)
242263
public // @testable
243264
static func _hash_alwaysInline(

0 commit comments

Comments
 (0)