Skip to content

Commit bda8aac

Browse files
authored
Merge pull request #59468 from gottesmm/pr-ca8c452eb2068fedf55ec81469906d60c22ab058
[move-only-wrapper] A few small mechanical fixes before the main no-implicit-copy rebase PR
2 parents 562e221 + 72523cf commit bda8aac

File tree

7 files changed

+38
-27
lines changed

7 files changed

+38
-27
lines changed

include/swift/SIL/AbstractionPattern.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,11 +1257,11 @@ class AbstractionPattern {
12571257

12581258
/// Given that the value being abstracted is a move only type, return the
12591259
/// abstraction pattern with the move only bit removed.
1260-
AbstractionPattern withoutMoveOnly() const;
1260+
AbstractionPattern removingMoveOnlyWrapper() const;
12611261

12621262
/// Given that the value being abstracted is not a move only type, return the
12631263
/// abstraction pattern with the move only bit added.
1264-
AbstractionPattern withMoveOnly() const;
1264+
AbstractionPattern addingMoveOnlyWrapper() const;
12651265

12661266
/// Given that the value being abstracted is a tuple type, return
12671267
/// the abstraction pattern for its object type.

include/swift/SIL/SILBuilder.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,14 +1299,16 @@ class SILBuilder {
12991299
MoveOnlyWrapperToCopyableValueInst *
13001300
createOwnedMoveOnlyWrapperToCopyableValue(SILLocation loc, SILValue src) {
13011301
return insert(new (getModule()) MoveOnlyWrapperToCopyableValueInst(
1302-
*F, getSILDebugLocation(loc), src, OwnershipKind::Owned));
1302+
*F, getSILDebugLocation(loc), src,
1303+
MoveOnlyWrapperToCopyableValueInst::Owned));
13031304
}
13041305

13051306
MoveOnlyWrapperToCopyableValueInst *
13061307
createGuaranteedMoveOnlyWrapperToCopyableValue(SILLocation loc,
13071308
SILValue src) {
13081309
return insert(new (getModule()) MoveOnlyWrapperToCopyableValueInst(
1309-
*F, getSILDebugLocation(loc), src, OwnershipKind::Guaranteed));
1310+
*F, getSILDebugLocation(loc), src,
1311+
MoveOnlyWrapperToCopyableValueInst::Guaranteed));
13101312
}
13111313

13121314
UnconditionalCheckedCastInst *

include/swift/SIL/SILInstruction.h

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7627,19 +7627,29 @@ class CopyableToMoveOnlyWrapperValueInst
76277627
class MoveOnlyWrapperToCopyableValueInst
76287628
: public UnaryInstructionBase<
76297629
SILInstructionKind::MoveOnlyWrapperToCopyableValueInst,
7630-
SingleValueInstruction>,
7631-
public OwnershipForwardingMixin {
7630+
FirstArgOwnershipForwardingSingleValueInst> {
7631+
public:
7632+
enum InitialKind {
7633+
Guaranteed,
7634+
Owned,
7635+
};
7636+
7637+
private:
76327638
friend class SILBuilder;
76337639

7640+
InitialKind initialKind;
7641+
76347642
MoveOnlyWrapperToCopyableValueInst(const SILFunction &fn,
76357643
SILDebugLocation DebugLoc,
7636-
SILValue operand,
7637-
OwnershipKind forwardingOwnershipKind)
7638-
: UnaryInstructionBase(DebugLoc, operand,
7639-
operand->getType().removingMoveOnlyWrapper()),
7640-
OwnershipForwardingMixin(
7641-
SILInstructionKind::MoveOnlyWrapperToCopyableValueInst,
7642-
forwardingOwnershipKind) {}
7644+
SILValue operand, InitialKind kind)
7645+
: UnaryInstructionBase(
7646+
DebugLoc, operand, operand->getType().removingMoveOnlyWrapper(),
7647+
kind == InitialKind::Guaranteed ? OwnershipKind::Guaranteed
7648+
: OwnershipKind::Owned),
7649+
initialKind(kind) {}
7650+
7651+
public:
7652+
InitialKind getInitialKind() const { return initialKind; }
76437653
};
76447654

76457655
/// Given an object reference, return true iff it is non-nil and refers
@@ -9783,8 +9793,7 @@ inline bool OwnershipForwardingMixin::isa(SILInstructionKind kind) {
97839793
OwnershipForwardingConversionInst::classof(kind) ||
97849794
OwnershipForwardingSelectEnumInstBase::classof(kind) ||
97859795
OwnershipForwardingMultipleValueInstruction::classof(kind) ||
9786-
kind == SILInstructionKind::MarkMustCheckInst ||
9787-
kind == SILInstructionKind::MoveOnlyWrapperToCopyableValueInst;
9796+
kind == SILInstructionKind::MarkMustCheckInst;
97889797
}
97899798

97909799
inline OwnershipForwardingMixin *

include/swift/SIL/TypeLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ class TypeLowering {
296296
IsInfiniteType_t isInfinite() const {
297297
return IsInfiniteType_t((Flags & InfiniteFlag) != 0);
298298
}
299-
IsMoveOnly_t isMoveOnly() const {
299+
IsMoveOnly_t isMoveOnlyWrapped() const {
300300
return IsMoveOnly_t((Flags & MoveOnlyFlag) != 0);
301301
}
302302

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ AbstractionPattern::getTupleElementType(unsigned index) const {
401401
llvm_unreachable("bad kind");
402402
}
403403

404-
AbstractionPattern AbstractionPattern::withoutMoveOnly() const {
404+
AbstractionPattern AbstractionPattern::removingMoveOnlyWrapper() const {
405405
switch (getKind()) {
406406
case Kind::Invalid:
407407
llvm_unreachable("querying invalid abstraction pattern!");
@@ -435,7 +435,7 @@ AbstractionPattern AbstractionPattern::withoutMoveOnly() const {
435435
llvm_unreachable("bad kind");
436436
}
437437

438-
AbstractionPattern AbstractionPattern::withMoveOnly() const {
438+
AbstractionPattern AbstractionPattern::addingMoveOnlyWrapper() const {
439439
switch (getKind()) {
440440
case Kind::Invalid:
441441
llvm_unreachable("querying invalid abstraction pattern!");

lib/SIL/IR/SILPrinter.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,15 +1921,11 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
19211921

19221922
void visitMoveOnlyWrapperToCopyableValueInst(
19231923
MoveOnlyWrapperToCopyableValueInst *I) {
1924-
switch (I->getForwardingOwnershipKind()) {
1925-
case OwnershipKind::None:
1926-
case OwnershipKind::Any:
1927-
case OwnershipKind::Unowned:
1928-
llvm_unreachable("Move only values are always non-trivial");
1929-
case OwnershipKind::Owned:
1924+
switch (I->getInitialKind()) {
1925+
case MoveOnlyWrapperToCopyableValueInst::Owned:
19301926
*this << "[owned] ";
19311927
break;
1932-
case OwnershipKind::Guaranteed:
1928+
case MoveOnlyWrapperToCopyableValueInst::Guaranteed:
19331929
*this << "[guaranteed] ";
19341930
break;
19351931
}

lib/SIL/IR/TypeLowering.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ namespace {
697697
RetTy visitSILMoveOnlyType(CanSILMoveOnlyType type,
698698
AbstractionPattern origType,
699699
IsTypeExpansionSensitive_t isSensitive) {
700-
AbstractionPattern innerAbstraction = origType.withoutMoveOnly();
700+
AbstractionPattern innerAbstraction = origType.removingMoveOnlyWrapper();
701701
CanType innerType = type->getInnerType();
702702
auto &lowering =
703703
TC.getTypeLowering(innerAbstraction, innerType, Expansion);
@@ -2558,7 +2558,11 @@ TypeConverter::getTypeLowering(SILType type,
25582558
CanGenericSignature sig) {
25592559
// The type lowering for a type parameter relies on its context.
25602560
assert(sig || !type.getASTType()->hasTypeParameter());
2561-
auto loweredType = type.getASTType();
2561+
2562+
// We use the Raw AST type to ensure that moveonlywrapped values use the move
2563+
// only type lowering. This ensures that trivial moveonlywrapped values are
2564+
// not trivial.
2565+
auto loweredType = type.getRawASTType();
25622566
auto isTypeExpansionSensitive = loweredType->hasOpaqueArchetype()
25632567
? IsTypeExpansionSensitive
25642568
: IsNotTypeExpansionSensitive;

0 commit comments

Comments
 (0)