Skip to content

Commit b07a17e

Browse files
authored
Merge branch 'master' into objc-protocols-have-a-layout-constraint
2 parents 92bc89b + 0e6cf6d commit b07a17e

File tree

190 files changed

+6501
-7456
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+6501
-7456
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ option(SWIFT_REPORT_STATISTICS
369369
"Create json files which contain internal compilation statistics"
370370
FALSE)
371371

372+
option(SWIFT_DISABLE_OBJC_INTEROP
373+
"Disable Objective-C interoperability even on platforms what would normally have it"
374+
FALSE)
375+
372376
#
373377
# User-configurable experimental options. Do not use in production builds.
374378
#

cmake/modules/AddSwift.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function(_add_host_variant_c_compile_link_flags name)
9393

9494
set(_sysroot
9595
"${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}")
96-
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
96+
if(SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_USE_ISYSROOT)
9797
target_compile_options(${name} PRIVATE -isysroot;${_sysroot})
9898
elseif(NOT SWIFT_COMPILER_IS_MSVC_LIKE AND NOT "${_sysroot}" STREQUAL "/")
9999
target_compile_options(${name} PRIVATE --sysroot=${_sysroot})

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ endfunction()
145145
# SWIFT_SDK_${prefix}_LIB_SUBDIR Library subdir for this SDK
146146
# SWIFT_SDK_${prefix}_VERSION_MIN_NAME Version min name for this SDK
147147
# SWIFT_SDK_${prefix}_TRIPLE_NAME Triple name for this SDK
148+
# SWIFT_SDK_${prefix}_OBJECT_FORMAT The object file format (e.g. MACHO)
149+
# SWIFT_SDK_${prefix}_USE_ISYSROOT Whether to use -isysroot
148150
# SWIFT_SDK_${prefix}_ARCHITECTURES Architectures (as a list)
149151
# SWIFT_SDK_${prefix}_IS_SIMULATOR Whether this is a simulator target.
150152
# SWIFT_SDK_${prefix}_ARCH_${ARCH}_TRIPLE Triple name
@@ -187,6 +189,7 @@ macro(configure_sdk_darwin
187189
set(SWIFT_SDK_${prefix}_VERSION_MIN_NAME "${version_min_name}")
188190
set(SWIFT_SDK_${prefix}_TRIPLE_NAME "${triple_name}")
189191
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "MACHO")
192+
set(SWIFT_SDK_${prefix}_USE_ISYSROOT TRUE)
190193

191194
set(SWIFT_SDK_${prefix}_ARCHITECTURES ${architectures})
192195
if(SWIFT_DARWIN_SUPPORTED_ARCHS)
@@ -270,6 +273,7 @@ macro(configure_sdk_unix name architectures)
270273
else()
271274
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "ELF")
272275
endif()
276+
set(SWIFT_SDK_${prefix}_USE_ISYSROOT FALSE)
273277

274278
foreach(arch ${architectures})
275279
if("${prefix}" STREQUAL "ANDROID")
@@ -432,6 +436,7 @@ macro(configure_sdk_windows name environment architectures)
432436
set(SWIFT_SDK_${prefix}_LIB_SUBDIR "windows")
433437
set(SWIFT_SDK_${prefix}_ARCHITECTURES "${architectures}")
434438
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "COFF")
439+
set(SWIFT_SDK_${prefix}_USE_ISYSROOT FALSE)
435440

436441
foreach(arch ${architectures})
437442
if(arch STREQUAL armv7)

docs/ABI/Mangling.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,3 +1107,40 @@ nominal type descriptor symbol for ``CxxStruct`` while compiling the ``main`` mo
11071107
.. code::
11081108
11091109
sSo9CxxStructVMn // -> nominal type descriptor for __C.CxxStruct
1110+
1111+
Importing C++ class template instantiations
1112+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1113+
1114+
A class template instantiation is imported as a struct named
1115+
``__CxxTemplateInst`` plus Itanium mangled type of the instantiation (see the
1116+
``type`` production in the Itanium specification). Note that Itanium mangling is
1117+
used on all platforms, regardless of the ABI of the C++ toolchain, to ensure
1118+
that the mangled name is a valid Swift type name (this is not the case for MSVC
1119+
mangled names). A prefix with a double underscore (to ensure we have a reserved
1120+
C++ identifier) is added to limit the possibility for conflicts with names of
1121+
user-defined structs. The struct is notionally defined in the ``__C`` module,
1122+
similarly to regular C and C++ structs and classes. Consider the following C++
1123+
module:
1124+
1125+
.. code-block:: c++
1126+
1127+
template<class T>
1128+
struct MagicWrapper {
1129+
T t;
1130+
};
1131+
1132+
struct MagicNumber {};
1133+
1134+
typedef MagicWrapper<MagicNumber> WrappedMagicNumber;
1135+
1136+
``WrappedMagicNumber`` is imported as a typealias for struct
1137+
``__CxxTemplateInst12MagicWrapperI11MagicNumberE``. Interface of the imported
1138+
module looks as follows:
1139+
1140+
.. code-block:: swift
1141+
1142+
struct __CxxTemplateInst12MagicWrapperI11MagicNumberE {
1143+
var t: MagicNumber
1144+
}
1145+
struct MagicNumber {}
1146+
typealias WrappedMagicNumber = __CxxTemplateInst12MagicWrapperI11MagicNumberE

docs/CppInteroperabilityManifesto.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Assumptions:
6767
+ [Function templates: calls with generic type parameters](#function-templates-calls-with-generic-type-parameters)
6868
+ [Function templates: importing as real generic functions](#function-templates-importing-as-real-generic-functions)
6969
+ [Class templates](#class-templates)
70+
+ [Class templates: importing instantiation behind typedef](#class-templates-importing-instantiation-behind-typedef)
7071
+ [Class templates: importing specific specilalizations](#class-templates-importing-specific-specilalizations)
7172
+ [Class templates: using with generic type parameters](#class-templates-using-with-generic-type-parameters)
7273
+ [Class templates: using in generic code through a synthesized protocol](#class-templates-using-in-generic-code-through-a-synthesized-protocol)
@@ -2575,6 +2576,45 @@ We could ignore explicit specializations of function templates, because they
25752576
don't affect the API. Explicit specializations of class templates can
25762577
dramatically change the API of the type.
25772578

2579+
### Class templates: Importing full class template instantiations
2580+
2581+
A class template instantiation could be imported as a struct named
2582+
`__CxxTemplateInst` plus Itanium mangled type of the instantiation (see the
2583+
`type` production in the Itanium specification). Note that Itanium mangling is
2584+
used on all platforms, regardless of the ABI of the C++ toolchain, to ensure
2585+
that the mangled name is a valid Swift type name (this is not the case for MSVC
2586+
mangled names). A prefix with a double underscore (to ensure we have a reserved
2587+
C++ identifier) is added to limit the possibility for conflicts with names of
2588+
user-defined structs. The struct is notionally defined in the `__C` module,
2589+
similarly to regular C and C++ structs and classes. Consider the following C++
2590+
module:
2591+
2592+
```c++
2593+
// C++ header.
2594+
2595+
template<class T>
2596+
struct MagicWrapper {
2597+
T t;
2598+
};
2599+
struct MagicNumber {};
2600+
2601+
typedef MagicWrapper<MagicNumber> WrappedMagicNumber;
2602+
```
2603+
2604+
`WrappedMagicNumber` will be imported as a typealias for a struct
2605+
`__CxxTemplateInst12MagicWrapperI11MagicNumberE`. Interface of the imported
2606+
module will look as follows:
2607+
2608+
```swift
2609+
// C++ header imported to Swift.
2610+
2611+
struct __CxxTemplateInst12MagicWrapperI11MagicNumberE {
2612+
var t: MagicNumber
2613+
}
2614+
struct MagicNumber {}
2615+
typealias WrappedMagicNumber = __CxxTemplateInst12MagicWrapperI11MagicNumberE
2616+
```
2617+
25782618
### Class templates: importing specific specilalizations
25792619

25802620
Just like with calls to C++ function templates, it is easy to compile a use of a
@@ -2752,7 +2792,7 @@ func useConcrete() {
27522792

27532793
### Class templates: importing as real generic structs
27542794

2755-
If we know the complete set of allowed type arguments to a C++ function
2795+
If we know the complete set of allowed type arguments to a C++ struct
27562796
template, we could import it as an actual Swift generic struct. Every method of
27572797
that struct will perform dynamic dispatch based on type parameters. See
27582798
the section about function templates for more details.

0 commit comments

Comments
 (0)