Skip to content

AST: support availability on Windows #34439

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

Merged
merged 1 commit into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions include/swift/AST/PlatformKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ AVAILABILITY_PLATFORM(macOSApplicationExtension, "application extensions for mac
AVAILABILITY_PLATFORM(macCatalyst, "Mac Catalyst")
AVAILABILITY_PLATFORM(macCatalystApplicationExtension, "application extensions for Mac Catalyst")
AVAILABILITY_PLATFORM(OpenBSD, "OpenBSD")
AVAILABILITY_PLATFORM(Windows, "Windows")

#undef AVAILABILITY_PLATFORM
2 changes: 2 additions & 0 deletions lib/AST/PlatformKind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ static bool isPlatformActiveForTarget(PlatformKind Platform,
return Target.isWatchOS();
case PlatformKind::OpenBSD:
return Target.isOSOpenBSD();
case PlatformKind::Windows:
return Target.isOSWindows();
case PlatformKind::none:
llvm_unreachable("handled above");
}
Expand Down
11 changes: 11 additions & 0 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,10 @@ PlatformAvailability::PlatformAvailability(const LangOptions &langOpts)
deprecatedAsUnavailableMessage = "";
break;

case PlatformKind::Windows:
deprecatedAsUnavailableMessage = "";
break;

case PlatformKind::none:
break;
}
Expand Down Expand Up @@ -1969,6 +1973,9 @@ bool PlatformAvailability::isPlatformRelevant(StringRef name) const {
case PlatformKind::OpenBSD:
return name == "openbsd";

case PlatformKind::Windows:
return name == "windows";

case PlatformKind::none:
return false;
}
Expand Down Expand Up @@ -2012,6 +2019,10 @@ bool PlatformAvailability::treatDeprecatedAsUnavailable(
case PlatformKind::OpenBSD:
// No deprecation filter on OpenBSD
return false;

case PlatformKind::Windows:
// No deprecation filter on Windows
return false;
}

llvm_unreachable("Unexpected platform");
Expand Down
3 changes: 3 additions & 0 deletions lib/PrintAsObjC/DeclAndTypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,9 @@ class DeclAndTypePrinter::Implementation
case PlatformKind::OpenBSD:
plat = "openbsd";
break;
case PlatformKind::Windows:
plat = "windows";
break;
case PlatformKind::none:
llvm_unreachable("handled above");
}
Expand Down
2 changes: 2 additions & 0 deletions lib/SymbolGraphGen/AvailabilityMixin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ StringRef getDomain(const AvailableAttr &AvAttr) {
return { "watchOSAppExtension" };
case swift::PlatformKind::OpenBSD:
return { "OpenBSD" };
case swift::PlatformKind::Windows:
return { "Windows" };
case swift::PlatformKind::none:
return { "*" };
}
Expand Down
2 changes: 2 additions & 0 deletions lib/TBDGen/TBDGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ getLinkerPlatformId(OriginallyDefinedInAttr::ActiveVersion Ver) {
llvm_unreachable("cannot find platform kind");
case swift::PlatformKind::OpenBSD:
llvm_unreachable("not used for this platform");
case swift::PlatformKind::Windows:
llvm_unreachable("not used for this platform");
case swift::PlatformKind::iOS:
case swift::PlatformKind::iOSApplicationExtension:
return Ver.IsSimulator ? LinkerPlatformId::iOS_sim:
Expand Down
1 change: 1 addition & 0 deletions test/IDE/complete_decl_attribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct MyStruct {}
// AVAILABILITY1-NEXT: Keyword/None: macCatalyst[#Platform#]; name=macCatalyst
// AVAILABILITY1-NEXT: Keyword/None: macCatalystApplicationExtension[#Platform#]; name=macCatalystApplicationExtension
// AVAILABILITY1-NEXT: Keyword/None: OpenBSD[#Platform#]; name=OpenBSD{{$}}
// AVAILABILITY1-NEXT: Keyword/None: Windows[#Platform#]; name=Windows{{$}}
// AVAILABILITY1-NEXT: End completions

@available(*, #^AVAILABILITY2^#)
Expand Down
28 changes: 28 additions & 0 deletions test/Parse/diagnose_availability_windows.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %target-typecheck-verify-swift
// REQUIRES: OS=windows-msvc

// expected-note@+2{{'unavailable()' has been explicitly marked unavailable here}}
@available(Windows, unavailable, message: "unsupported")
func unavailable() {}

// expected-error@+1 {{'unavailable()' is unavailable in Windows: unsupported}}
unavailable()

@available(Windows, introduced: 10.0.17763, deprecated: 10.0.19140)
func introduced_deprecated() {}

// expected-error@+1 {{'introduced_deprecated()' is only available in * 10.0.17763 or newe}}
introduced_deprecated()
// expected-note@-1 {{add 'if #available' version check}}

@available(Windows 10, *)
func windows10() {}

// expected-error@+1 {{'windows10()' is only available in * 10 or newer}}
windows10()
// expected-note@-1 {{add 'if #available' version check}}

func coniditonal_compilation() {
if #available(Windows 10, *) {
}
}
3 changes: 3 additions & 0 deletions tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ static void reportAttributes(ASTContext &Ctx,
static UIdent PlatformtvOSAppExt("source.availability.platform.tvos_app_extension");
static UIdent PlatformWatchOSAppExt("source.availability.platform.watchos_app_extension");
static UIdent PlatformOpenBSD("source.availability.platform.openbsd");
static UIdent PlatformWindows("source.availability.platform.windows");
std::vector<const DeclAttribute*> Scratch;

for (auto Attr : getDeclAttributes(D, Scratch)) {
Expand Down Expand Up @@ -690,6 +691,8 @@ static void reportAttributes(ASTContext &Ctx,
PlatformUID = PlatformWatchOSAppExt; break;
case PlatformKind::OpenBSD:
PlatformUID = PlatformOpenBSD; break;
case PlatformKind::Windows:
PlatformUID = PlatformWindows; break;
}

AvailableAttrInfo Info;
Expand Down