Skip to content

Commit 4a68116

Browse files
authored
Merge pull request #64673 from Azoy/builtin-module-feature
[Frontend] Add BuiltinModule experimental feature
2 parents aa3fd95 + c21899e commit 4a68116

File tree

7 files changed

+20
-10
lines changed

7 files changed

+20
-10
lines changed

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ EXPERIMENTAL_FEATURE(GenerateBindingsForThrowingFunctionsInCXX, false)
188188
/// Enable reference bindings.
189189
EXPERIMENTAL_FEATURE(ReferenceBindings, false)
190190

191+
/// Enable the explicit 'import Builtin' and allow Builtin usage.
192+
EXPERIMENTAL_FEATURE(BuiltinModule, true)
193+
191194
#undef EXPERIMENTAL_FEATURE
192195
#undef UPCOMING_FEATURE
193196
#undef SUPPRESSIBLE_LANGUAGE_FEATURE

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,6 @@ namespace swift {
556556
/// The model of concurrency to be used.
557557
ConcurrencyModel ActiveConcurrencyModel = ConcurrencyModel::Standard;
558558

559-
/// Allows the explicit 'import Builtin' within Swift modules.
560-
bool EnableBuiltinModule = false;
561-
562559
bool isConcurrencyModelTaskToThread() const {
563560
return ActiveConcurrencyModel == ConcurrencyModel::TaskToThread;
564561
}

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3338,6 +3338,10 @@ static bool usesFeatureReferenceBindings(Decl *decl) {
33383338
return vd && vd->getIntroducer() == VarDecl::Introducer::InOut;
33393339
}
33403340

3341+
static bool usesFeatureBuiltinModule(Decl *decl) {
3342+
return false;
3343+
}
3344+
33413345
/// Suppress the printing of a particular feature.
33423346
static void suppressingFeature(PrintOptions &options, Feature feature,
33433347
llvm::function_ref<void()> action) {

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
753753
if (Args.hasArg(OPT_enable_experimental_opaque_type_erasure))
754754
Opts.Features.insert(Feature::OpaqueTypeErasure);
755755

756+
if (Args.hasArg(OPT_enable_builtin_module))
757+
Opts.Features.insert(Feature::BuiltinModule);
758+
756759
Opts.EnableAppExtensionRestrictions |= Args.hasArg(OPT_enable_app_extension);
757760

758761
Opts.EnableSwift3ObjCInference =
@@ -1171,8 +1174,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
11711174
.Default(ConcurrencyModel::Standard);
11721175
}
11731176

1174-
Opts.EnableBuiltinModule = Args.hasArg(OPT_enable_builtin_module);
1175-
11761177
return HadError || UnsupportedOS || UnsupportedArch;
11771178
}
11781179

lib/Frontend/ModuleInterfaceSupport.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,12 @@ static void printImports(raw_ostream &out,
295295
continue;
296296
}
297297

298-
// Unless '-enable-builtin-module' was passed, do not print 'import Builtin'
299-
// in the interface. '-parse-stdlib' still implicitly imports it however...
298+
// Unless '-enable-builtin-module' /
299+
// '-enable-experimental-feature BuiltinModule' was passed, do not print
300+
// 'import Builtin' in the interface. '-parse-stdlib' still implicitly
301+
// imports it however...
300302
if (importedModule->isBuiltinModule() &&
301-
!M->getASTContext().LangOpts.EnableBuiltinModule) {
303+
!M->getASTContext().LangOpts.hasFeature(Feature::BuiltinModule)) {
302304
continue;
303305
}
304306

lib/Sema/ImportResolution.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,13 @@ ImportResolver::getModule(ImportPath::Module modulePath) {
374374

375375
// The Builtin module cannot be explicitly imported unless:
376376
// 1. We're in a .sil file
377-
// 2. '-enable-builtin-module' was passed.
377+
// 2. '-enable-builtin-module'/'-enable-experimental-feature BuiltinModule'
378+
// was passed.
378379
//
379380
// FIXME: Eventually, it would be nice to separate '-parse-stdlib' from
380381
// implicitly importing Builtin, but we're not there yet.
381-
if (SF.Kind == SourceFileKind::SIL || ctx.LangOpts.EnableBuiltinModule) {
382+
if (SF.Kind == SourceFileKind::SIL ||
383+
ctx.LangOpts.hasFeature(Feature::BuiltinModule)) {
382384
if (moduleID.Item == ctx.TheBuiltinModule->getName()) {
383385
return ctx.TheBuiltinModule;
384386
}

test/Frontend/enable_builtin_module.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: not %target-swift-frontend -typecheck -show-diagnostics-after-fatal -D BUILTIN_IMPORT %s 2>&1 | %FileCheck -check-prefix CHECK-NO-BUILTIN %s
22
// RUN: not %target-swift-frontend -typecheck -show-diagnostics-after-fatal -enable-builtin-module %s 2>&1 | %FileCheck -check-prefix CHECK-NO-BUILTIN-IMPORT %s
33
// RUN: %target-swift-frontend -typecheck -enable-builtin-module -D BUILTIN_IMPORT %s
4+
// RUN: %target-swift-frontend -typecheck -enable-experimental-feature BuiltinModule -D BUILTIN_IMPORT %s
45

56
// CHECK-NO-BUILTIN: no such module 'Builtin'
67

0 commit comments

Comments
 (0)