Skip to content

Fix resilient build #4932

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 5 commits into from
Oct 1, 2016
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
6 changes: 3 additions & 3 deletions include/swift/ABI/MetadataValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ struct TypeMetadataRecordFlags {
constexpr TypeMetadataRecordFlags(int_type Data) : Data(Data) {}

constexpr TypeMetadataRecordKind getTypeKind() const {
return TypeMetadataRecordKind((Data >> TypeKindShift) & TypeKindMask);
return TypeMetadataRecordKind((Data & TypeKindMask) >> TypeKindShift);
}
constexpr TypeMetadataRecordFlags withTypeKind(
TypeMetadataRecordKind ptk) const {
Expand Down Expand Up @@ -199,8 +199,8 @@ struct ProtocolConformanceFlags : public TypeMetadataRecordFlags {
(Data & ~TypeKindMask) | (int_type(ptk) << TypeKindShift));
}
constexpr ProtocolConformanceReferenceKind getConformanceKind() const {
return ProtocolConformanceReferenceKind((Data >> ConformanceKindShift)
& ConformanceKindMask);
return ProtocolConformanceReferenceKind((Data & ConformanceKindMask)
>> ConformanceKindShift);
}
constexpr ProtocolConformanceFlags withConformanceKind(
ProtocolConformanceReferenceKind pck) const {
Expand Down
5 changes: 5 additions & 0 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ namespace swift {
/// \brief Enable experimental nested generic types feature.
bool EnableExperimentalNestedGenericTypes = false;

/// \brief Staging flag for class resilience, which we do not want to enable
/// fully until more code is in place, to allow the standard library to be
/// tested with value type resilience only.
bool EnableClassResilience = false;

/// Should we check the target OSs of serialized modules to see that they're
/// new enough?
bool EnableTargetOSChecking = true;
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ def enable_resilience : Flag<["-"], "enable-resilience">,
HelpText<"Compile the module to export resilient interfaces for all "
"public declarations by default">;

def enable_class_resilience : Flag<["-"], "enable-class-resilience">,
HelpText<"Compile the module to export resilient interfaces for all "
"public classes by default (doesn't work yet)">;

def group_info_path : Separate<["-"], "group-info-path">,
HelpText<"The path to collect the group information of the compiled module">;

Expand Down
3 changes: 3 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.EnableExperimentalNestedGenericTypes |=
Args.hasArg(OPT_enable_experimental_nested_generic_types);

Opts.EnableClassResilience |=
Args.hasArg(OPT_enable_class_resilience);

Opts.DisableAvailabilityChecking |=
Args.hasArg(OPT_disable_availability_checking);
if (FrontendOpts.InputKind == InputFileKind::IFK_SIL)
Expand Down
3 changes: 2 additions & 1 deletion lib/IRGen/ClassMetadataLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ template <class Impl> class ClassMetadataLayout : public MetadataLayout<Impl> {
// Skip superclass fields if superclass is resilient.
// FIXME: Needs runtime support to ensure the field offset vector is
// populated correctly.
if (!IGM.isResilient(superclassDecl, ResilienceExpansion::Maximal)) {
if (!IGM.Context.LangOpts.EnableClassResilience ||
!IGM.isResilient(superclassDecl, ResilienceExpansion::Maximal)) {
addClassMembers(superclassDecl, superclass);
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/IRGen/EnumMetadataLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ template <class Impl> class EnumMetadataLayout : public MetadataLayout<Impl> {
// emitParentMetadataRef.

// Instantiation-specific.


// Add fields for generic cases.
asImpl().addGenericFields(Target, Target->getDeclaredTypeInContext());

// Reserve a word to cache the payload size if the type has dynamic layout.
auto &strategy = getEnumImplStrategy(IGM,
Target->DeclContext::getDeclaredTypeInContext()->getCanonicalType());
if (strategy.needsPayloadSizeInMetadata())
asImpl().addPayloadSize();

// Add fields for generic cases.
asImpl().addGenericFields(Target, Target->getDeclaredTypeInContext());
}
};

Expand Down
11 changes: 10 additions & 1 deletion lib/IRGen/GenClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,16 @@ namespace {

// If the superclass is resilient to us, we cannot statically
// know the layout of either its instances or its class objects.
ClassHasFixedFieldCount = false;
//
// FIXME: We need to implement indirect field/vtable entry access
// before we can enable this
if (IGM.Context.LangOpts.EnableClassResilience) {
ClassHasFixedFieldCount = false;
} else {
addFieldsForClass(superclass, superclassType);
NumInherited = Elements.size();
}

ClassHasFixedSize = false;

// Furthermore, if the superclass is a generic context, we have to
Expand Down
32 changes: 21 additions & 11 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2174,17 +2174,27 @@ llvm::Constant *IRGenModule::emitProtocolConformances() {
getPointerAlignment(), ProtocolDescriptorStructTy);
auto typeEntity = getTypeEntityInfo(*this,
conformance->getType()->getCanonicalType());
auto flags = typeEntity.flags
.withConformanceKind(ProtocolConformanceReferenceKind::WitnessTable);

// If the conformance is in this object's table, then the witness table
// should also be in this object file, so we can always directly reference
// it.
// TODO: Should use accessor kind for lazy conformances
// TODO: Produce a relative reference to a private generator function
// if the witness table requires lazy initialization, instantiation, or
// conditional conformance checking.
auto witnessTableVar = getAddrOfWitnessTable(conformance);
auto flags = typeEntity.flags;

llvm::Constant *witnessTableVar;

if (!isResilient(conformance->getProtocol(),
ResilienceExpansion::Maximal)) {
flags = flags.withConformanceKind(
ProtocolConformanceReferenceKind::WitnessTable);

// If the conformance is in this object's table, then the witness table
// should also be in this object file, so we can always directly reference
// it.
witnessTableVar = getAddrOfWitnessTable(conformance);
} else {
flags = flags.withConformanceKind(
ProtocolConformanceReferenceKind::WitnessTableAccessor);

witnessTableVar = getAddrOfWitnessTableAccessFunction(
conformance, ForDefinition);
}

auto witnessTableRef =
ConstantReference(witnessTableVar, ConstantReference::Direct);

Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4656,7 +4656,7 @@ namespace {
}

bool needsPayloadSizeInMetadata() const override {
llvm_unreachable("resilient enums cannot be defined");
return false;
}

void initializeMetadata(IRGenFunction &IGF,
Expand Down
4 changes: 4 additions & 0 deletions stdlib/public/core/ArrayBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import SwiftShims
internal typealias _ArrayBridgeStorage
= _BridgeStorage<_ContiguousArrayStorageBase, _NSArrayCore>

@_versioned
@_fixed_layout
internal struct _ArrayBuffer<Element> : _ArrayBufferProtocol {

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

@_versioned // FIXME(abi): Used from tests
internal init(nsArray: _NSArrayCore) {
_sanityCheck(_isClassOrObjCExistential(Element.self))
_storage = _ArrayBridgeStorage(objC: nsArray)
Expand Down Expand Up @@ -113,6 +115,7 @@ extension _ArrayBuffer {
/// Convert to an NSArray.
///
/// O(1) if the element type is bridged verbatim, O(*n*) otherwise.
@_versioned // FIXME(abi): Used from tests
internal func _asCocoaArray() -> _NSArrayCore {
return _fastPath(_isNative) ? _native._asCocoaArray() : _nonNative
}
Expand Down Expand Up @@ -273,6 +276,7 @@ extension _ArrayBuffer {
/// A pointer to the first element.
///
/// - Precondition: The elements are known to be stored contiguously.
@_versioned
internal var firstElementAddress: UnsafeMutablePointer<Element> {
_sanityCheck(_isNative, "must be a native buffer")
return _native.firstElementAddress
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/ArrayBufferProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

/// The underlying buffer for an ArrayType conforms to
/// `_ArrayBufferProtocol`. This buffer does not provide value semantics.
@_versioned
internal protocol _ArrayBufferProtocol
: MutableCollection, RandomAccessCollection {

Expand Down
2 changes: 2 additions & 0 deletions stdlib/public/core/Builtin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public func _onFastPath() {
// Declare it here instead of RuntimeShims.h, because we need to specify
// the type of argument to be AnyClass. This is currently not possible
// when using RuntimeShims.h
@_versioned
@_silgen_name("swift_objc_class_usesNativeSwiftReferenceCounting")
func _usesNativeSwiftReferenceCounting(_ theClass: AnyClass) -> Bool
#else
Expand Down Expand Up @@ -480,6 +481,7 @@ internal func _makeBridgeObject(
)
}

@_versioned
@_silgen_name("_swift_class_getSuperclass")
internal func _swift_class_getSuperclass(_ t: AnyClass) -> AnyClass?

Expand Down
4 changes: 4 additions & 0 deletions stdlib/public/core/ContiguousArrayBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ final class _ContiguousArrayStorage<Element> : _ContiguousArrayStorage1 {
}
}

@_versioned
@_fixed_layout
internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {

Expand Down Expand Up @@ -247,6 +248,7 @@ internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
}

/// A pointer to the first element.
@_versioned
internal var firstElementAddress: UnsafeMutablePointer<Element> {
return UnsafeMutablePointer(Builtin.projectTailElems(_storage,
Element.self))
Expand Down Expand Up @@ -318,6 +320,7 @@ internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
}

/// Get or set the value of the ith element.
@_versioned
internal subscript(i: Int) -> Element {
get {
return getElement(i)
Expand Down Expand Up @@ -434,6 +437,7 @@ internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
#endif

/// An object that keeps the elements stored in this buffer alive.
@_versioned
internal var owner: AnyObject {
return _storage
}
Expand Down
11 changes: 11 additions & 0 deletions stdlib/public/core/HashedCollections.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -2508,6 +2508,7 @@ internal struct _HashedContainerStorageHeader {
/// Enough bytes are allocated to hold the bitmap for marking valid entries,
/// keys, and values. The data layout starts with the bitmap, followed by the
/// keys, followed by the values.
@_versioned
final internal class _Native${Self}StorageImpl<${TypeParameters}> {
// Note: It is intended that ${TypeParameters}
// (without : Hashable) is used here - this storage must work
Expand Down Expand Up @@ -3229,6 +3230,7 @@ final internal class _Native${Self}StorageKeyNSEnumerator<
/// is also a proper `NS${Self}` subclass, which is returned to Objective-C
/// during bridging. `${Self}Index` points directly to
/// `_Native${Self}Storage`.
@_versioned
final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
: _SwiftNativeNS${Self}, _NS${Self}Core {

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

#if _runtime(_ObjC)
@_versioned
@_fixed_layout
internal struct _Cocoa${Self}Storage : _HashStorage {
@_versioned
internal var cocoa${Self}: _NS${Self}

internal typealias Index = _Cocoa${Self}Index
Expand Down Expand Up @@ -3695,6 +3700,8 @@ internal struct _Cocoa${Self}Storage : _HashStorage {
internal struct _Cocoa${Self}Storage {}
#endif

@_versioned
@_fixed_layout
internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorage {

internal typealias NativeStorage = _Native${Self}Storage<${TypeParameters}>
Expand Down Expand Up @@ -4408,6 +4415,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorage {
}
}

@_versioned
internal struct _Native${Self}Index<${TypeParametersDecl}> :
Comparable {

Expand All @@ -4418,6 +4426,8 @@ internal struct _Native${Self}Index<${TypeParametersDecl}> :
// the new model.
@_versioned
internal var nativeStorage: NativeStorage

@_versioned
internal var offset: Int

@_versioned
Expand Down Expand Up @@ -4799,6 +4809,7 @@ final internal class _Cocoa${Self}Iterator : IteratorProtocol {
final internal class _Cocoa${Self}Iterator {}
#endif

@_versioned
internal enum ${Self}IteratorRepresentation<${TypeParametersDecl}> {
internal typealias _Iterator = ${Self}Iterator<${TypeParameters}>
internal typealias _NativeStorageOwner =
Expand Down
21 changes: 21 additions & 0 deletions stdlib/public/core/SipHash.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
/// * Daniel J. Bernstein <[email protected]>
//===----------------------------------------------------------------------===//

@_versioned
internal enum _SipHashDetail {
@_versioned
@inline(__always)
internal static func _rotate(_ x: UInt64, leftBy amount: Int) -> UInt64 {
return (x << UInt64(amount)) | (x >> (64 - UInt64(amount)))
}

@_versioned
@inline(__always)
internal static func _loadUnalignedUInt64LE(
from p: UnsafeRawPointer
Expand All @@ -40,6 +43,7 @@ internal enum _SipHashDetail {
(UInt64(p.load(fromByteOffset: 7, as: UInt8.self)) << 56)
}

@_versioned
@inline(__always)
internal static func _loadPartialUnalignedUInt64LE(
from p: UnsafeRawPointer,
Expand All @@ -57,6 +61,7 @@ internal enum _SipHashDetail {
return result
}

@_versioned
@inline(__always)
internal static func _sipRound(
v0: inout UInt64,
Expand Down Expand Up @@ -87,16 +92,28 @@ internal enum _SipHashDetail {
public // @testable
struct ${Self} {
// "somepseudorandomlygeneratedbytes"
@_versioned
internal var v0: UInt64 = 0x736f6d6570736575

@_versioned
internal var v1: UInt64 = 0x646f72616e646f6d

@_versioned
internal var v2: UInt64 = 0x6c7967656e657261

@_versioned
internal var v3: UInt64 = 0x7465646279746573

@_versioned
internal var hashedByteCount: UInt64 = 0

@_versioned
internal var dataTail: UInt64 = 0

@_versioned
internal var dataTailByteCount: Int = 0

@_versioned
internal var finalizedHash: UInt64?

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

// FIXME(ABI)#63 (UnsafeRawBufferPointer): Use UnsafeRawBufferPointer.
@_versioned
@inline(__always)
internal mutating func _append_alwaysInline(
_ data: UnsafeRawPointer,
Expand Down Expand Up @@ -165,6 +183,7 @@ struct ${Self} {

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

@_versioned
@inline(__always)
internal mutating func _finalizeAndReturnHash_alwaysInline() -> UInt64 {
if let finalizedHash = finalizedHash {
Expand Down Expand Up @@ -238,6 +258,7 @@ struct ${Self} {
}

// FIXME(ABI)#65 (UnsafeRawBufferPointer): Use UnsafeRawBufferPointer.
@_versioned
@inline(__always)
public // @testable
static func _hash_alwaysInline(
Expand Down
Loading