Skip to content

Commit b9adb29

Browse files
authored
SE-0106: "macOS" instead of "OSX" in #available, @available, and #if
Merge pull request #3395 from jrose-apple/osx-is-dead-long-live-macos
2 parents f32541e + d6a726e commit b9adb29

File tree

11 files changed

+60
-26
lines changed

11 files changed

+60
-26
lines changed

include/swift/AST/Stmt.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,10 @@ class alignas(8) PoundAvailableInfo final :
269269
const VersionRange &getAvailableRange() const { return AvailableRange; }
270270
void setAvailableRange(const VersionRange &Range) { AvailableRange = Range; }
271271

272-
void getPlatformKeywordRanges(SmallVectorImpl<CharSourceRange>
273-
&PlatformRanges);
272+
void getPlatformKeywordLocs(SmallVectorImpl<SourceLoc> &PlatformLocs);
274273
};
275274

276-
277275

278-
279276
/// This represents an entry in an "if" or "while" condition. Pattern bindings
280277
/// can bind any number of names in the pattern binding decl, and may have an
281278
/// associated where clause. When "if let" is involved, an arbitrary number of

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ namespace swift {
235235

236236
/// Returns true if the 'os' platform condition argument represents
237237
/// a supported target operating system.
238-
static bool isPlatformConditionOSSupported(StringRef OSName);
238+
///
239+
/// Note that this also canonicalizes the OS name if the check returns
240+
/// true.
241+
static bool checkPlatformConditionOS(StringRef &OSName);
239242

240243
/// Returns true if the 'arch' platform condition argument represents
241244
/// a supported target architecture.

lib/AST/PlatformKind.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Optional<PlatformKind> swift::platformFromString(StringRef Name) {
5151
return llvm::StringSwitch<Optional<PlatformKind>>(Name)
5252
#define AVAILABILITY_PLATFORM(X, PrettyName) .Case(#X, PlatformKind::X)
5353
#include "swift/AST/PlatformKinds.def"
54+
.Case("macOS", PlatformKind::OSX)
55+
.Case("macOSApplicationExtension", PlatformKind::OSXApplicationExtension)
5456
.Default(Optional<PlatformKind>());
5557
}
5658

lib/AST/Stmt.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,24 +284,14 @@ SourceLoc PoundAvailableInfo::getEndLoc() const {
284284
}
285285

286286
void PoundAvailableInfo::
287-
getPlatformKeywordRanges(SmallVectorImpl<CharSourceRange> &PlatformRanges) {
287+
getPlatformKeywordLocs(SmallVectorImpl<SourceLoc> &PlatformLocs) {
288288
for (unsigned i = 0; i < NumQueries; i++) {
289289
auto *VersionSpec =
290290
dyn_cast<VersionConstraintAvailabilitySpec>(getQueries()[i]);
291291
if (!VersionSpec)
292292
continue;
293293

294-
auto Loc = VersionSpec->getPlatformLoc();
295-
auto Platform = VersionSpec->getPlatform();
296-
switch (Platform) {
297-
case PlatformKind::none:
298-
break;
299-
#define AVAILABILITY_PLATFORM(X, PrettyName) \
300-
case PlatformKind::X: \
301-
PlatformRanges.push_back(CharSourceRange(Loc, strlen(#X))); \
302-
break;
303-
#include "swift/AST/PlatformKinds.def"
304-
}
294+
PlatformLocs.push_back(VersionSpec->getPlatformLoc());
305295
}
306296
}
307297

lib/Basic/LangOptions.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ bool contains(const Type (&Array)[N], const Type &V) {
5555
return std::find(std::begin(Array), std::end(Array), V) != std::end(Array);
5656
}
5757

58-
bool LangOptions::isPlatformConditionOSSupported(StringRef OSName) {
58+
bool LangOptions::checkPlatformConditionOS(StringRef &OSName) {
59+
if (OSName == "macOS")
60+
OSName = "OSX";
5961
return contains(SupportedConditionalCompilationOSs, OSName);
6062
}
6163

lib/IDE/SyntaxModel.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -549,12 +549,13 @@ void ModelASTWalker::handleStmtCondition(StmtCondition cond) {
549549
for (const auto &elt : cond) {
550550
if (elt.getKind() != StmtConditionElement::CK_Availability) continue;
551551

552-
SmallVector<CharSourceRange, 5> PlatformRanges;
553-
elt.getAvailability()->getPlatformKeywordRanges(PlatformRanges);
554-
std::for_each(PlatformRanges.begin(), PlatformRanges.end(),
555-
[&](CharSourceRange &Range) {
556-
passNonTokenNode({SyntaxNodeKind::Keyword, Range});
557-
});
552+
SmallVector<SourceLoc, 5> PlatformLocs;
553+
elt.getAvailability()->getPlatformKeywordLocs(PlatformLocs);
554+
std::for_each(PlatformLocs.begin(), PlatformLocs.end(),
555+
[&](SourceLoc loc) {
556+
auto range = charSourceRangeFromSourceRange(SM, loc);
557+
passNonTokenNode({SyntaxNodeKind::Keyword, range});
558+
});
558559
}
559560
}
560561

lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,7 @@ Parser::evaluateConditionalCompilationExpr(Expr *condition) {
17111711
return ConditionalCompilationExprState::error();
17121712
}
17131713
if (fnName == "os") {
1714-
if (!LangOptions::isPlatformConditionOSSupported(argument)) {
1714+
if (!LangOptions::checkPlatformConditionOS(argument)) {
17151715
diagnose(UDRE->getLoc(), diag::unknown_platform_condition_argument,
17161716
"operating system", fnName);
17171717
return ConditionalCompilationExprState::error();

test/Parse/ConditionalCompilation/x64OSXTarget.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ class C {}
66
var x = C()
77
#endif
88
var y = x
9+
10+
11+
#if arch(x86_64) && os(macOS) && _runtime(_ObjC) && _endian(little)
12+
class CC {}
13+
var xx = CC()
14+
#endif
15+
var yy = xx

test/Parse/availability_query.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,8 @@ if 1 != 2, #available(iOS 8.0, *) {}
9999
if case 42 = 42, #available(iOS 8.0, *) {}
100100
if let x = Optional(42), #available(iOS 8.0, *) {}
101101

102+
// Allow "macOS" as well.
103+
if #available(macOS 10.51, *) {
104+
}
102105

103106

test/SILGen/availability_query.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ if #available(iOS 7.1, *) {
2929
if #available(OSX 10.52, *) {
3030
}
3131

32+
// CHECK: [[MAJOR:%.*]] = integer_literal $Builtin.Word, 10
33+
// CHECK: [[MINOR:%.*]] = integer_literal $Builtin.Word, 52
34+
// CHECK: [[PATCH:%.*]] = integer_literal $Builtin.Word, 0
35+
// CHECK: [[QUERY_FUNC:%.*]] = function_ref @_TFs26_stdlib_isOSVersionAtLeastFTBwBwBw_Bi1_ : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
36+
// CHECK: [[QUERY_RESULT:%.*]] = apply [[QUERY_FUNC]]([[MAJOR]], [[MINOR]], [[PATCH]]) : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1
37+
if #available(macOS 10.52, *) {
38+
}
39+
3240
// CHECK: [[MAJOR:%.*]] = integer_literal $Builtin.Word, 10
3341
// CHECK: [[MINOR:%.*]] = integer_literal $Builtin.Word, 0
3442
// CHECK: [[PATCH:%.*]] = integer_literal $Builtin.Word, 0

0 commit comments

Comments
 (0)