Skip to content

Commit 48241ba

Browse files
authored
Merge branch 'main' into wip-distributed-irgenmangler-more
2 parents 58ed3f0 + 9957f52 commit 48241ba

File tree

240 files changed

+2865
-612
lines changed

Some content is hidden

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

240 files changed

+2865
-612
lines changed

CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ option(SWIFT_STDLIB_ASSERTIONS
464464
"Enable internal checks for the Swift standard library (useful for debugging the library itself, does not affect checks required for safety)"
465465
"${SWIFT_STDLIB_ASSERTIONS_default}")
466466

467+
option(SWIFT_STDLIB_ENABLE_STRICT_AVAILABILITY
468+
"Enable strict availability; this will cause things to break at desk or in CI if the host OS is a lower version than some `@availability` annotations in the runtime code"
469+
FALSE)
470+
467471
option(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER
468472
"Use the host compiler and not the internal clang to build the swift runtime"
469473
FALSE)
@@ -1406,8 +1410,9 @@ endif()
14061410

14071411
if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
14081412
message(STATUS "Building Swift standard library and overlays for SDKs: ${SWIFT_SDKS}")
1409-
message(STATUS " Build type: ${SWIFT_STDLIB_BUILD_TYPE}")
1410-
message(STATUS " Assertions: ${SWIFT_STDLIB_ASSERTIONS}")
1413+
message(STATUS " Build type: ${SWIFT_STDLIB_BUILD_TYPE}")
1414+
message(STATUS " Assertions: ${SWIFT_STDLIB_ASSERTIONS}")
1415+
message(STATUS " Strict availability: ${SWIFT_STDLIB_ENABLE_STRICT_AVAILABILITY}")
14111416
message(STATUS "")
14121417

14131418
message(STATUS "Building Swift runtime with:")

Runtimes/Core/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ set(SwiftCore_VENDOR_MODULE_DIR "${SwiftCore_CMAKE_MODULES_DIR}/vendor"
7878
include(GNUInstallDirs)
7979
include(CheckSymbolExists)
8080
include(CheckIncludeFileCXX)
81-
include(AvailabilityMacros)
8281
include(CompilerSettings)
8382
include(DefaultSettings)
8483
include(EmitSwiftInterface)
@@ -87,6 +86,7 @@ include(PlatformInfo)
8786
include(gyb)
8887
include(ResourceEmbedding)
8988
include(CatalystSupport)
89+
include(AvailabilityMacros)
9090

9191
check_symbol_exists("asl_log" "asl.h" SwiftCore_HAS_ASL)
9292
check_symbol_exists("dladdr" "dlfcn.h" SwiftCore_HAS_DLADDR)
@@ -126,6 +126,7 @@ defaulted_option(SwiftCore_ENABLE_BACKTRACING "Enable backtracing runtime suppor
126126
defaulted_set(SwiftCore_BACKTRACER_PATH STRING "Set a fixed path to the Swift backtracer")
127127
defaulted_option(SwiftCore_ENABLE_FATALERROR_BACKTRACE "Build stdlib fatalError with backtrace output")
128128
defaulted_option(SwiftCore_ENABLE_PRESPECIALIZATION "Enable generic metadata prespecialization")
129+
defaulted_option(SwiftCore_ENABLE_STRICT_AVAILABILITY "Enable strict availability; this will cause things to break at desk or in CI if the host OS is a lower version than some `@availability` annotations in the runtime code")
129130

130131
option(SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS "" OFF)
131132
option(SwiftCore_ENABLE_RUNTIME_LEAK_CHECKER "" OFF)

Runtimes/Core/cmake/caches/Vendors/Apple/apple-common.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ set(SwiftCore_ENABLE_VECTOR_TYPES ON CACHE BOOL "")
1212
set(SwiftCore_ENABLE_RUNTIME_FUNCTION_COUNTERS ON CACHE BOOL "")
1313
set(SwiftCore_ENABLE_BACKDEPLOYMENT_SUPPORT ON CACHE BOOL "")
1414
set(SwiftCore_ENABLE_FILESYSTEM_SUPPORT ON CACHE BOOL "")
15+
set(SwiftCore_ENABLE_STRICT_AVAILABILITY ON CACHE BOOL "")
16+
1517
set(SwiftCore_OPTIMIZATION_REMARKS "bitstream" CACHE STRING "")
1618

1719
set(SwiftCore_INSTALL_NESTED_SUBDIR OFF CACHE BOOL "")

Runtimes/Core/cmake/modules/AvailabilityMacros.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,32 @@ file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/availability-macros.def" availability_
55
list(FILTER availability_defs EXCLUDE REGEX "^\\s*(#.*)?$")
66
foreach(def ${availability_defs})
77
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -define-availability -Xfrontend \"${def}\">")
8+
9+
if("${def}" MATCHES "SwiftStdlib .*")
10+
# For each SwiftStdlib x.y, also define SwiftStdlibCurrentOS x.y, which,
11+
# will expand to the current `-target` platform if the macro defines a
12+
# newer platform as its availability.
13+
#
14+
# There is a setting, SwiftCore_ENABLE_STRICT_AVAILABILITY, which if set
15+
# ON will cause us to use the "proper" availability instead.
16+
string(REPLACE "SwiftStdlib" "SwiftStdlibCurrentOS" current "${def}")
17+
if(NOT SwiftCore_ENABLE_STRICT_AVAILABILITY AND SwiftCore_SWIFT_AVAILABILITY_PLATFORM)
18+
if("${SwiftCore_SWIFT_AVAILABILITY_PLATFORM}" STREQUAL "macOS" AND "${SwiftCore_VARIANT_AVAILABILITY_PLATFORM}" STREQUAL "iOS")
19+
string(REGEX MATCH "iOS ([0-9]+(\.[0-9]+)+)" ios_platform_version "${def}")
20+
string(REGEX MATCH "[0-9]+(\.[0-9]+)+" ios_version "${ios_platform_version}")
21+
string(REGEX MATCH "macOS ([0-9]+(\.[0-9]+)+)" macos_platform_version "${def}")
22+
string(REGEX MATCH "[0-9]+(\.[0-9]+)+" macos_version "${macos_platform_version}")
23+
if((NOT macos_version STREQUAL "9999" OR NOT ios_version STREQUAL "9999") AND (macos_version VERSION_GREATER CMAKE_OSX_DEPLOYMENT_TARGET OR ios_version VERSION_GREATER SwiftCore_VARIANT_DEPLOYMENT_VERSION))
24+
string(REGEX REPLACE ":.*" ": macOS ${CMAKE_OSX_DEPLOYMENT_VERSION}, iOS ${SwiftCore_VARIANT_DEPLOYMENT_VERSION}" current "${current}")
25+
endif()
26+
else()
27+
string(REGEX MATCH "${SwiftCore_SWIFT_AVAILABILITY_PLATFORM} ([0-9]+(\.[0-9]+)+)" platform_version "${def}")
28+
string(REGEX MATCH "[0-9]+(\.[0-9]+)+" version "${platform_version}")
29+
if(NOT version STREQUAL "9999" AND version VERSION_GREATER CMAKE_OSX_DEPLOYMENT_TARGET)
30+
string(REGEX REPLACE ":.*" ":${SwiftCore_SWIFT_AVAILABILITY_PLATFORM} ${CMAKE_OSX_DEPLOYMENT_TARGET}" current "${current}")
31+
endif()
32+
endif()
33+
endif()
34+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -define-availability -Xfrontend \"${current}\">")
35+
endif()
836
endforeach()

Runtimes/Core/cmake/modules/CatalystSupport.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,12 @@ if(SwiftCore_COMPILER_VARIANT_TARGET)
3434
set(SwiftCore_VARIANT_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used for installed swift{module,interface} files for the target variant")
3535
mark_as_advanced(SwiftCore_VARIANT_MODULE_TRIPLE)
3636
message(CONFIGURE_LOG "Swift target variant module triple: ${module_triple}")
37+
38+
string(JSON triple GET "${target_info_json}" "target" "triple")
39+
if(triple MATCHES "apple-([a-zA-Z]+)([0-9]+[.0-9]*)-macabi")
40+
set(SwiftCore_VARIANT_DEPLOYMENT_VERSION "${CMAKE_MATCH_2}")
41+
mark_as_advanced(SwiftCore_VARIANT_DEPLOYMENT_VERSION)
42+
message(CONFIGURE_LOG "Swift target variant deployment version: ${SwiftCore_VARIANT_DEPLOYMENT_VERSION}")
43+
endif()
3744
endif()
3845
endif()

Runtimes/Core/cmake/modules/DefaultSettings.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ set(SwiftCore_ENABLE_BACKTRACING_default OFF) # TODO: enable this by default
1010
set(SwiftCore_ENABLE_STDIN_default ON)
1111
set(SwiftCore_ENABLE_TYPE_PRINTING_default ON)
1212

13+
set(SwiftCore_ENABLE_STRICT_AVAILABILITY_default OFF)
14+
1315
set(SwiftCore_BACKTRACER_PATH_default "")
1416

1517
# Provide a boolean option that a user can optionally enable.
@@ -19,7 +21,7 @@ macro(defaulted_option variable helptext)
1921
if(NOT DEFINED ${variable}_default)
2022
set(${variable}_default OFF)
2123
endif()
22-
option(${variable} ${helptext} ${${variable}_default})
24+
option(${variable} "${helptext}" ${${variable}_default})
2325
endmacro()
2426

2527
# Create a defaulted cache entry
@@ -50,6 +52,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "WASM")
5052
set(SwiftCore_CONCURRENCY_GLOBAL_EXECUTOR_default "none")
5153
elseif(LINUX OR ANDROID OR BSD)
5254
set(SwiftCore_OBJECT_FORMAT_default "elf")
55+
56+
set(SwiftCore_ENABLE_REFLECTION_default ON)
5357
set(SwiftCore_ENABLE_FATALERROR_BACKTRACE_default ON)
5458
if(LINUX)
5559
set(SwiftCore_THREADING_PACKAGE_default "LINUX")

Runtimes/Core/cmake/modules/ExperimentalFeatures.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_compile_options(
44
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature SE427NoInferenceOnExtension>"
55
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NonescapableTypes>"
66
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature LifetimeDependence>"
7+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature InoutLifetimeDependence>"
78
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature LifetimeDependenceMutableAccessors>"
89
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature MemberImportVisibility>"
910
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature TypedThrows>"

Runtimes/Core/cmake/modules/PlatformInfo.cmake

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,47 @@ if(NOT SwiftCore_ARCH_SUBDIR)
3636

3737
message(CONFIGURE_LOG "Swift Arch: ${arch}")
3838
endif()
39+
40+
# Note: *moduleTriple* doesn't have an "x" on the end of "macos"; just to be
41+
# safe, we support both cases here.
42+
set(availability_platform_macos "macOS")
43+
set(availaiblity_platform_macosx "macOS")
44+
set(availability_platform_ios "iOS")
45+
set(availability_platform_watchos "watchOS")
46+
set(availability_platform_tvos "tvOS")
47+
set(availability_platform_xros "visionOS")
48+
set(availability_platform_bridgeos "bridgeOS")
49+
50+
if(NOT SwiftCore_SWIFT_AVAILABILITY_PLATFORM)
51+
if(SwiftCore_MODULE_TRIPLE MATCHES ".*-([^-]+)-simulator$")
52+
set(platform "${CMAKE_MATCH_1}")
53+
elseif(SwiftCore_MODULE_TRIPLE MATCHES ".*-([^-]+)-msvc$")
54+
set(platform "${CMAKE_MATCH_1}")
55+
elseif(SwiftCore_MODULE_TRIPLE MATCHES ".*-([^-]+)$")
56+
set(platform "${CMAKE_MATCH_1}")
57+
else()
58+
message(WARNING "Unable to extract platform name from triple ${SwiftCore_MODULE_TRIPLE}")
59+
endif()
60+
61+
if(availability_platform_${platform})
62+
set(SwiftCore_SWIFT_AVAILABILITY_PLATFORM "${availability_platform_${platform}}")
63+
else()
64+
set(SwiftCore_SWIFT_AVAILABILITY_PLATFORM "unknown")
65+
message(WARNING "Unknown platform ${platform} for availability")
66+
endif()
67+
endif()
68+
69+
set(SwiftCore_VARIANT_AVAILABILITY_PLATFORM "none")
70+
if(SwiftCore_VARIANT_MODULE_TRIPLE)
71+
if(SwiftCore_VARIANT_MODULE_TRIPLE MATCHES ".*-([^-]+)$")
72+
set(platform "${CMAKE_MATCH_1}")
73+
else()
74+
message(FATAL_ERROR "Unable to extract platform name from triple ${SwiftCore_VARIANT_MODULE_TRIPLE}")
75+
endif()
76+
77+
if(availability_platform_${platform})
78+
set(SwiftCore_VARIANT_AVAILABILITY_PLATFORM "${availability_platform_${platform}}")
79+
else()
80+
message(WARNING "Unknown platform ${platform} for variant availability")
81+
endif()
82+
endif()

Runtimes/Supplemental/Synchronization/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ add_library(swiftSynchronization
9898
Cell.swift
9999
Mutex/Mutex.swift
100100
$<$<PLATFORM_ID:Darwin>:Mutex/DarwinImpl.swift>
101-
$<$<PLATFORM_ID:Linux>:Mutex/LinuxImpl.swift>
102-
$<$<PLATFORM_ID:WASI>:Mutex/SpinLoopHint.swift>
101+
$<$<PLATFORM_ID:Android,Linux>:Mutex/LinuxImpl.swift>
102+
$<$<PLATFORM_ID:Android,WASI>:Mutex/SpinLoopHint.swift>
103103
$<$<PLATFORM_ID:Windows>:Mutex/WindowsImpl.swift>)
104104

105105
set_target_properties(swiftSynchronization PROPERTIES

Runtimes/Supplemental/cmake/modules/FindSwiftCore.cmake

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,48 @@ elseif(WIN32)
114114
INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}")
115115
find_package_handle_standard_args(SwiftCore DEFAULT_MSG
116116
SwiftCore_LIBRARY SwiftCore_INCLUDE_DIR)
117+
elseif(ANDROID)
118+
if(BUILD_SHARED_LIBS)
119+
find_path(SwiftCore_INCLUDE_DIR
120+
"Swift.swiftmodule"
121+
NO_CMAKE_FIND_ROOT_PATH
122+
HINTS
123+
"${Swift_SDKROOT}/usr/lib/swift/android"
124+
"$ENV{SDKROOT}/usr/lib/swift/android")
125+
find_library(SwiftCore_LIBRARY
126+
NO_CMAKE_FIND_ROOT_PATH
127+
NAMES "libswiftCore.so"
128+
HINTS
129+
"${Swift_SDKROOT}/usr/lib/swift/android/${SwiftCore_ARCH_SUBDIR}"
130+
"${Swift_SDKROOT}/usr/lib/swift"
131+
"$ENV{SDKROOT}/usr/lib/swift/android/${SwiftCore_ARCH_SUBDIR}"
132+
"$ENV{SDKROOT}/usr/lib/swift")
133+
134+
add_library(swiftCore SHARED IMPORTED GLOBAL)
135+
else()
136+
find_path(SwiftCore_INCLUDE_DIR
137+
"Swift.swiftmodule"
138+
NO_CMAKE_FIND_ROOT_PATH
139+
HINTS
140+
"${Swift_SDKROOT}/usr/lib/swift_static/android"
141+
"$ENV{SDKROOT}/usr/lib/swift_static/android")
142+
find_library(SwiftCore_LIBRARY
143+
NO_CMAKE_FIND_ROOT_PATH
144+
NAMES "libswiftCore.a"
145+
HINTS
146+
"${Swift_SDKROOT}/usr/lib/swift_static/android/${SwiftCore_ARCH_SUBDIR}"
147+
"${Swift_SDKROOT}/usr/lib/swift_static"
148+
"$ENV{SDKROOT}/usr/lib/swift_static/android/${SwiftCore_ARCH_SUBDIR}"
149+
"$ENV{SDKROOT}/usr/lib/swift_static")
150+
151+
add_library(swiftCore STATIC IMPORTED GLOBAL)
152+
endif()
153+
154+
set_target_properties(swiftCore PROPERTIES
155+
IMPORTED_LOCATION "${SwiftCore_LIBRARY}"
156+
INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}")
157+
find_package_handle_standard_args(SwiftCore DEFAULT_MSG
158+
SwiftCore_LIBRARY SwiftCore_INCLUDE_DIR)
117159
else()
118160
message(FATAL_ERROR "FindSwiftCore.cmake module search not implemented for targeted platform\n"
119161
" Build Core for your platform and set `SwiftCore_DIR` to"

SwiftCompilerSources/Sources/AST/Declarations.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ final public class TopLevelCodeDecl: Decl {}
124124

125125
final public class ImportDecl: Decl {}
126126

127+
final public class UsingDecl: Decl {}
128+
127129
final public class PrecedenceGroupDecl: Decl {}
128130

129131
final public class MissingDecl: Decl {}

SwiftCompilerSources/Sources/AST/Registration.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public func registerAST() {
3636
registerDecl(ExtensionDecl.self)
3737
registerDecl(TopLevelCodeDecl.self)
3838
registerDecl(ImportDecl.self)
39+
registerDecl(UsingDecl.self)
3940
registerDecl(PrecedenceGroupDecl.self)
4041
registerDecl(MissingDecl.self)
4142
registerDecl(MissingMemberDecl.self)

SwiftCompilerSources/Sources/Optimizer/ModulePasses/MandatoryPerformanceOptimizations.swift

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private func optimizeFunctionsTopDown(using worklist: inout FunctionWorklist,
6464
// We need handle this case with a function signature optimization.
6565
removeMetatypeArgumentsInCallees(of: f, moduleContext)
6666

67-
worklist.addCallees(of: f)
67+
worklist.addCallees(of: f, moduleContext)
6868
}
6969
}
7070

@@ -496,29 +496,41 @@ fileprivate struct FunctionWorklist {
496496
return
497497
}
498498

499-
mutating func addCallees(of function: Function) {
499+
mutating func addCallees(of function: Function, _ context: ModulePassContext) {
500500
for inst in function.instructions {
501501
switch inst {
502-
case let apply as ApplySite:
503-
if let callee = apply.referencedFunction {
504-
pushIfNotVisited(callee)
502+
case let fri as FunctionRefInst:
503+
pushIfNotVisited(fri.referencedFunction)
504+
case let alloc as AllocRefInst:
505+
if context.options.enableEmbeddedSwift {
506+
addVTableMethods(forClassType: alloc.type, context)
505507
}
506-
case let bi as BuiltinInst:
507-
switch bi.id {
508-
case .Once, .OnceWithContext:
509-
if let fri = bi.operands[1].value as? FunctionRefInst {
510-
pushIfNotVisited(fri.referencedFunction)
508+
case let metatype as MetatypeInst:
509+
if context.options.enableEmbeddedSwift {
510+
let instanceType = metatype.type.loweredInstanceTypeOfMetatype(in: function)
511+
if instanceType.isClass {
512+
addVTableMethods(forClassType: instanceType, context)
511513
}
512-
break;
513-
default:
514-
break
515514
}
515+
516516
default:
517517
break
518518
}
519519
}
520520
}
521521

522+
mutating func addVTableMethods(forClassType classType: Type, _ context: ModulePassContext) {
523+
guard let vtable = classType.isGenericAtAnyLevel ?
524+
context.lookupSpecializedVTable(for: classType) :
525+
context.lookupVTable(for: classType.nominal!)
526+
else {
527+
return
528+
}
529+
for entry in vtable.entries where !entry.implementation.isGeneric {
530+
pushIfNotVisited(entry.implementation)
531+
}
532+
}
533+
522534
mutating func addWitnessMethods(of witnessTable: WitnessTable) {
523535
for entry in witnessTable.entries {
524536
if case .method(_, let witness) = entry,

0 commit comments

Comments
 (0)