mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
* Refactor Bincompat Organize everything around internal functions that test for a particular OS version. Correctly handle cases where we don't know the version of the app. Make all bincompat functions consistently return `true` for the legacy semantics, `false` for new semantics. Consistently name them all to reflect this. * Conditionalize the support for SR-14635 SR-14635 pointed out a hole in the updated dynamic casting logic that allowed certain casts that should have been illegal. In particular, when casting certain types to Obj-C protocols, the Swift value gets boxed; we would permit the cast to succeed whenever the resulting box satisfied the protocol. For example, this allowed any Swift value to be cast to `NSCopying` regardless of whether or not it implemented the required `copy(with:)` method. This was fixed in #37683 to reject such casts but of course some folks were depending on this behavior to pass Swift data into Obj-C functions. (The properly supported approach for passing arbitrary Swift data into Obj-C functions is to cast the Swift value to `AnyObject`.) This change makes that new behavior conditional. For now, the legacy semantics are enabled on Apple platforms and the new semantics are in use everywhere else. This will allow us to gradually enable enforcement of the new behavior over time. * Just skip this test on Apple platforms, since it is inconsistently implemented there (and is therefore not really testable)
46 lines
1.5 KiB
C++
46 lines
1.5 KiB
C++
//===--- 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.
|
|
/// Default is false starting with Swift 5.4.
|
|
bool useLegacyProtocolConformanceReverseIteration();
|
|
|
|
/// Whether we should crash when we encounter a non-nullable Obj-C
|
|
/// reference with a null value as the source of a cast.
|
|
/// Default is true starting with Swift 5.4.
|
|
bool useLegacyPermissiveObjCNullSemanticsInCasting();
|
|
|
|
/// Whether we should use the legacy semantics for casting nil optionals
|
|
/// to nested optionals
|
|
bool useLegacyOptionalNilInjectionInCasting();
|
|
|
|
/// Whether to use legacy semantics when boxing Swift values for
|
|
/// Obj-C interop
|
|
bool useLegacyObjCBoxingInCasting();
|
|
|
|
} // namespace bincompat
|
|
|
|
} // namespace runtime
|
|
|
|
} // namespace swift
|