Skip to content

Commit 8607953

Browse files
committed
Frontend: Lift restrictions on lazy typechecking options.
The `-experimental-skip-all-function-bodies` flag is specified when producing modules for indexing. These modules are not used for compilation, so it should be safe to allow `-experimental-lazy-typecheck` and `-experimental-skip-non-exportable-decls` as well without `-enable-library-evolution`. Resolves rdar://128706306
1 parent 741a721 commit 8607953

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,14 +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-
} else {
1161-
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 {
11621167
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
11631168
"-experimental-skip-non-exportable-decls",
11641169
"-enable-library-evolution");
1170+
}
11651171
}
11661172

11671173
Opts.AllowNonResilientAccess =
@@ -1707,13 +1713,18 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
17071713
Opts.DebugGenericSignatures |= Args.hasArg(OPT_debug_generic_signatures);
17081714
Opts.DebugInverseRequirements |= Args.hasArg(OPT_debug_inverse_requirements);
17091715

1710-
if (Args.hasArg(OPT_enable_library_evolution)) {
1711-
Opts.EnableLazyTypecheck |= Args.hasArg(OPT_experimental_lazy_typecheck);
1712-
} else {
1713-
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 {
17141724
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
17151725
"-experimental-lazy-typecheck",
17161726
"-enable-library-evolution");
1727+
}
17171728
}
17181729

17191730
if (LangOpts.AllowNonResilientAccess &&

test/Serialization/lazy-typecheck.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
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

0 commit comments

Comments
 (0)