Skip to content

Commit bb4dc43

Browse files
committed
[NFC] Basic: Extract feature API definitions into their own file
1 parent c7e4a73 commit bb4dc43

File tree

3 files changed

+86
-64
lines changed

3 files changed

+86
-64
lines changed

lib/Basic/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ add_swift_host_library(swiftBasic STATIC
5252
Edit.cpp
5353
EditorPlaceholder.cpp
5454
ExponentialGrowthAppendingBinaryByteStream.cpp
55+
Feature.cpp
5556
FileSystem.cpp
5657
FileTypes.cpp
5758
Fingerprint.cpp

lib/Basic/Feature.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//===--- Feature.cpp --------------------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 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+
#include "swift/Basic/Feature.h"
14+
#include "llvm/ADT/StringSwitch.h"
15+
#include "llvm/Support/ErrorHandling.h"
16+
17+
using namespace swift;
18+
19+
bool swift::isFeatureAvailableInProduction(Feature feature) {
20+
switch (feature) {
21+
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) \
22+
case Feature::FeatureName: \
23+
return true;
24+
#define EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) \
25+
case Feature::FeatureName: \
26+
return AvailableInProd;
27+
#include "swift/Basic/Features.def"
28+
}
29+
llvm_unreachable("covered switch");
30+
}
31+
32+
llvm::StringRef swift::getFeatureName(Feature feature) {
33+
switch (feature) {
34+
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) \
35+
case Feature::FeatureName: \
36+
return #FeatureName;
37+
#include "swift/Basic/Features.def"
38+
}
39+
llvm_unreachable("covered switch");
40+
}
41+
42+
std::optional<Feature> swift::getUpcomingFeature(llvm::StringRef name) {
43+
return llvm::StringSwitch<std::optional<Feature>>(name)
44+
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description)
45+
#define UPCOMING_FEATURE(FeatureName, SENumber, Version) \
46+
.Case(#FeatureName, Feature::FeatureName)
47+
#include "swift/Basic/Features.def"
48+
.Default(std::nullopt);
49+
}
50+
51+
std::optional<Feature> swift::getExperimentalFeature(llvm::StringRef name) {
52+
return llvm::StringSwitch<std::optional<Feature>>(name)
53+
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description)
54+
#define EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) \
55+
.Case(#FeatureName, Feature::FeatureName)
56+
#include "swift/Basic/Features.def"
57+
.Default(std::nullopt);
58+
}
59+
60+
std::optional<unsigned> swift::getFeatureLanguageVersion(Feature feature) {
61+
switch (feature) {
62+
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description)
63+
#define UPCOMING_FEATURE(FeatureName, SENumber, Version) \
64+
case Feature::FeatureName: \
65+
return Version;
66+
#include "swift/Basic/Features.def"
67+
default:
68+
return std::nullopt;
69+
}
70+
}
71+
72+
bool swift::includeInModuleInterface(Feature feature) {
73+
switch (feature) {
74+
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) \
75+
case Feature::FeatureName: \
76+
return true;
77+
#define EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE(FeatureName, \
78+
AvailableInProd) \
79+
case Feature::FeatureName: \
80+
return false;
81+
#include "swift/Basic/Features.def"
82+
}
83+
llvm_unreachable("covered switch");
84+
}

lib/Basic/LangOptions.cpp

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -619,69 +619,6 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
619619
return { false, false };
620620
}
621621

622-
llvm::StringRef swift::getFeatureName(Feature feature) {
623-
switch (feature) {
624-
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) \
625-
case Feature::FeatureName: \
626-
return #FeatureName;
627-
#include "swift/Basic/Features.def"
628-
}
629-
llvm_unreachable("covered switch");
630-
}
631-
632-
bool swift::isFeatureAvailableInProduction(Feature feature) {
633-
switch (feature) {
634-
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) \
635-
case Feature::FeatureName: \
636-
return true;
637-
#define EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) \
638-
case Feature::FeatureName: return AvailableInProd;
639-
#include "swift/Basic/Features.def"
640-
}
641-
llvm_unreachable("covered switch");
642-
}
643-
644-
std::optional<Feature> swift::getUpcomingFeature(llvm::StringRef name) {
645-
return llvm::StringSwitch<std::optional<Feature>>(name)
646-
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description)
647-
#define UPCOMING_FEATURE(FeatureName, SENumber, Version) \
648-
.Case(#FeatureName, Feature::FeatureName)
649-
#include "swift/Basic/Features.def"
650-
.Default(std::nullopt);
651-
}
652-
653-
std::optional<Feature> swift::getExperimentalFeature(llvm::StringRef name) {
654-
return llvm::StringSwitch<std::optional<Feature>>(name)
655-
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description)
656-
#define EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) \
657-
.Case(#FeatureName, Feature::FeatureName)
658-
#include "swift/Basic/Features.def"
659-
.Default(std::nullopt);
660-
}
661-
662-
std::optional<unsigned> swift::getFeatureLanguageVersion(Feature feature) {
663-
switch (feature) {
664-
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description)
665-
#define UPCOMING_FEATURE(FeatureName, SENumber, Version) \
666-
case Feature::FeatureName: return Version;
667-
#include "swift/Basic/Features.def"
668-
default:
669-
return std::nullopt;
670-
}
671-
}
672-
673-
bool swift::includeInModuleInterface(Feature feature) {
674-
switch (feature) {
675-
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) \
676-
case Feature::FeatureName: \
677-
return true;
678-
#define EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE(FeatureName, AvailableInProd) \
679-
case Feature::FeatureName: return false;
680-
#include "swift/Basic/Features.def"
681-
}
682-
llvm_unreachable("covered switch");
683-
}
684-
685622
llvm::StringRef swift::getPlaygroundOptionName(PlaygroundOption option) {
686623
switch (option) {
687624
#define PLAYGROUND_OPTION(OptionName, Description, DefaultOn, HighPerfOn) \

0 commit comments

Comments
 (0)