Skip to content

[6.2] Cherry-pick recent CompatibilitySpan work #80680

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
merged 9 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Runtimes/Core/cmake/modules/AvailabilityMacros.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
file(STRINGS "${SwiftCore_SWIFTC_SOURCE_DIR}/utils/availability-macros.def" availability_defs)
configure_file("${SwiftCore_SWIFTC_SOURCE_DIR}/utils/availability-macros.def"
"${CMAKE_CURRENT_BINARY_DIR}/availability-macros.def"
COPYONLY)
file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/availability-macros.def" availability_defs)
list(FILTER availability_defs EXCLUDE REGEX "^\\s*(#.*)?$")
foreach(def ${availability_defs})
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -define-availability -Xfrontend \"${def}\">")
Expand Down
3 changes: 2 additions & 1 deletion Runtimes/Core/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ target_compile_options(swiftCore PRIVATE
$<$<COMPILE_LANGUAGE:Swift>:-nostdimport>
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -group-info-path -Xfrontend ${CMAKE_CURRENT_SOURCE_DIR}/GroupInfo.json>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-objc-attr-requires-foundation-module>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -require-explicit-availability=ignore>")
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -require-explicit-availability=ignore>"
"$<$<AND:$<PLATFORM_ID:Darwin>,$<COMPILE_LANGUAGE:Swift>>:SHELL:-Xfrontend -previous-module-installname-map-file -Xfrontend ${CMAKE_CURRENT_SOURCE_DIR}/PreviousModuleInstallName.json>")
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
# Using these in MinSizeRel would result in a 15% increase in the binary size
target_compile_options(swiftCore PRIVATE
Expand Down
5 changes: 4 additions & 1 deletion include/swift/AST/RuntimeVersions.def
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ RUNTIME_VERSION(

RUNTIME_VERSION(
(6, 1),
FUTURE
PLATFORM(macOS, (15, 4, 0))
PLATFORM(iOS, (18, 4, 0))
PLATFORM(watchOS, (11, 4, 0))
PLATFORM(visionOS,(2, 4, 0))
)

RUNTIME_VERSION(
Expand Down
25 changes: 22 additions & 3 deletions stdlib/cmake/modules/AddSwiftStdlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,8 @@ endfunction()
# [DONT_EMBED_BITCODE]
# [IS_STDLIB]
# [IS_STDLIB_CORE]
# [ONLY_SWIFTMODULE]
# [NO_SWIFTMODULE]
# [IS_SDK_OVERLAY]
# [IS_FRAGILE]
# INSTALL_IN_COMPONENT comp
Expand All @@ -742,9 +744,6 @@ endfunction()
# STATIC
# Build a static library.
#
# ONLY_SWIFTMODULE
# Do not build either static or shared, build just the .swiftmodule.
#
# SDK sdk
# SDK to build for.
#
Expand Down Expand Up @@ -784,6 +783,12 @@ endfunction()
# IS_STDLIB_CORE
# Compile as the standard library core.
#
# ONLY_SWIFTMODULE
# Do not build either static or shared, build just the .swiftmodule.
#
# NO_SWIFTMODULE
# Only build either static or shared, and skip the .swiftmodule.
#
# IS_SDK_OVERLAY
# Treat the library as a part of the Swift SDK overlay.
#
Expand Down Expand Up @@ -811,6 +816,7 @@ function(add_swift_target_library_single target name)
SHARED
STATIC
ONLY_SWIFTMODULE
NO_SWIFTMODULE
NO_LINK_NAME
INSTALL_WITH_SHARED
IS_FRAGILE)
Expand Down Expand Up @@ -1032,6 +1038,7 @@ function(add_swift_target_library_single target name)
${SWIFTLIB_SINGLE_IS_SDK_OVERLAY_keyword}
${SWIFTLIB_SINGLE_IS_FRAGILE_keyword}
${SWIFTLIB_SINGLE_ONLY_SWIFTMODULE_keyword}
${SWIFTLIB_SINGLE_NO_SWIFTMODULE_keyword}
${embed_bitcode_arg}
${SWIFTLIB_SINGLE_STATIC_keyword}
${SWIFTLIB_SINGLE_NO_LINK_NAME_keyword}
Expand Down Expand Up @@ -1683,6 +1690,8 @@ endfunction()
# [INSTALL]
# [IS_STDLIB]
# [IS_STDLIB_CORE]
# [ONLY_SWIFTMODULE]
# [NO_SWIFTMODULE]
# [INSTALL_WITH_SHARED]
# INSTALL_IN_COMPONENT comp
# DEPLOYMENT_VERSION_OSX version
Expand Down Expand Up @@ -1791,6 +1800,12 @@ endfunction()
# IS_STDLIB_CORE
# Compile as the Swift standard library core.
#
# ONLY_SWIFTMODULE
# Do not build either static or shared, build just the .swiftmodule.
#
# NO_SWIFTMODULE
# Only build either static or shared, and skip the .swiftmodule.
#
# IS_SDK_OVERLAY
# Treat the library as a part of the Swift SDK overlay.
#
Expand Down Expand Up @@ -1879,6 +1894,8 @@ function(add_swift_target_library name)
IS_STDLIB_CORE
IS_SWIFT_ONLY
NOSWIFTRT
ONLY_SWIFTMODULE
NO_SWIFTMODULE
OBJECT_LIBRARY
SHARED
STATIC
Expand Down Expand Up @@ -2490,6 +2507,8 @@ function(add_swift_target_library name)
${SWIFTLIB_IS_STDLIB_CORE_keyword}
${SWIFTLIB_IS_SDK_OVERLAY_keyword}
${SWIFTLIB_NOSWIFTRT_keyword}
${SWIFTLIB_ONLY_SWIFTMODULE_keyword}
${SWIFTLIB_NO_SWIFTMODULE_keyword}
DARWIN_INSTALL_NAME_DIR "${SWIFTLIB_DARWIN_INSTALL_NAME_DIR}"
INSTALL_IN_COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
DEPLOYMENT_VERSION_OSX "${SWIFTLIB_DEPLOYMENT_VERSION_OSX}"
Expand Down
16 changes: 11 additions & 5 deletions stdlib/cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function(handle_swift_sources
dependency_sibgen_target_out_var_name
sourcesvar externalvar name)
cmake_parse_arguments(SWIFTSOURCES
"IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE;STATIC;NO_LINK_NAME;IS_FRAGILE;ONLY_SWIFTMODULE"
"IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE;STATIC;NO_LINK_NAME;IS_FRAGILE;ONLY_SWIFTMODULE;NO_SWIFTMODULE"
"SDK;ARCHITECTURE;INSTALL_IN_COMPONENT;DEPLOYMENT_VERSION_OSX;DEPLOYMENT_VERSION_IOS;DEPLOYMENT_VERSION_TVOS;DEPLOYMENT_VERSION_WATCHOS;MACCATALYST_BUILD_FLAVOR;BOOTSTRAPPING;INSTALL_BINARY_SWIFTMODULE"
"DEPENDS;COMPILE_FLAGS;MODULE_NAME;MODULE_DIR;ENABLE_LTO"
${ARGN})
Expand All @@ -66,6 +66,7 @@ function(handle_swift_sources
translate_flag(${SWIFTSOURCES_NO_LINK_NAME} "NO_LINK_NAME" NO_LINK_NAME_arg)
translate_flag(${SWIFTSOURCES_IS_FRAGILE} "IS_FRAGILE" IS_FRAGILE_arg)
translate_flag(${SWIFTSOURCES_ONLY_SWIFTMODULE} "ONLY_SWIFTMODULE" ONLY_SWIFTMODULE_arg)
translate_flag(${SWIFTSOURCES_NO_SWIFTMODULE} "NO_SWIFTMODULE" NO_SWIFTMODULE_arg)
if(DEFINED SWIFTSOURCES_BOOTSTRAPPING)
set(BOOTSTRAPPING_arg "BOOTSTRAPPING" ${SWIFTSOURCES_BOOTSTRAPPING})
endif()
Expand Down Expand Up @@ -161,6 +162,7 @@ function(handle_swift_sources
${BOOTSTRAPPING_arg}
${IS_FRAGILE_arg}
${ONLY_SWIFTMODULE_arg}
${NO_SWIFTMODULE_arg}
INSTALL_BINARY_SWIFTMODULE ${SWIFTSOURCES_INSTALL_BINARY_SWIFTMODULE}
INSTALL_IN_COMPONENT "${SWIFTSOURCES_INSTALL_IN_COMPONENT}"
DEPLOYMENT_VERSION_OSX ${SWIFTSOURCES_DEPLOYMENT_VERSION_OSX}
Expand Down Expand Up @@ -405,6 +407,8 @@ endfunction()
# [IS_MAIN] # This is an executable, not a library
# [IS_STDLIB]
# [IS_STDLIB_CORE] # This is the core standard library
# [ONLY_SWIFTMODULE] # Emit swiftmodule only, no binary
# [NO_SWIFTMODULE] # Emit binary only, no swiftmodule
# [OPT_FLAGS] # Optimization flags (overrides SWIFT_OPTIMIZE)
# [MODULE_DIR] # Put .swiftmodule, .swiftdoc., and .o
# # into this directory.
Expand All @@ -419,7 +423,7 @@ function(_compile_swift_files
dependency_sib_target_out_var_name dependency_sibopt_target_out_var_name
dependency_sibgen_target_out_var_name)
cmake_parse_arguments(SWIFTFILE
"IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE;STATIC;IS_FRAGILE;ONLY_SWIFTMODULE"
"IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE;STATIC;IS_FRAGILE;ONLY_SWIFTMODULE;NO_SWIFTMODULE"
"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"
"SOURCES;FLAGS;DEPENDS;SDK;ARCHITECTURE;OPT_FLAGS;MODULE_DIR"
${ARGN})
Expand Down Expand Up @@ -678,6 +682,10 @@ function(_compile_swift_files
get_bootstrapping_path(lib_dir ${SWIFTLIB_DIR} "${SWIFTFILE_BOOTSTRAPPING}")

if(NOT SWIFTFILE_IS_MAIN)
list(APPEND swift_flags "-parse-as-library")
endif()

if(NOT SWIFTFILE_IS_MAIN AND NOT SWIFTFILE_NO_SWIFTMODULE)
# Determine the directory where the module file should be placed.
if(SWIFTFILE_MODULE_DIR)
set(module_dir "${SWIFTFILE_MODULE_DIR}")
Expand All @@ -687,8 +695,6 @@ function(_compile_swift_files
message(FATAL_ERROR "Don't know where to put the module files")
endif()

list(APPEND swift_flags "-parse-as-library")

set(module_base "${module_dir}/${SWIFTFILE_MODULE_NAME}")

set(module_dir_static "${SWIFTSTATICLIB_DIR}/${library_subdir}")
Expand Down Expand Up @@ -1068,7 +1074,7 @@ function(_compile_swift_files
#
# We only build these when we are not producing a main file. We could do this
# with sib/sibgen, but it is useful for looking at the stdlib.
if (NOT SWIFTFILE_IS_MAIN)
if (NOT SWIFTFILE_IS_MAIN AND NOT SWIFTFILE_NO_SWIFTMODULE)
add_custom_command_target(
module_dependency_target
COMMAND
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/PreviousModuleInstallName.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"module": "CompatibilitySpan",
"install_name": "/usr/lib/swift/libswiftCompatibilitySpan.dylib"
"install_name": "@rpath/libswiftCompatibilitySpan.dylib"
}
]
42 changes: 31 additions & 11 deletions stdlib/public/core/Span/MutableRawSpan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
//
//===----------------------------------------------------------------------===//

#if SPAN_COMPATIBILITY_STUB
import Swift
#endif

// A MutableRawSpan represents a span of memory which
// contains initialized `Element` instances.
@safe
@frozen
@available(SwiftStdlib 6.2, *)
@available(SwiftCompatibilitySpan 5.0, *)
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
public struct MutableRawSpan: ~Copyable & ~Escapable {
@usableFromInline
internal let _pointer: UnsafeMutableRawPointer?
Expand All @@ -40,10 +45,12 @@ public struct MutableRawSpan: ~Copyable & ~Escapable {
}
}

@available(SwiftStdlib 6.2, *)
@available(SwiftCompatibilitySpan 5.0, *)
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
extension MutableRawSpan: @unchecked Sendable {}

@available(SwiftStdlib 6.2, *)
@available(SwiftCompatibilitySpan 5.0, *)
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
extension MutableRawSpan {

@unsafe
Expand Down Expand Up @@ -115,7 +122,8 @@ extension MutableRawSpan {
}
}

@available(SwiftStdlib 6.2, *)
@available(SwiftCompatibilitySpan 5.0, *)
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
extension MutableRawSpan {
@_alwaysEmitIntoClient
public var byteCount: Int { _count }
Expand All @@ -129,7 +137,8 @@ extension MutableRawSpan {
}
}

@available(SwiftStdlib 6.2, *)
@available(SwiftCompatibilitySpan 5.0, *)
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
extension MutableRawSpan {

@_alwaysEmitIntoClient
Expand All @@ -154,7 +163,8 @@ extension MutableRawSpan {
}
}

@available(SwiftStdlib 6.2, *)
@available(SwiftCompatibilitySpan 5.0, *)
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
extension RawSpan {

@_alwaysEmitIntoClient
Expand All @@ -166,7 +176,8 @@ extension RawSpan {
}
}

@available(SwiftStdlib 6.2, *)
@available(SwiftCompatibilitySpan 5.0, *)
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
extension MutableRawSpan {

public var bytes: RawSpan {
Expand Down Expand Up @@ -202,7 +213,8 @@ extension MutableRawSpan {
}
}

@available(SwiftStdlib 6.2, *)
@available(SwiftCompatibilitySpan 5.0, *)
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
extension MutableRawSpan {

/// Returns a new instance of the given type, constructed from the raw memory
Expand Down Expand Up @@ -338,8 +350,13 @@ extension MutableRawSpan {
}
}

// FIXME: The functions in this extension crash the SIL optimizer when built inside
// the stub. But these declarations don't generate a public symbol anyway.
#if !SPAN_COMPATIBILITY_STUB

//MARK: copyMemory
@available(SwiftStdlib 6.2, *)
@available(SwiftCompatibilitySpan 5.0, *)
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
extension MutableRawSpan {

@_alwaysEmitIntoClient
Expand Down Expand Up @@ -429,9 +446,11 @@ extension MutableRawSpan {
update(fromContentsOf: source.bytes)
}
}
#endif

// MARK: sub-spans
@available(SwiftStdlib 6.2, *)
@available(SwiftCompatibilitySpan 5.0, *)
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
extension MutableRawSpan {

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

// MARK: prefixes and suffixes
@available(SwiftStdlib 6.2, *)
@available(SwiftCompatibilitySpan 5.0, *)
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
extension MutableRawSpan {

/// Returns a span containing the initial elements of this span,
Expand Down
Loading