Skip to content

Commit fdff522

Browse files
authored
Merge pull request swiftlang#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
}

0 commit comments

Comments
 (0)