Skip to content

Commit 52ddcea

Browse files
committed
Diagnose Building SwiftONoneSupport with -experimental-skip-function-bodies
This allows us to push the validation and, importantly, the mutation of this flag into the compiler invocation where it belongs.
1 parent eac92e3 commit 52ddcea

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,17 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
682682
// body skipping.
683683
Opts.SkipNonInlinableFunctionBodies |= Args.hasArg(OPT_tbd_is_installapi);
684684

685+
if (Opts.SkipNonInlinableFunctionBodies &&
686+
FrontendOpts.ModuleName == SWIFT_ONONE_SUPPORT) {
687+
// Disable this optimization if we're compiling SwiftOnoneSupport, because
688+
// we _definitely_ need to look inside every declaration to figure out
689+
// what gets prespecialized.
690+
Opts.SkipNonInlinableFunctionBodies = false;
691+
Diags.diagnose(SourceLoc(),
692+
diag::module_incompatible_with_skip_function_bodies,
693+
SWIFT_ONONE_SUPPORT);
694+
}
695+
685696
Opts.DisableConstraintSolverPerformanceHacks |=
686697
Args.hasArg(OPT_disable_constraint_solver_performance_hacks);
687698

@@ -908,12 +919,14 @@ void parseExclusivityEnforcementOptions(const llvm::opt::Arg *A,
908919

909920
static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
910921
IRGenOptions &IRGenOpts,
911-
FrontendOptions &FEOpts,
922+
const FrontendOptions &FEOpts,
923+
const TypeCheckerOptions &TCOpts,
912924
DiagnosticEngine &Diags,
913925
const llvm::Triple &Triple,
914926
ClangImporterOptions &ClangOpts) {
915927
using namespace options;
916928

929+
917930
if (const Arg *A = Args.getLastArg(OPT_sil_inline_threshold)) {
918931
if (StringRef(A->getValue()).getAsInteger(10, Opts.InlineThreshold)) {
919932
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
@@ -956,8 +969,9 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
956969
if (Args.hasArg(OPT_sil_merge_partial_modules))
957970
Opts.MergePartialModules = true;
958971

959-
if (Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies))
960-
Opts.SkipNonInlinableFunctionBodies = true;
972+
// Propagate the typechecker's understanding of
973+
// -experimental-skip-non-inlinable-function-bodies to SIL.
974+
Opts.SkipNonInlinableFunctionBodies = TCOpts.SkipNonInlinableFunctionBodies;
961975

962976
// Parse the optimization level.
963977
// Default to Onone settings if no option is passed.
@@ -1629,7 +1643,8 @@ bool CompilerInvocation::parseArgs(
16291643
return true;
16301644
}
16311645

1632-
if (ParseSILArgs(SILOpts, ParsedArgs, IRGenOpts, FrontendOpts, Diags,
1646+
if (ParseSILArgs(SILOpts, ParsedArgs, IRGenOpts, FrontendOpts,
1647+
TypeCheckerOpts, Diags,
16331648
LangOpts.Target, ClangImporterOpts)) {
16341649
return true;
16351650
}

lib/Sema/TypeChecker.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,6 @@ TypeCheckSourceFileRequest::evaluate(Evaluator &eval, SourceFile *SF) const {
332332
FrontendStatsTracer tracer(Ctx.Stats,
333333
"Type checking and Semantic analysis");
334334

335-
if (Ctx.TypeCheckerOpts.SkipNonInlinableFunctionBodies)
336-
// Disable this optimization if we're compiling SwiftOnoneSupport, because
337-
// we _definitely_ need to look inside every declaration to figure out
338-
// what gets prespecialized.
339-
if (SF->getParentModule()->isOnoneSupportModule())
340-
Ctx.TypeCheckerOpts.SkipNonInlinableFunctionBodies = false;
341-
342335
if (!Ctx.LangOpts.DisableAvailabilityChecking) {
343336
// Build the type refinement hierarchy for the primary
344337
// file before type checking.

test/Frontend/skip-non-inlinable-function-bodies.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// RUN: %empty-directory(%t)
22

3-
// 1. Make sure you can't -emit-ir or -c when you're skipping non-inlinable function bodies
3+
// 1a. Make sure you can't -emit-ir or -c when you're skipping non-inlinable function bodies
4+
// 1b. Also make sure we warn when you try to build SwiftONoneSupport with this option enabled
45

56
// RUN: not %target-swift-frontend -emit-ir %s -experimental-skip-non-inlinable-function-bodies %s 2>&1 | %FileCheck %s --check-prefix ERROR
67
// RUN: not %target-swift-frontend -c %s -experimental-skip-non-inlinable-function-bodies %s 2>&1 | %FileCheck %s --check-prefix ERROR
8+
// RUN: %target-swift-frontend -typecheck -experimental-skip-non-inlinable-function-bodies -module-name SwiftOnoneSupport %s 2>&1 | %FileCheck %s --check-prefix WARNING
79
// ERROR: -experimental-skip-non-inlinable-function-bodies does not support emitting IR
10+
// WARNING: module 'SwiftOnoneSupport' cannot be built with -experimental-skip-non-inlinable-function-bodies; this option has been automatically disabled
811

912
// 2. Emit the SIL for a module and check it against the expected strings in function bodies.
1013
// If we're doing the right skipping, then the strings that are CHECK-NOT'd won't have been typechecked or SILGen'd.

0 commit comments

Comments
 (0)