Skip to content

Commit 084b639

Browse files
committed
save progress on enabling move-only by default
1 parent 2d20644 commit 084b639

10 files changed

+39
-99
lines changed

lib/AST/Type.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ bool TypeBase::isAny() {
166166
}
167167

168168
bool TypeBase::isPureMoveOnly() {
169+
// FIXME: this should probably turn into a request
169170
if (auto *nom = getNominalOrBoundGenericNominal())
170171
return nom->isMoveOnly();
171172

lib/SILGen/SILGenDecl.cpp

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,7 @@ class LetValueInitialization : public Initialization {
468468
public:
469469
LetValueInitialization(VarDecl *vd, SILGenFunction &SGF) : vd(vd) {
470470
const TypeLowering *lowering = nullptr;
471-
if (SGF.getASTContext().LangOpts.Features.count(Feature::MoveOnly) &&
472-
vd->isNoImplicitCopy()) {
471+
if (vd->isNoImplicitCopy()) {
473472
lowering = &SGF.getTypeLowering(
474473
SILMoveOnlyWrappedType::get(vd->getType()->getCanonicalType()));
475474
} else {
@@ -509,8 +508,7 @@ class LetValueInitialization : public Initialization {
509508

510509
// Make sure that we have a non-address only type when binding a
511510
// @_noImplicitCopy let.
512-
if (SGF.getASTContext().LangOpts.Features.count(Feature::MoveOnly) &&
513-
lowering->isAddressOnly() && vd->isNoImplicitCopy()) {
511+
if (lowering->isAddressOnly() && vd->isNoImplicitCopy()) {
514512
auto d = diag::noimplicitcopy_used_on_generic_or_existential;
515513
diagnose(SGF.getASTContext(), vd->getLoc(), d);
516514
}
@@ -588,10 +586,6 @@ class LetValueInitialization : public Initialization {
588586
SILValue value, bool wasPlusOne) {
589587
// If we have none...
590588
if (value->getOwnershipKind() == OwnershipKind::None) {
591-
// If we don't have move only features enabled, just return, we are done.
592-
if (!SGF.getASTContext().LangOpts.Features.count(Feature::MoveOnly))
593-
return value;
594-
595589
// Then check if we have a pure move only type. In that case, we need to
596590
// insert a no implicit copy
597591
if (value->getType().isPureMoveOnly()) {
@@ -616,15 +610,6 @@ class LetValueInitialization : public Initialization {
616610
MarkMustCheckInst::CheckKind::ConsumableAndAssignable);
617611
}
618612

619-
// Then if we don't have move only, just perform a lexical borrow if the
620-
// lifetime is lexical.
621-
if (!SGF.getASTContext().LangOpts.Features.count(Feature::MoveOnly)) {
622-
if (SGF.F.getLifetime(vd, value->getType()).isLexical())
623-
return SGF.B.createBeginBorrow(PrologueLoc, value, /*isLexical*/ true);
624-
else
625-
return value;
626-
}
627-
628613
// Otherwise, we need to perform some additional processing. First, if we
629614
// have an owned moveonly value that had a cleanup, then create a move_value
630615
// that acts as a consuming use of the value. The reason why we want this is
@@ -1971,35 +1956,22 @@ void SILGenFunction::destroyLocalVariable(SILLocation silLoc, VarDecl *vd) {
19711956
return;
19721957
}
19731958

1974-
if (getASTContext().LangOpts.hasFeature(Feature::MoveOnly)) {
1975-
if (auto *mvi = dyn_cast<MarkMustCheckInst>(Val.getDefiningInstruction())) {
1976-
if (mvi->hasMoveCheckerKind()) {
1977-
if (auto *cvi = dyn_cast<CopyValueInst>(mvi->getOperand())) {
1978-
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
1979-
if (bbi->isLexical()) {
1980-
B.emitDestroyValueOperation(silLoc, mvi);
1981-
B.createEndBorrow(silLoc, bbi);
1982-
B.emitDestroyValueOperation(silLoc, bbi->getOperand());
1983-
return;
1984-
}
1985-
}
1986-
}
1987-
1988-
if (auto *copyToMove = dyn_cast<CopyableToMoveOnlyWrapperValueInst>(
1989-
mvi->getOperand())) {
1990-
if (auto *cvi = dyn_cast<CopyValueInst>(copyToMove->getOperand())) {
1991-
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
1992-
if (bbi->isLexical()) {
1993-
B.emitDestroyValueOperation(silLoc, mvi);
1994-
B.createEndBorrow(silLoc, bbi);
1995-
B.emitDestroyValueOperation(silLoc, bbi->getOperand());
1996-
return;
1997-
}
1998-
}
1959+
if (auto *mvi = dyn_cast<MarkMustCheckInst>(Val.getDefiningInstruction())) {
1960+
if (mvi->hasMoveCheckerKind()) {
1961+
if (auto *cvi = dyn_cast<CopyValueInst>(mvi->getOperand())) {
1962+
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
1963+
if (bbi->isLexical()) {
1964+
B.emitDestroyValueOperation(silLoc, mvi);
1965+
B.createEndBorrow(silLoc, bbi);
1966+
B.emitDestroyValueOperation(silLoc, bbi->getOperand());
1967+
return;
19991968
}
20001969
}
1970+
}
20011971

2002-
if (auto *cvi = dyn_cast<ExplicitCopyValueInst>(mvi->getOperand())) {
1972+
if (auto *copyToMove = dyn_cast<CopyableToMoveOnlyWrapperValueInst>(
1973+
mvi->getOperand())) {
1974+
if (auto *cvi = dyn_cast<CopyValueInst>(copyToMove->getOperand())) {
20031975
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
20041976
if (bbi->isLexical()) {
20051977
B.emitDestroyValueOperation(silLoc, mvi);
@@ -2009,15 +1981,26 @@ void SILGenFunction::destroyLocalVariable(SILLocation silLoc, VarDecl *vd) {
20091981
}
20101982
}
20111983
}
1984+
}
20121985

2013-
// Handle trivial arguments.
2014-
if (auto *move = dyn_cast<MoveValueInst>(mvi->getOperand())) {
2015-
if (move->isLexical()) {
1986+
if (auto *cvi = dyn_cast<ExplicitCopyValueInst>(mvi->getOperand())) {
1987+
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
1988+
if (bbi->isLexical()) {
20161989
B.emitDestroyValueOperation(silLoc, mvi);
1990+
B.createEndBorrow(silLoc, bbi);
1991+
B.emitDestroyValueOperation(silLoc, bbi->getOperand());
20171992
return;
20181993
}
20191994
}
20201995
}
1996+
1997+
// Handle trivial arguments.
1998+
if (auto *move = dyn_cast<MoveValueInst>(mvi->getOperand())) {
1999+
if (move->isLexical()) {
2000+
B.emitDestroyValueOperation(silLoc, mvi);
2001+
return;
2002+
}
2003+
}
20212004
}
20222005
}
20232006

lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableAddressesChecker.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2399,10 +2399,6 @@ class ConsumeOperatorCopyableAddressesCheckerPass
23992399
auto *fn = getFunction();
24002400
auto &astContext = fn->getASTContext();
24012401

2402-
// Only run this pass if the move only language feature is enabled.
2403-
if (!astContext.LangOpts.Features.contains(Feature::MoveOnly))
2404-
return;
2405-
24062402
// Don't rerun diagnostics on deserialized functions.
24072403
if (getFunction()->wasDeserializedCanonical())
24082404
return;

lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableValuesChecker.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,6 @@ class ConsumeOperatorCopyableValuesCheckerPass : public SILFunctionTransform {
526526
void run() override {
527527
auto *fn = getFunction();
528528

529-
// Only run this pass if the move only language feature is enabled.
530-
if (!fn->getASTContext().LangOpts.Features.contains(Feature::MoveOnly))
531-
return;
532-
533529
// Don't rerun diagnostics on deserialized functions.
534530
if (fn->wasDeserializedCanonical())
535531
return;

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerTester.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ class MoveOnlyAddressCheckerTesterPass : public SILFunctionTransform {
7878
void run() override {
7979
auto *fn = getFunction();
8080

81-
// Only run this pass if the move only language feature is enabled.
82-
if (!fn->getASTContext().LangOpts.Features.contains(Feature::MoveOnly))
83-
return;
84-
8581
// Don't rerun diagnostics on deserialized functions.
8682
if (getFunction()->wasDeserializedCanonical())
8783
return;

lib/SILOptimizer/Mandatory/MoveOnlyBorrowToDestructureTester.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ class MoveOnlyBorrowToDestructureTransformPass : public SILFunctionTransform {
7171
void run() override {
7272
auto *fn = getFunction();
7373

74-
// Only run this pass if the move only language feature is enabled.
75-
if (!fn->getASTContext().LangOpts.Features.contains(Feature::MoveOnly))
76-
return;
77-
7874
// Don't rerun diagnostics on deserialized functions.
7975
if (getFunction()->wasDeserializedCanonical())
8076
return;

lib/SILOptimizer/Mandatory/MoveOnlyChecker.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ class MoveOnlyCheckerPass : public SILFunctionTransform {
146146
void run() override {
147147
auto *fn = getFunction();
148148

149-
// Only run this pass if the move only language feature is enabled.
150-
if (!fn->getASTContext().LangOpts.Features.contains(Feature::MoveOnly))
151-
return;
152-
153149
// Don't rerun diagnostics on deserialized functions.
154150
if (getFunction()->wasDeserializedCanonical())
155151
return;

lib/SILOptimizer/Mandatory/MoveOnlyObjectCheckerTester.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ class MoveOnlyObjectCheckerTesterPass : public SILFunctionTransform {
7575
void run() override {
7676
auto *fn = getFunction();
7777

78-
// Only run this pass if the move only language feature is enabled.
79-
if (!fn->getASTContext().LangOpts.Features.contains(Feature::MoveOnly))
80-
return;
81-
8278
// Don't rerun diagnostics on deserialized functions.
8379
if (getFunction()->wasDeserializedCanonical())
8480
return;

lib/Sema/MiscDiagnostics.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -428,31 +428,13 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
428428
}
429429

430430
void checkMoveExpr(MoveExpr *moveExpr) {
431-
// Make sure the MoveOnly feature is set. If not, error.
432-
// This should not currently be reached because the parse should ignore
433-
// the _move keyword unless the feature flag is set.
434-
if (!Ctx.LangOpts.hasFeature(Feature::MoveOnly)) {
435-
auto error =
436-
diag::experimental_moveonly_feature_can_only_be_used_when_enabled;
437-
Ctx.Diags.diagnose(moveExpr->getLoc(), error);
438-
}
439-
440431
if (!isa<DeclRefExpr>(moveExpr->getSubExpr())) {
441432
Ctx.Diags.diagnose(moveExpr->getLoc(),
442433
diag::move_expression_not_passed_lvalue);
443434
}
444435
}
445436

446437
void checkBorrowExpr(BorrowExpr *borrowExpr) {
447-
// Make sure the MoveOnly feature is set. If not, error.
448-
// This should not currently be reached because the parse should ignore
449-
// the _move keyword unless the feature flag is set.
450-
if (!Ctx.LangOpts.hasFeature(Feature::MoveOnly)) {
451-
auto error =
452-
diag::experimental_moveonly_feature_can_only_be_used_when_enabled;
453-
Ctx.Diags.diagnose(borrowExpr->getLoc(), error);
454-
}
455-
456438
// Allow for a chain of member_ref exprs that end in a decl_ref expr.
457439
auto *subExpr = borrowExpr->getSubExpr();
458440
while (auto *memberRef = dyn_cast<MemberRefExpr>(subExpr))
@@ -6166,11 +6148,6 @@ bool swift::diagnoseUnhandledThrowsInAsyncContext(DeclContext *dc,
61666148

61676149
void swift::diagnoseCopyableTypeContainingMoveOnlyType(
61686150
NominalTypeDecl *copyableNominalType) {
6169-
// If we don't have move only enabled, bail early.
6170-
if (!copyableNominalType->getASTContext().LangOpts.Features.contains(
6171-
Feature::MoveOnly))
6172-
return;
6173-
61746151
// If we already have a move only type, just bail, we have no further work to
61756152
// do.
61766153
if (copyableNominalType->isMoveOnly())

lib/Sema/TypeCheckAttr.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,12 +2157,15 @@ void AttributeChecker::visitFinalAttr(FinalAttr *attr) {
21572157
}
21582158

21592159
void AttributeChecker::visitMoveOnlyAttr(MoveOnlyAttr *attr) {
2160-
if (!D->getASTContext().LangOpts.hasFeature(Feature::MoveOnly)) {
2161-
auto error =
2162-
diag::experimental_moveonly_feature_can_only_be_used_when_enabled;
2163-
diagnoseAndRemoveAttr(attr, error);
2164-
return;
2165-
}
2160+
#ifndef NDEBUG
2161+
// Try to catch uses of @_moveOnly when we don't have the Copyable protocol.
2162+
// This can only happen in rare circumstances with test cases where you're
2163+
// building with -parse-stdlib. You need to also specify that you're building
2164+
// the Swift module (`-module-name Swift`) and then explicitly define Copyable
2165+
if (!D->getASTContext().getProtocol(KnownProtocolKind::Copyable))
2166+
llvm_unreachable("must define Copyable protocol when using -parse-stdlib");
2167+
#endif
2168+
21662169

21672170
if (isa<StructDecl>(D) || isa<EnumDecl>(D))
21682171
return;

0 commit comments

Comments
 (0)