Skip to content

Commit c7a9360

Browse files
authored
[Reflection] Build the _Runtime and Reflection modules (swiftlang#62973)
* Move Runtime into _Runtime Fix more _Runtime names * Add availability to all API * Build _Runtime and Reflection modules * Use threading's mutex for all platforms add stdlib include
1 parent 9e4f9f7 commit c7a9360

File tree

89 files changed

+636
-161
lines changed

Some content is hidden

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

89 files changed

+636
-161
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,10 @@ option(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING
565565
"Enable experimental string processing"
566566
FALSE)
567567

568+
option(SWIFT_ENABLE_EXPERIMENTAL_REFLECTION
569+
"Enable build of the Swift reflection module"
570+
FALSE)
571+
568572
option(SWIFT_ENABLE_DISPATCH
569573
"Enable use of libdispatch"
570574
TRUE)
@@ -1110,6 +1114,7 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
11101114
message(STATUS "Distributed Support: ${SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED}")
11111115
message(STATUS "String Processing Support: ${SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING}")
11121116
message(STATUS "Unicode Support: ${SWIFT_STDLIB_ENABLE_UNICODE_DATA}")
1117+
message(STATUS "Reflection Support: ${SWIFT_ENABLE_EXPERIMENTAL_REFLECTION}")
11131118
message(STATUS "")
11141119
else()
11151120
message(STATUS "Not building Swift standard library, SDK overlays, and runtime")

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ function(_add_target_variant_swift_compile_flags
294294
list(APPEND result "-D" "SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING")
295295
endif()
296296

297+
if(SWIFT_ENABLE_EXPERIMENTAL_REFLECTION)
298+
list(APPEND result "-D" "SWIFT_ENABLE_EXPERIMENTAL_REFLECTION")
299+
endif()
300+
297301
if(SWIFT_STDLIB_OS_VERSIONING)
298302
list(APPEND result "-D" "SWIFT_RUNTIME_OS_VERSIONING")
299303
endif()

stdlib/public/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ if(SWIFT_BUILD_STDLIB)
146146
add_subdirectory(StringProcessing)
147147
add_subdirectory(RegexBuilder)
148148
endif()
149+
150+
if(SWIFT_ENABLE_EXPERIMENTAL_REFLECTION)
151+
add_subdirectory(Reflection)
152+
endif()
149153
endif()
150154

151155
if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_REMOTE_MIRROR)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#===--- CMakeLists.txt - Reflection support library ---------------------===#
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2023 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
#===----------------------------------------------------------------------===#
12+
13+
add_subdirectory(Sources/_Runtime)
14+
add_subdirectory(Sources/Reflection)

stdlib/public/Reflection/Package.swift

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,35 @@
22

33
import PackageDescription
44

5+
let commonFlags = [
6+
"-I", "\(Context.packageDirectory)/Sources/_SwiftRuntimeShims",
7+
8+
"-Xfrontend" ,"-define-availability",
9+
"-Xfrontend", "SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999"
10+
]
11+
12+
let libraryFlags = [
13+
"-parse-stdlib",
14+
"-enable-library-evolution",
15+
"-Xfrontend", "-disable-implicit-concurrency-module-import",
16+
"-Xfrontend", "-disable-implicit-string-processing-module-import",
17+
"-assert-config", "Release",
18+
]
19+
20+
let testFlags = [
21+
"-Xfrontend", "-disable-availability-checking"
22+
]
23+
524
let package = Package(
625
name: "Reflection",
726
platforms: [
827
.macOS(.v13)
928
],
1029
products: [
1130
.library(
12-
name: "Runtime",
31+
name: "_Runtime",
1332
type: .dynamic,
14-
targets: ["Runtime"]
33+
targets: ["_Runtime"]
1534
),
1635
.library(
1736
name: "Reflection",
@@ -21,42 +40,38 @@ let package = Package(
2140
],
2241
targets: [
2342
.target(
24-
name: "CRuntime"
25-
),
26-
.target(
27-
name: "Runtime",
28-
dependencies: ["CRuntime"],
43+
name: "_Runtime",
44+
exclude: [
45+
"CMakeLists.txt"
46+
],
2947
swiftSettings: [
30-
.unsafeFlags([
31-
"-parse-stdlib",
32-
"-enable-library-evolution",
33-
"-Xfrontend", "-disable-implicit-concurrency-module-import",
34-
"-Xfrontend", "-disable-implicit-string-processing-module-import",
35-
"-assert-config", "Release"
36-
])
48+
.unsafeFlags(commonFlags + libraryFlags)
3749
]
3850
),
3951
.target(
4052
name: "Reflection",
41-
dependencies: ["Runtime"],
53+
dependencies: ["_Runtime"],
54+
exclude: [
55+
"CMakeLists.txt"
56+
],
4257
swiftSettings: [
43-
.unsafeFlags([
44-
"-parse-stdlib",
45-
"-enable-library-evolution",
46-
"-Xfrontend", "-disable-implicit-concurrency-module-import",
47-
"-Xfrontend", "-disable-implicit-string-processing-module-import",
48-
"-assert-config", "Release"
49-
])
58+
.unsafeFlags(commonFlags + libraryFlags)
5059
]
5160
),
5261

5362
.testTarget(
5463
name: "RuntimeTests",
55-
dependencies: ["Runtime"]
64+
dependencies: ["_Runtime"],
65+
swiftSettings: [
66+
.unsafeFlags(commonFlags + testFlags)
67+
]
5668
),
5769
.testTarget(
5870
name: "ReflectionTests",
59-
dependencies: ["Runtime", "Reflection"]
71+
dependencies: ["_Runtime", "Reflection"],
72+
swiftSettings: [
73+
.unsafeFlags(commonFlags + testFlags)
74+
]
6075
),
6176
]
6277
)

stdlib/public/Reflection/Sources/CRuntime/Functions.c

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#===--- CMakeLists.txt - Reflection support library ---------------------===#
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2023 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
#===----------------------------------------------------------------------===#
12+
13+
set(SWIFT_REFLECTION_SWIFT_FLAGS)
14+
15+
list(APPEND SWIFT_REFLECTION_SWIFT_FLAGS
16+
"-parse-stdlib")
17+
18+
add_swift_target_library(swiftReflection ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
19+
Case.swift
20+
Field.swift
21+
GenericArguments.swift
22+
KeyPath.swift
23+
PartialType.swift
24+
Type.swift
25+
26+
SWIFT_COMPILE_FLAGS
27+
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
28+
${SWIFT_REFLECTION_SWIFT_FLAGS}
29+
SWIFT_MODULE_DEPENDS _Runtime
30+
INSTALL_IN_COMPONENT stdlib)

stdlib/public/Reflection/Sources/Reflection/Case.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
import Swift
13-
import Runtime
13+
import _Runtime
1414

15+
@available(SwiftStdlib 9999, *)
1516
@frozen
1617
public struct Case {
1718
@usableFromInline
@@ -43,6 +44,7 @@ public struct Case {
4344
}
4445
}
4546

47+
@available(SwiftStdlib 9999, *)
4648
extension Case {
4749
@inlinable
4850
public var hasPayload: Bool {
@@ -75,6 +77,7 @@ extension Case {
7577
}
7678
}
7779

80+
@available(SwiftStdlib 9999, *)
7881
extension Case: CustomStringConvertible {
7982
@inlinable
8083
public var description: String {
@@ -94,6 +97,7 @@ extension Case: CustomStringConvertible {
9497
}
9598
}
9699

100+
@available(SwiftStdlib 9999, *)
97101
@frozen
98102
public struct Cases {
99103
@usableFromInline
@@ -105,6 +109,7 @@ public struct Cases {
105109
}
106110
}
107111

112+
@available(SwiftStdlib 9999, *)
108113
extension Cases: RandomAccessCollection {
109114
@inlinable
110115
public var startIndex: Int {
@@ -138,6 +143,7 @@ extension Cases: RandomAccessCollection {
138143
}
139144
}
140145

146+
@available(SwiftStdlib 9999, *)
141147
extension Type {
142148
@inlinable
143149
public var cases: Cases {

stdlib/public/Reflection/Sources/Reflection/Field.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
import Swift
13-
import Runtime
13+
import _Runtime
1414

15+
@available(SwiftStdlib 9999, *)
1516
@frozen
1617
public struct Field {
1718
@usableFromInline
@@ -27,6 +28,7 @@ public struct Field {
2728
}
2829
}
2930

31+
@available(SwiftStdlib 9999, *)
3032
extension Field {
3133
@inlinable
3234
public var isVar: Bool {
@@ -92,6 +94,7 @@ extension Field {
9294
}
9395
}
9496

97+
@available(SwiftStdlib 9999, *)
9598
extension Field: CustomStringConvertible {
9699
@inlinable
97100
public var description: String {
@@ -109,6 +112,7 @@ extension Field: CustomStringConvertible {
109112
}
110113
}
111114

115+
@available(SwiftStdlib 9999, *)
112116
@frozen
113117
public struct Fields {
114118
@usableFromInline
@@ -120,6 +124,7 @@ public struct Fields {
120124
}
121125
}
122126

127+
@available(SwiftStdlib 9999, *)
123128
extension Fields: RandomAccessCollection {
124129
@inlinable
125130
public var startIndex: Int {
@@ -159,6 +164,7 @@ extension Fields: RandomAccessCollection {
159164
}
160165
}
161166

167+
@available(SwiftStdlib 9999, *)
162168
extension Type {
163169
@inlinable
164170
public var fields: Fields {

stdlib/public/Reflection/Sources/Reflection/GenericArguments.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
import Swift
13-
import Runtime
13+
import _Runtime
1414

15+
@available(SwiftStdlib 9999, *)
1516
@frozen
1617
public struct GenericArguments {
1718
@usableFromInline
@@ -27,6 +28,7 @@ public struct GenericArguments {
2728
}
2829
}
2930

31+
@available(SwiftStdlib 9999, *)
3032
extension GenericArguments: RandomAccessCollection {
3133
@inlinable
3234
public var startIndex: Int {
@@ -53,6 +55,7 @@ extension GenericArguments: RandomAccessCollection {
5355
}
5456
}
5557

58+
@available(SwiftStdlib 9999, *)
5659
extension GenericArguments: BidirectionalCollection {
5760
@inlinable
5861
public func index(before i: Int) -> Int {

0 commit comments

Comments
 (0)