Skip to content

Commit a10356a

Browse files
authored
Merge pull request #80680 from slavapestov/compatibility-span-6.2
[6.2] Cherry-pick recent CompatibilitySpan work
2 parents cbb0347 + d62e385 commit a10356a

File tree

17 files changed

+266
-70
lines changed

17 files changed

+266
-70
lines changed

Runtimes/Core/cmake/modules/AvailabilityMacros.cmake

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
file(STRINGS "${SwiftCore_SWIFTC_SOURCE_DIR}/utils/availability-macros.def" availability_defs)
1+
configure_file("${SwiftCore_SWIFTC_SOURCE_DIR}/utils/availability-macros.def"
2+
"${CMAKE_CURRENT_BINARY_DIR}/availability-macros.def"
3+
COPYONLY)
4+
file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/availability-macros.def" availability_defs)
25
list(FILTER availability_defs EXCLUDE REGEX "^\\s*(#.*)?$")
36
foreach(def ${availability_defs})
47
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -define-availability -Xfrontend \"${def}\">")

Runtimes/Core/core/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ target_compile_options(swiftCore PRIVATE
301301
$<$<COMPILE_LANGUAGE:Swift>:-nostdimport>
302302
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -group-info-path -Xfrontend ${CMAKE_CURRENT_SOURCE_DIR}/GroupInfo.json>"
303303
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-objc-attr-requires-foundation-module>"
304-
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -require-explicit-availability=ignore>")
304+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -require-explicit-availability=ignore>"
305+
"$<$<AND:$<PLATFORM_ID:Darwin>,$<COMPILE_LANGUAGE:Swift>>:SHELL:-Xfrontend -previous-module-installname-map-file -Xfrontend ${CMAKE_CURRENT_SOURCE_DIR}/PreviousModuleInstallName.json>")
305306
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
306307
# Using these in MinSizeRel would result in a 15% increase in the binary size
307308
target_compile_options(swiftCore PRIVATE

include/swift/AST/RuntimeVersions.def

+4-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ RUNTIME_VERSION(
152152

153153
RUNTIME_VERSION(
154154
(6, 1),
155-
FUTURE
155+
PLATFORM(macOS, (15, 4, 0))
156+
PLATFORM(iOS, (18, 4, 0))
157+
PLATFORM(watchOS, (11, 4, 0))
158+
PLATFORM(visionOS,(2, 4, 0))
156159
)
157160

158161
RUNTIME_VERSION(

stdlib/cmake/modules/AddSwiftStdlib.cmake

+22-3
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,8 @@ endfunction()
721721
# [DONT_EMBED_BITCODE]
722722
# [IS_STDLIB]
723723
# [IS_STDLIB_CORE]
724+
# [ONLY_SWIFTMODULE]
725+
# [NO_SWIFTMODULE]
724726
# [IS_SDK_OVERLAY]
725727
# [IS_FRAGILE]
726728
# INSTALL_IN_COMPONENT comp
@@ -742,9 +744,6 @@ endfunction()
742744
# STATIC
743745
# Build a static library.
744746
#
745-
# ONLY_SWIFTMODULE
746-
# Do not build either static or shared, build just the .swiftmodule.
747-
#
748747
# SDK sdk
749748
# SDK to build for.
750749
#
@@ -784,6 +783,12 @@ endfunction()
784783
# IS_STDLIB_CORE
785784
# Compile as the standard library core.
786785
#
786+
# ONLY_SWIFTMODULE
787+
# Do not build either static or shared, build just the .swiftmodule.
788+
#
789+
# NO_SWIFTMODULE
790+
# Only build either static or shared, and skip the .swiftmodule.
791+
#
787792
# IS_SDK_OVERLAY
788793
# Treat the library as a part of the Swift SDK overlay.
789794
#
@@ -811,6 +816,7 @@ function(add_swift_target_library_single target name)
811816
SHARED
812817
STATIC
813818
ONLY_SWIFTMODULE
819+
NO_SWIFTMODULE
814820
NO_LINK_NAME
815821
INSTALL_WITH_SHARED
816822
IS_FRAGILE)
@@ -1035,6 +1041,7 @@ function(add_swift_target_library_single target name)
10351041
${SWIFTLIB_SINGLE_IS_SDK_OVERLAY_keyword}
10361042
${SWIFTLIB_SINGLE_IS_FRAGILE_keyword}
10371043
${SWIFTLIB_SINGLE_ONLY_SWIFTMODULE_keyword}
1044+
${SWIFTLIB_SINGLE_NO_SWIFTMODULE_keyword}
10381045
${embed_bitcode_arg}
10391046
${SWIFTLIB_SINGLE_STATIC_keyword}
10401047
${SWIFTLIB_SINGLE_NO_LINK_NAME_keyword}
@@ -1686,6 +1693,8 @@ endfunction()
16861693
# [INSTALL]
16871694
# [IS_STDLIB]
16881695
# [IS_STDLIB_CORE]
1696+
# [ONLY_SWIFTMODULE]
1697+
# [NO_SWIFTMODULE]
16891698
# [INSTALL_WITH_SHARED]
16901699
# INSTALL_IN_COMPONENT comp
16911700
# DEPLOYMENT_VERSION_OSX version
@@ -1794,6 +1803,12 @@ endfunction()
17941803
# IS_STDLIB_CORE
17951804
# Compile as the Swift standard library core.
17961805
#
1806+
# ONLY_SWIFTMODULE
1807+
# Do not build either static or shared, build just the .swiftmodule.
1808+
#
1809+
# NO_SWIFTMODULE
1810+
# Only build either static or shared, and skip the .swiftmodule.
1811+
#
17971812
# IS_SDK_OVERLAY
17981813
# Treat the library as a part of the Swift SDK overlay.
17991814
#
@@ -1882,6 +1897,8 @@ function(add_swift_target_library name)
18821897
IS_STDLIB_CORE
18831898
IS_SWIFT_ONLY
18841899
NOSWIFTRT
1900+
ONLY_SWIFTMODULE
1901+
NO_SWIFTMODULE
18851902
OBJECT_LIBRARY
18861903
SHARED
18871904
STATIC
@@ -2493,6 +2510,8 @@ function(add_swift_target_library name)
24932510
${SWIFTLIB_IS_STDLIB_CORE_keyword}
24942511
${SWIFTLIB_IS_SDK_OVERLAY_keyword}
24952512
${SWIFTLIB_NOSWIFTRT_keyword}
2513+
${SWIFTLIB_ONLY_SWIFTMODULE_keyword}
2514+
${SWIFTLIB_NO_SWIFTMODULE_keyword}
24962515
DARWIN_INSTALL_NAME_DIR "${SWIFTLIB_DARWIN_INSTALL_NAME_DIR}"
24972516
INSTALL_IN_COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
24982517
DEPLOYMENT_VERSION_OSX "${SWIFTLIB_DEPLOYMENT_VERSION_OSX}"

stdlib/cmake/modules/SwiftSource.cmake

+11-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function(handle_swift_sources
4949
dependency_sibgen_target_out_var_name
5050
sourcesvar externalvar name)
5151
cmake_parse_arguments(SWIFTSOURCES
52-
"IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE;STATIC;NO_LINK_NAME;IS_FRAGILE;ONLY_SWIFTMODULE"
52+
"IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE;STATIC;NO_LINK_NAME;IS_FRAGILE;ONLY_SWIFTMODULE;NO_SWIFTMODULE"
5353
"SDK;ARCHITECTURE;INSTALL_IN_COMPONENT;DEPLOYMENT_VERSION_OSX;DEPLOYMENT_VERSION_IOS;DEPLOYMENT_VERSION_TVOS;DEPLOYMENT_VERSION_WATCHOS;MACCATALYST_BUILD_FLAVOR;BOOTSTRAPPING;INSTALL_BINARY_SWIFTMODULE"
5454
"DEPENDS;COMPILE_FLAGS;MODULE_NAME;MODULE_DIR;ENABLE_LTO"
5555
${ARGN})
@@ -66,6 +66,7 @@ function(handle_swift_sources
6666
translate_flag(${SWIFTSOURCES_NO_LINK_NAME} "NO_LINK_NAME" NO_LINK_NAME_arg)
6767
translate_flag(${SWIFTSOURCES_IS_FRAGILE} "IS_FRAGILE" IS_FRAGILE_arg)
6868
translate_flag(${SWIFTSOURCES_ONLY_SWIFTMODULE} "ONLY_SWIFTMODULE" ONLY_SWIFTMODULE_arg)
69+
translate_flag(${SWIFTSOURCES_NO_SWIFTMODULE} "NO_SWIFTMODULE" NO_SWIFTMODULE_arg)
6970
if(DEFINED SWIFTSOURCES_BOOTSTRAPPING)
7071
set(BOOTSTRAPPING_arg "BOOTSTRAPPING" ${SWIFTSOURCES_BOOTSTRAPPING})
7172
endif()
@@ -161,6 +162,7 @@ function(handle_swift_sources
161162
${BOOTSTRAPPING_arg}
162163
${IS_FRAGILE_arg}
163164
${ONLY_SWIFTMODULE_arg}
165+
${NO_SWIFTMODULE_arg}
164166
INSTALL_BINARY_SWIFTMODULE ${SWIFTSOURCES_INSTALL_BINARY_SWIFTMODULE}
165167
INSTALL_IN_COMPONENT "${SWIFTSOURCES_INSTALL_IN_COMPONENT}"
166168
DEPLOYMENT_VERSION_OSX ${SWIFTSOURCES_DEPLOYMENT_VERSION_OSX}
@@ -405,6 +407,8 @@ endfunction()
405407
# [IS_MAIN] # This is an executable, not a library
406408
# [IS_STDLIB]
407409
# [IS_STDLIB_CORE] # This is the core standard library
410+
# [ONLY_SWIFTMODULE] # Emit swiftmodule only, no binary
411+
# [NO_SWIFTMODULE] # Emit binary only, no swiftmodule
408412
# [OPT_FLAGS] # Optimization flags (overrides SWIFT_OPTIMIZE)
409413
# [MODULE_DIR] # Put .swiftmodule, .swiftdoc., and .o
410414
# # into this directory.
@@ -419,7 +423,7 @@ function(_compile_swift_files
419423
dependency_sib_target_out_var_name dependency_sibopt_target_out_var_name
420424
dependency_sibgen_target_out_var_name)
421425
cmake_parse_arguments(SWIFTFILE
422-
"IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE;STATIC;IS_FRAGILE;ONLY_SWIFTMODULE"
426+
"IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE;STATIC;IS_FRAGILE;ONLY_SWIFTMODULE;NO_SWIFTMODULE"
423427
"OUTPUT;MODULE_NAME;INSTALL_IN_COMPONENT;DEPLOYMENT_VERSION_OSX;DEPLOYMENT_VERSION_IOS;DEPLOYMENT_VERSION_TVOS;DEPLOYMENT_VERSION_WATCHOS;MACCATALYST_BUILD_FLAVOR;BOOTSTRAPPING;INSTALL_BINARY_SWIFTMODULE"
424428
"SOURCES;FLAGS;DEPENDS;SDK;ARCHITECTURE;OPT_FLAGS;MODULE_DIR"
425429
${ARGN})
@@ -678,6 +682,10 @@ function(_compile_swift_files
678682
get_bootstrapping_path(lib_dir ${SWIFTLIB_DIR} "${SWIFTFILE_BOOTSTRAPPING}")
679683

680684
if(NOT SWIFTFILE_IS_MAIN)
685+
list(APPEND swift_flags "-parse-as-library")
686+
endif()
687+
688+
if(NOT SWIFTFILE_IS_MAIN AND NOT SWIFTFILE_NO_SWIFTMODULE)
681689
# Determine the directory where the module file should be placed.
682690
if(SWIFTFILE_MODULE_DIR)
683691
set(module_dir "${SWIFTFILE_MODULE_DIR}")
@@ -687,8 +695,6 @@ function(_compile_swift_files
687695
message(FATAL_ERROR "Don't know where to put the module files")
688696
endif()
689697

690-
list(APPEND swift_flags "-parse-as-library")
691-
692698
set(module_base "${module_dir}/${SWIFTFILE_MODULE_NAME}")
693699

694700
set(module_dir_static "${SWIFTSTATICLIB_DIR}/${library_subdir}")
@@ -1068,7 +1074,7 @@ function(_compile_swift_files
10681074
#
10691075
# We only build these when we are not producing a main file. We could do this
10701076
# with sib/sibgen, but it is useful for looking at the stdlib.
1071-
if (NOT SWIFTFILE_IS_MAIN)
1077+
if (NOT SWIFTFILE_IS_MAIN AND NOT SWIFTFILE_NO_SWIFTMODULE)
10721078
add_custom_command_target(
10731079
module_dependency_target
10741080
COMMAND
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
33
"module": "CompatibilitySpan",
4-
"install_name": "/usr/lib/swift/libswiftCompatibilitySpan.dylib"
4+
"install_name": "@rpath/libswiftCompatibilitySpan.dylib"
55
}
66
]

stdlib/public/core/Span/MutableRawSpan.swift

+31-11
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if SPAN_COMPATIBILITY_STUB
14+
import Swift
15+
#endif
16+
1317
// A MutableRawSpan represents a span of memory which
1418
// contains initialized `Element` instances.
1519
@safe
1620
@frozen
17-
@available(SwiftStdlib 6.2, *)
21+
@available(SwiftCompatibilitySpan 5.0, *)
22+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
1823
public struct MutableRawSpan: ~Copyable & ~Escapable {
1924
@usableFromInline
2025
internal let _pointer: UnsafeMutableRawPointer?
@@ -40,10 +45,12 @@ public struct MutableRawSpan: ~Copyable & ~Escapable {
4045
}
4146
}
4247

43-
@available(SwiftStdlib 6.2, *)
48+
@available(SwiftCompatibilitySpan 5.0, *)
49+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
4450
extension MutableRawSpan: @unchecked Sendable {}
4551

46-
@available(SwiftStdlib 6.2, *)
52+
@available(SwiftCompatibilitySpan 5.0, *)
53+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
4754
extension MutableRawSpan {
4855

4956
@unsafe
@@ -115,7 +122,8 @@ extension MutableRawSpan {
115122
}
116123
}
117124

118-
@available(SwiftStdlib 6.2, *)
125+
@available(SwiftCompatibilitySpan 5.0, *)
126+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
119127
extension MutableRawSpan {
120128
@_alwaysEmitIntoClient
121129
public var byteCount: Int { _count }
@@ -129,7 +137,8 @@ extension MutableRawSpan {
129137
}
130138
}
131139

132-
@available(SwiftStdlib 6.2, *)
140+
@available(SwiftCompatibilitySpan 5.0, *)
141+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
133142
extension MutableRawSpan {
134143

135144
@_alwaysEmitIntoClient
@@ -154,7 +163,8 @@ extension MutableRawSpan {
154163
}
155164
}
156165

157-
@available(SwiftStdlib 6.2, *)
166+
@available(SwiftCompatibilitySpan 5.0, *)
167+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
158168
extension RawSpan {
159169

160170
@_alwaysEmitIntoClient
@@ -166,7 +176,8 @@ extension RawSpan {
166176
}
167177
}
168178

169-
@available(SwiftStdlib 6.2, *)
179+
@available(SwiftCompatibilitySpan 5.0, *)
180+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
170181
extension MutableRawSpan {
171182

172183
public var bytes: RawSpan {
@@ -202,7 +213,8 @@ extension MutableRawSpan {
202213
}
203214
}
204215

205-
@available(SwiftStdlib 6.2, *)
216+
@available(SwiftCompatibilitySpan 5.0, *)
217+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
206218
extension MutableRawSpan {
207219

208220
/// Returns a new instance of the given type, constructed from the raw memory
@@ -338,8 +350,13 @@ extension MutableRawSpan {
338350
}
339351
}
340352

353+
// FIXME: The functions in this extension crash the SIL optimizer when built inside
354+
// the stub. But these declarations don't generate a public symbol anyway.
355+
#if !SPAN_COMPATIBILITY_STUB
356+
341357
//MARK: copyMemory
342-
@available(SwiftStdlib 6.2, *)
358+
@available(SwiftCompatibilitySpan 5.0, *)
359+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
343360
extension MutableRawSpan {
344361

345362
@_alwaysEmitIntoClient
@@ -429,9 +446,11 @@ extension MutableRawSpan {
429446
update(fromContentsOf: source.bytes)
430447
}
431448
}
449+
#endif
432450

433451
// MARK: sub-spans
434-
@available(SwiftStdlib 6.2, *)
452+
@available(SwiftCompatibilitySpan 5.0, *)
453+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
435454
extension MutableRawSpan {
436455

437456
/// Constructs a new span over the items within the supplied range of
@@ -546,7 +565,8 @@ extension MutableRawSpan {
546565
}
547566

548567
// MARK: prefixes and suffixes
549-
@available(SwiftStdlib 6.2, *)
568+
@available(SwiftCompatibilitySpan 5.0, *)
569+
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
550570
extension MutableRawSpan {
551571

552572
/// Returns a span containing the initial elements of this span,

0 commit comments

Comments
 (0)