-
Notifications
You must be signed in to change notification settings - Fork 440
[SwiftSyntax] Add #_objectFileFormat compilation conditional #3027
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
Changes from 3 commits
025b60c
1861b8d
96f7e24
069bc30
fc75c9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,6 +214,21 @@ public protocol BuildConfiguration { | |
/// pointer authentication scheme. | ||
func isActiveTargetPointerAuthentication(name: String) throws -> Bool | ||
|
||
/// 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., | ||
/// | ||
/// ```swift | ||
/// #if _objectFileFormat(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. | ||
func isActiveTargetObjectFileFormat(name: String) throws -> Bool | ||
|
||
/// The bit width of a data pointer for the target architecture. | ||
/// | ||
/// The target's pointer bit width (which also corresponds to the number of | ||
|
@@ -276,3 +291,11 @@ public protocol BuildConfiguration { | |
/// #endif | ||
var compilerVersion: VersionTuple { get } | ||
} | ||
|
||
/// Default implementation of BuildConfiguration, to avoid a revlock with the | ||
/// swift repo. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not only to avoid revlock with the compiler repo. It is also to not introduce a new requirement to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed comment |
||
extension BuildConfiguration { | ||
func isActiveTargetObjectFileFormat(name: String) throws -> Bool { | ||
return false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this method should throw an error that has a description like The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ enum IfConfigDiagnostic: Error, CustomStringConvertible { | |
case likelySimulatorPlatform(syntax: ExprSyntax) | ||
case likelyTargetOS(syntax: ExprSyntax, replacement: ExprSyntax?) | ||
case endiannessDoesNotMatch(syntax: ExprSyntax, argument: String) | ||
case objectFileFormatDoesNotMatch(syntax: ExprSyntax, argument: String) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this used anywhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
case macabiIsMacCatalyst(syntax: ExprSyntax) | ||
case expectedModuleName(syntax: ExprSyntax) | ||
case badInfixOperator(syntax: ExprSyntax) | ||
|
@@ -102,6 +103,9 @@ enum IfConfigDiagnostic: Error, CustomStringConvertible { | |
case .endiannessDoesNotMatch: | ||
return "unknown endianness for build configuration '_endian' (must be 'big' or 'little')" | ||
|
||
case .objectFileFormatDoesNotMatch: | ||
return "unknown object file format for build configuration '_objectFileFormat'" | ||
|
||
case .expectedModuleName: | ||
return "expected module name" | ||
|
||
|
@@ -136,6 +140,7 @@ enum IfConfigDiagnostic: Error, CustomStringConvertible { | |
.likelySimulatorPlatform(syntax: let syntax), | ||
.likelyTargetOS(syntax: let syntax, replacement: _), | ||
.endiannessDoesNotMatch(syntax: let syntax, argument: _), | ||
.objectFileFormatDoesNotMatch(syntax: let syntax, argument: _), | ||
.macabiIsMacCatalyst(syntax: let syntax), | ||
.expectedModuleName(syntax: let syntax), | ||
.badInfixOperator(syntax: let syntax), | ||
|
@@ -159,7 +164,8 @@ extension IfConfigDiagnostic: DiagnosticMessage { | |
var severity: SwiftDiagnostics.DiagnosticSeverity { | ||
switch self { | ||
case .compilerVersionSecondComponentNotWildcard, .ignoredTrailingComponents, | ||
.likelySimulatorPlatform, .likelyTargetOS, .endiannessDoesNotMatch, .macabiIsMacCatalyst: | ||
.likelySimulatorPlatform, .likelyTargetOS, .endiannessDoesNotMatch, .objectFileFormatDoesNotMatch, | ||
.macabiIsMacCatalyst: | ||
return .warning | ||
default: return .error | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a default implementation returning
false
so that we can land thisswift-syntax
PR independently beforeswift
repo counterpart?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test failure is because the default implementation is not
public
🙏There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also make this
@_spi(ExperimentalLanguageFeatures)
so that clients can’t call it as public API and start relying on it.