Skip to content

Commit 0c2f28f

Browse files
committed
AST: Remove GenericSignature parameter from OpenedArchetypeType::get()
1 parent e6c3ac8 commit 0c2f28f

33 files changed

+95
-204
lines changed

include/swift/AST/Types.h

+5-17
Original file line numberDiff line numberDiff line change
@@ -912,8 +912,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
912912
bool isClassExistentialType();
913913

914914
/// Opens an existential instance or meta-type and returns the opened type.
915-
Type openAnyExistentialType(OpenedArchetypeType *&opened,
916-
GenericSignature parentSig);
915+
Type openAnyExistentialType(OpenedArchetypeType *&opened);
917916

918917
/// Break an existential down into a set of constraints.
919918
ExistentialLayout getExistentialLayout();
@@ -6810,27 +6809,21 @@ class OpenedArchetypeType final : public LocalArchetypeType,
68106809
/// of an existential value.
68116810
///
68126811
/// \param existential The existential type to open.
6813-
/// \param parentSig The generic signature of the context opening
6814-
/// this existential.
6815-
///
68166812
/// \param knownID When non-empty, the known ID of the archetype. When empty,
68176813
/// a fresh archetype with a unique ID will be opened.
68186814
static CanTypeWrapper<OpenedArchetypeType>
6819-
get(CanType existential, GenericSignature parentSig,
6820-
std::optional<UUID> knownID = std::nullopt);
6815+
get(CanType existential, std::optional<UUID> knownID = std::nullopt);
68216816

68226817
/// Get or create an archetype that represents the opened type
68236818
/// of an existential value.
68246819
///
68256820
/// \param existential The existential type to open.
68266821
/// \param interfaceType The interface type represented by this archetype.
6827-
/// \param parentSig The generic signature of the context opening
6828-
/// this existential.
68296822
///
68306823
/// \param knownID When non-empty, the known ID of the archetype. When empty,
68316824
/// a fresh archetype with a unique ID will be opened.
68326825
static CanTypeWrapper<OpenedArchetypeType>
6833-
get(CanType existential, Type interfaceType, GenericSignature parentSig,
6826+
get(CanType existential, Type interfaceType,
68346827
std::optional<UUID> knownID = std::nullopt);
68356828

68366829
/// Create a new archetype that represents the opened type
@@ -6842,10 +6835,7 @@ class OpenedArchetypeType final : public LocalArchetypeType,
68426835
///
68436836
/// \param existential The existential type or existential metatype to open.
68446837
/// \param interfaceType The interface type represented by this archetype.
6845-
/// \param parentSig The generic signature of the context opening
6846-
/// this existential.
6847-
static CanType getAny(CanType existential, Type interfaceType,
6848-
GenericSignature parentSig);
6838+
static CanType getAny(CanType existential, Type interfaceType);
68496839

68506840
/// Create a new archetype that represents the opened type
68516841
/// of an existential value.
@@ -6855,9 +6845,7 @@ class OpenedArchetypeType final : public LocalArchetypeType,
68556845
/// will unwrap any existential metatype containers.
68566846
///
68576847
/// \param existential The existential type or existential metatype to open.
6858-
/// \param parentSig The generic signature of the context opening
6859-
/// this existential.
6860-
static CanType getAny(CanType existential, GenericSignature parentSig);
6848+
static CanType getAny(CanType existential);
68616849

68626850
/// Retrieve the ID number of this opened existential.
68636851
UUID getOpenedExistentialID() const;

include/swift/SIL/SILCloner.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,10 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
337337
void remapRootOpenedType(CanOpenedArchetypeType archetypeTy) {
338338
assert(archetypeTy->isRoot());
339339

340-
auto sig = Builder.getFunction().getGenericSignature();
341340
auto origExistentialTy = archetypeTy->getExistentialType()
342341
->getCanonicalType();
343342
auto substExistentialTy = getOpASTType(origExistentialTy);
344-
auto replacementTy = OpenedArchetypeType::get(substExistentialTy, sig);
343+
auto replacementTy = OpenedArchetypeType::get(substExistentialTy);
345344
registerLocalArchetypeRemapping(archetypeTy, replacementTy);
346345
}
347346

lib/AST/ASTContext.cpp

+12-15
Original file line numberDiff line numberDiff line change
@@ -5309,50 +5309,47 @@ CanTypeWrapper<OpenedArchetypeType> OpenedArchetypeType::getNew(
53095309
}
53105310

53115311
CanTypeWrapper<OpenedArchetypeType>
5312-
OpenedArchetypeType::get(CanType existential, GenericSignature parentSig,
5313-
std::optional<UUID> knownID) {
5312+
OpenedArchetypeType::get(CanType existential, std::optional<UUID> knownID) {
53145313
assert(existential->isExistentialType());
53155314
auto interfaceType = OpenedArchetypeType::getSelfInterfaceTypeFromContext(
5316-
parentSig, existential->getASTContext());
5317-
return get(existential, interfaceType, parentSig, knownID);
5315+
GenericSignature(), existential->getASTContext());
5316+
return get(existential, interfaceType, knownID);
53185317
}
53195318

53205319
CanOpenedArchetypeType OpenedArchetypeType::get(CanType existential,
53215320
Type interfaceType,
5322-
GenericSignature parentSig,
53235321
std::optional<UUID> knownID) {
5324-
assert(!interfaceType->hasArchetype() && "must be interface type");
5322+
assert(!existential->hasTypeParameter());
53255323

53265324
if (!knownID)
53275325
knownID = UUID::fromTime();
53285326

53295327
auto *genericEnv =
5330-
GenericEnvironment::forOpenedExistential(existential, parentSig, *knownID);
5328+
GenericEnvironment::forOpenedExistential(
5329+
existential, GenericSignature(), *knownID);
53315330

53325331
// Map the interface type into that environment.
53335332
auto result = genericEnv->mapTypeIntoContext(interfaceType)
53345333
->castTo<OpenedArchetypeType>();
53355334
return CanOpenedArchetypeType(result);
53365335
}
53375336

5338-
CanType OpenedArchetypeType::getAny(CanType existential, Type interfaceType,
5339-
GenericSignature parentSig) {
5337+
CanType OpenedArchetypeType::getAny(CanType existential, Type interfaceType) {
53405338
assert(existential->isAnyExistentialType());
53415339
if (auto metatypeTy = existential->getAs<ExistentialMetatypeType>()) {
53425340
auto instanceTy =
53435341
metatypeTy->getExistentialInstanceType()->getCanonicalType();
53445342
return CanMetatypeType::get(
5345-
OpenedArchetypeType::getAny(instanceTy, interfaceType, parentSig));
5343+
OpenedArchetypeType::getAny(instanceTy, interfaceType));
53465344
}
53475345
assert(existential->isExistentialType());
5348-
return OpenedArchetypeType::get(existential, interfaceType, parentSig);
5346+
return OpenedArchetypeType::get(existential, interfaceType);
53495347
}
53505348

5351-
CanType OpenedArchetypeType::getAny(CanType existential,
5352-
GenericSignature parentSig) {
5349+
CanType OpenedArchetypeType::getAny(CanType existential) {
53535350
auto interfaceTy = OpenedArchetypeType::getSelfInterfaceTypeFromContext(
5354-
parentSig, existential->getASTContext());
5355-
return getAny(existential, interfaceTy, parentSig);
5351+
GenericSignature(), existential->getASTContext());
5352+
return getAny(existential, interfaceTy);
53565353
}
53575354

53585355
void SubstitutionMap::Storage::Profile(

lib/AST/Type.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -4395,20 +4395,17 @@ SILBoxType::SILBoxType(ASTContext &C,
43954395
assert(Substitutions.isCanonical());
43964396
}
43974397

4398-
Type TypeBase::openAnyExistentialType(OpenedArchetypeType *&opened,
4399-
GenericSignature parentSig) {
4398+
Type TypeBase::openAnyExistentialType(OpenedArchetypeType *&opened) {
44004399
assert(isAnyExistentialType());
44014400
if (auto metaty = getAs<ExistentialMetatypeType>()) {
44024401
opened = OpenedArchetypeType::get(
4403-
metaty->getExistentialInstanceType()->getCanonicalType(),
4404-
parentSig.getCanonicalSignature());
4402+
metaty->getExistentialInstanceType()->getCanonicalType());
44054403
if (metaty->hasRepresentation())
44064404
return MetatypeType::get(opened, metaty->getRepresentation());
44074405
else
44084406
return MetatypeType::get(opened);
44094407
}
4410-
opened = OpenedArchetypeType::get(getCanonicalType(),
4411-
parentSig.getCanonicalSignature());
4408+
opened = OpenedArchetypeType::get(getCanonicalType());
44124409
return opened;
44134410
}
44144411

lib/IDE/CompletionLookup.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -2479,8 +2479,7 @@ void CompletionLookup::getValueExprCompletions(Type ExprType, ValueDecl *VD,
24792479

24802480
if (!ExprType->getMetatypeInstanceType()->isAnyObject()) {
24812481
if (ExprType->isAnyExistentialType()) {
2482-
ExprType = OpenedArchetypeType::getAny(ExprType->getCanonicalType(),
2483-
CurrDeclContext->getGenericSignatureOfContext());
2482+
ExprType = OpenedArchetypeType::getAny(ExprType->getCanonicalType());
24842483
}
24852484
}
24862485
if (!IsSelfRefExpr && !IsSuperRefExpr && ExprType->getAnyNominal() &&

lib/IRGen/GenCast.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ llvm::Value *irgen::emitCheckedCast(IRGenFunction &IGF,
9292
FailableCastResult irgen::emitClassIdenticalCast(IRGenFunction &IGF,
9393
llvm::Value *from,
9494
SILType fromType,
95-
SILType toType,
96-
GenericSignature fnSig) {
95+
SILType toType) {
9796
// Check metatype objects directly. Don't try to find their meta-metatype.
9897
auto isMetatype = false;
9998
if (auto metaType = toType.getAs<MetatypeType>()) {
@@ -130,7 +129,7 @@ FailableCastResult irgen::emitClassIdenticalCast(IRGenFunction &IGF,
130129
// =>
131130
// icmp eq %1, @metadata.Sub
132131
llvm::Value *objectMetadata = isMetatype ? from :
133-
emitHeapMetadataRefForHeapObject(IGF, from, fromType, fnSig);
132+
emitHeapMetadataRefForHeapObject(IGF, from, fromType);
134133

135134
objectMetadata = IGF.Builder.CreateBitCast(objectMetadata,
136135
targetMetadata->getType());
@@ -534,7 +533,7 @@ llvm::Value *irgen::emitMetatypeToAnyObjectDowncast(IRGenFunction &IGF,
534533
void irgen::emitScalarExistentialDowncast(
535534
IRGenFunction &IGF, llvm::Value *value, SILType srcType, SILType destType,
536535
CheckedCastMode mode, std::optional<MetatypeRepresentation> metatypeKind,
537-
GenericSignature fnSig, Explosion &ex) {
536+
Explosion &ex) {
538537
auto srcInstanceType = srcType.getASTType();
539538
auto destInstanceType = destType.getASTType();
540539
while (auto metatypeType = dyn_cast<ExistentialMetatypeType>(
@@ -765,8 +764,7 @@ void irgen::emitScalarExistentialDowncast(
765764
// Get the type metadata for the instance.
766765
metadataValue = emitDynamicTypeOfHeapObject(IGF, value,
767766
MetatypeRepresentation::Thick,
768-
srcType,
769-
fnSig);
767+
srcType);
770768
}
771769

772770
// Look up witness tables for the protocols that need them.
@@ -849,7 +847,6 @@ void irgen::emitScalarCheckedCast(IRGenFunction &IGF,
849847
SILType targetLoweredType,
850848
CanType targetFormalType,
851849
CheckedCastMode mode,
852-
GenericSignature fnSig,
853850
Explosion &out) {
854851
assert(sourceLoweredType.isObject());
855852
assert(targetLoweredType.isObject());
@@ -938,7 +935,6 @@ void irgen::emitScalarCheckedCast(IRGenFunction &IGF,
938935
emitScalarExistentialDowncast(IGF, metatypeVal, sourceLoweredType,
939936
targetLoweredType, mode,
940937
existential->getRepresentation(),
941-
fnSig,
942938
out);
943939
return;
944940

@@ -1007,7 +1003,7 @@ void irgen::emitScalarCheckedCast(IRGenFunction &IGF,
10071003
llvm::Value *instance;
10081004
if (sourceLoweredType.isExistentialType()) {
10091005
instance = emitClassExistentialProjection(IGF, value, sourceLoweredType,
1010-
CanArchetypeType(), fnSig);
1006+
CanArchetypeType());
10111007
} else {
10121008
instance = value.claimNext();
10131009
}
@@ -1016,7 +1012,7 @@ void irgen::emitScalarCheckedCast(IRGenFunction &IGF,
10161012
Explosion outRes;
10171013
emitScalarExistentialDowncast(
10181014
IGF, instance, sourceLoweredType, targetLoweredType, mode,
1019-
/*not a metatype*/ std::nullopt, fnSig, outRes);
1015+
/*not a metatype*/ std::nullopt, outRes);
10201016
returnNilCheckedResult(IGF.Builder, outRes);
10211017
return;
10221018
}
@@ -1107,7 +1103,7 @@ llvm::Value *irgen::emitFastClassCastIfPossible(
11071103

11081104
// Load the isa pointer.
11091105
llvm::Value *objMetadata = emitHeapMetadataRefForHeapObject(IGF, instance,
1110-
sourceFormalType, GenericSignature(), /*suppress cast*/ true);
1106+
sourceFormalType, /*suppress cast*/ true);
11111107
llvm::Value *rhs = IGF.Builder.CreateBitCast(objMetadata, IGF.IGM.Int8PtrTy);
11121108

11131109
// return isa_ptr == metadata_ptr ? instance : nullptr

lib/IRGen/GenCast.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ namespace irgen {
5454
SILType targetLoweredType,
5555
CanType targetFormalType,
5656
CheckedCastMode mode,
57-
GenericSignature fnSig,
5857
Explosion &out);
5958

6059
llvm::Value *emitFastClassCastIfPossible(
@@ -81,8 +80,7 @@ namespace irgen {
8180
FailableCastResult emitClassIdenticalCast(IRGenFunction &IGF,
8281
llvm::Value *from,
8382
SILType fromType,
84-
SILType toType,
85-
GenericSignature fnSig);
83+
SILType toType);
8684

8785
/// Emit a checked cast of a metatype.
8886
void emitMetatypeDowncast(IRGenFunction &IGF,
@@ -99,7 +97,7 @@ namespace irgen {
9997
void emitScalarExistentialDowncast(
10098
IRGenFunction &IGF, llvm::Value *orig, SILType srcType, SILType destType,
10199
CheckedCastMode mode, std::optional<MetatypeRepresentation> metatypeKind,
102-
GenericSignature fnSig, Explosion &ex);
100+
Explosion &ex);
103101

104102
/// Emit a checked cast from a metatype to AnyObject.
105103
llvm::Value *emitMetatypeToAnyObjectDowncast(IRGenFunction &IGF,

lib/IRGen/GenClass.cpp

+10-17
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,7 @@ OwnedAddress irgen::projectPhysicalClassMemberAddress(IRGenFunction &IGF,
651651
llvm::Value *base,
652652
SILType baseType,
653653
SILType fieldType,
654-
VarDecl *field,
655-
GenericSignature fnSig) {
654+
VarDecl *field) {
656655
// If the field is empty, its address doesn't matter.
657656
auto &fieldTI = IGF.getTypeInfo(fieldType);
658657
if (fieldTI.isKnownEmpty(ResilienceExpansion::Maximal)) {
@@ -686,7 +685,7 @@ OwnedAddress irgen::projectPhysicalClassMemberAddress(IRGenFunction &IGF,
686685
}
687686

688687
case FieldAccess::ConstantIndirect: {
689-
auto metadata = emitHeapMetadataRefForHeapObject(IGF, base, baseType, fnSig);
688+
auto metadata = emitHeapMetadataRefForHeapObject(IGF, base, baseType);
690689
auto offset = emitClassFieldOffset(IGF, baseClass, field, metadata);
691690
return emitAddressAtOffset(IGF, baseType, base, offset, field);
692691
}
@@ -728,8 +727,7 @@ irgen::getPhysicalClassMemberAccessStrategy(IRGenModule &IGM,
728727

729728
Address irgen::emitTailProjection(IRGenFunction &IGF, llvm::Value *Base,
730729
SILType ClassType,
731-
SILType TailType,
732-
GenericSignature fnSig) {
730+
SILType TailType) {
733731
const ClassTypeInfo &classTI = IGF.getTypeInfo(ClassType).as<ClassTypeInfo>();
734732

735733
llvm::Value *Offset = nullptr;
@@ -745,8 +743,7 @@ Address irgen::emitTailProjection(IRGenFunction &IGF, llvm::Value *Base,
745743
Align = HeapObjAlign.alignmentAtOffset(ClassSize);
746744
} else {
747745
llvm::Value *metadata = emitHeapMetadataRefForHeapObject(IGF, Base,
748-
ClassType,
749-
fnSig);
746+
ClassType);
750747
Offset = emitClassResilientInstanceSizeAndAlignMask(IGF,
751748
ClassType.getClassOrBoundGenericClass(),
752749
metadata).first;
@@ -971,7 +968,6 @@ static void getInstanceSizeAndAlignMask(IRGenFunction &IGF,
971968
SILType selfType,
972969
ClassDecl *selfClass,
973970
llvm::Value *selfValue,
974-
GenericSignature fnSig,
975971
llvm::Value *&size,
976972
llvm::Value *&alignMask) {
977973
// Try to determine the size of the object we're deallocating.
@@ -988,7 +984,7 @@ static void getInstanceSizeAndAlignMask(IRGenFunction &IGF,
988984

989985
// Otherwise, get them from the metadata.
990986
llvm::Value *metadata =
991-
emitHeapMetadataRefForHeapObject(IGF, selfValue, selfType, fnSig);
987+
emitHeapMetadataRefForHeapObject(IGF, selfValue, selfType);
992988
std::tie(size, alignMask)
993989
= emitClassResilientInstanceSizeAndAlignMask(IGF, selfClass, metadata);
994990
}
@@ -1000,8 +996,7 @@ static llvm::Value *emitCastToHeapObject(IRGenFunction &IGF,
1000996

1001997
void irgen::emitClassDeallocation(IRGenFunction &IGF,
1002998
SILType selfType,
1003-
llvm::Value *selfValue,
1004-
GenericSignature fnSig) {
999+
llvm::Value *selfValue) {
10051000
auto *theClass = selfType.getClassOrBoundGenericClass();
10061001

10071002
// We want to deallocate default actors or potential default
@@ -1033,7 +1028,7 @@ void irgen::emitClassDeallocation(IRGenFunction &IGF,
10331028
}
10341029

10351030
llvm::Value *size, *alignMask;
1036-
getInstanceSizeAndAlignMask(IGF, selfType, theClass, selfValue, fnSig,
1031+
getInstanceSizeAndAlignMask(IGF, selfType, theClass, selfValue,
10371032
size, alignMask);
10381033

10391034
selfValue = emitCastToHeapObject(IGF, selfValue);
@@ -1043,13 +1038,12 @@ void irgen::emitClassDeallocation(IRGenFunction &IGF,
10431038
void irgen::emitPartialClassDeallocation(IRGenFunction &IGF,
10441039
SILType selfType,
10451040
llvm::Value *selfValue,
1046-
llvm::Value *metadataValue,
1047-
GenericSignature fnSig) {
1041+
llvm::Value *metadataValue) {
10481042
auto *theClass = selfType.getClassOrBoundGenericClass();
10491043
assert(theClass->getForeignClassKind() == ClassDecl::ForeignKind::Normal);
10501044

10511045
llvm::Value *size, *alignMask;
1052-
getInstanceSizeAndAlignMask(IGF, selfType, theClass, selfValue, fnSig,
1046+
getInstanceSizeAndAlignMask(IGF, selfType, theClass, selfValue,
10531047
size, alignMask);
10541048

10551049
selfValue = IGF.Builder.CreateBitCast(selfValue, IGF.IGM.RefCountedPtrTy);
@@ -3143,7 +3137,6 @@ irgen::emitVirtualMethodValue(IRGenFunction &IGF,
31433137
SILType baseType,
31443138
SILDeclRef method,
31453139
CanSILFunctionType methodType,
3146-
GenericSignature fnSig,
31473140
bool useSuperVTable) {
31483141
// Find the metadata.
31493142
llvm::Value *metadata;
@@ -3162,7 +3155,7 @@ irgen::emitVirtualMethodValue(IRGenFunction &IGF,
31623155
metadata = base;
31633156
} else {
31643157
// Otherwise, load the class metadata from the 'self' value's isa pointer.
3165-
metadata = emitHeapMetadataRefForHeapObject(IGF, base, baseType, fnSig,
3158+
metadata = emitHeapMetadataRefForHeapObject(IGF, base, baseType,
31663159
/*suppress cast*/ true);
31673160
}
31683161
}

0 commit comments

Comments
 (0)