Skip to content

Commit 2f8d9e5

Browse files
authored
Merge pull request #70095 from tshortli/infer-lazy-typecheck-from-skip-non-inlinable-option
Frontend: Add -experimental-skip-non-inlinable-function-bodies-is-lazy
2 parents 45d1e95 + 5e5578a commit 2f8d9e5

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

include/swift/Option/FrontendOptions.td

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

1133+
def experimental_skip_non_inlinable_function_bodies_is_lazy
1134+
: Flag<["-"], "experimental-skip-non-inlinable-function-bodies-is-lazy">,
1135+
HelpText<"Infer lazy typechecking for "
1136+
"-experimental-skip-non-inlinable-function-bodies">;
1137+
11331138
def experimental_allow_module_with_compiler_errors:
11341139
Flag<["-"], "experimental-allow-module-with-compiler-errors">,
11351140
Flags<[HelpHidden]>,

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,16 @@ bool ArgsToFrontendOptionsConverter::convert(
322322

323323
Opts.SkipNonExportableDecls |=
324324
Args.hasArg(OPT_experimental_skip_non_exportable_decls);
325+
Opts.SkipNonExportableDecls |=
326+
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) &&
327+
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies_is_lazy);
328+
// HACK: The driver currently erroneously passes all flags to module interface
329+
// verification jobs. -experimental-skip-non-exportable-decls is not
330+
// appropriate for verification tasks and should be ignored, though.
331+
if (Opts.RequestedAction ==
332+
FrontendOptions::ActionType::TypecheckModuleFromInterface)
333+
Opts.SkipNonExportableDecls = false;
334+
325335
Opts.DebugPrefixSerializedDebuggingOptions |=
326336
Args.hasArg(OPT_prefix_serialized_debugging_options);
327337
Opts.EnableSourceImport |= Args.hasArg(OPT_enable_source_import);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,15 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
15031503
Opts.DebugGenericSignatures |= Args.hasArg(OPT_debug_generic_signatures);
15041504

15051505
Opts.EnableLazyTypecheck |= Args.hasArg(OPT_experimental_lazy_typecheck);
1506+
Opts.EnableLazyTypecheck |=
1507+
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) &&
1508+
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies_is_lazy);
1509+
// HACK: The driver currently erroneously passes all flags to module interface
1510+
// verification jobs. -experimental-skip-non-exportable-decls is not
1511+
// appropriate for verification tasks and should be ignored, though.
1512+
if (FrontendOpts.RequestedAction ==
1513+
FrontendOptions::ActionType::TypecheckModuleFromInterface)
1514+
Opts.EnableLazyTypecheck = false;
15061515

15071516
return HadError;
15081517
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-compiler-version: Swift version 5.11
3+
// swift-module-flags: -swift-version 5 -enable-library-evolution -module-name Test
4+
// expected-error @-3 {{failed to verify module interface of 'Test'}}
5+
import Swift
6+
public struct S {
7+
@inlinable public func foo() {
8+
doesNotExist() // expected-error {{cannot find 'doesNotExist' in scope}}
9+
}
10+
}
11+
12+
// RUN: %target-swift-typecheck-module-from-interface(%s) -module-name Test -verify -verify-ignore-unknown -experimental-lazy-typecheck

test/Serialization/lazy-typecheck.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +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-
// FIXME: Re-run the test with -experimental-skip-non-inlinable-function-bodies
14+
// (3) Verify that a module built with -experimental-lazy-typecheck, -experimental-skip-non-inlinable-function-bodies,
15+
// and -experimental-skip-non-exportable-decls can be used by the same client as in (1).
16+
// 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
17+
// 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)