Skip to content

Commit 44bd180

Browse files
committed
[moveOnly] Add a frontend flag -enable-experimental-move-only to control usage of move only features.
These include _move and @_noImplicitCopy. I still need to wire up the parsing of those behind this feature. The reason that I am adding this now is that I am going to now need to make some changes behind a feature flag and I have not yet needed to add one. The specific reason I needed to add one here is to ensure that I properly guard inside _move the call to Builtin.move so as to prevent a "cond_fail" incident. P.S.: This work depends on experimental lexical lifetimes being enabled as well, so I did that at the same time in this PR.
1 parent ac85770 commit 44bd180

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ namespace swift {
320320
/// Enable experimental 'distributed' actors and functions.
321321
bool EnableExperimentalDistributed = false;
322322

323+
/// Enable experimental 'move only' features.
324+
bool EnableExperimentalMoveOnly = false;
325+
323326
/// Disable the implicit import of the _Concurrency module.
324327
bool DisableImplicitConcurrencyModuleImport =
325328
!SWIFT_IMPLICIT_CONCURRENCY_IMPORT;

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ def enable_experimental_lexical_lifetimes :
259259
Flag<["-"], "enable-experimental-lexical-lifetimes">,
260260
HelpText<"Enable experimental lexical lifetimes">;
261261

262+
def enable_experimental_move_only :
263+
Flag<["-"], "enable-experimental-move-only">,
264+
HelpText<"Enable experimental move only">;
265+
262266
def enable_experimental_distributed :
263267
Flag<["-"], "enable-experimental-distributed">,
264268
HelpText<"Enable experimental 'distributed' actors and functions">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
443443
Opts.EnableExperimentalDistributed |=
444444
Args.hasArg(OPT_enable_experimental_distributed);
445445

446+
Opts.EnableExperimentalMoveOnly |=
447+
Args.hasArg(OPT_enable_experimental_move_only);
448+
446449
Opts.EnableInferPublicSendable |=
447450
Args.hasFlag(OPT_enable_infer_public_concurrent_value,
448451
OPT_disable_infer_public_concurrent_value,
@@ -1399,6 +1402,11 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
13991402

14001403
Opts.EnableExperimentalLexicalLifetimes |=
14011404
Args.hasArg(OPT_enable_experimental_lexical_lifetimes);
1405+
// If experimental move only is enabled, always enable lexical lifetime as
1406+
// well. Move only depends on lexical lifetimes.
1407+
Opts.EnableExperimentalLexicalLifetimes |=
1408+
Args.hasArg(OPT_enable_experimental_move_only);
1409+
14021410
Opts.EnableCopyPropagation |= Args.hasArg(OPT_enable_copy_propagation);
14031411
Opts.DisableCopyPropagation |= Args.hasArg(OPT_disable_copy_propagation);
14041412
Opts.EnableARCOptimizations &= !Args.hasArg(OPT_disable_arc_opts);

tools/sil-opt/SILOpt.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ static llvm::cl::opt<bool> EnableExperimentalLexicalLifetimes(
108108
"enable-experimental-lexical-lifetimes",
109109
llvm::cl::desc("Enable experimental lexical lifetimes."));
110110

111+
static llvm::cl::opt<bool>
112+
EnableExperimentalMoveOnly("enable-experimental-move-only",
113+
llvm::cl::desc("Enable experimental distributed actors."));
114+
111115
static llvm::cl::opt<bool>
112116
EnableExperimentalDistributed("enable-experimental-distributed",
113117
llvm::cl::desc("Enable experimental distributed actors."));
@@ -424,6 +428,8 @@ int main(int argc, char **argv) {
424428
EnableExperimentalConcurrency;
425429
Invocation.getLangOptions().EnableExperimentalDistributed =
426430
EnableExperimentalDistributed;
431+
Invocation.getLangOptions().EnableExperimentalMoveOnly =
432+
EnableExperimentalMoveOnly;
427433

428434
Invocation.getLangOptions().EnableObjCInterop =
429435
EnableObjCInterop ? true :
@@ -513,6 +519,11 @@ int main(int argc, char **argv) {
513519
SILOpts.DisableCopyPropagation = DisableCopyPropagation;
514520
SILOpts.EnableExperimentalLexicalLifetimes =
515521
EnableExperimentalLexicalLifetimes;
522+
// Also enable lexical lifetimes if experimental move only is enabled. This is
523+
// because move only depends on lexical lifetimes being enabled and it saved
524+
// some typing ; ).
525+
SILOpts.EnableExperimentalLexicalLifetimes |=
526+
EnableExperimentalMoveOnly;
516527

517528
serialization::ExtendedValidationInfo extendedInfo;
518529
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =

0 commit comments

Comments
 (0)