Skip to content

[Frontend] Add BuiltinModule experimental feature #64673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ EXPERIMENTAL_FEATURE(GenerateBindingsForThrowingFunctionsInCXX, false)
/// Enable reference bindings.
EXPERIMENTAL_FEATURE(ReferenceBindings, false)

/// Enable the explicit 'import Builtin' and allow Builtin usage.
EXPERIMENTAL_FEATURE(BuiltinModule, true)

#undef EXPERIMENTAL_FEATURE
#undef UPCOMING_FEATURE
#undef SUPPRESSIBLE_LANGUAGE_FEATURE
Expand Down
3 changes: 0 additions & 3 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,6 @@ namespace swift {
/// The model of concurrency to be used.
ConcurrencyModel ActiveConcurrencyModel = ConcurrencyModel::Standard;

/// Allows the explicit 'import Builtin' within Swift modules.
bool EnableBuiltinModule = false;

bool isConcurrencyModelTaskToThread() const {
return ActiveConcurrencyModel == ConcurrencyModel::TaskToThread;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3279,6 +3279,10 @@ static bool usesFeatureReferenceBindings(Decl *decl) {
return vd && vd->getIntroducer() == VarDecl::Introducer::InOut;
}

static bool usesFeatureBuiltinModule(Decl *decl) {
return false;
}

/// Suppress the printing of a particular feature.
static void suppressingFeature(PrintOptions &options, Feature feature,
llvm::function_ref<void()> action) {
Expand Down
5 changes: 3 additions & 2 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
if (Args.hasArg(OPT_enable_experimental_opaque_type_erasure))
Opts.Features.insert(Feature::OpaqueTypeErasure);

if (Args.hasArg(OPT_enable_builtin_module))
Opts.Features.insert(Feature::BuiltinModule);

Opts.EnableAppExtensionRestrictions |= Args.hasArg(OPT_enable_app_extension);

Opts.EnableSwift3ObjCInference =
Expand Down Expand Up @@ -1153,8 +1156,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
.Default(ConcurrencyModel::Standard);
}

Opts.EnableBuiltinModule = Args.hasArg(OPT_enable_builtin_module);

return HadError || UnsupportedOS || UnsupportedArch;
}

Expand Down
8 changes: 5 additions & 3 deletions lib/Frontend/ModuleInterfaceSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,12 @@ static void printImports(raw_ostream &out,
continue;
}

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

Expand Down
6 changes: 4 additions & 2 deletions lib/Sema/ImportResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,13 @@ ImportResolver::getModule(ImportPath::Module modulePath) {

// The Builtin module cannot be explicitly imported unless:
// 1. We're in a .sil file
// 2. '-enable-builtin-module' was passed.
// 2. '-enable-builtin-module'/'-enable-experimental-feature BuiltinModule'
// was passed.
//
// FIXME: Eventually, it would be nice to separate '-parse-stdlib' from
// implicitly importing Builtin, but we're not there yet.
if (SF.Kind == SourceFileKind::SIL || ctx.LangOpts.EnableBuiltinModule) {
if (SF.Kind == SourceFileKind::SIL ||
ctx.LangOpts.hasFeature(Feature::BuiltinModule)) {
if (moduleID.Item == ctx.TheBuiltinModule->getName()) {
return ctx.TheBuiltinModule;
}
Expand Down
1 change: 1 addition & 0 deletions test/Frontend/enable_builtin_module.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: not %target-swift-frontend -typecheck -show-diagnostics-after-fatal -D BUILTIN_IMPORT %s 2>&1 | %FileCheck -check-prefix CHECK-NO-BUILTIN %s
// RUN: not %target-swift-frontend -typecheck -show-diagnostics-after-fatal -enable-builtin-module %s 2>&1 | %FileCheck -check-prefix CHECK-NO-BUILTIN-IMPORT %s
// RUN: %target-swift-frontend -typecheck -enable-builtin-module -D BUILTIN_IMPORT %s
// RUN: %target-swift-frontend -typecheck -enable-experimental-feature BuiltinModule -D BUILTIN_IMPORT %s

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

Expand Down