Skip to content

Commit 2d23c5d

Browse files
committed
Merge pull request swiftlang#64673 from Azoy/builtin-module-feature
[Frontend] Add BuiltinModule experimental feature
1 parent 1f4bc22 commit 2d23c5d

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
@@ -192,6 +192,9 @@ EXPERIMENTAL_FEATURE(GenerateBindingsForThrowingFunctionsInCXX, false)
192192
/// Enable reference bindings.
193193
EXPERIMENTAL_FEATURE(ReferenceBindings, false)
194194

195+
/// Enable the explicit 'import Builtin' and allow Builtin usage.
196+
EXPERIMENTAL_FEATURE(BuiltinModule, true)
197+
195198
#undef EXPERIMENTAL_FEATURE
196199
#undef UPCOMING_FEATURE
197200
#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
@@ -3398,6 +3398,10 @@ static bool usesFeatureParameterPacks(Decl *decl) {
33983398
return false;
33993399
}
34003400

3401+
static bool usesFeatureBuiltinModule(Decl *decl) {
3402+
return false;
3403+
}
3404+
34013405
/// Suppress the printing of a particular feature.
34023406
static void suppressingFeature(PrintOptions &options, Feature feature,
34033407
llvm::function_ref<void()> action) {

lib/Frontend/CompilerInvocation.cpp

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

764+
if (Args.hasArg(OPT_enable_builtin_module))
765+
Opts.Features.insert(Feature::BuiltinModule);
766+
764767
Opts.EnableAppExtensionRestrictions |= Args.hasArg(OPT_enable_app_extension);
765768

766769
Opts.EnableSwift3ObjCInference =
@@ -1177,8 +1180,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
11771180
.Default(ConcurrencyModel::Standard);
11781181
}
11791182

1180-
Opts.EnableBuiltinModule = Args.hasArg(OPT_enable_builtin_module);
1181-
11821183
return HadError || UnsupportedOS || UnsupportedArch;
11831184
}
11841185

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)