Skip to content

[6.0] Frontend: Allow any experimental feature to be enabled when compiling a module #72637

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
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
1 change: 1 addition & 0 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ class FrontendOptions {
static bool doesActionGenerateIR(ActionType);
static bool doesActionProduceOutput(ActionType);
static bool doesActionProduceTextualOutput(ActionType);
static bool doesActionBuildModuleFromInterface(ActionType);
static bool needsProperModuleName(ActionType);
static file_types::ID formatForPrincipalOutputFileForAction(ActionType);
};
Expand Down
10 changes: 4 additions & 6 deletions lib/Frontend/ArgsToFrontendOptionsConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ bool ArgsToFrontendOptionsConverter::convert(
Opts.RequestedAction = determineRequestedAction(Args);
}

if (Opts.RequestedAction == FrontendOptions::ActionType::CompileModuleFromInterface ||
Opts.RequestedAction == FrontendOptions::ActionType::TypecheckModuleFromInterface) {
if (FrontendOptions::doesActionBuildModuleFromInterface(
Opts.RequestedAction)) {
// The situations where we use this action, e.g. explicit module building and
// generating prebuilt module cache, don't need synchronization. We should avoid
// using lock files for them.
Expand Down Expand Up @@ -695,10 +695,8 @@ bool ArgsToFrontendOptionsConverter::

bool ArgsToFrontendOptionsConverter::checkBuildFromInterfaceOnlyOptions()
const {
if (Opts.RequestedAction !=
FrontendOptions::ActionType::CompileModuleFromInterface &&
Opts.RequestedAction !=
FrontendOptions::ActionType::TypecheckModuleFromInterface &&
if (!FrontendOptions::doesActionBuildModuleFromInterface(
Opts.RequestedAction) &&
Opts.ExplicitInterfaceBuild) {
Diags.diagnose(SourceLoc(),
diag::error_cannot_explicit_interface_build_in_mode);
Expand Down
16 changes: 7 additions & 9 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
DiagnosticEngine &Diags,
const FrontendOptions &FrontendOpts) {
using namespace options;
bool buildingFromInterface =
FrontendOptions::doesActionBuildModuleFromInterface(
FrontendOpts.RequestedAction);
bool HadError = false;

if (auto A = Args.getLastArg(OPT_swift_version)) {
Expand Down Expand Up @@ -791,10 +794,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
OPT_disable_testable_attr_requires_testable_module)) {
Opts.EnableTestableAttrRequiresTestableModule
= A->getOption().matches(OPT_enable_testable_attr_requires_testable_module);
} else if (FrontendOpts.RequestedAction ==
FrontendOptions::ActionType::TypecheckModuleFromInterface ||
FrontendOpts.RequestedAction ==
FrontendOptions::ActionType::CompileModuleFromInterface) {
} else if (buildingFromInterface) {
Opts.EnableObjCAttrRequiresFoundation = false;
}

Expand Down Expand Up @@ -873,7 +873,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
// (non-release) builds for testing purposes.
if (auto feature = getExperimentalFeature(value)) {
#ifdef NDEBUG
if (!isFeatureAvailableInProduction(*feature)) {
if (!buildingFromInterface && !isFeatureAvailableInProduction(*feature)) {
Diags.diagnose(SourceLoc(), diag::experimental_not_supported_in_production,
A->getValue());
HadError = true;
Expand Down Expand Up @@ -1142,10 +1142,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
}
// If built from interface, non-resilient access should not be allowed.
if (Opts.AllowNonResilientAccess &&
(FrontendOpts.RequestedAction ==
FrontendOptions::ActionType::CompileModuleFromInterface ||
FrontendOpts.RequestedAction ==
FrontendOptions::ActionType::TypecheckModuleFromInterface)) {
FrontendOptions::doesActionBuildModuleFromInterface(
FrontendOpts.RequestedAction)) {
Diags.diagnose(
SourceLoc(), diag::warn_ignore_option_overriden_by,
"-experimental-allow-non-resilient-access",
Expand Down
6 changes: 2 additions & 4 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,8 @@ void CompilerInstance::recordPrimaryInputBuffer(unsigned BufID) {
}

bool CompilerInstance::setUpASTContextIfNeeded() {
if ((Invocation.getFrontendOptions().RequestedAction ==
FrontendOptions::ActionType::CompileModuleFromInterface ||
Invocation.getFrontendOptions().RequestedAction ==
FrontendOptions::ActionType::TypecheckModuleFromInterface) &&
if (FrontendOptions::doesActionBuildModuleFromInterface(
Invocation.getFrontendOptions().RequestedAction) &&
!Invocation.getFrontendOptions().ExplicitInterfaceBuild) {
// Compiling a module interface from source uses its own CompilerInstance
// with options read from the input file. Don't bother setting up an
Expand Down
41 changes: 41 additions & 0 deletions lib/Frontend/FrontendOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,47 @@ bool FrontendOptions::doesActionGenerateIR(ActionType action) {
llvm_unreachable("unhandled action");
}

bool FrontendOptions::doesActionBuildModuleFromInterface(ActionType action) {
switch (action) {
case ActionType::CompileModuleFromInterface:
case ActionType::TypecheckModuleFromInterface:
return true;
case ActionType::NoneAction:
case ActionType::Parse:
case ActionType::DumpParse:
case ActionType::DumpInterfaceHash:
case ActionType::DumpAST:
case ActionType::PrintAST:
case ActionType::PrintASTDecl:
case ActionType::DumpScopeMaps:
case ActionType::DumpTypeRefinementContexts:
case ActionType::DumpTypeInfo:
case ActionType::Typecheck:
case ActionType::ResolveImports:
case ActionType::MergeModules:
case ActionType::EmitModuleOnly:
case ActionType::EmitPCH:
case ActionType::EmitSILGen:
case ActionType::EmitSIL:
case ActionType::EmitSIBGen:
case ActionType::EmitSIB:
case ActionType::EmitImportedModules:
case ActionType::EmitPCM:
case ActionType::DumpPCM:
case ActionType::ScanDependencies:
case ActionType::PrintVersion:
case ActionType::PrintFeature:
case ActionType::Immediate:
case ActionType::REPL:
case ActionType::EmitIRGen:
case ActionType::EmitIR:
case ActionType::EmitBC:
case ActionType::EmitAssembly:
case ActionType::EmitObject:
return false;
}
llvm_unreachable("unhandled action");
}

const PrimarySpecificPaths &
FrontendOptions::getPrimarySpecificPathsForAtMostOnePrimary() const {
Expand Down
14 changes: 14 additions & 0 deletions test/ModuleInterface/ExperimentalFeatures.swiftinterface
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// swift-interface-format-version: 1.0
// swift-module-flags: -module-name ExperimentalFeatures -enable-experimental-feature ParserRoundTrip

// Building a module from this interface should always succeed, even though
// ParserRoundTrip is an experimental feature that is not enabled in production
// compilers.

// RUN: %target-swift-frontend -compile-module-from-interface -module-name ExperimentalFeatures -o /dev/null %s -verify
// RUN: %target-swift-frontend -typecheck-module-from-interface -module-name ExperimentalFeatures %s -verify

import Swift
extension Int {
public static var fortytwo: Int = 42
}