Skip to content

Commit 89c053d

Browse files
authored
Merge pull request #1452 from swiftwasm/release/5.3
[pull] swiftwasm-release/5.3 from release/5.3
2 parents cd095d1 + b528731 commit 89c053d

26 files changed

+531
-569
lines changed

include/swift/AST/Attr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,8 @@ class AvailableAttr : public DeclAttribute {
814814
}
815815

816816
/// Returns the string for the platform of the attribute.
817-
StringRef platformString() const {
818-
return swift::platformString(Platform);
817+
StringRef platformString(bool PreferMacOSSpelling = false) const {
818+
return swift::platformString(Platform, PreferMacOSSpelling);
819819
}
820820

821821
/// Returns the human-readable string for the platform of the attribute.

include/swift/AST/PlatformKind.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ enum class PlatformKind: uint8_t {
3535

3636
/// Returns the short string representing the platform, suitable for
3737
/// use in availability specifications (e.g., "OSX").
38-
StringRef platformString(PlatformKind platform);
38+
///
39+
/// \param useMacOSSpelling whether use the "macOS" spelling in place of "OSX".
40+
StringRef platformString(PlatformKind platform, bool useMacOSSpelling = false);
3941

4042
/// Returns the platform kind corresponding to the passed-in short platform name
4143
/// or None if such a platform kind does not exist.

include/swift/AST/PrintOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ struct PrintOptions {
442442
/// (e.g. MyFramework).
443443
bool MapCrossImportOverlaysToDeclaringModule = false;
444444

445+
bool PreferMacOSSpelling = false;
446+
445447
bool PrintAsMember = false;
446448

447449
/// Whether to print parameter specifiers as 'let' and 'var'.
@@ -530,6 +532,7 @@ struct PrintOptions {
530532
result.SkipUnderscoredKeywords = true;
531533
result.EnumRawValues = EnumRawValueMode::PrintObjCOnly;
532534
result.MapCrossImportOverlaysToDeclaringModule = true;
535+
result.PreferMacOSSpelling = true;
533536
return result;
534537
}
535538

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===--- FoundationSupport.cpp - Support functions for Foundation ---------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2020 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+
// Helper functions for the Foundation framework.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SWIFT_RUNTIME_FOUNDATION_SUPPORT_H
18+
#define SWIFT_RUNTIME_FOUNDATION_SUPPORT_H
19+
20+
#include "swift/Runtime/Config.h"
21+
22+
#if SWIFT_OBJC_INTEROP
23+
#include <objc/runtime.h>
24+
25+
#ifdef __cplusplus
26+
namespace swift { extern "C" {
27+
#endif
28+
29+
/// Returns a boolean indicating whether the Objective-C name of a class type is
30+
/// stable across executions, i.e., if the class name is safe to serialize. (The
31+
/// names of private and local types are unstable.)
32+
SWIFT_RUNTIME_STDLIB_SPI
33+
bool _swift_isObjCTypeNameSerializable(Class theClass);
34+
35+
#ifdef __cplusplus
36+
}} // extern "C", namespace swift
37+
#endif
38+
39+
#endif // SWIFT_OBJC_INTEROP
40+
#endif // SWIFT_RUNTIME_FOUNDATION_SUPPORT_H

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,9 @@ void PrintAST::printAttributes(const Decl *D) {
991991
}
992992

993993
// SPI groups
994-
if (Options.PrintSPIs) {
994+
if (Options.PrintSPIs &&
995+
DeclAttribute::canAttributeAppearOnDeclKind(
996+
DAK_SPIAccessControl, D->getKind())) {
995997
interleave(D->getSPIGroups(),
996998
[&](Identifier spiName) {
997999
Printer.printAttrName("_spi", true);

lib/AST/Attr.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ static void printShortFormAvailable(ArrayRef<const DeclAttribute *> Attrs,
427427
assert(AvailAttr->Introduced.hasValue());
428428
if (isShortFormAvailabilityImpliedByOther(AvailAttr, Attrs))
429429
continue;
430-
Printer << platformString(AvailAttr->Platform) << " "
430+
Printer << platformString(AvailAttr->Platform,
431+
Options.PreferMacOSSpelling) << " "
431432
<< AvailAttr->Introduced.getValue().getAsString() << ", ";
432433
}
433434
Printer << "*)";
@@ -844,8 +845,8 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
844845
Printer << "(module: ";
845846
auto Attr = cast<OriginallyDefinedInAttr>(this);
846847
Printer << "\"" << Attr->OriginalModuleName << "\", ";
847-
Printer << platformString(Attr->Platform) << " " <<
848-
Attr->MovedVersion.getAsString();
848+
Printer << platformString(Attr->Platform, Options.PreferMacOSSpelling) <<
849+
" " << Attr->MovedVersion.getAsString();
849850
Printer << ")";
850851
break;
851852
}
@@ -859,7 +860,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
859860
else if (Attr->isPackageDescriptionVersionSpecific())
860861
Printer << "_PackageDescription";
861862
else
862-
Printer << Attr->platformString();
863+
Printer << Attr->platformString(Options.PreferMacOSSpelling);
863864

864865
if (Attr->isUnconditionallyUnavailable())
865866
Printer << ", unavailable";

lib/AST/PlatformKind.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,18 @@
2323

2424
using namespace swift;
2525

26-
StringRef swift::platformString(PlatformKind platform) {
26+
StringRef swift::platformString(PlatformKind platform, bool useMacOSSpelling) {
27+
if (useMacOSSpelling) {
28+
switch (platform) {
29+
case PlatformKind::OSX:
30+
return "macOS";
31+
case PlatformKind::OSXApplicationExtension:
32+
return "macOSApplicationExtension";
33+
default:
34+
break;
35+
}
36+
}
37+
2738
switch (platform) {
2839
case PlatformKind::none:
2940
return "*";

lib/Frontend/CompilerInvocation.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ void CompilerInvocation::setDefaultPrebuiltCacheIfNecessary() {
7676
platform = getPlatformNameForTriple(LangOpts.Target);
7777
}
7878
llvm::sys::path::append(defaultPrebuiltPath, platform, "prebuilt-modules");
79+
80+
// If the SDK version is given, we should check if SDK-versioned prebuilt
81+
// module cache is available and use it if so.
82+
if (auto ver = LangOpts.SDKVersion) {
83+
// "../macosx/prebuilt-modules"
84+
SmallString<64> defaultPrebuiltPathWithSDKVer = defaultPrebuiltPath;
85+
// "../macosx/prebuilt-modules/10.15"
86+
llvm::sys::path::append(defaultPrebuiltPathWithSDKVer, ver->getAsString());
87+
// If the versioned prebuilt module cache exists in the disk, use it.
88+
if (llvm::sys::fs::exists(defaultPrebuiltPathWithSDKVer)) {
89+
FrontendOpts.PrebuiltModuleCachePath = defaultPrebuiltPathWithSDKVer.str();
90+
return;
91+
}
92+
}
7993
FrontendOpts.PrebuiltModuleCachePath = defaultPrebuiltPath.str();
8094
}
8195

stdlib/public/Darwin/Foundation/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_swift_target_library(swiftFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES
77
BundleLookup.mm
88
Calendar.swift
99
CharacterSet.swift
10-
CheckClass.mm
10+
CheckClass.swift
1111
Codable.swift
1212
Collections+DataProtocol.swift
1313
CombineTypealiases.swift

0 commit comments

Comments
 (0)