Skip to content

[no-implicit-copy] Rename SILMoveOnlyType -> SILMoveOnlyWrappedType. #59859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/swift/AST/TypeDifferenceVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ class CanTypeDifferenceVisitor : public CanTypePairVisitor<Impl, bool> {
return asImpl().visit(type1->getCaptureType(), type2->getCaptureType());
}

bool visitSILMoveOnlyType(CanSILMoveOnlyType type1,
CanSILMoveOnlyType type2) {
bool visitSILMoveOnlyWrappedType(CanSILMoveOnlyWrappedType type1,
CanSILMoveOnlyWrappedType type2) {
return asImpl().visit(type1->getInnerType(), type2->getInnerType());
}

Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/TypeMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class TypeMatcher {
TRIVIAL_CASE(SILFunctionType)
TRIVIAL_CASE(SILBlockStorageType)
TRIVIAL_CASE(SILBoxType)
TRIVIAL_CASE(SILMoveOnlyType)
TRIVIAL_CASE(SILMoveOnlyWrappedType)

bool visitProtocolCompositionType(CanProtocolCompositionType firstProtocolComposition,
Type secondType,
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/TypeNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ ABSTRACT_TYPE(AnyFunction, Type)
ARTIFICIAL_TYPE(SILFunction, Type)
ARTIFICIAL_TYPE(SILBlockStorage, Type)
ARTIFICIAL_TYPE(SILBox, Type)
ARTIFICIAL_TYPE(SILMoveOnly, Type)
ARTIFICIAL_TYPE(SILMoveOnlyWrapped, Type)
ARTIFICIAL_TYPE(SILToken, Type)
TYPE(ProtocolComposition, Type)
TYPE(ParameterizedProtocol, Type)
Expand Down
15 changes: 8 additions & 7 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -5002,19 +5002,20 @@ class SILBoxType final : public TypeBase, public llvm::FoldingSetNode
};
DEFINE_EMPTY_CAN_TYPE_WRAPPER(SILBoxType, Type)

class SILMoveOnlyType;
class SILMoveOnlyWrappedType;
class SILModule; // From SIL
typedef CanTypeWrapper<SILMoveOnlyType> CanMoveOnlyType;
typedef CanTypeWrapper<SILMoveOnlyWrappedType> CanMoveOnlyType;

/// A wrapper type that marks an inner type as being a move only value. Can not
/// be written directly at the Swift level, instead it is triggered by adding
/// the type attribute @_moveOnly to a different type. We transform these in
/// TypeLowering into a moveOnly SILType on the inner type.
class SILMoveOnlyType final : public TypeBase, public llvm::FoldingSetNode {
class SILMoveOnlyWrappedType final : public TypeBase,
public llvm::FoldingSetNode {
CanType innerType;

SILMoveOnlyType(CanType innerType)
: TypeBase(TypeKind::SILMoveOnly, &innerType->getASTContext(),
SILMoveOnlyWrappedType(CanType innerType)
: TypeBase(TypeKind::SILMoveOnlyWrapped, &innerType->getASTContext(),
innerType->getRecursiveProperties()),
innerType(innerType) {}

Expand All @@ -5024,10 +5025,10 @@ class SILMoveOnlyType final : public TypeBase, public llvm::FoldingSetNode {
static CanMoveOnlyType get(CanType innerType);

static bool classof(const TypeBase *T) {
return T->getKind() == TypeKind::SILMoveOnly;
return T->getKind() == TypeKind::SILMoveOnlyWrapped;
}
};
DEFINE_EMPTY_CAN_TYPE_WRAPPER(SILMoveOnlyType, Type)
DEFINE_EMPTY_CAN_TYPE_WRAPPER(SILMoveOnlyWrappedType, Type)

class SILBlockStorageType;
typedef CanTypeWrapper<SILBlockStorageType> CanSILBlockStorageType;
Expand Down
6 changes: 3 additions & 3 deletions include/swift/SIL/SILType.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,15 +607,15 @@ class SILType {
/// Canonical way to check if a SILType is move only. Using is/getAs/castTo
/// will look through moveonly-ness.
bool isMoveOnlyWrapped() const {
return getRawASTType()->is<SILMoveOnlyType>();
return getRawASTType()->is<SILMoveOnlyWrappedType>();
}

/// If this is already a move only wrapped type, return *this. Otherwise, wrap
/// the copyable type in the mov eonly wrapper.
SILType addingMoveOnlyWrapper() const {
if (isMoveOnlyWrapped())
return *this;
auto newType = SILMoveOnlyType::get(getRawASTType());
auto newType = SILMoveOnlyWrappedType::get(getRawASTType());
return SILType::getPrimitiveType(newType, getCategory());
}

Expand All @@ -624,7 +624,7 @@ class SILType {
SILType removingMoveOnlyWrapper() const {
if (!isMoveOnlyWrapped())
return *this;
auto moveOnly = getRawASTType()->castTo<SILMoveOnlyType>();
auto moveOnly = getRawASTType()->castTo<SILMoveOnlyWrappedType>();
return SILType::getPrimitiveType(moveOnly->getInnerType(), getCategory());
}

Expand Down
2 changes: 1 addition & 1 deletion include/swift/SIL/SILValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ class ValueBase : public SILNode, public SILAllocated<ValueBase> {
/// otherwise.
///
/// NOTE: Please do not use this directly! It is only meant to be used by the
/// optimizer pass: SILMoveOnlyTypeEliminator.
/// optimizer pass: SILMoveOnlyWrappedTypeEliminator.
bool unsafelyEliminateMoveOnlyWrapper() {
if (!Type.isMoveOnlyWrapped())
return false;
Expand Down
19 changes: 10 additions & 9 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ struct ASTContext::Implementation {
llvm::FoldingSet<GenericFunctionType> GenericFunctionTypes;
llvm::FoldingSet<SILFunctionType> SILFunctionTypes;
llvm::DenseMap<CanType, SILBlockStorageType *> SILBlockStorageTypes;
llvm::DenseMap<CanType, SILMoveOnlyType *> SILMoveOnlyTypes;
llvm::DenseMap<CanType, SILMoveOnlyWrappedType *> SILMoveOnlyWrappedTypes;
llvm::FoldingSet<SILBoxType> SILBoxTypes;
llvm::DenseMap<BuiltinIntegerWidth, BuiltinIntegerType*> IntegerTypes;
llvm::FoldingSet<BuiltinVectorType> BuiltinVectorTypes;
Expand Down Expand Up @@ -4074,17 +4074,18 @@ SILFunctionType::SILFunctionType(
#endif
}

CanSILMoveOnlyType SILMoveOnlyType::get(CanType innerType) {
CanSILMoveOnlyWrappedType SILMoveOnlyWrappedType::get(CanType innerType) {
ASTContext &ctx = innerType->getASTContext();
auto found = ctx.getImpl().SILMoveOnlyTypes.find(innerType);
if (found != ctx.getImpl().SILMoveOnlyTypes.end())
return CanSILMoveOnlyType(found->second);
auto found = ctx.getImpl().SILMoveOnlyWrappedTypes.find(innerType);
if (found != ctx.getImpl().SILMoveOnlyWrappedTypes.end())
return CanSILMoveOnlyWrappedType(found->second);

void *mem = ctx.Allocate(sizeof(SILMoveOnlyType), alignof(SILMoveOnlyType));
void *mem = ctx.Allocate(sizeof(SILMoveOnlyWrappedType),
alignof(SILMoveOnlyWrappedType));

auto *storageTy = new (mem) SILMoveOnlyType(innerType);
ctx.getImpl().SILMoveOnlyTypes.insert({innerType, storageTy});
return CanSILMoveOnlyType(storageTy);
auto *storageTy = new (mem) SILMoveOnlyWrappedType(innerType);
ctx.getImpl().SILMoveOnlyWrappedTypes.insert({innerType, storageTy});
return CanSILMoveOnlyWrappedType(storageTy);
}

CanSILBlockStorageType SILBlockStorageType::get(CanType captureType) {
Expand Down
3 changes: 2 additions & 1 deletion lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3935,7 +3935,8 @@ namespace {
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}

void visitSILMoveOnlyType(SILMoveOnlyType *T, StringRef label) {
void visitSILMoveOnlyWrappedType(SILMoveOnlyWrappedType *T,
StringRef label) {
printCommon(label, "sil_move_only_type");
printRec(T->getInnerType());
PrintWithColorRAII(OS, ParenthesisColor) << ')';
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ void ASTMangler::appendType(Type type, GenericSignature sig,

return;
}
case TypeKind::SILMoveOnly:
case TypeKind::SILMoveOnlyWrapped:
// If we hit this, we just mangle the underlying name and move on.
llvm_unreachable("should never be mangled?");
case TypeKind::SILBlockStorage:
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6203,7 +6203,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
}
}

void visitSILMoveOnlyType(SILMoveOnlyType *T) {
void visitSILMoveOnlyWrappedType(SILMoveOnlyWrappedType *T) {
Printer << "@moveOnly ";
printWithParensIfNotSimple(T->getInnerType());
}
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ExistentialGeneralization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class Generalizer : public CanTypeVisitor<Generalizer, Type> {
INVALID_TO_GENERALIZE(SILBox)
INVALID_TO_GENERALIZE(SILFunction)
INVALID_TO_GENERALIZE(SILToken)
INVALID_TO_GENERALIZE(SILMoveOnly)
INVALID_TO_GENERALIZE(SILMoveOnlyWrapped)
#undef INVALID_TO_GENERALIZE

/// Generalize the generic arguments of the given generic type.s
Expand Down
23 changes: 13 additions & 10 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ bool CanType::isReferenceTypeImpl(CanType type, const GenericSignatureImpl *sig,
case TypeKind::DynamicSelf:
return isReferenceTypeImpl(cast<DynamicSelfType>(type).getSelfType(),
sig, functionsCount);
case TypeKind::SILMoveOnly:
return isReferenceTypeImpl(cast<SILMoveOnlyType>(type)->getInnerType(), sig,
functionsCount);
case TypeKind::SILMoveOnlyWrapped:
return isReferenceTypeImpl(
cast<SILMoveOnlyWrappedType>(type)->getInnerType(), sig,
functionsCount);

// Archetypes and existentials are only class references if class-bounded.
case TypeKind::PrimaryArchetype:
Expand Down Expand Up @@ -330,7 +331,7 @@ ExistentialLayout CanType::getExistentialLayout() {
CanType ty = *this;

// Always remove one layer of move only ness.
if (auto mv = dyn_cast<SILMoveOnlyType>(ty))
if (auto mv = dyn_cast<SILMoveOnlyWrappedType>(ty))
ty = mv->getInnerType();

if (auto existential = dyn_cast<ExistentialType>(ty))
Expand Down Expand Up @@ -1685,7 +1686,7 @@ CanType TypeBase::computeCanonicalType() {
case TypeKind::SILBox:
case TypeKind::SILFunction:
case TypeKind::SILToken:
case TypeKind::SILMoveOnly:
case TypeKind::SILMoveOnlyWrapped:
llvm_unreachable("SIL-only types are always canonical!");

case TypeKind::ProtocolComposition: {
Expand Down Expand Up @@ -5149,15 +5150,15 @@ case TypeKind::Id:
return storageTy;
}

case TypeKind::SILMoveOnly: {
auto *storageTy = cast<SILMoveOnlyType>(base);
case TypeKind::SILMoveOnlyWrapped: {
auto *storageTy = cast<SILMoveOnlyWrappedType>(base);
Type transCap = storageTy->getInnerType().transformWithPosition(
TypePosition::Invariant, fn);
if (!transCap)
return Type();
CanType canTransCap = transCap->getCanonicalType();
if (canTransCap != storageTy->getInnerType())
return SILMoveOnlyType::get(canTransCap);
return SILMoveOnlyWrappedType::get(canTransCap);
return storageTy;
}

Expand Down Expand Up @@ -6071,8 +6072,10 @@ ReferenceCounting TypeBase::getReferenceCounting() {
case TypeKind::DynamicSelf:
return cast<DynamicSelfType>(type).getSelfType()
->getReferenceCounting();
case TypeKind::SILMoveOnly:
return cast<SILMoveOnlyType>(type)->getInnerType()->getReferenceCounting();
case TypeKind::SILMoveOnlyWrapped:
return cast<SILMoveOnlyWrappedType>(type)
->getInnerType()
->getReferenceCounting();

case TypeKind::PrimaryArchetype:
case TypeKind::OpenedArchetype:
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/TypeWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class Traversal : public TypeVisitor<Traversal, bool>
return doIt(ty->getCaptureType());
}

bool visitSILMoveOnlyType(SILMoveOnlyType *ty) {
bool visitSILMoveOnlyWrappedType(SILMoveOnlyWrappedType *ty) {
return doIt(ty->getInnerType());
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,7 @@ class GetSendableType :
NEVER_VISIT(SILBlockStorageType)
NEVER_VISIT(SILBoxType)
NEVER_VISIT(SILTokenType)
NEVER_VISIT(SILMoveOnlyType)
NEVER_VISIT(SILMoveOnlyWrappedType)

VISIT(ProtocolCompositionType, compose)

Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2169,7 +2169,7 @@ const TypeInfo *TypeConverter::convertType(CanType ty) {
case TypeKind::BoundGenericEnum:
case TypeKind::BoundGenericStruct:
return convertAnyNominalType(ty, cast<BoundGenericType>(ty)->getDecl());
case TypeKind::SILMoveOnly:
case TypeKind::SILMoveOnlyWrapped:
llvm_unreachable("implement this");
case TypeKind::InOut:
return convertInOutType(cast<InOutType>(ty));
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenType.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class TypeConverter {
const TypeInfo *convertBoxType(SILBoxType *T);
const TypeInfo *convertArchetypeType(ArchetypeType *T);
const TypeInfo *convertInOutType(InOutType *T);
const TypeInfo *convertSILMoveOnlyType(SILMoveOnlyType *T) {
const TypeInfo *convertSILMoveOnlyWrappedType(SILMoveOnlyWrappedType *T) {
return convertType(T->getInnerType());
}
const TypeInfo *convertExistentialMetatypeType(ExistentialMetatypeType *T);
Expand Down
3 changes: 1 addition & 2 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1725,8 +1725,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
case TypeKind::SILToken:
case TypeKind::BuiltinUnsafeValueBuffer:
case TypeKind::BuiltinDefaultActorStorage:
case TypeKind::SILMoveOnly:

case TypeKind::SILMoveOnlyWrapped:
LLVM_DEBUG(llvm::dbgs() << "Unhandled type: ";
DbgTy.getType()->dump(llvm::dbgs()); llvm::dbgs() << "\n");
MangledName = "<unknown>";
Expand Down
5 changes: 3 additions & 2 deletions lib/IRGen/MetadataRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1944,8 +1944,9 @@ namespace {
DynamicMetadataRequest request) {
llvm_unreachable("should not be asking for metadata of a SILToken type");
}
MetadataResponse visitSILMoveOnlyType(CanSILMoveOnlyType type,
DynamicMetadataRequest request) {
MetadataResponse
visitSILMoveOnlyWrappedType(CanSILMoveOnlyWrappedType type,
DynamicMetadataRequest request) {
llvm_unreachable("should not be asking for metadata of a move only type");
}
MetadataResponse visitArchetypeType(CanArchetypeType type,
Expand Down
6 changes: 3 additions & 3 deletions lib/SIL/IR/AbstractionPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ AbstractionPattern AbstractionPattern::removingMoveOnlyWrapper() const {
case Kind::Opaque:
case Kind::Tuple:
case Kind::Type:
if (auto mvi = dyn_cast<SILMoveOnlyType>(getType())) {
if (auto mvi = dyn_cast<SILMoveOnlyWrappedType>(getType())) {
return AbstractionPattern(getGenericSignature(), mvi->getInnerType());
}
return *this;
Expand Down Expand Up @@ -460,10 +460,10 @@ AbstractionPattern AbstractionPattern::addingMoveOnlyWrapper() const {
case Kind::Opaque:
case Kind::Tuple:
case Kind::Type:
if (isa<SILMoveOnlyType>(getType()))
if (isa<SILMoveOnlyWrappedType>(getType()))
return *this;
return AbstractionPattern(getGenericSignature(),
SILMoveOnlyType::get(getType()));
SILMoveOnlyWrappedType::get(getType()));
}

llvm_unreachable("bad kind");
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/IR/SILType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ SILType SILType::getFieldType(VarDecl *field, TypeConverter &TC,
// If this type is not a class type, then we propagate "move only"-ness to the
// field. Example:
if (!getClassOrBoundGenericClass() && isMoveOnlyWrapped())
loweredTy = SILMoveOnlyType::get(loweredTy);
loweredTy = SILMoveOnlyWrappedType::get(loweredTy);

if (isAddress() || getClassOrBoundGenericClass() != nullptr) {
return SILType::getPrimitiveAddressType(loweredTy);
Expand Down
6 changes: 3 additions & 3 deletions lib/SIL/IR/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,9 @@ namespace {
type, getReferenceRecursiveProperties(isSensitive));
}

RetTy visitSILMoveOnlyType(CanSILMoveOnlyType type,
AbstractionPattern origType,
IsTypeExpansionSensitive_t isSensitive) {
RetTy visitSILMoveOnlyWrappedType(CanSILMoveOnlyWrappedType type,
AbstractionPattern origType,
IsTypeExpansionSensitive_t isSensitive) {
AbstractionPattern innerAbstraction = origType.removingMoveOnlyWrapper();
CanType innerType = type->getInnerType();
auto &lowering =
Expand Down
7 changes: 4 additions & 3 deletions lib/SILGen/SILGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ class LetValueInitialization : public Initialization {
if (SGF.getASTContext().LangOpts.Features.count(Feature::MoveOnly) &&
vd->getAttrs().hasAttribute<NoImplicitCopyAttr>()) {
lowering = &SGF.getTypeLowering(
SILMoveOnlyType::get(vd->getType()->getCanonicalType()));
SILMoveOnlyWrappedType::get(vd->getType()->getCanonicalType()));
} else {
lowering = &SGF.getTypeLowering(vd->getType());
}
Expand Down Expand Up @@ -576,8 +576,9 @@ class LetValueInitialization : public Initialization {
value->getOwnershipKind() == OwnershipKind::Owned) {
assert(wasPlusOne);
// NOTE: If our type is trivial when not wrapped in a
// SILMoveOnlyType, this will return a trivial value. We rely on the
// checker to determine if this is an acceptable use of the value.
// SILMoveOnlyWrappedType, this will return a trivial value. We rely
// on the checker to determine if this is an acceptable use of the
// value.
value = SGF.B.createOwnedMoveOnlyWrapperToCopyableValue(PrologueLoc,
value);
}
Expand Down
Loading