Skip to content

Commit 6f5fc1f

Browse files
authored
Merge pull request #72637 from tshortli/allow-non-production-features-in-module-interface-6.0
[6.0] Frontend: Allow any experimental feature to be enabled when compiling a module
2 parents e1ca80a + 81fc10a commit 6f5fc1f

File tree

6 files changed

+69
-19
lines changed

6 files changed

+69
-19
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ class FrontendOptions {
568568
static bool doesActionGenerateIR(ActionType);
569569
static bool doesActionProduceOutput(ActionType);
570570
static bool doesActionProduceTextualOutput(ActionType);
571+
static bool doesActionBuildModuleFromInterface(ActionType);
571572
static bool needsProperModuleName(ActionType);
572573
static file_types::ID formatForPrincipalOutputFileForAction(ActionType);
573574
};

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ bool ArgsToFrontendOptionsConverter::convert(
227227
Opts.RequestedAction = determineRequestedAction(Args);
228228
}
229229

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

696696
bool ArgsToFrontendOptionsConverter::checkBuildFromInterfaceOnlyOptions()
697697
const {
698-
if (Opts.RequestedAction !=
699-
FrontendOptions::ActionType::CompileModuleFromInterface &&
700-
Opts.RequestedAction !=
701-
FrontendOptions::ActionType::TypecheckModuleFromInterface &&
698+
if (!FrontendOptions::doesActionBuildModuleFromInterface(
699+
Opts.RequestedAction) &&
702700
Opts.ExplicitInterfaceBuild) {
703701
Diags.diagnose(SourceLoc(),
704702
diag::error_cannot_explicit_interface_build_in_mode);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
582582
DiagnosticEngine &Diags,
583583
const FrontendOptions &FrontendOpts) {
584584
using namespace options;
585+
bool buildingFromInterface =
586+
FrontendOptions::doesActionBuildModuleFromInterface(
587+
FrontendOpts.RequestedAction);
585588
bool HadError = false;
586589

587590
if (auto A = Args.getLastArg(OPT_swift_version)) {
@@ -791,10 +794,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
791794
OPT_disable_testable_attr_requires_testable_module)) {
792795
Opts.EnableTestableAttrRequiresTestableModule
793796
= A->getOption().matches(OPT_enable_testable_attr_requires_testable_module);
794-
} else if (FrontendOpts.RequestedAction ==
795-
FrontendOptions::ActionType::TypecheckModuleFromInterface ||
796-
FrontendOpts.RequestedAction ==
797-
FrontendOptions::ActionType::CompileModuleFromInterface) {
797+
} else if (buildingFromInterface) {
798798
Opts.EnableObjCAttrRequiresFoundation = false;
799799
}
800800

@@ -873,7 +873,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
873873
// (non-release) builds for testing purposes.
874874
if (auto feature = getExperimentalFeature(value)) {
875875
#ifdef NDEBUG
876-
if (!isFeatureAvailableInProduction(*feature)) {
876+
if (!buildingFromInterface && !isFeatureAvailableInProduction(*feature)) {
877877
Diags.diagnose(SourceLoc(), diag::experimental_not_supported_in_production,
878878
A->getValue());
879879
HadError = true;
@@ -1142,10 +1142,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
11421142
}
11431143
// If built from interface, non-resilient access should not be allowed.
11441144
if (Opts.AllowNonResilientAccess &&
1145-
(FrontendOpts.RequestedAction ==
1146-
FrontendOptions::ActionType::CompileModuleFromInterface ||
1147-
FrontendOpts.RequestedAction ==
1148-
FrontendOptions::ActionType::TypecheckModuleFromInterface)) {
1145+
FrontendOptions::doesActionBuildModuleFromInterface(
1146+
FrontendOpts.RequestedAction)) {
11491147
Diags.diagnose(
11501148
SourceLoc(), diag::warn_ignore_option_overriden_by,
11511149
"-experimental-allow-non-resilient-access",

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,8 @@ void CompilerInstance::recordPrimaryInputBuffer(unsigned BufID) {
276276
}
277277

278278
bool CompilerInstance::setUpASTContextIfNeeded() {
279-
if ((Invocation.getFrontendOptions().RequestedAction ==
280-
FrontendOptions::ActionType::CompileModuleFromInterface ||
281-
Invocation.getFrontendOptions().RequestedAction ==
282-
FrontendOptions::ActionType::TypecheckModuleFromInterface) &&
279+
if (FrontendOptions::doesActionBuildModuleFromInterface(
280+
Invocation.getFrontendOptions().RequestedAction) &&
283281
!Invocation.getFrontendOptions().ExplicitInterfaceBuild) {
284282
// Compiling a module interface from source uses its own CompilerInstance
285283
// with options read from the input file. Don't bother setting up an

lib/Frontend/FrontendOptions.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,47 @@ bool FrontendOptions::doesActionGenerateIR(ActionType action) {
956956
llvm_unreachable("unhandled action");
957957
}
958958

959+
bool FrontendOptions::doesActionBuildModuleFromInterface(ActionType action) {
960+
switch (action) {
961+
case ActionType::CompileModuleFromInterface:
962+
case ActionType::TypecheckModuleFromInterface:
963+
return true;
964+
case ActionType::NoneAction:
965+
case ActionType::Parse:
966+
case ActionType::DumpParse:
967+
case ActionType::DumpInterfaceHash:
968+
case ActionType::DumpAST:
969+
case ActionType::PrintAST:
970+
case ActionType::PrintASTDecl:
971+
case ActionType::DumpScopeMaps:
972+
case ActionType::DumpTypeRefinementContexts:
973+
case ActionType::DumpTypeInfo:
974+
case ActionType::Typecheck:
975+
case ActionType::ResolveImports:
976+
case ActionType::MergeModules:
977+
case ActionType::EmitModuleOnly:
978+
case ActionType::EmitPCH:
979+
case ActionType::EmitSILGen:
980+
case ActionType::EmitSIL:
981+
case ActionType::EmitSIBGen:
982+
case ActionType::EmitSIB:
983+
case ActionType::EmitImportedModules:
984+
case ActionType::EmitPCM:
985+
case ActionType::DumpPCM:
986+
case ActionType::ScanDependencies:
987+
case ActionType::PrintVersion:
988+
case ActionType::PrintFeature:
989+
case ActionType::Immediate:
990+
case ActionType::REPL:
991+
case ActionType::EmitIRGen:
992+
case ActionType::EmitIR:
993+
case ActionType::EmitBC:
994+
case ActionType::EmitAssembly:
995+
case ActionType::EmitObject:
996+
return false;
997+
}
998+
llvm_unreachable("unhandled action");
999+
}
9591000

9601001
const PrimarySpecificPaths &
9611002
FrontendOptions::getPrimarySpecificPathsForAtMostOnePrimary() const {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -module-name ExperimentalFeatures -enable-experimental-feature ParserRoundTrip
3+
4+
// Building a module from this interface should always succeed, even though
5+
// ParserRoundTrip is an experimental feature that is not enabled in production
6+
// compilers.
7+
8+
// RUN: %target-swift-frontend -compile-module-from-interface -module-name ExperimentalFeatures -o /dev/null %s -verify
9+
// RUN: %target-swift-frontend -typecheck-module-from-interface -module-name ExperimentalFeatures %s -verify
10+
11+
import Swift
12+
extension Int {
13+
public static var fortytwo: Int = 42
14+
}

0 commit comments

Comments
 (0)