Skip to content

Commit 5f9b898

Browse files
committed
Add a feature and module interface printing support for Builtin.Job
1 parent e7d7585 commit 5f9b898

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ LANGUAGE_FEATURE(Actors, 0, "actors", langOpts.EnableExperimentalConcurrency)
4141
LANGUAGE_FEATURE(ConcurrentFunctions, 0, "@concurrent functions", true)
4242
LANGUAGE_FEATURE(RethrowsProtocol, 0, "@rethrows protocol", true)
4343
LANGUAGE_FEATURE(GlobalActors, 0, "Global actors", langOpts.EnableExperimentalConcurrency)
44+
LANGUAGE_FEATURE(BuiltinJob, 0, "Builtin.Job type", true)
4445

4546
#undef LANGUAGE_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "swift/AST/ASTMangler.h"
2020
#include "swift/AST/ASTVisitor.h"
2121
#include "swift/AST/Attr.h"
22+
#include "swift/AST/Builtins.h"
2223
#include "swift/AST/ClangModuleLoader.h"
2324
#include "swift/AST/Comment.h"
2425
#include "swift/AST/Decl.h"
@@ -2577,6 +2578,34 @@ static bool usesFeatureGlobalActors(Decl *decl) {
25772578
return false;
25782579
}
25792580

2581+
static bool usesFeatureBuiltinJob(Decl *decl) {
2582+
auto typeHasBuiltinJob = [](Type type) {
2583+
return type.findIf([&](Type type) {
2584+
if (auto builtinTy = type->getAs<BuiltinType>())
2585+
return builtinTy->getBuiltinTypeKind() == BuiltinTypeKind::BuiltinJob;
2586+
2587+
return false;
2588+
});
2589+
};
2590+
2591+
if (auto value = dyn_cast<ValueDecl>(decl)) {
2592+
if (Type type = value->getInterfaceType()) {
2593+
if (typeHasBuiltinJob(type))
2594+
return true;
2595+
}
2596+
}
2597+
2598+
if (auto patternBinding = dyn_cast<PatternBindingDecl>(decl)) {
2599+
for (unsigned idx : range(patternBinding->getNumPatternEntries())) {
2600+
if (Type type = patternBinding->getPattern(idx)->getType())
2601+
if (typeHasBuiltinJob(type))
2602+
return true;
2603+
}
2604+
}
2605+
2606+
return false;
2607+
}
2608+
25802609
/// Determine the set of "new" features used on a given declaration.
25812610
///
25822611
/// Note: right now, all features we check for are "new". At some point, we'll

0 commit comments

Comments
 (0)