forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request swiftlang#25030 from jckarter/SR-10600-back-deploy
Introduce a backward-deployment library for SR-10600.
- Loading branch information
Showing
11 changed files
with
260 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
set(swift_runtime_compile_flags ${SWIFT_RUNTIME_CORE_CXX_FLAGS}) | ||
set(swift_runtime_linker_flags ${SWIFT_RUNTIME_CORE_LINK_FLAGS}) | ||
|
||
add_swift_target_library(swiftCompatibility50 TARGET_LIBRARY STATIC | ||
ProtocolConformance.cpp | ||
Overrides.cpp | ||
C_COMPILE_FLAGS ${swift_runtime_library_compile_flags} | ||
LINK_FLAGS ${swift_runtime_linker_flags} | ||
TARGET_SDKS ${SWIFT_APPLE_PLATFORMS} | ||
INSTALL_IN_COMPONENT stdlib) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//===--- Overrides.cpp - Compat override table for Swift 5.0 runtime ------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file provides compatibility override hooks for Swift 5.0 runtimes. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "Overrides.h" | ||
#include "../runtime/CompatibilityOverride.h" | ||
|
||
using namespace swift; | ||
|
||
struct OverrideSection { | ||
uintptr_t version; | ||
#define OVERRIDE(name, ret, attrs, ccAttrs, namespace, typedArgs, namedArgs) \ | ||
Override_ ## name name; | ||
#include "../runtime/CompatibilityOverride.def" | ||
}; | ||
|
||
OverrideSection Overrides | ||
__attribute__((used, section("__DATA,__swift_hooks"))) = { | ||
.version = 0, | ||
.conformsToProtocol = swift50override_conformsToProtocol, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//===--- Overrides.cpp - Compat overrides for Swift 5.0 runtime ----s------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file provides compatibility override hooks for Swift 5.0 runtimes. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "swift/Basic/LLVM.h" | ||
#include "swift/Runtime/Metadata.h" | ||
|
||
namespace swift { | ||
|
||
using ConformsToProtocol_t = | ||
const WitnessTable *(const Metadata *, const ProtocolDescriptor *); | ||
|
||
const WitnessTable * | ||
swift50override_conformsToProtocol(const Metadata * const type, | ||
const ProtocolDescriptor *protocol, | ||
ConformsToProtocol_t *original); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//===--- ProtocolConformance.cpp - Swift protocol conformance checking ----===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Checking and caching of Swift protocol conformances. | ||
// | ||
// This implementation is intended to be backward-deployed into Swift 5.0 | ||
// runtimes. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "Overrides.h" | ||
#include "../runtime/Private.h" | ||
#include "swift/Basic/Lazy.h" | ||
#include <objc/runtime.h> | ||
|
||
using namespace swift; | ||
|
||
// Clone of private function getRootSuperclass. This returns the SwiftObject | ||
// class in the ABI-stable dylib, regardless of what the local runtime build | ||
// does, since we're always patching an ABI-stable dylib. | ||
__attribute__((visibility("hidden"), weak)) | ||
const ClassMetadata *swift::getRootSuperclass() { | ||
auto theClass = SWIFT_LAZY_CONSTANT(objc_getClass("_TtCs12_SwiftObject")); | ||
return (const ClassMetadata *)theClass; | ||
} | ||
|
||
// Clone of private helper swift::_swiftoverride_class_getSuperclass | ||
// for use in the override implementation. | ||
static const Metadata *_swift50override_class_getSuperclass( | ||
const Metadata *theClass) { | ||
if (const ClassMetadata *classType = theClass->getClassObject()) { | ||
if (classHasSuperclass(classType)) | ||
return getMetadataForClass(classType->Superclass); | ||
} | ||
|
||
if (const ForeignClassMetadata *foreignClassType | ||
= dyn_cast<ForeignClassMetadata>(theClass)) { | ||
if (const Metadata *superclass = foreignClassType->Superclass) | ||
return superclass; | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
const WitnessTable * | ||
swift::swift50override_conformsToProtocol(const Metadata *type, | ||
const ProtocolDescriptor *protocol, | ||
ConformsToProtocol_t *original_conformsToProtocol) | ||
{ | ||
// The implementation of swift_conformsToProtocol in Swift 5.0 would return | ||
// a false negative answer when asking whether a subclass conforms using | ||
// a conformance from a superclass. Work around this by walking up the | ||
// superclass chain in cases where the original implementation returns | ||
// null. | ||
do { | ||
auto result = original_conformsToProtocol(type, protocol); | ||
if (result) | ||
return result; | ||
} while ((type = _swift50override_class_getSuperclass(type))); | ||
|
||
return nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// RUN: %target-run-simple-swift | %FileCheck %s | ||
|
||
public class BaseView { } | ||
public class GenericView<T>: BaseView { } | ||
public class FinalView: GenericView<ContentForTheView> { } | ||
|
||
|
||
public class ContentForTheView { } | ||
extension ContentForTheView: InfoNeededByControllers { } | ||
|
||
public protocol ConditionallyConformed { } | ||
public protocol InfoNeededByControllers { } | ||
|
||
extension GenericView: ConditionallyConformed where T: InfoNeededByControllers { } | ||
|
||
open class BaseGenericController<T> where T: BaseView & ConditionallyConformed { } | ||
|
||
|
||
open class FinalController: BaseGenericController<FinalView> { public override init() { } } | ||
|
||
// CHECK: FinalController | ||
print(FinalController()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters