Skip to content

Commit 76107ed

Browse files
committed
expose more of SILGen to move-only types by default
Also removes some redundant checks in SILGen for the flag in order to process `_move` and `_borrow` that are already checked for in Sema. We will keep those behind the feature flag for now.
1 parent 5ad38da commit 76107ed

File tree

2 files changed

+29
-69
lines changed

2 files changed

+29
-69
lines changed

lib/SILGen/SILGenDecl.cpp

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,7 @@ class LetValueInitialization : public Initialization {
620620
public:
621621
LetValueInitialization(VarDecl *vd, SILGenFunction &SGF) : vd(vd) {
622622
const TypeLowering *lowering = nullptr;
623-
if (SGF.getASTContext().LangOpts.Features.count(Feature::MoveOnly) &&
624-
vd->isNoImplicitCopy()) {
623+
if (vd->isNoImplicitCopy()) {
625624
lowering = &SGF.getTypeLowering(
626625
SILMoveOnlyWrappedType::get(vd->getType()->getCanonicalType()));
627626
} else {
@@ -661,8 +660,7 @@ class LetValueInitialization : public Initialization {
661660

662661
// Make sure that we have a non-address only type when binding a
663662
// @_noImplicitCopy let.
664-
if (SGF.getASTContext().LangOpts.Features.count(Feature::MoveOnly) &&
665-
lowering->isAddressOnly() && vd->isNoImplicitCopy()) {
663+
if (lowering->isAddressOnly() && vd->isNoImplicitCopy()) {
666664
auto d = diag::noimplicitcopy_used_on_generic_or_existential;
667665
diagnose(SGF.getASTContext(), vd->getLoc(), d);
668666
}
@@ -740,10 +738,6 @@ class LetValueInitialization : public Initialization {
740738
SILValue value, bool wasPlusOne) {
741739
// If we have none...
742740
if (value->getOwnershipKind() == OwnershipKind::None) {
743-
// If we don't have move only features enabled, just return, we are done.
744-
if (!SGF.getASTContext().LangOpts.Features.count(Feature::MoveOnly))
745-
return value;
746-
747741
// Then check if we have a pure move only type. In that case, we need to
748742
// insert a no implicit copy
749743
if (value->getType().isPureMoveOnly()) {
@@ -768,15 +762,6 @@ class LetValueInitialization : public Initialization {
768762
MarkMustCheckInst::CheckKind::ConsumableAndAssignable);
769763
}
770764

771-
// Then if we don't have move only, just perform a lexical borrow if the
772-
// lifetime is lexical.
773-
if (!SGF.getASTContext().LangOpts.Features.count(Feature::MoveOnly)) {
774-
if (SGF.F.getLifetime(vd, value->getType()).isLexical())
775-
return SGF.B.createBeginBorrow(PrologueLoc, value, /*isLexical*/ true);
776-
else
777-
return value;
778-
}
779-
780765
// Otherwise, we need to perform some additional processing. First, if we
781766
// have an owned moveonly value that had a cleanup, then create a move_value
782767
// that acts as a consuming use of the value. The reason why we want this is
@@ -2136,35 +2121,22 @@ void SILGenFunction::destroyLocalVariable(SILLocation silLoc, VarDecl *vd) {
21362121
return;
21372122
}
21382123

2139-
if (getASTContext().LangOpts.hasFeature(Feature::MoveOnly)) {
2140-
if (auto *mvi = dyn_cast<MarkMustCheckInst>(Val.getDefiningInstruction())) {
2141-
if (mvi->hasMoveCheckerKind()) {
2142-
if (auto *cvi = dyn_cast<CopyValueInst>(mvi->getOperand())) {
2143-
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
2144-
if (bbi->isLexical()) {
2145-
B.emitDestroyValueOperation(silLoc, mvi);
2146-
B.createEndBorrow(silLoc, bbi);
2147-
B.emitDestroyValueOperation(silLoc, bbi->getOperand());
2148-
return;
2149-
}
2150-
}
2151-
}
2152-
2153-
if (auto *copyToMove = dyn_cast<CopyableToMoveOnlyWrapperValueInst>(
2154-
mvi->getOperand())) {
2155-
if (auto *cvi = dyn_cast<CopyValueInst>(copyToMove->getOperand())) {
2156-
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
2157-
if (bbi->isLexical()) {
2158-
B.emitDestroyValueOperation(silLoc, mvi);
2159-
B.createEndBorrow(silLoc, bbi);
2160-
B.emitDestroyValueOperation(silLoc, bbi->getOperand());
2161-
return;
2162-
}
2163-
}
2124+
if (auto *mvi = dyn_cast<MarkMustCheckInst>(Val.getDefiningInstruction())) {
2125+
if (mvi->hasMoveCheckerKind()) {
2126+
if (auto *cvi = dyn_cast<CopyValueInst>(mvi->getOperand())) {
2127+
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
2128+
if (bbi->isLexical()) {
2129+
B.emitDestroyValueOperation(silLoc, mvi);
2130+
B.createEndBorrow(silLoc, bbi);
2131+
B.emitDestroyValueOperation(silLoc, bbi->getOperand());
2132+
return;
21642133
}
21652134
}
2135+
}
21662136

2167-
if (auto *cvi = dyn_cast<ExplicitCopyValueInst>(mvi->getOperand())) {
2137+
if (auto *copyToMove = dyn_cast<CopyableToMoveOnlyWrapperValueInst>(
2138+
mvi->getOperand())) {
2139+
if (auto *cvi = dyn_cast<CopyValueInst>(copyToMove->getOperand())) {
21682140
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
21692141
if (bbi->isLexical()) {
21702142
B.emitDestroyValueOperation(silLoc, mvi);
@@ -2174,15 +2146,26 @@ void SILGenFunction::destroyLocalVariable(SILLocation silLoc, VarDecl *vd) {
21742146
}
21752147
}
21762148
}
2149+
}
21772150

2178-
// Handle trivial arguments.
2179-
if (auto *move = dyn_cast<MoveValueInst>(mvi->getOperand())) {
2180-
if (move->isLexical()) {
2151+
if (auto *cvi = dyn_cast<ExplicitCopyValueInst>(mvi->getOperand())) {
2152+
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
2153+
if (bbi->isLexical()) {
21812154
B.emitDestroyValueOperation(silLoc, mvi);
2155+
B.createEndBorrow(silLoc, bbi);
2156+
B.emitDestroyValueOperation(silLoc, bbi->getOperand());
21822157
return;
21832158
}
21842159
}
21852160
}
2161+
2162+
// Handle trivial arguments.
2163+
if (auto *move = dyn_cast<MoveValueInst>(mvi->getOperand())) {
2164+
if (move->isLexical()) {
2165+
B.emitDestroyValueOperation(silLoc, mvi);
2166+
return;
2167+
}
2168+
}
21862169
}
21872170
}
21882171

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))
@@ -6177,11 +6159,6 @@ bool swift::diagnoseUnhandledThrowsInAsyncContext(DeclContext *dc,
61776159

61786160
void swift::diagnoseCopyableTypeContainingMoveOnlyType(
61796161
NominalTypeDecl *copyableNominalType) {
6180-
// If we don't have move only enabled, bail early.
6181-
if (!copyableNominalType->getASTContext().LangOpts.Features.contains(
6182-
Feature::MoveOnly))
6183-
return;
6184-
61856162
// If we already have a move only type, just bail, we have no further work to
61866163
// do.
61876164
if (copyableNominalType->isMoveOnly())

0 commit comments

Comments
 (0)