Skip to content

Commit 2f2c0ba

Browse files
committed
Add a flag to enable ConcurrentValue inference for public structs/enums.
1 parent 7496701 commit 2f2c0ba

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ namespace swift {
247247
/// Enable experimental flow-sensitive concurrent captures.
248248
bool EnableExperimentalFlowSensitiveConcurrentCaptures = false;
249249

250+
/// Enable inference of ConcurrentValue conformances for public types.
251+
bool EnableInferPublicConcurrentValue = false;
252+
250253
/// Enable experimental derivation of `Codable` for enums.
251254
bool EnableExperimentalEnumCodableDerivation = false;
252255

include/swift/Option/FrontendOptions.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ def batch_scan_input_file
188188
def import_prescan : Flag<["-"], "import-prescan">,
189189
HelpText<"When performing a dependency scan, only dentify all imports of the main Swift module sources">;
190190

191+
def enable_infer_public_concurrent_value : Flag<["-"], "enable-infer-public-concurrent-value">,
192+
HelpText<"Enable inference of ConcurrentValue conformances for public structs and enums">;
193+
194+
def disable_infer_public_concurrent_value : Flag<["-"], "disable-infer-public-concurrent-value">,
195+
HelpText<"Disable inference of ConcurrentValue conformances for public structs and enums">;
196+
191197
} // end let Flags = [FrontendOption, NoDriverOption]
192198

193199
def debug_crash_Group : OptionGroup<"<automatic crashing options>">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
385385

386386
Opts.EnableExperimentalConcurrency |=
387387
Args.hasArg(OPT_enable_experimental_concurrency);
388+
Opts.EnableInferPublicConcurrentValue |=
389+
Args.hasFlag(OPT_enable_infer_public_concurrent_value,
390+
OPT_disable_infer_public_concurrent_value,
391+
false);
388392
Opts.EnableExperimentalFlowSensitiveConcurrentCaptures |=
389393
Args.hasArg(OPT_enable_experimental_flow_sensitive_concurrent_captures);
390394

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2510,7 +2510,8 @@ NormalProtocolConformance *GetImplicitConcurrentValueRequest::evaluate(
25102510

25112511
// Public, non-frozen structs and enums defined in Swift don't get implicit
25122512
// ConcurrentValue conformances.
2513-
if (nominal->getFormalAccessScope(
2513+
if (!nominal->getASTContext().LangOpts.EnableInferPublicConcurrentValue &&
2514+
nominal->getFormalAccessScope(
25142515
/*useDC=*/nullptr,
25152516
/*treatUsableFromInlineAsPublic=*/true).isPublic() &&
25162517
!(nominal->hasClangNode() ||
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-typecheck-verify-swift -enable-infer-public-concurrent-value
2+
3+
func acceptCV<T: ConcurrentValue>(_: T) { }
4+
5+
public struct PublicStruct {
6+
var i: Int
7+
}
8+
9+
public enum PublicEnum {
10+
case some
11+
}
12+
13+
func testCV(ps: PublicStruct, pe: PublicEnum) {
14+
acceptCV(ps)
15+
acceptCV(pe)
16+
}

0 commit comments

Comments
 (0)