Add a flag to enable ConcurrentValue inference for public structs/enums.

This commit is contained in:
Doug Gregor
2021-03-02 17:03:21 -08:00
parent 7496701c9f
commit 2f2c0ba437
5 changed files with 31 additions and 1 deletions

View File

@@ -247,6 +247,9 @@ namespace swift {
/// Enable experimental flow-sensitive concurrent captures.
bool EnableExperimentalFlowSensitiveConcurrentCaptures = false;
/// Enable inference of ConcurrentValue conformances for public types.
bool EnableInferPublicConcurrentValue = false;
/// Enable experimental derivation of `Codable` for enums.
bool EnableExperimentalEnumCodableDerivation = false;

View File

@@ -188,6 +188,12 @@ def batch_scan_input_file
def import_prescan : Flag<["-"], "import-prescan">,
HelpText<"When performing a dependency scan, only dentify all imports of the main Swift module sources">;
def enable_infer_public_concurrent_value : Flag<["-"], "enable-infer-public-concurrent-value">,
HelpText<"Enable inference of ConcurrentValue conformances for public structs and enums">;
def disable_infer_public_concurrent_value : Flag<["-"], "disable-infer-public-concurrent-value">,
HelpText<"Disable inference of ConcurrentValue conformances for public structs and enums">;
} // end let Flags = [FrontendOption, NoDriverOption]
def debug_crash_Group : OptionGroup<"<automatic crashing options>">;

View File

@@ -385,6 +385,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.EnableExperimentalConcurrency |=
Args.hasArg(OPT_enable_experimental_concurrency);
Opts.EnableInferPublicConcurrentValue |=
Args.hasFlag(OPT_enable_infer_public_concurrent_value,
OPT_disable_infer_public_concurrent_value,
false);
Opts.EnableExperimentalFlowSensitiveConcurrentCaptures |=
Args.hasArg(OPT_enable_experimental_flow_sensitive_concurrent_captures);

View File

@@ -2510,7 +2510,8 @@ NormalProtocolConformance *GetImplicitConcurrentValueRequest::evaluate(
// Public, non-frozen structs and enums defined in Swift don't get implicit
// ConcurrentValue conformances.
if (nominal->getFormalAccessScope(
if (!nominal->getASTContext().LangOpts.EnableInferPublicConcurrentValue &&
nominal->getFormalAccessScope(
/*useDC=*/nullptr,
/*treatUsableFromInlineAsPublic=*/true).isPublic() &&
!(nominal->hasClangNode() ||

View File

@@ -0,0 +1,16 @@
// RUN: %target-typecheck-verify-swift -enable-infer-public-concurrent-value
func acceptCV<T: ConcurrentValue>(_: T) { }
public struct PublicStruct {
var i: Int
}
public enum PublicEnum {
case some
}
func testCV(ps: PublicStruct, pe: PublicEnum) {
acceptCV(ps)
acceptCV(pe)
}