Skip to content

Commit ec35838

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 dee62b6 commit ec35838

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
@@ -510,8 +510,7 @@ class LetValueInitialization : public Initialization {
510510
public:
511511
LetValueInitialization(VarDecl *vd, SILGenFunction &SGF) : vd(vd) {
512512
const TypeLowering *lowering = nullptr;
513-
if (SGF.getASTContext().LangOpts.Features.count(Feature::MoveOnly) &&
514-
vd->isNoImplicitCopy()) {
513+
if (vd->isNoImplicitCopy()) {
515514
lowering = &SGF.getTypeLowering(
516515
SILMoveOnlyWrappedType::get(vd->getType()->getCanonicalType()));
517516
} else {
@@ -551,8 +550,7 @@ class LetValueInitialization : public Initialization {
551550

552551
// Make sure that we have a non-address only type when binding a
553552
// @_noImplicitCopy let.
554-
if (SGF.getASTContext().LangOpts.Features.count(Feature::MoveOnly) &&
555-
lowering->isAddressOnly() && vd->isNoImplicitCopy()) {
553+
if (lowering->isAddressOnly() && vd->isNoImplicitCopy()) {
556554
auto d = diag::noimplicitcopy_used_on_generic_or_existential;
557555
diagnose(SGF.getASTContext(), vd->getLoc(), d);
558556
}
@@ -630,10 +628,6 @@ class LetValueInitialization : public Initialization {
630628
SILValue value, bool wasPlusOne) {
631629
// If we have none...
632630
if (value->getOwnershipKind() == OwnershipKind::None) {
633-
// If we don't have move only features enabled, just return, we are done.
634-
if (!SGF.getASTContext().LangOpts.Features.count(Feature::MoveOnly))
635-
return value;
636-
637631
// Then check if we have a pure move only type. In that case, we need to
638632
// insert a no implicit copy
639633
if (value->getType().isPureMoveOnly()) {
@@ -658,15 +652,6 @@ class LetValueInitialization : public Initialization {
658652
MarkMustCheckInst::CheckKind::ConsumableAndAssignable);
659653
}
660654

661-
// Then if we don't have move only, just perform a lexical borrow if the
662-
// lifetime is lexical.
663-
if (!SGF.getASTContext().LangOpts.Features.count(Feature::MoveOnly)) {
664-
if (SGF.F.getLifetime(vd, value->getType()).isLexical())
665-
return SGF.B.createBeginBorrow(PrologueLoc, value, /*isLexical*/ true);
666-
else
667-
return value;
668-
}
669-
670655
// Otherwise, we need to perform some additional processing. First, if we
671656
// have an owned moveonly value that had a cleanup, then create a move_value
672657
// that acts as a consuming use of the value. The reason why we want this is
@@ -2025,35 +2010,22 @@ void SILGenFunction::destroyLocalVariable(SILLocation silLoc, VarDecl *vd) {
20252010
return;
20262011
}
20272012

2028-
if (getASTContext().LangOpts.hasFeature(Feature::MoveOnly)) {
2029-
if (auto *mvi = dyn_cast<MarkMustCheckInst>(Val.getDefiningInstruction())) {
2030-
if (mvi->hasMoveCheckerKind()) {
2031-
if (auto *cvi = dyn_cast<CopyValueInst>(mvi->getOperand())) {
2032-
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
2033-
if (bbi->isLexical()) {
2034-
B.emitDestroyValueOperation(silLoc, mvi);
2035-
B.createEndBorrow(silLoc, bbi);
2036-
B.emitDestroyValueOperation(silLoc, bbi->getOperand());
2037-
return;
2038-
}
2039-
}
2040-
}
2041-
2042-
if (auto *copyToMove = dyn_cast<CopyableToMoveOnlyWrapperValueInst>(
2043-
mvi->getOperand())) {
2044-
if (auto *cvi = dyn_cast<CopyValueInst>(copyToMove->getOperand())) {
2045-
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
2046-
if (bbi->isLexical()) {
2047-
B.emitDestroyValueOperation(silLoc, mvi);
2048-
B.createEndBorrow(silLoc, bbi);
2049-
B.emitDestroyValueOperation(silLoc, bbi->getOperand());
2050-
return;
2051-
}
2052-
}
2013+
if (auto *mvi = dyn_cast<MarkMustCheckInst>(Val.getDefiningInstruction())) {
2014+
if (mvi->hasMoveCheckerKind()) {
2015+
if (auto *cvi = dyn_cast<CopyValueInst>(mvi->getOperand())) {
2016+
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
2017+
if (bbi->isLexical()) {
2018+
B.emitDestroyValueOperation(silLoc, mvi);
2019+
B.createEndBorrow(silLoc, bbi);
2020+
B.emitDestroyValueOperation(silLoc, bbi->getOperand());
2021+
return;
20532022
}
20542023
}
2024+
}
20552025

2056-
if (auto *cvi = dyn_cast<ExplicitCopyValueInst>(mvi->getOperand())) {
2026+
if (auto *copyToMove = dyn_cast<CopyableToMoveOnlyWrapperValueInst>(
2027+
mvi->getOperand())) {
2028+
if (auto *cvi = dyn_cast<CopyValueInst>(copyToMove->getOperand())) {
20572029
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
20582030
if (bbi->isLexical()) {
20592031
B.emitDestroyValueOperation(silLoc, mvi);
@@ -2063,15 +2035,26 @@ void SILGenFunction::destroyLocalVariable(SILLocation silLoc, VarDecl *vd) {
20632035
}
20642036
}
20652037
}
2038+
}
20662039

2067-
// Handle trivial arguments.
2068-
if (auto *move = dyn_cast<MoveValueInst>(mvi->getOperand())) {
2069-
if (move->isLexical()) {
2040+
if (auto *cvi = dyn_cast<ExplicitCopyValueInst>(mvi->getOperand())) {
2041+
if (auto *bbi = dyn_cast<BeginBorrowInst>(cvi->getOperand())) {
2042+
if (bbi->isLexical()) {
20702043
B.emitDestroyValueOperation(silLoc, mvi);
2044+
B.createEndBorrow(silLoc, bbi);
2045+
B.emitDestroyValueOperation(silLoc, bbi->getOperand());
20712046
return;
20722047
}
20732048
}
20742049
}
2050+
2051+
// Handle trivial arguments.
2052+
if (auto *move = dyn_cast<MoveValueInst>(mvi->getOperand())) {
2053+
if (move->isLexical()) {
2054+
B.emitDestroyValueOperation(silLoc, mvi);
2055+
return;
2056+
}
2057+
}
20752058
}
20762059
}
20772060

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

0 commit comments

Comments
 (0)