Skip to content

Commit 60f3d61

Browse files
authored
Merge pull request swiftlang#39943 from gottesmm/pr-65ca66f5402c00e0f0fa0608409ef1c732d1fd2b
[moveOnly] Add a skeleton _move function
2 parents 9e41e37 + 1147897 commit 60f3d61

23 files changed

+226
-31
lines changed

include/swift/AST/Builtins.def

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,6 @@ BUILTIN_SIL_OPERATION(WithUnsafeThrowingContinuation, "withUnsafeThrowingContinu
515515
/// Force the current task to be rescheduled on the specified actor.
516516
BUILTIN_SIL_OPERATION(HopToActor, "hopToActor", None)
517517

518-
/// Generate a move_value instruction to convert a T to a @_moveOnly T.
519-
BUILTIN_SIL_OPERATION(Move, "move", Special)
520-
521518
#undef BUILTIN_SIL_OPERATION
522519

523520
// BUILTIN_RUNTIME_CALL - A call into a runtime function.
@@ -780,6 +777,19 @@ BUILTIN_MISC_OPERATION(CreateTaskGroup,
780777
BUILTIN_MISC_OPERATION(DestroyTaskGroup,
781778
"destroyTaskGroup", "", Special)
782779

780+
781+
/// A builtin that can only be called from a transparent generic function. Takes
782+
/// two operands, the first operand the result address, the second operand the
783+
/// input address. Transforms into load [take] + move_value + store [init] when
784+
/// transparently inlined into a caller that has the generic of the callee
785+
/// specialized into a loadable type. If the transparent inlining does not
786+
/// specialize the type (due to being inlined into a non-generic context, the
787+
/// SILVerifier will abort).
788+
///
789+
/// Illegal to call except for in Swift._move in the stdlib. This is enforced by
790+
/// the SILVerifier.
791+
BUILTIN_MISC_OPERATION(Move, "move", "", Special)
792+
783793
// BUILTIN_MISC_OPERATION_WITH_SILGEN - Miscellaneous operations that are
784794
// specially emitted during SIL generation.
785795
//

include/swift/AST/DiagnosticsSIL.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,5 +686,9 @@ NOTE(capturepromotion_concurrentcapture_capturinguse_here, none,
686686
NOTE(capturepromotion_variable_defined_here,none,
687687
"variable defined here", ())
688688

689+
// move operator used on generic or evalue
690+
ERROR(move_operator_used_on_generic_or_existential_value, none,
691+
"move() used on a generic or existential value", ())
692+
689693
#define UNDEFINE_DIAGNOSTIC_MACROS
690694
#include "DefineDiagnosticMacros.h"

include/swift/AST/SemanticAttrs.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,7 @@ SEMANTICS_ATTR(FORCE_EMIT_OPT_REMARK_PREFIX, "optremark")
113113
/// for testing purposes.
114114
SEMANTICS_ATTR(OBJC_FORBID_ASSOCIATED_OBJECTS, "objc.forbidAssociatedObjects")
115115

116+
SEMANTICS_ATTR(LIFETIMEMANAGEMENT_MOVE, "lifetimemanagement.move")
117+
116118
#undef SEMANTICS_ATTR
117119

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ LANGUAGE_FEATURE(ImplicitSelfCapture, 0, "@_implicitSelfCapture attribute", true
5454
LANGUAGE_FEATURE(BuiltinBuildExecutor, 0, "Executor-building builtins", true)
5555
LANGUAGE_FEATURE(BuiltinBuildMainExecutor, 0, "MainActor executor building builtin", true)
5656
LANGUAGE_FEATURE(BuiltinCreateAsyncTaskInGroup, 0, "MainActor executor building builtin", true)
57+
LANGUAGE_FEATURE(BuiltinMove, 0, "Builtin.move()", true)
5758

5859
#undef LANGUAGE_FEATURE

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">;

include/swift/SIL/SILType.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,9 @@ class SILType {
620620
/// Get the SIL token type.
621621
static SILType getSILTokenType(const ASTContext &C);
622622

623+
/// Return '()'
624+
static SILType getEmptyTupleType(const ASTContext &C);
625+
623626
//
624627
// Utilities for treating SILType as a pointer-like type.
625628
//

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,6 +2812,10 @@ static bool usesFeatureBuiltinCreateAsyncTaskInGroup(Decl *decl) {
28122812
return false;
28132813
}
28142814

2815+
static bool usesFeatureBuiltinMove(Decl *decl) {
2816+
return false;
2817+
}
2818+
28152819
static bool usesFeatureInheritActorContext(Decl *decl) {
28162820
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
28172821
for (auto param : *func->getParameters()) {

lib/AST/Builtins.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,7 @@ static ValueDecl *getDestroyArrayOperation(ASTContext &ctx, Identifier id) {
856856

857857
static ValueDecl *getMoveOperation(ASTContext &ctx, Identifier id) {
858858
return getBuiltinFunction(ctx, id, _thin, _generics(_unrestricted),
859-
_parameters(_owned(_typeparam(0))),
860-
_moveOnly(_typeparam(0)));
859+
_parameters(_owned(_typeparam(0))), _typeparam(0));
861860
}
862861

863862
static ValueDecl *getTransferArrayOperation(ASTContext &ctx, Identifier id) {

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);

0 commit comments

Comments
 (0)