Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 8 additions & 6 deletions Sources/SwiftIfConfig/BuildConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ public enum CanImportVersion {

enum BuildConfigurationError: Error, CustomStringConvertible {
case experimentalFeature(name: String)
case notImplemented(name: String)

var description: String {
switch self {
case .experimentalFeature(let name):
return "'\(name)' is an experimental feature"
case .notImplemented(let name):
return "'\(name)' not implemented"
}
}
}
Expand Down Expand Up @@ -228,18 +231,17 @@ public protocol BuildConfiguration {
/// Determine whether the given name is the active target object file format (e.g., ELF).
///
/// The target object file format can only be queried by an experimental
/// syntax `_objectFileFormat(<name>)`, e.g.,
/// syntax `objectFormat(<name>)`, e.g.,
///
/// ```swift
/// #if _objectFileFormat(ELF)
/// #if objectFormat(ELF)
/// // Special logic for ELF object file formats
/// #endif
/// ```
/// - Parameters:
/// - name: The name of the object file format.
/// - Returns: Whether the target object file format matches the given name.
@_spi(ExperimentalLanguageFeatures)
func isActiveTargetObjectFileFormat(name: String) throws -> Bool
func isActiveTargetObjectFormat(name: String) throws -> Bool

/// The bit width of a data pointer for the target architecture.
///
Expand Down Expand Up @@ -309,7 +311,7 @@ public protocol BuildConfiguration {
extension BuildConfiguration {
/// FIXME: This should be @_spi(ExperimentalLanguageFeatures) but cannot due
/// to rdar://147943518, https://github.com/swiftlang/swift/issues/80313
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this FIXME is no longer relevant now, right?

Also, could you mark this default implementation as deprecated so that clients conforming to BuildConfiguration without implementing isActiveTargetObjectFormat get a warning, similar to what we do in

@available(*, deprecated, message: "`MacroExpansionContext` conformance must implement `lexicalContext`")

public func isActiveTargetObjectFileFormat(name: String) throws -> Bool {
throw BuildConfigurationError.experimentalFeature(name: "_objectFileFormat")
public func isActiveTargetObjectFormat(name: String) throws -> Bool {
throw BuildConfigurationError.notImplemented(name: "isActiveTargetObjectFormat")
}
}
8 changes: 4 additions & 4 deletions Sources/SwiftIfConfig/IfConfigEvaluation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ func evaluateIfConfig(
case .targetEnvironment:
return doSingleIdentifierArgumentCheck(configuration.isActiveTargetEnvironment, role: "environment")

case ._objectFileFormat:
return doSingleIdentifierArgumentCheck(configuration.isActiveTargetObjectFileFormat, role: "object file format")
case .objectFormat:
return doSingleIdentifierArgumentCheck(configuration.isActiveTargetObjectFormat, role: "object file format")

case ._runtime:
return doSingleIdentifierArgumentCheck(configuration.isActiveTargetRuntime, role: "runtime")
Expand Down Expand Up @@ -821,8 +821,8 @@ private struct CanImportSuppressingBuildConfiguration<Other: BuildConfiguration>
return try other.isActiveTargetPointerAuthentication(name: name)
}

func isActiveTargetObjectFileFormat(name: String) throws -> Bool {
return try other.isActiveTargetObjectFileFormat(name: name)
func isActiveTargetObjectFormat(name: String) throws -> Bool {
return try other.isActiveTargetObjectFormat(name: name)
}

var targetPointerBitWidth: Int { return other.targetPointerBitWidth }
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftIfConfig/IfConfigFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ enum IfConfigFunctions: String {
case _pointerBitWidth

/// A check for the target object file format (e.g., ELF)
case _objectFileFormat
case objectFormat

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

case .hasAttribute, .hasFeature, .canImport, .os, .arch, .targetEnvironment,
._hasAtomicBitWidth, ._endian, ._pointerBitWidth, ._objectFileFormat, ._runtime, ._ptrauth, .defined:
._hasAtomicBitWidth, ._endian, ._pointerBitWidth, .objectFormat, ._runtime, ._ptrauth, .defined:
return false
}
}
Expand Down
3 changes: 1 addition & 2 deletions Sources/SwiftIfConfig/StaticBuildConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,7 @@ extension StaticBuildConfiguration: BuildConfiguration {
/// - Parameters:
/// - name: The name of the object file format.
/// - Returns: Whether the target object file format matches the given name.
@_spi(ExperimentalLanguageFeatures)
public func isActiveTargetObjectFileFormat(name: String) -> Bool {
public func isActiveTargetObjectFormat(name: String) -> Bool {
targetObjectFileFormats.contains(name)
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftIfConfigTest/EvaluateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ public class EvaluateTests: XCTestCase {
assertIfConfig("_pointerBitWidth(_32)", .inactive)
assertIfConfig("_hasAtomicBitWidth(_64)", .active)
assertIfConfig("_hasAtomicBitWidth(_128)", .inactive)
assertIfConfig("_objectFileFormat(ELF)", .active)
assertIfConfig("_objectFileFormat(MachO)", .inactive)
assertIfConfig("objectFormat(ELF)", .active)
assertIfConfig("objectFormat(MachO)", .inactive)

assertIfConfig(
"_endian(mid)",
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftIfConfigTest/TestingBuildConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct TestingBuildConfiguration: BuildConfiguration {
name == "arm64e"
}

func isActiveTargetObjectFileFormat(name: String) throws -> Bool {
func isActiveTargetObjectFormat(name: String) throws -> Bool {
name == "ELF"
}

Expand Down