Skip to content

Commit 3ad19e1

Browse files
committed
Merge pull request #64673 from Azoy/builtin-module-feature
[Frontend] Add BuiltinModule experimental feature
1 parent e6ee37a commit 3ad19e1

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

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

include/swift/Basic/LangOptions.h

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

562-
/// Allows the explicit 'import Builtin' within Swift modules.
563-
bool EnableBuiltinModule = false;
564-
565562
bool isConcurrencyModelTaskToThread() const {
566563
return ActiveConcurrencyModel == ConcurrencyModel::TaskToThread;
567564
}

lib/AST/ASTPrinter.cpp

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

3308+
static bool usesFeatureBuiltinModule(Decl *decl) {
3309+
return false;
3310+
}
3311+
33083312
/// Suppress the printing of a particular feature.
33093313
static void suppressingFeature(PrintOptions &options, Feature feature,
33103314
llvm::function_ref<void()> action) {

lib/Frontend/CompilerInvocation.cpp

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

751+
if (Args.hasArg(OPT_enable_builtin_module))
752+
Opts.Features.insert(Feature::BuiltinModule);
753+
751754
Opts.EnableAppExtensionRestrictions |= Args.hasArg(OPT_enable_app_extension);
752755

753756
Opts.EnableSwift3ObjCInference =
@@ -1166,8 +1169,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
11661169
.Default(ConcurrencyModel::Standard);
11671170
}
11681171

1169-
Opts.EnableBuiltinModule = Args.hasArg(OPT_enable_builtin_module);
1170-
11711172
return HadError || UnsupportedOS || UnsupportedArch;
11721173
}
11731174

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)