Skip to content

Commit fdff522

Browse files
authored
Merge pull request #34489 from bnbarham/benb/skip-all-function-bodies
[SILGen] Add flag to skip typechecking and SIL gen for all function bodies
2 parents 4b91350 + 7cee600 commit fdff522

19 files changed

+550
-349
lines changed

include/swift/AST/Decl.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -5659,13 +5659,14 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
56595659
/// Set a new body for the function.
56605660
void setBody(BraceStmt *S, BodyKind NewBodyKind);
56615661

5662-
/// Note that the body was skipped for this function. Function body
5662+
/// Note that the body was skipped for this function. Function body
56635663
/// cannot be attached after this call.
56645664
void setBodySkipped(SourceRange bodyRange) {
5665-
// FIXME: Remove 'Parsed' from this once we can delay parsing function
5666-
// bodies. Right now -experimental-skip-non-inlinable-function-bodies
5667-
// requires being able to change the state from Parsed to Skipped,
5668-
// because we're still eagerly parsing function bodies.
5665+
// FIXME: Remove 'Parsed' from this list once we can always delay
5666+
// parsing bodies. The -experimental-skip-*-function-bodies options
5667+
// do currently skip parsing, unless disabled through other means in
5668+
// SourceFile::hasDelayedBodyParsing (eg. needing to build the full
5669+
// syntax tree due to -verify-syntax-tree).
56695670
assert(getBodyKind() == BodyKind::None ||
56705671
getBodyKind() == BodyKind::Unparsed ||
56715672
getBodyKind() == BodyKind::Parsed);

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -128,8 +128,7 @@ ERROR(error_mode_cannot_emit_interface,none,
128128
ERROR(error_mode_cannot_emit_module_summary,none,
129129
"this mode does not support emitting module summary files", ())
130130
ERROR(cannot_emit_ir_skipping_function_bodies,none,
131-
"-experimental-skip-non-inlinable-function-bodies does not support "
132-
"emitting IR", ())
131+
"-experimental-skip-*-function-bodies do not support emitting IR", ())
133132

134133
WARNING(emit_reference_dependencies_without_primary_file,none,
135134
"ignoring -emit-reference-dependencies (requires -primary-file)", ())
@@ -416,7 +415,7 @@ ERROR(expectation_missing_opening_braces,none,
416415
ERROR(expectation_missing_closing_braces,none,
417416
"didn't find '}}' to match '{{' in expectation", ())
418417

419-
WARNING(module_incompatible_with_skip_function_bodies,none,
418+
WARNING(module_incompatible_with_skip_non_inlinable_function_bodies,none,
420419
"module '%0' cannot be built with "
421420
"-experimental-skip-non-inlinable-function-bodies; this option has "
422421
"been automatically disabled", (StringRef))

include/swift/AST/SILOptions.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -18,14 +18,15 @@
1818
#ifndef SWIFT_AST_SILOPTIONS_H
1919
#define SWIFT_AST_SILOPTIONS_H
2020

21-
#include "swift/Basic/Sanitizers.h"
22-
#include "swift/Basic/OptionSet.h"
21+
#include "swift/Basic/FunctionBodySkipping.h"
2322
#include "swift/Basic/OptimizationMode.h"
23+
#include "swift/Basic/OptionSet.h"
24+
#include "swift/Basic/Sanitizers.h"
2425
#include "llvm/ADT/Hashing.h"
2526
#include "llvm/ADT/StringRef.h"
2627
#include "llvm/Remarks/RemarkFormat.h"
27-
#include <string>
2828
#include <climits>
29+
#include <string>
2930

3031
namespace swift {
3132

@@ -88,8 +89,8 @@ class SILOptions {
8889
/// and go from OSSA to non-ownership SIL.
8990
bool StopOptimizationBeforeLoweringOwnership = false;
9091

91-
/// Whether to skip emitting non-inlinable function bodies.
92-
bool SkipNonInlinableFunctionBodies = false;
92+
// The kind of function bodies to skip emitting.
93+
FunctionBodySkipping SkipFunctionBodies = FunctionBodySkipping::None;
9394

9495
/// Optimization mode being used.
9596
OptimizationMode OptMode = OptimizationMode::NotSet;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===------------------- FunctionBodySkipping.h -----------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_BASIC_FUNCTIONBODYSKIPPING_H
14+
#define SWIFT_BASIC_FUNCTIONBODYSKIPPING_H
15+
16+
#include "llvm/Support/DataTypes.h"
17+
18+
namespace swift {
19+
20+
/// Describes the function bodies that can be skipped in type-checking.
21+
enum class FunctionBodySkipping : uint8_t {
22+
/// Do not skip type-checking for any function bodies.
23+
None,
24+
/// Only non-inlinable function bodies should be skipped.
25+
NonInlinable,
26+
/// All function bodies should be skipped, where not otherwise required
27+
/// for type inference.
28+
All
29+
};
30+
31+
} // end namespace swift
32+
33+
#endif // SWIFT_BASIC_FUNCTIONBODYSKIPPING_H

include/swift/Basic/LangOptions.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -18,18 +18,19 @@
1818
#ifndef SWIFT_BASIC_LANGOPTIONS_H
1919
#define SWIFT_BASIC_LANGOPTIONS_H
2020

21-
#include "swift/Config.h"
21+
#include "swift/Basic/FunctionBodySkipping.h"
2222
#include "swift/Basic/LLVM.h"
2323
#include "swift/Basic/Version.h"
24+
#include "swift/Config.h"
2425
#include "llvm/ADT/ArrayRef.h"
2526
#include "llvm/ADT/Hashing.h"
27+
#include "llvm/ADT/SmallString.h"
2628
#include "llvm/ADT/SmallVector.h"
2729
#include "llvm/ADT/StringRef.h"
28-
#include "llvm/ADT/SmallString.h"
2930
#include "llvm/ADT/Triple.h"
3031
#include "llvm/Support/Regex.h"
31-
#include "llvm/Support/raw_ostream.h"
3232
#include "llvm/Support/VersionTuple.h"
33+
#include "llvm/Support/raw_ostream.h"
3334
#include <string>
3435
#include <vector>
3536

@@ -489,9 +490,8 @@ namespace swift {
489490
/// dumped to llvm::errs().
490491
bool DebugTimeExpressions = false;
491492

492-
/// Indicate that the type checker should skip type-checking non-inlinable
493-
/// function bodies.
494-
bool SkipNonInlinableFunctionBodies = false;
493+
/// Controls the function bodies to skip during type-checking.
494+
FunctionBodySkipping SkipFunctionBodies = FunctionBodySkipping::None;
495495

496496
///
497497
/// Flags for developers

include/swift/Option/FrontendOptions.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,4 +762,9 @@ def use_static_resource_dir
762762
def disable_building_interface
763763
: Flag<["-"], "disable-building-interface">,
764764
HelpText<"Disallow building binary module from textual interface">;
765+
766+
def experimental_skip_all_function_bodies:
767+
Flag<["-"], "experimental-skip-all-function-bodies">,
768+
HelpText<"Skip type-checking function bodies and all SIL generation">;
769+
765770
} // end let Flags = [FrontendOption, NoDriverOption, HelpHidden]

include/swift/Option/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -191,6 +191,9 @@ PASS(GenericSpecializer, "generic-specializer",
191191
"Generic Function Specialization on Static Types")
192192
PASS(ExistentialSpecializer, "existential-specializer",
193193
"Existential Specializer")
194+
PASS(SILSkippingChecker, "check-sil-skipping",
195+
"Utility pass to ensure -experimental-skip-*-function-bodies skip "
196+
"SIL generation of not-to-be-serialized functions entirely")
194197
PASS(GlobalOpt, "global-opt",
195198
"SIL Global Optimization")
196199
PASS(GlobalPropertyOpt, "global-property-opt",
@@ -345,9 +348,6 @@ PASS(SerializeSILPass, "serialize-sil",
345348
"Utility pass. Serializes the current SILModule")
346349
PASS(CMOSerializeSILPass, "cmo-serialize-sil",
347350
"Utility pass. Serializes the current SILModule for cross-module-optimization")
348-
PASS(NonInlinableFunctionSkippingChecker, "check-non-inlinable-function-skipping",
349-
"Utility pass to ensure -experimental-skip-non-inlinable-function-bodies "
350-
"skips everything it should")
351351
PASS(YieldOnceCheck, "yield-once-check",
352352
"Check correct usage of yields in yield-once coroutines")
353353
PASS(OSLogOptimization, "os-log-optimization", "Optimize os log calls")

lib/Frontend/ArgsToFrontendInputsConverter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@ bool ArgsToFrontendOptionsConverter::convert(
193193
if (checkUnusedSupplementaryOutputPaths())
194194
return true;
195195

196-
if (FrontendOptions::doesActionGenerateIR(Opts.RequestedAction)
197-
&& Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies)) {
196+
if (FrontendOptions::doesActionGenerateIR(Opts.RequestedAction) &&
197+
(Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) ||
198+
Args.hasArg(OPT_experimental_skip_all_function_bodies))) {
198199
Diags.diagnose(SourceLoc(), diag::cannot_emit_ir_skipping_function_bodies);
199200
return true;
200201
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -715,22 +715,26 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
715715
Opts.DebugTimeFunctionBodies |= Args.hasArg(OPT_debug_time_function_bodies);
716716
Opts.DebugTimeExpressions |=
717717
Args.hasArg(OPT_debug_time_expression_type_checking);
718-
Opts.SkipNonInlinableFunctionBodies |=
719-
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies);
720718

721719
// If asked to perform InstallAPI, go ahead and enable non-inlinable function
722720
// body skipping.
723-
Opts.SkipNonInlinableFunctionBodies |= Args.hasArg(OPT_tbd_is_installapi);
721+
if (Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) ||
722+
Args.hasArg(OPT_tbd_is_installapi))
723+
Opts.SkipFunctionBodies = FunctionBodySkipping::NonInlinable;
724724

725-
if (Opts.SkipNonInlinableFunctionBodies &&
725+
if (Args.hasArg(OPT_experimental_skip_all_function_bodies))
726+
Opts.SkipFunctionBodies = FunctionBodySkipping::All;
727+
728+
if (Opts.SkipFunctionBodies == FunctionBodySkipping::NonInlinable &&
726729
FrontendOpts.ModuleName == SWIFT_ONONE_SUPPORT) {
727730
// Disable this optimization if we're compiling SwiftOnoneSupport, because
728731
// we _definitely_ need to look inside every declaration to figure out
729732
// what gets prespecialized.
730-
Opts.SkipNonInlinableFunctionBodies = false;
731-
Diags.diagnose(SourceLoc(),
732-
diag::module_incompatible_with_skip_function_bodies,
733-
SWIFT_ONONE_SUPPORT);
733+
Opts.SkipFunctionBodies = FunctionBodySkipping::None;
734+
Diags.diagnose(
735+
SourceLoc(),
736+
diag::module_incompatible_with_skip_non_inlinable_function_bodies,
737+
SWIFT_ONONE_SUPPORT);
734738
}
735739

736740
Opts.DisableConstraintSolverPerformanceHacks |=
@@ -1060,8 +1064,8 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
10601064
Opts.StopOptimizationAfterSerialization = true;
10611065

10621066
// Propagate the typechecker's understanding of
1063-
// -experimental-skip-non-inlinable-function-bodies to SIL.
1064-
Opts.SkipNonInlinableFunctionBodies = TCOpts.SkipNonInlinableFunctionBodies;
1067+
// -experimental-skip-*-function-bodies to SIL.
1068+
Opts.SkipFunctionBodies = TCOpts.SkipFunctionBodies;
10651069

10661070
// Parse the optimization level.
10671071
// Default to Onone settings if no option is passed.

lib/Frontend/Frontend.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -1039,8 +1039,11 @@ CompilerInstance::getSourceFileParsingOptions(bool forPrimary) const {
10391039
}
10401040

10411041
if (forPrimary || isWholeModuleCompilation()) {
1042-
// Disable delayed body parsing for primaries and in WMO.
1043-
opts |= SourceFile::ParsingFlags::DisableDelayedBodies;
1042+
// Disable delayed body parsing for primaries and in WMO, unless
1043+
// forcefully skipping function bodies
1044+
auto typeOpts = getASTContext().TypeCheckerOpts;
1045+
if (typeOpts.SkipFunctionBodies == FunctionBodySkipping::None)
1046+
opts |= SourceFile::ParsingFlags::DisableDelayedBodies;
10441047
} else {
10451048
// Suppress parse warnings for non-primaries, as they'll get parsed multiple
10461049
// times.

lib/SILGen/SILGen.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -1946,6 +1946,12 @@ ASTLoweringRequest::evaluate(Evaluator &evaluator,
19461946

19471947
auto silMod = SILModule::createEmptyModule(desc.context, desc.conv,
19481948
desc.opts);
1949+
1950+
// If all function bodies are being skipped there's no reason to do any
1951+
// SIL generation.
1952+
if (desc.opts.SkipFunctionBodies == FunctionBodySkipping::All)
1953+
return silMod;
1954+
19491955
SILGenModuleRAII scope(*silMod);
19501956

19511957
// Emit a specific set of SILDeclRefs if needed.

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -116,10 +116,10 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
116116
P.addClosureLifetimeFixup();
117117

118118
#ifndef NDEBUG
119-
// Add a verification pass to check our work when skipping non-inlinable
119+
// Add a verification pass to check our work when skipping
120120
// function bodies.
121-
if (Options.SkipNonInlinableFunctionBodies)
122-
P.addNonInlinableFunctionSkippingChecker();
121+
if (Options.SkipFunctionBodies != FunctionBodySkipping::None)
122+
P.addSILSkippingChecker();
123123
#endif
124124

125125
if (Options.shouldOptimize()) {

lib/SILOptimizer/UtilityPasses/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ target_sources(swiftSILOptimizer PRIVATE
99
BugReducerTester.cpp
1010
CFGPrinter.cpp
1111
CallerAnalysisPrinter.cpp
12-
NonInlinableFunctionSkippingChecker.cpp
1312
ComputeDominanceInfo.cpp
1413
ComputeLoopInfo.cpp
1514
ConstantEvaluatorTester.cpp
@@ -29,6 +28,7 @@ target_sources(swiftSILOptimizer PRIVATE
2928
RCIdentityDumper.cpp
3029
SerializeSILPass.cpp
3130
SILDebugInfoGenerator.cpp
31+
SILSkippingChecker.cpp
3232
SideEffectsDumper.cpp
3333
SimplifyUnreachableContainingBlocks.cpp
3434
StripDebugInfo.cpp

0 commit comments

Comments
 (0)