Skip to content

[6.0] Frontend: Lift restrictions on lazy type checking options #73906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -1150,11 +1150,6 @@ def experimental_skip_all_function_bodies:
Flag<["-"], "experimental-skip-all-function-bodies">,
HelpText<"Skip type-checking function bodies and all SIL generation">;

def experimental_skip_non_inlinable_function_bodies_is_lazy
: Flag<["-"], "experimental-skip-non-inlinable-function-bodies-is-lazy">,
HelpText<"Infer lazy typechecking for "
"-experimental-skip-non-inlinable-function-bodies">;

def experimental_allow_module_with_compiler_errors:
Flag<["-"], "experimental-allow-module-with-compiler-errors">,
Flags<[HelpHidden]>,
Expand Down
44 changes: 20 additions & 24 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,19 +1159,20 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,

Opts.EnableSkipExplicitInterfaceModuleBuildRemarks = Args.hasArg(OPT_remark_skip_explicit_interface_build);

if (Args.hasArg(OPT_enable_library_evolution)) {
Opts.SkipNonExportableDecls |=
Args.hasArg(OPT_experimental_skip_non_exportable_decls);

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

Opts.AllowNonResilientAccess =
Expand Down Expand Up @@ -1690,23 +1691,18 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
Opts.DebugGenericSignatures |= Args.hasArg(OPT_debug_generic_signatures);
Opts.DebugInverseRequirements |= Args.hasArg(OPT_debug_inverse_requirements);

if (Args.hasArg(OPT_enable_library_evolution)) {
Opts.EnableLazyTypecheck |= Args.hasArg(OPT_experimental_lazy_typecheck);
Opts.EnableLazyTypecheck |=
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) &&
Args.hasArg(
OPT_experimental_skip_non_inlinable_function_bodies_is_lazy);
} else {
if (Args.hasArg(OPT_experimental_lazy_typecheck))
if (Args.hasArg(OPT_experimental_lazy_typecheck)) {
// Same restrictions as -experimental-skip-non-exportable-decls. These
// could be relaxed in the future, since lazy typechecking is probably not
// inherently unsafe without these options.
if (Args.hasArg(OPT_enable_library_evolution) ||
Args.hasArg(OPT_experimental_skip_all_function_bodies)) {
Opts.EnableLazyTypecheck |= Args.hasArg(OPT_experimental_lazy_typecheck);
} else {
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
"-experimental-lazy-typecheck",
"-enable-library-evolution");

if (Args.hasArg(
OPT_experimental_skip_non_inlinable_function_bodies_is_lazy))
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
"-experimental-skip-non-inlinable-function-bodies-is-lazy",
"-enable-library-evolution");
}
}

// HACK: The driver currently erroneously passes all flags to module interface
Expand Down
10 changes: 5 additions & 5 deletions test/Serialization/lazy-typecheck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
// 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
// RUN: %target-swift-frontend -package-name Package -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -DFLAG -I %t/lazy-skip-all

// (2a) Verify that -experimental-lazy-typecheck and -experimental-skip-non-exportable-decls do not require
// -enable-library-evolution if -experimental-skip-all-function-bodies is specified.
// 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
// RUN: %target-swift-frontend -package-name Package -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -DFLAG -I %t/lazy-skip-all-non-resilient

// (3) Verify that a module built with -experimental-lazy-typecheck, -experimental-skip-non-inlinable-function-bodies,
// and -experimental-skip-non-exportable-decls can be used by the same client as in (1).
// 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
// RUN: %target-swift-frontend -package-name Package -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -DFLAG -I %t/lazy-skip-non-inlinable

// (4) Verify that a module built with -experimental-skip-non-inlinable-function-bodies-is-lazy implies
// -experimental-lazy-typecheck and -experimental-skip-non-exportable-decls.
// 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
// RUN: %target-swift-frontend -package-name Package -typecheck -verify %S/../Inputs/lazy_typecheck_client.swift -DFLAG -I %t/lazy-skip-non-inlinable-is-lazy