Skip to content

Commit 3693592

Browse files
authored
Merge pull request #73905 from tshortli/allow-skip-non-exportable-with-skip-all-function-bodies
Frontend: Lift restrictions on lazy type checking options
2 parents c0af25c + 8607953 commit 3693592

File tree

4 files changed

+27
-36
lines changed

4 files changed

+27
-36
lines changed

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,11 +1158,6 @@ def experimental_skip_all_function_bodies:
11581158
Flag<["-"], "experimental-skip-all-function-bodies">,
11591159
HelpText<"Skip type-checking function bodies and all SIL generation">;
11601160

1161-
def experimental_skip_non_inlinable_function_bodies_is_lazy
1162-
: Flag<["-"], "experimental-skip-non-inlinable-function-bodies-is-lazy">,
1163-
HelpText<"Infer lazy typechecking for "
1164-
"-experimental-skip-non-inlinable-function-bodies">;
1165-
11661161
def experimental_allow_module_with_compiler_errors:
11671162
Flag<["-"], "experimental-allow-module-with-compiler-errors">,
11681163
Flags<[HelpHidden]>,

include/swift/Sema/ConstraintSystem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4423,7 +4423,7 @@ class ConstraintSystem {
44234423
/// \param UseDC The context of the access. Some variables have different
44244424
/// types depending on where they are used.
44254425
///
4426-
/// \param memberLocator The locator anchored at this value reference, when
4426+
/// \param locator The locator anchored at this value reference, when
44274427
/// it is a member reference.
44284428
///
44294429
/// \param wantInterfaceType Whether we want the interface type, if available.
@@ -4441,7 +4441,7 @@ class ConstraintSystem {
44414441
/// \param UseDC The context of the access. Some variables have different
44424442
/// types depending on where they are used.
44434443
///
4444-
/// \param memberLocator The locator anchored at this value reference, when
4444+
/// \param locator The locator anchored at this value reference, when
44454445
/// it is a member reference.
44464446
///
44474447
/// \param wantInterfaceType Whether we want the interface type, if available.

lib/Frontend/CompilerInvocation.cpp

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,19 +1154,20 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
11541154

11551155
Opts.EnableSkipExplicitInterfaceModuleBuildRemarks = Args.hasArg(OPT_remark_skip_explicit_interface_build);
11561156

1157-
if (Args.hasArg(OPT_enable_library_evolution)) {
1158-
Opts.SkipNonExportableDecls |=
1159-
Args.hasArg(OPT_experimental_skip_non_exportable_decls);
1160-
1161-
Opts.SkipNonExportableDecls |=
1162-
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) &&
1163-
Args.hasArg(
1164-
OPT_experimental_skip_non_inlinable_function_bodies_is_lazy);
1165-
} else {
1166-
if (Args.hasArg(OPT_experimental_skip_non_exportable_decls))
1157+
if (Args.hasArg(OPT_experimental_skip_non_exportable_decls)) {
1158+
// Only allow -experimental-skip-non-exportable-decls if either library
1159+
// evolution is enabled (in which case the module's ABI is independent of
1160+
// internal declarations) or when -experimental-skip-all-function-bodies is
1161+
// present. The latter implies the module will not be used for code
1162+
// generation, so omitting details needed for ABI should be safe.
1163+
if (Args.hasArg(OPT_enable_library_evolution) ||
1164+
Args.hasArg(OPT_experimental_skip_all_function_bodies)) {
1165+
Opts.SkipNonExportableDecls |= true;
1166+
} else {
11671167
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
11681168
"-experimental-skip-non-exportable-decls",
11691169
"-enable-library-evolution");
1170+
}
11701171
}
11711172

11721173
Opts.AllowNonResilientAccess =
@@ -1712,23 +1713,18 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
17121713
Opts.DebugGenericSignatures |= Args.hasArg(OPT_debug_generic_signatures);
17131714
Opts.DebugInverseRequirements |= Args.hasArg(OPT_debug_inverse_requirements);
17141715

1715-
if (Args.hasArg(OPT_enable_library_evolution)) {
1716-
Opts.EnableLazyTypecheck |= Args.hasArg(OPT_experimental_lazy_typecheck);
1717-
Opts.EnableLazyTypecheck |=
1718-
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) &&
1719-
Args.hasArg(
1720-
OPT_experimental_skip_non_inlinable_function_bodies_is_lazy);
1721-
} else {
1722-
if (Args.hasArg(OPT_experimental_lazy_typecheck))
1716+
if (Args.hasArg(OPT_experimental_lazy_typecheck)) {
1717+
// Same restrictions as -experimental-skip-non-exportable-decls. These
1718+
// could be relaxed in the future, since lazy typechecking is probably not
1719+
// inherently unsafe without these options.
1720+
if (Args.hasArg(OPT_enable_library_evolution) ||
1721+
Args.hasArg(OPT_experimental_skip_all_function_bodies)) {
1722+
Opts.EnableLazyTypecheck |= Args.hasArg(OPT_experimental_lazy_typecheck);
1723+
} else {
17231724
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
17241725
"-experimental-lazy-typecheck",
17251726
"-enable-library-evolution");
1726-
1727-
if (Args.hasArg(
1728-
OPT_experimental_skip_non_inlinable_function_bodies_is_lazy))
1729-
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
1730-
"-experimental-skip-non-inlinable-function-bodies-is-lazy",
1731-
"-enable-library-evolution");
1727+
}
17321728
}
17331729

17341730
if (LangOpts.AllowNonResilientAccess &&

test/Serialization/lazy-typecheck.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -enable-library-evolution -parse-as-library -package-name Package -DFLAG -emit-module -emit-module-path %t/lazy-skip-all/lazy_typecheck.swiftmodule -debug-forbid-typecheck-prefix NoTypecheck -experimental-lazy-typecheck -experimental-skip-all-function-bodies -experimental-skip-non-exportable-decls
1212
// RUN: %target-swift-frontend -package-name Package -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -DFLAG -I %t/lazy-skip-all
1313

14+
// (2a) Verify that -experimental-lazy-typecheck and -experimental-skip-non-exportable-decls do not require
15+
// -enable-library-evolution if -experimental-skip-all-function-bodies is specified.
16+
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -parse-as-library -package-name Package -DFLAG -emit-module -emit-module-path %t/lazy-skip-all-non-resilient/lazy_typecheck.swiftmodule -debug-forbid-typecheck-prefix NoTypecheck -experimental-lazy-typecheck -experimental-skip-all-function-bodies -experimental-skip-non-exportable-decls
17+
// RUN: %target-swift-frontend -package-name Package -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -DFLAG -I %t/lazy-skip-all-non-resilient
18+
1419
// (3) Verify that a module built with -experimental-lazy-typecheck, -experimental-skip-non-inlinable-function-bodies,
1520
// and -experimental-skip-non-exportable-decls can be used by the same client as in (1).
1621
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -enable-library-evolution -parse-as-library -package-name Package -DFLAG -emit-module -emit-module-path %t/lazy-skip-non-inlinable/lazy_typecheck.swiftmodule -debug-forbid-typecheck-prefix NoTypecheck -experimental-lazy-typecheck -experimental-skip-non-inlinable-function-bodies -experimental-skip-non-exportable-decls
1722
// RUN: %target-swift-frontend -package-name Package -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -DFLAG -I %t/lazy-skip-non-inlinable
18-
19-
// (4) Verify that a module built with -experimental-skip-non-inlinable-function-bodies-is-lazy implies
20-
// -experimental-lazy-typecheck and -experimental-skip-non-exportable-decls.
21-
// RUN: %target-swift-frontend -swift-version 5 %S/../Inputs/lazy_typecheck.swift -module-name lazy_typecheck -enable-library-evolution -parse-as-library -package-name Package -DFLAG -emit-module -emit-module-path %t/lazy-skip-non-inlinable-is-lazy/lazy_typecheck.swiftmodule -debug-forbid-typecheck-prefix NoTypecheck -experimental-skip-non-inlinable-function-bodies -experimental-skip-non-inlinable-function-bodies-is-lazy
22-
// RUN: %target-swift-frontend -package-name Package -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -DFLAG -I %t/lazy-skip-non-inlinable-is-lazy

0 commit comments

Comments
 (0)