Skip to content

Drop experimental prefixes from PackageCMO flags. #75154

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
merged 2 commits into from
Jul 11, 2024
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
4 changes: 2 additions & 2 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -780,10 +780,10 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
/// Whether this module has been built with C++ interoperability enabled.
HasCxxInteroperability : 1,

/// Whether this module has been built with -experimental-allow-non-resilient-access.
/// Whether this module has been built with -allow-non-resilient-access.
AllowNonResilientAccess : 1,

/// Whether this module has been built with -experimental-package-cmo.
/// Whether this module has been built with -package-cmo.
SerializePackageEnabled : 1
);

Expand Down
9 changes: 5 additions & 4 deletions include/swift/AST/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ class ModuleDecl
Bits.ModuleDecl.IsBuiltFromInterface = flag;
}

/// Returns true if -experimental-allow-non-resilient-access was passed
/// Returns true if -allow-non-resilient-access was passed
/// and the module is built from source.
bool allowNonResilientAccess() const {
return Bits.ModuleDecl.AllowNonResilientAccess &&
Expand All @@ -736,11 +736,12 @@ class ModuleDecl
Bits.ModuleDecl.AllowNonResilientAccess = flag;
}

/// Returns true if -experimental-package-cmo was passed, which
/// Returns true if -package-cmo was passed, which
/// enables serialization of package, public, and inlinable decls in a
/// package. This requires -experimental-allow-non-resilient-access.
/// package. This requires -allow-non-resilient-access.
bool serializePackageEnabled() const {
return Bits.ModuleDecl.SerializePackageEnabled;
return Bits.ModuleDecl.SerializePackageEnabled &&
allowNonResilientAccess();
}
void setSerializePackageEnabled(bool flag = true) {
Bits.ModuleDecl.SerializePackageEnabled = flag;
Expand Down
10 changes: 4 additions & 6 deletions include/swift/AST/SILOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,10 @@ class SILOptions {
/// Controls whether cross module optimization is enabled.
CrossModuleOptimizationMode CMOMode = CrossModuleOptimizationMode::Off;

/// Optimization to perform default CMO within a package boundary.
/// Unlike the existing CMO, package CMO can be built with
/// -enable-library-evolution since package modules are required
/// to be built in the same project. To enable this optimization, the
/// module also needs to opt in to allow non-resilient access with
/// -experimental-allow-non-resilient-access.
/// Optimization to perform default mode CMO within a package boundary.
/// Package CMO can be performed for resiliently built modules as package
/// modules are required to be built together in the same project. To enable
/// this optimization, the module also needs -allow-non-resilient-access.
bool EnableSerializePackage = false;

/// Enables the emission of stack protectors in functions.
Expand Down
5 changes: 1 addition & 4 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ namespace swift {
/// Disable API availability checking.
bool DisableAvailabilityChecking = false;

/// Enable optimization to bypass resilience checks in a package
bool EnableBypassResilienceInPackage = false;

/// Optimization mode for unavailable declarations.
std::optional<UnavailableDeclOptimization> UnavailableDeclOptimizationMode;

Expand Down Expand Up @@ -583,7 +580,7 @@ namespace swift {
/// Skips decls that cannot be referenced externally.
bool SkipNonExportableDecls = false;

/// True if -experimental-allow-non-resilient-access is passed and built
/// True if -allow-non-resilient-access is passed and built
/// from source.
bool AllowNonResilientAccess = false;

Expand Down
14 changes: 11 additions & 3 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,15 @@ def unavailable_decl_optimization_EQ : Joined<["-"], "unavailable-decl-optimizat

def experimental_package_bypass_resilience : Flag<["-"], "experimental-package-bypass-resilience">,
Flags<[FrontendOption]>,
HelpText<"Enable optimization to bypass resilience within a package">;
HelpText<"Deprecated; has no effect">;

def experimental_allow_non_resilient_access : Flag<["-"], "experimental-allow-non-resilient-access">,
Flags<[FrontendOption]>,
HelpText<"Allow non-resilient access by generating all contents besides exportable decls">;
HelpText<"Deprecated; use -allow-non-resilient-access instead">;

def allow_non_resilient_access : Flag<["-"], "allow-non-resilient-access">,
Flags<[FrontendOption]>,
HelpText<"Ensures all contents are generated besides exportable decls in the binary module, so non-resilient access can be allowed">;

def library_level : Separate<["-"], "library-level">,
MetaVarName<"<level>">,
Expand Down Expand Up @@ -998,7 +1002,11 @@ def Oplayground : Flag<["-"], "Oplayground">, Group<O_Group>,

def ExperimentalPackageCMO : Flag<["-"], "experimental-package-cmo">,
Flags<[FrontendOption]>,
HelpText<"Enable optimization to perform default CMO within a package boundary">;
HelpText<"Deprecated; use -package-cmo instead">;

def PackageCMO : Flag<["-"], "package-cmo">,
Flags<[FrontendOption]>,
HelpText<"Enable optimization to perform defalut CMO within a package boundary">;

def EnbaleDefaultCMO : Flag<["-"], "enable-default-cmo">,
Flags<[HelpHidden, FrontendOption]>,
Expand Down
23 changes: 7 additions & 16 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4396,23 +4396,14 @@ bool ValueDecl::hasOpenAccess(const DeclContext *useDC) const {
}

bool ValueDecl::bypassResilienceInPackage(ModuleDecl *accessingModule) const {
// If the defining module is built with package-cmo, bypass
// resilient access from the use site that belongs to a module
// in the same package.
auto declModule = getModuleContext();
if (declModule->inSamePackage(accessingModule) &&
declModule->allowNonResilientAccess()) {
// If the defining module is built with package-cmo,
// allow direct access from the use site that belongs
// to accessingModule (client module).
if (declModule->isResilient() &&
declModule->serializePackageEnabled())
return true;

// If not, check if the client can still opt in to
// have a direct access to this decl from the use
// site with a flag.
// FIXME: serialize this flag to Module and get it via accessingModule.
return getASTContext().LangOpts.EnableBypassResilienceInPackage;
}
return false;
return declModule->inSamePackage(accessingModule) &&
declModule->isResilient() &&
declModule->allowNonResilientAccess() &&
declModule->serializePackageEnabled();
}

/// Given the formal access level for using \p VD, compute the scope where
Expand Down
1 change: 1 addition & 0 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
inputArgs.AddLastArg(arguments, options::OPT_suppress_remarks);
inputArgs.AddLastArg(arguments, options::OPT_experimental_package_bypass_resilience);
inputArgs.AddLastArg(arguments, options::OPT_ExperimentalPackageCMO);
inputArgs.AddLastArg(arguments, options::OPT_PackageCMO);
inputArgs.AddLastArg(arguments, options::OPT_profile_generate);
inputArgs.AddLastArg(arguments, options::OPT_profile_use);
inputArgs.AddLastArg(arguments, options::OPT_profile_coverage_mapping);
Expand Down
24 changes: 11 additions & 13 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,10 +786,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.EnablePackageInterfaceLoad = Args.hasArg(OPT_experimental_package_interface_load) ||
::getenv("SWIFT_ENABLE_PACKAGE_INTERFACE_LOAD");

Opts.EnableBypassResilienceInPackage =
Args.hasArg(OPT_experimental_package_bypass_resilience) ||
Opts.hasFeature(Feature::ClientBypassResilientAccessInPackage);

Opts.DisableAvailabilityChecking |=
Args.hasArg(OPT_disable_availability_checking);
if (Args.hasArg(OPT_check_api_availability_only))
Expand Down Expand Up @@ -1239,13 +1235,14 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,

Opts.AllowNonResilientAccess =
Args.hasArg(OPT_experimental_allow_non_resilient_access) ||
Args.hasArg(OPT_allow_non_resilient_access) ||
Opts.hasFeature(Feature::AllowNonResilientAccessInPackage);
if (Opts.AllowNonResilientAccess) {
// Override the option to skip non-exportable decls.
if (Opts.SkipNonExportableDecls) {
Diags.diagnose(SourceLoc(), diag::warn_ignore_option_overriden_by,
"-experimental-skip-non-exportable-decls",
"-experimental-allow-non-resilient-access");
"-allow-non-resilient-access");
Opts.SkipNonExportableDecls = false;
}
// If built from interface, non-resilient access should not be allowed.
Expand All @@ -1254,7 +1251,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
FrontendOpts.RequestedAction)) {
Diags.diagnose(
SourceLoc(), diag::warn_ignore_option_overriden_by,
"-experimental-allow-non-resilient-access",
"-allow-non-resilient-access",
"-compile-module-from-interface or -typecheck-module-from-interface");
Opts.AllowNonResilientAccess = false;
}
Expand Down Expand Up @@ -1671,7 +1668,7 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
if (LangOpts.AllowNonResilientAccess)
Diags.diagnose(SourceLoc(), diag::warn_ignore_option_overriden_by,
"-experimental-skip-non-inlinable-function-bodies-without-types",
"-experimental-allow-non-resilient-access");
"-allow-non-resilient-access");
else
Opts.SkipFunctionBodies = FunctionBodySkipping::NonInlinableWithoutTypes;
}
Expand All @@ -1682,7 +1679,7 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
if (LangOpts.AllowNonResilientAccess)
Diags.diagnose(SourceLoc(), diag::warn_ignore_option_overriden_by,
"-experimental-skip-non-inlinable-function-bodies",
"-experimental-allow-non-resilient-access");
"-allow-non-resilient-access");
else
Opts.SkipFunctionBodies = FunctionBodySkipping::NonInlinable;
}
Expand All @@ -1691,7 +1688,7 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
if (LangOpts.AllowNonResilientAccess)
Diags.diagnose(SourceLoc(), diag::warn_ignore_option_overriden_by,
"-tbd-is-installapi",
"-experimental-allow-non-resilient-access");
"-allow-non-resilient-access");
else
Opts.SkipFunctionBodies = FunctionBodySkipping::NonInlinable;
}
Expand All @@ -1700,7 +1697,7 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
if (LangOpts.AllowNonResilientAccess)
Diags.diagnose(SourceLoc(), diag::warn_ignore_option_overriden_by,
"-experimental-skip-all-function-bodies",
"-experimental-allow-non-resilient-access");
"-allow-non-resilient-access");
else
Opts.SkipFunctionBodies = FunctionBodySkipping::All;
}
Expand Down Expand Up @@ -1774,7 +1771,7 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
Opts.EnableLazyTypecheck) {
Diags.diagnose(SourceLoc(), diag::warn_ignore_option_overriden_by,
"-experimental-lazy-typecheck",
"-experimental-allow-non-resilient-access");
"-allow-non-resilient-access");
Opts.EnableLazyTypecheck = false;
}

Expand Down Expand Up @@ -2608,11 +2605,12 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
}

if (Args.hasArg(OPT_ExperimentalPackageCMO) ||
Args.hasArg(OPT_PackageCMO) ||
LangOpts.hasFeature(Feature::PackageCMO)) {
if (!LangOpts.AllowNonResilientAccess) {
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
"-experimental-package-cmo",
"-experimental-allow-non-resilient-access");
"-package-cmo",
"-allow-non-resilient-access");
} else {
Opts.EnableSerializePackage = true;
Opts.CMOMode = CrossModuleOptimizationMode::Default;
Expand Down
2 changes: 1 addition & 1 deletion lib/Serialization/ModuleFileSharedCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ void ModuleFileSharedCore::outputDiagnosticInfo(llvm::raw_ostream &os) const {
<< " against SDK " << SDKVersion
<< ", " << (resilient? "resilient": "non-resilient");
if (Bits.AllowNonResilientAccess)
os << ", built with -experimental-allow-non-resilient-access";
os << ", built with -allow-non-resilient-access";
if (Bits.IsAllowModuleWithCompilerErrorsEnabled)
os << ", built with -experimental-allow-module-with-compiler-errors";
if (ModuleInputBuffer)
Expand Down
4 changes: 2 additions & 2 deletions lib/Serialization/ModuleFileSharedCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,10 @@ class ModuleFileSharedCore {
/// Whether this module is built with C++ interoperability enabled.
unsigned HasCxxInteroperability : 1;

/// Whether this module is built with -experimental-allow-non-resilient-access.
/// Whether this module is built with -allow-non-resilient-access.
unsigned AllowNonResilientAccess : 1;

/// Whether this module is built with -experimental-package-cmo.
/// Whether this module is built with -package-cmo.
unsigned SerializePackageEnabled : 1;

// Explicitly pad out to the next word boundary.
Expand Down
13 changes: 12 additions & 1 deletion test/IRGen/package_bypass_resilience_class.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@
// RUN: -emit-tbd -emit-tbd-path %t/libCore.tbd \
// RUN: -Xfrontend -tbd-install_name=libCore.dylib -Xfrontend -validate-tbd-against-ir=all

/// Build without -experimental-allow-non-resilient-access
/// Build with -allow-non-resilient-access
// RUN: %target-build-swift %t/Core.swift \
// RUN: -module-name=Core -package-name Pkg \
// RUN: -Xfrontend -allow-non-resilient-access \
// RUN: -enable-library-evolution -O -wmo \
// RUN: -emit-ir -o %t/Core2.ir \
// RUN: -emit-tbd -emit-tbd-path %t/libCore2.tbd \
// RUN: -Xfrontend -tbd-install_name=libCore2.dylib -Xfrontend -validate-tbd-against-ir=all

/// Build without -allow-non-resilient-access
// RUN: %target-build-swift %t/Core.swift \
// RUN: -module-name=Core -package-name Pkg \
// RUN: -enable-library-evolution -O -wmo \
Expand All @@ -19,7 +28,9 @@
// RUN: -Xfrontend -tbd-install_name=libCoreRes.dylib -Xfrontend -validate-tbd-against-ir=all

// RUN: %FileCheck %s --check-prefixes=CHECK-COMMON,CHECK-OPT < %t/Core.ir
// RUN: %FileCheck %s --check-prefixes=CHECK-COMMON,CHECK-OPT < %t/Core2.ir
// RUN: %FileCheck %s --check-prefixes=CHECK-TBD-COMMON,CHECK-TBD-OPT < %t/libCore.tbd
// RUN: %FileCheck %s --check-prefixes=CHECK-TBD-COMMON,CHECK-TBD-OPT < %t/libCore2.tbd
// RUN: %FileCheck %s --check-prefixes=CHECK-COMMON,CHECK-RES < %t/CoreRes.ir
// RUN: %FileCheck %s --check-prefixes=CHECK-TBD-COMMON,CHECK-TBD-RES < %t/libCoreRes.tbd

Expand Down
16 changes: 6 additions & 10 deletions test/IRGen/package_resilience.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
//
// Unlike its counterparts in the other *_resilience.swift files, the goal is
// for the package's component modules to all be considered within the same
// resilience domain. This file ensures that we use direct access to package
// decls at use site as much as possible with -experimental-package-bypass-resilience.
// Tests resilient access is bypassed when package optimization flags are passed.
//

// RUN: %empty-directory(%t)
// RUN: %{python} %utils/chex.py < %s > %t/package_resilience.swift
// RUN: %target-swift-frontend -package-name MyPkg -emit-module -enable-library-evolution -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct -experimental-allow-non-resilient-access %S/Inputs/package_types/resilient_struct.swift
// RUN: %target-swift-frontend -package-name MyPkg -emit-module -enable-library-evolution -emit-module-path=%t/resilient_enum.swiftmodule -module-name=resilient_enum -I %t %S/Inputs/package_types/resilient_enum.swift -experimental-allow-non-resilient-access
// RUN: %target-swift-frontend -package-name MyPkg -emit-module -enable-library-evolution -emit-module-path=%t/resilient_class.swiftmodule -module-name=resilient_class -I %t %S/Inputs/package_types/resilient_class.swift -experimental-allow-non-resilient-access
// RUN: %target-swift-frontend -package-name MyPkg -emit-module -enable-library-evolution -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct -allow-non-resilient-access -package-cmo %S/Inputs/package_types/resilient_struct.swift
// RUN: %target-swift-frontend -package-name MyPkg -emit-module -enable-library-evolution -emit-module-path=%t/resilient_enum.swiftmodule -module-name=resilient_enum -I %t %S/Inputs/package_types/resilient_enum.swift -allow-non-resilient-access -package-cmo
// RUN: %target-swift-frontend -package-name MyPkg -emit-module -enable-library-evolution -emit-module-path=%t/resilient_class.swiftmodule -module-name=resilient_class -I %t %S/Inputs/package_types/resilient_class.swift -allow-non-resilient-access -package-cmo

// RUN: %target-swift-frontend -package-name MyPkg -module-name=package_resilience -experimental-package-bypass-resilience -enable-objc-interop -I %t -emit-ir -enable-library-evolution %t/package_resilience.swift | %FileCheck %t/package_resilience.swift --check-prefixes=CHECK,CHECK-objc,CHECK-objc%target-ptrsize,CHECK-%target-ptrsize,CHECK-%target-cpu,CHECK-%target-import-type-objc-STABLE-ABI-%target-mandates-stable-abi,CHECK-%target-sdk-name -DINT=i%target-ptrsize -D#MDWORDS=7 -D#MDSIZE32=52 -D#MDSIZE64=80 -D#WORDSIZE=%target-alignment
// RUN: %target-swift-frontend -package-name MyPkg -module-name=package_resilience -enable-objc-interop -I %t -emit-ir -enable-library-evolution %t/package_resilience.swift | %FileCheck %t/package_resilience.swift --check-prefixes=CHECK,CHECK-objc,CHECK-objc%target-ptrsize,CHECK-%target-ptrsize,CHECK-%target-cpu,CHECK-%target-import-type-objc-STABLE-ABI-%target-mandates-stable-abi,CHECK-%target-sdk-name -DINT=i%target-ptrsize -D#MDWORDS=7 -D#MDSIZE32=52 -D#MDSIZE64=80 -D#WORDSIZE=%target-alignment

// RUN: %target-swift-frontend -package-name MyPkg -module-name=package_resilience -experimental-package-bypass-resilience -disable-objc-interop -I %t -emit-ir -enable-library-evolution %t/package_resilience.swift | %FileCheck %t/package_resilience.swift --check-prefixes=CHECK,CHECK-native,CHECK-native%target-ptrsize,CHECK-%target-ptrsize,CHECK-%target-cpu,CHECK-native-STABLE-ABI-%target-mandates-stable-abi,CHECK-%target-sdk-name -DINT=i%target-ptrsize -D#MDWORDS=4 -D#MDSIZE32=40 -D#MDSIZE64=56 -D#WORDSIZE=%target-alignment
// RUN: %target-swift-frontend -package-name MyPkg -module-name=package_resilience -disable-objc-interop -I %t -emit-ir -enable-library-evolution %t/package_resilience.swift | %FileCheck %t/package_resilience.swift --check-prefixes=CHECK,CHECK-native,CHECK-native%target-ptrsize,CHECK-%target-ptrsize,CHECK-%target-cpu,CHECK-native-STABLE-ABI-%target-mandates-stable-abi,CHECK-%target-sdk-name -DINT=i%target-ptrsize -D#MDWORDS=4 -D#MDSIZE32=40 -D#MDSIZE64=56 -D#WORDSIZE=%target-alignment

// RUN: %target-swift-frontend -package-name MyPkg -module-name=package_resilience -experimental-package-bypass-resilience -I %t -emit-ir -enable-library-evolution -O %t/package_resilience.swift -package-name MyPkg

Expand Down
Loading