mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Add workaround flag for lazy import-as-member
In rdar://123649082, a project failed to build because of the lazy import-as-member loading changes in #71320. That project was configured in a way that broke modularization and the correct solution is to fix it, but out of an abundance of caution, add a `-disable-named-lazy-import-as-member-loading` frontend flag in case a project needs to temporarily restore the old behavior. As a bonus, this lets us write a test to verify that lazy import-as-member loading has positive performance impact.
This commit is contained in:
@@ -377,6 +377,11 @@ namespace swift {
|
|||||||
/// Enable experimental eager Clang module diagnostics.
|
/// Enable experimental eager Clang module diagnostics.
|
||||||
bool EnableExperimentalEagerClangModuleDiagnostics = false;
|
bool EnableExperimentalEagerClangModuleDiagnostics = false;
|
||||||
|
|
||||||
|
/// Force ClangImporter's import-as-member extensions to load thier members
|
||||||
|
/// immediately, bypassing their SwiftLookupTables. This emulates an
|
||||||
|
/// implementation quirk of previous compilers.
|
||||||
|
bool DisableNamedLazyImportAsMemberLoading = false;
|
||||||
|
|
||||||
/// Enable inference of Sendable conformances for public types.
|
/// Enable inference of Sendable conformances for public types.
|
||||||
bool EnableInferPublicSendable = false;
|
bool EnableInferPublicSendable = false;
|
||||||
|
|
||||||
|
|||||||
@@ -372,7 +372,13 @@ def debug_constraints_on_line_EQ : Joined<["-"], "debug-constraints-on-line=">,
|
|||||||
Alias<debug_constraints_on_line>;
|
Alias<debug_constraints_on_line>;
|
||||||
|
|
||||||
def disable_named_lazy_member_loading : Flag<["-"], "disable-named-lazy-member-loading">,
|
def disable_named_lazy_member_loading : Flag<["-"], "disable-named-lazy-member-loading">,
|
||||||
HelpText<"Disable per-name lazy member loading">;
|
HelpText<"Disable per-name lazy member loading (obsolete)">;
|
||||||
|
|
||||||
|
def disable_named_lazy_import_as_member_loading :
|
||||||
|
Flag<["-"], "disable-named-lazy-import-as-member-loading">,
|
||||||
|
HelpText<"Import all of a type's import-as-member globals together, as Swift "
|
||||||
|
"5.10 and earlier did; temporary workaround for modules that are "
|
||||||
|
"sensitive to this change">;
|
||||||
|
|
||||||
def dump_requirement_machine : Flag<["-"], "dump-requirement-machine">,
|
def dump_requirement_machine : Flag<["-"], "dump-requirement-machine">,
|
||||||
HelpText<"Enables dumping rewrite systems from the generics implementation">;
|
HelpText<"Enables dumping rewrite systems from the generics implementation">;
|
||||||
|
|||||||
@@ -1446,10 +1446,25 @@ void MemberLookupTable::addMembers(DeclRange members) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool shouldLoadMembersImmediately(ExtensionDecl *ext) {
|
||||||
|
assert(ext->hasLazyMembers());
|
||||||
|
if (ext->wasDeserialized() || ext->hasClangNode())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// This extension is lazy but is not deserialized or backed by a clang node,
|
||||||
|
// so it's a ClangImporter extension containing import-as-member globals.
|
||||||
|
// Historically, Swift forced these extensions to load their members
|
||||||
|
// immediately, bypassing the module's SwiftLookupTable. Using the
|
||||||
|
// SwiftLookupTable *ought* to work the same, but in practice it sometimes
|
||||||
|
// gives different results when a header is not properly modularized. Provide
|
||||||
|
// a flag to temporarily re-enable the old behavior.
|
||||||
|
return ext->getASTContext().LangOpts.DisableNamedLazyImportAsMemberLoading;
|
||||||
|
}
|
||||||
|
|
||||||
void MemberLookupTable::addExtension(ExtensionDecl *ext) {
|
void MemberLookupTable::addExtension(ExtensionDecl *ext) {
|
||||||
// If we can lazy-load this extension, only take the members we've loaded
|
// If we can lazy-load this extension, only take the members we've loaded
|
||||||
// so far.
|
// so far.
|
||||||
if (ext->hasLazyMembers()) {
|
if (ext->hasLazyMembers() && !shouldLoadMembersImmediately(ext)) {
|
||||||
addMembers(ext->getCurrentMembersWithoutLoading());
|
addMembers(ext->getCurrentMembersWithoutLoading());
|
||||||
clearLazilyCompleteCache();
|
clearLazilyCompleteCache();
|
||||||
clearLazilyCompleteForMacroExpansionCache();
|
clearLazilyCompleteForMacroExpansionCache();
|
||||||
|
|||||||
@@ -623,6 +623,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
|||||||
!Args.hasArg(OPT_disable_experimental_clang_importer_diagnostics) &&
|
!Args.hasArg(OPT_disable_experimental_clang_importer_diagnostics) &&
|
||||||
Args.hasArg(OPT_enable_experimental_eager_clang_module_diagnostics);
|
Args.hasArg(OPT_enable_experimental_eager_clang_module_diagnostics);
|
||||||
|
|
||||||
|
Opts.DisableNamedLazyImportAsMemberLoading |=
|
||||||
|
Args.hasArg(OPT_disable_named_lazy_import_as_member_loading);
|
||||||
|
|
||||||
Opts.DisableImplicitConcurrencyModuleImport |=
|
Opts.DisableImplicitConcurrencyModuleImport |=
|
||||||
Args.hasArg(OPT_disable_implicit_concurrency_module_import);
|
Args.hasArg(OPT_disable_implicit_concurrency_module_import);
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
// RUN: %target-typecheck-verify-swift -dump-clang-lookup-tables -import-objc-header %S/Inputs/swift_name.h -I %S/Inputs/custom-modules > %t.frontend.log 2>&1
|
// RUN: %target-typecheck-verify-swift -dump-clang-lookup-tables -import-objc-header %S/Inputs/swift_name.h -I %S/Inputs/custom-modules > %t.frontend.log 2>&1
|
||||||
// RUN: %FileCheck %s < %t.frontend.log
|
// RUN: %FileCheck %s < %t.frontend.log
|
||||||
// RUN: false
|
|
||||||
|
|
||||||
// REQUIRES: objc_interop
|
// REQUIRES: objc_interop
|
||||||
import ImportAsMember
|
import ImportAsMember
|
||||||
|
|||||||
@@ -138,3 +138,6 @@
|
|||||||
|
|
||||||
@interface PrivateDoer(Category) <PrivateMethods>
|
@interface PrivateDoer(Category) <PrivateMethods>
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
typedef NSString * const SimpleDoerMode NS_TYPED_ENUM NS_SWIFT_NAME(SimpleDoer.Mode);
|
||||||
|
typedef NSString * const SimpleDoerKind NS_TYPED_ENUM NS_SWIFT_NAME(SimpleDoer.Kind);
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// REQUIRES: objc_interop
|
||||||
|
// REQUIRES: OS=macosx
|
||||||
|
|
||||||
|
// RUN: %empty-directory(%t/stats-lazy)
|
||||||
|
// RUN: %empty-directory(%t/stats-eager)
|
||||||
|
|
||||||
|
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers %s -stats-output-dir %t/stats-lazy
|
||||||
|
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers %s -stats-output-dir %t/stats-eager -disable-named-lazy-import-as-member-loading
|
||||||
|
|
||||||
|
// stats-lazy should only have imported SimpleDoer.Mode; stats-eager should also
|
||||||
|
// have imported SimpleDoer.Kind
|
||||||
|
// RUN: %{python} %utils/process-stats-dir.py --evaluate-delta 'NumTotalClangImportedEntities == 1' %t/stats-lazy %t/stats-eager
|
||||||
|
|
||||||
|
import NamedLazyMembers
|
||||||
|
|
||||||
|
func fn(_: SimpleDoer.Mode) {}
|
||||||
Reference in New Issue
Block a user