-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Runtime] Add a disabled workaround for protocol conformance checking to check conformances in reverse order. #35061
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
mikeash
merged 1 commit into
swiftlang:main
from
mikeash:protocol-conformance-iteration-order-workaround
Dec 14, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,31 @@ | ||
//===--- Bincompat.h - Binary compatibility checks. -------------*- C++ -*-===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2020 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Checks for enabling binary compatibility workarounds. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
namespace swift { | ||
|
||
namespace runtime { | ||
|
||
namespace bincompat { | ||
|
||
/// Whether protocol conformance iteration should be reversed, to prefer | ||
/// conformances from images that are later in the list over earlier ones. | ||
bool workaroundProtocolConformanceReverseIteration(); | ||
|
||
} // namespace bincompat | ||
|
||
} // namespace runtime | ||
|
||
} // namespace swift |
This file contains hidden or 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,31 @@ | ||
//===--- Bincompat.cpp - Binary compatibility checks. -----------*- C++ -*-===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2020 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Checks for enabling binary compatibility workarounds. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "swift/Runtime/Bincompat.h" | ||
|
||
namespace swift { | ||
|
||
namespace runtime { | ||
|
||
namespace bincompat { | ||
|
||
bool workaroundProtocolConformanceReverseIteration() { return false; } | ||
|
||
} // namespace bincompat | ||
|
||
} // namespace runtime | ||
|
||
} // namespace swift |
This file contains hidden or 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 hidden or 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 hidden or 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,76 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-build-swift %s -o %t/newSDK %target-link-sdk-future-version | ||
// RUN: %target-codesign %t/newSDK | ||
// RUN: %target-run %t/newSDK newSDK | ||
// RUN: %target-build-swift %s -o %t/oldSDK %target-link-sdk-2020-version | ||
// RUN: %target-codesign %t/oldSDK | ||
// RUN: %target-run %t/oldSDK oldSDK | ||
|
||
// REQUIRES: VENDOR=apple | ||
|
||
// Simulators refuse to run binaries built with an SDK newer than the simulator. | ||
// UNSUPPORTED: DARWIN_SIMULATOR=ios | ||
// UNSUPPORTED: DARWIN_SIMULATOR=tvos | ||
// UNSUPPORTED: DARWIN_SIMULATOR=watchos | ||
|
||
import Accelerate | ||
import Foundation | ||
import StdlibUnittest | ||
import SwiftShims | ||
|
||
|
||
extension CFString: Hashable { | ||
static var localHashableCallCount = 0 | ||
public var hashValue: Int { | ||
Self.localHashableCallCount += 1 | ||
return (self as String).hashValue | ||
} | ||
} | ||
|
||
protocol P { | ||
func firstHashValue() -> Int | ||
} | ||
|
||
extension Set: P { | ||
func firstHashValue() -> Int { | ||
return first!.hashValue | ||
} | ||
} | ||
|
||
@_optimize(none) | ||
func firstHashValue(_ x: P) -> Int { | ||
x.firstHashValue() | ||
} | ||
|
||
let osHasWorkaround: Bool | ||
// These are deliberately NOT version 9999, as we don't want to hit the special | ||
// case where development runtimes always return true for 9999. This check needs | ||
// to be false until real version numbers are put in. | ||
if #available(macOS 99990, iOS 99990, tvOS 99990, watchOS 99990, *) { | ||
osHasWorkaround = true | ||
} else { | ||
osHasWorkaround = false | ||
} | ||
|
||
let testingOldSDK = CommandLine.arguments.last == "oldSDK" | ||
|
||
var tests: TestSuite | ||
|
||
if testingOldSDK { | ||
tests = TestSuite("old SDK protocol conformance collision") | ||
tests.test("CFString: Hashable conformance") { | ||
_ = firstHashValue(NSSet(object: "Whatever") as! Set<CFString>) | ||
|
||
let expectedCallCount = osHasWorkaround ? 1 : 0 | ||
expectEqual(expectedCallCount, CFString.localHashableCallCount) | ||
} | ||
} else { | ||
tests = TestSuite("new SDK protocol conformance collision") | ||
tests.test("CFString: Hashable conformance") { | ||
_ = firstHashValue(NSSet(object: "Whatever") as! Set<CFString>) | ||
|
||
expectEqual(0, CFString.localHashableCallCount) | ||
} | ||
} | ||
|
||
runAllTests() |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to do something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed offline, we can't mutate in place, but we settled on: