Skip to content

Commit 2bfd6a4

Browse files
authored
Merge pull request #3170 from swiftlang/object-format-stabilize
Update syntax for #objectFormat per SE-0492
2 parents d81296e + 42ec79a commit 2bfd6a4

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

Sources/SwiftIfConfig/BuildConfiguration.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ public enum CanImportVersion {
3939

4040
enum BuildConfigurationError: Error, CustomStringConvertible {
4141
case experimentalFeature(name: String)
42+
case notImplemented(name: String)
4243

4344
var description: String {
4445
switch self {
4546
case .experimentalFeature(let name):
4647
return "'\(name)' is an experimental feature"
48+
case .notImplemented(let name):
49+
return "'\(name)' not implemented"
4750
}
4851
}
4952
}
@@ -228,18 +231,17 @@ public protocol BuildConfiguration {
228231
/// Determine whether the given name is the active target object file format (e.g., ELF).
229232
///
230233
/// The target object file format can only be queried by an experimental
231-
/// syntax `_objectFileFormat(<name>)`, e.g.,
234+
/// syntax `objectFormat(<name>)`, e.g.,
232235
///
233236
/// ```swift
234-
/// #if _objectFileFormat(ELF)
237+
/// #if objectFormat(ELF)
235238
/// // Special logic for ELF object file formats
236239
/// #endif
237240
/// ```
238241
/// - Parameters:
239242
/// - name: The name of the object file format.
240243
/// - Returns: Whether the target object file format matches the given name.
241-
@_spi(ExperimentalLanguageFeatures)
242-
func isActiveTargetObjectFileFormat(name: String) throws -> Bool
244+
func isActiveTargetObjectFormat(name: String) throws -> Bool
243245

244246
/// The bit width of a data pointer for the target architecture.
245247
///
@@ -307,9 +309,8 @@ public protocol BuildConfiguration {
307309
/// Default implementation of BuildConfiguration, to avoid a revlock with the
308310
/// swift repo, and breaking clients with the new addition to the protocol.
309311
extension BuildConfiguration {
310-
/// FIXME: This should be @_spi(ExperimentalLanguageFeatures) but cannot due
311-
/// to rdar://147943518, https://github.com/swiftlang/swift/issues/80313
312-
public func isActiveTargetObjectFileFormat(name: String) throws -> Bool {
313-
throw BuildConfigurationError.experimentalFeature(name: "_objectFileFormat")
312+
@available(*, deprecated, message: "`BuildConfiguration` conformance must implement `isActiveTargetObjectFormat`")
313+
public func isActiveTargetObjectFormat(name: String) throws -> Bool {
314+
throw BuildConfigurationError.notImplemented(name: "isActiveTargetObjectFormat")
314315
}
315316
}

Sources/SwiftIfConfig/IfConfigEvaluation.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ func evaluateIfConfig(
307307
case .targetEnvironment:
308308
return doSingleIdentifierArgumentCheck(configuration.isActiveTargetEnvironment, role: "environment")
309309

310-
case ._objectFileFormat:
311-
return doSingleIdentifierArgumentCheck(configuration.isActiveTargetObjectFileFormat, role: "object file format")
310+
case .objectFormat:
311+
return doSingleIdentifierArgumentCheck(configuration.isActiveTargetObjectFormat, role: "object file format")
312312

313313
case ._runtime:
314314
return doSingleIdentifierArgumentCheck(configuration.isActiveTargetRuntime, role: "runtime")
@@ -821,8 +821,8 @@ private struct CanImportSuppressingBuildConfiguration<Other: BuildConfiguration>
821821
return try other.isActiveTargetPointerAuthentication(name: name)
822822
}
823823

824-
func isActiveTargetObjectFileFormat(name: String) throws -> Bool {
825-
return try other.isActiveTargetObjectFileFormat(name: name)
824+
func isActiveTargetObjectFormat(name: String) throws -> Bool {
825+
return try other.isActiveTargetObjectFormat(name: name)
826826
}
827827

828828
var targetPointerBitWidth: Int { return other.targetPointerBitWidth }

Sources/SwiftIfConfig/IfConfigFunctions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ enum IfConfigFunctions: String {
5050
case _pointerBitWidth
5151

5252
/// A check for the target object file format (e.g., ELF)
53-
case _objectFileFormat
53+
case objectFormat
5454

5555
/// A check for the target runtime paired with the Swift runtime (e.g., _ObjC)
5656
/// via `_runtime(<name>)`.
@@ -72,7 +72,7 @@ enum IfConfigFunctions: String {
7272
return true
7373

7474
case .hasAttribute, .hasFeature, .canImport, .os, .arch, .targetEnvironment,
75-
._hasAtomicBitWidth, ._endian, ._pointerBitWidth, ._objectFileFormat, ._runtime, ._ptrauth, .defined:
75+
._hasAtomicBitWidth, ._endian, ._pointerBitWidth, .objectFormat, ._runtime, ._ptrauth, .defined:
7676
return false
7777
}
7878
}

Sources/SwiftIfConfig/StaticBuildConfiguration.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,7 @@ extension StaticBuildConfiguration: BuildConfiguration {
413413
/// - Parameters:
414414
/// - name: The name of the object file format.
415415
/// - Returns: Whether the target object file format matches the given name.
416-
@_spi(ExperimentalLanguageFeatures)
417-
public func isActiveTargetObjectFileFormat(name: String) -> Bool {
416+
public func isActiveTargetObjectFormat(name: String) -> Bool {
418417
targetObjectFileFormats.contains(name)
419418
}
420419

Tests/SwiftIfConfigTest/EvaluateTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ public class EvaluateTests: XCTestCase {
228228
assertIfConfig("_pointerBitWidth(_32)", .inactive)
229229
assertIfConfig("_hasAtomicBitWidth(_64)", .active)
230230
assertIfConfig("_hasAtomicBitWidth(_128)", .inactive)
231-
assertIfConfig("_objectFileFormat(ELF)", .active)
232-
assertIfConfig("_objectFileFormat(MachO)", .inactive)
231+
assertIfConfig("objectFormat(ELF)", .active)
232+
assertIfConfig("objectFormat(MachO)", .inactive)
233233

234234
assertIfConfig(
235235
"_endian(mid)",

Tests/SwiftIfConfigTest/TestingBuildConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ struct TestingBuildConfiguration: BuildConfiguration {
9999
name == "arm64e"
100100
}
101101

102-
func isActiveTargetObjectFileFormat(name: String) throws -> Bool {
102+
func isActiveTargetObjectFormat(name: String) throws -> Bool {
103103
name == "ELF"
104104
}
105105

0 commit comments

Comments
 (0)