Skip to content

Commit c21899e

Browse files
committed
Add BuiltinModule experimental feature
1 parent 175e712 commit c21899e

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
@@ -183,6 +183,9 @@ EXPERIMENTAL_FEATURE(GenerateBindingsForThrowingFunctionsInCXX, false)
183183
/// Enable reference bindings.
184184
EXPERIMENTAL_FEATURE(ReferenceBindings, false)
185185

186+
/// Enable the explicit 'import Builtin' and allow Builtin usage.
187+
EXPERIMENTAL_FEATURE(BuiltinModule, true)
188+
186189
#undef EXPERIMENTAL_FEATURE
187190
#undef UPCOMING_FEATURE
188191
#undef SUPPRESSIBLE_LANGUAGE_FEATURE

include/swift/Basic/LangOptions.h

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

539-
/// Allows the explicit 'import Builtin' within Swift modules.
540-
bool EnableBuiltinModule = false;
541-
542539
bool isConcurrencyModelTaskToThread() const {
543540
return ActiveConcurrencyModel == ConcurrencyModel::TaskToThread;
544541
}

lib/AST/ASTPrinter.cpp

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

3282+
static bool usesFeatureBuiltinModule(Decl *decl) {
3283+
return false;
3284+
}
3285+
32823286
/// Suppress the printing of a particular feature.
32833287
static void suppressingFeature(PrintOptions &options, Feature feature,
32843288
llvm::function_ref<void()> action) {

lib/Frontend/CompilerInvocation.cpp

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

738+
if (Args.hasArg(OPT_enable_builtin_module))
739+
Opts.Features.insert(Feature::BuiltinModule);
740+
738741
Opts.EnableAppExtensionRestrictions |= Args.hasArg(OPT_enable_app_extension);
739742

740743
Opts.EnableSwift3ObjCInference =
@@ -1153,8 +1156,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
11531156
.Default(ConcurrencyModel::Standard);
11541157
}
11551158

1156-
Opts.EnableBuiltinModule = Args.hasArg(OPT_enable_builtin_module);
1157-
11581159
return HadError || UnsupportedOS || UnsupportedArch;
11591160
}
11601161

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
@@ -365,11 +365,13 @@ ImportResolver::getModule(ImportPath::Module modulePath) {
365365

366366
// The Builtin module cannot be explicitly imported unless:
367367
// 1. We're in a .sil file
368-
// 2. '-enable-builtin-module' was passed.
368+
// 2. '-enable-builtin-module'/'-enable-experimental-feature BuiltinModule'
369+
// was passed.
369370
//
370371
// FIXME: Eventually, it would be nice to separate '-parse-stdlib' from
371372
// implicitly importing Builtin, but we're not there yet.
372-
if (SF.Kind == SourceFileKind::SIL || ctx.LangOpts.EnableBuiltinModule) {
373+
if (SF.Kind == SourceFileKind::SIL ||
374+
ctx.LangOpts.hasFeature(Feature::BuiltinModule)) {
373375
if (moduleID.Item == ctx.TheBuiltinModule->getName()) {
374376
return ctx.TheBuiltinModule;
375377
}

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)