Skip to content

Commit 07217b4

Browse files
authored
Merge pull request swiftlang#19580 from slavapestov/fewer-gsb-part-1
Preliminary cleanups for creating fewer GenericSignatureBuilders
2 parents b9b568b + 87a49ff commit 07217b4

15 files changed

+29
-91
lines changed

include/swift/SIL/TypeLowering.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -508,20 +508,15 @@ struct SILConstantInfo {
508508

509509
/// The SIL function type of the constant.
510510
CanSILFunctionType SILFnType;
511-
512-
/// The generic environment used by the constant.
513-
GenericEnvironment *GenericEnv;
514511

515512
SILConstantInfo(CanAnyFunctionType formalType,
516513
AbstractionPattern formalPattern,
517514
CanAnyFunctionType loweredType,
518-
CanSILFunctionType silFnTy,
519-
GenericEnvironment *env)
515+
CanSILFunctionType silFnTy)
520516
: FormalType(formalType),
521517
FormalPattern(formalPattern),
522518
LoweredType(loweredType),
523-
SILFnType(silFnTy),
524-
GenericEnv(env) {}
519+
SILFnType(silFnTy) {}
525520

526521
SILType getSILType() const {
527522
return SILType::getPrimitiveObjectType(SILFnType);
@@ -530,8 +525,7 @@ struct SILConstantInfo {
530525
friend bool operator==(SILConstantInfo lhs, SILConstantInfo rhs) {
531526
return lhs.FormalType == rhs.FormalType &&
532527
lhs.LoweredType == rhs.LoweredType &&
533-
lhs.SILFnType == rhs.SILFnType &&
534-
lhs.GenericEnv == rhs.GenericEnv;
528+
lhs.SILFnType == rhs.SILFnType;
535529
}
536530
friend bool operator!=(SILConstantInfo lhs, SILConstantInfo rhs) {
537531
return !(lhs == rhs);
@@ -670,9 +664,6 @@ class TypeConverter {
670664

671665
CanAnyFunctionType makeConstantInterfaceType(SILDeclRef constant);
672666

673-
/// Get the generic environment for a constant.
674-
GenericEnvironment *getConstantGenericEnvironment(SILDeclRef constant);
675-
676667
// Types converted during foreign bridging.
677668
#define BRIDGING_KNOWN_TYPE(BridgedModule,BridgedType) \
678669
Optional<CanType> BridgedType##Ty;
@@ -793,6 +784,9 @@ class TypeConverter {
793784
/// for a constant reference.
794785
const SILConstantInfo &getConstantInfo(SILDeclRef constant);
795786

787+
/// Get the generic environment for a constant.
788+
GenericEnvironment *getConstantGenericEnvironment(SILDeclRef constant);
789+
796790
/// Returns the SIL type of a constant reference.
797791
SILType getConstantType(SILDeclRef constant) {
798792
return getConstantInfo(constant).getSILType();

lib/AST/ASTVerifier.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,9 @@ class Verifier : public ASTWalker {
592592
abort();
593593
}
594594

595+
if (!type->hasArchetype())
596+
return;
597+
595598
bool foundError = type->getCanonicalType().findIf([&](Type type) -> bool {
596599
if (auto archetype = type->getAs<ArchetypeType>()) {
597600
// Only visit each archetype once.

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5440,8 +5440,7 @@ class GenericSignatureBuilder::InferRequirementsWalker : public TypeWalker {
54405440
return Action::Continue;
54415441

54425442
/// Retrieve the substitution.
5443-
auto subMap = ty->getContextSubstitutionMap(&module, decl,
5444-
decl->getGenericEnvironment());
5443+
auto subMap = ty->getContextSubstitutionMap(&module, decl);
54455444

54465445
// Handle the requirements.
54475446
// FIXME: Inaccurate TypeReprs.

lib/SIL/SILFunctionType.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,7 +2089,6 @@ const SILConstantInfo &TypeConverter::getConstantInfo(SILDeclRef constant) {
20892089
// First, get a function type for the constant. This creates the
20902090
// right type for a getter or setter.
20912091
auto formalInterfaceType = makeConstantInterfaceType(constant);
2092-
auto *genericEnv = getConstantGenericEnvironment(constant);
20932092

20942093
// The formal type is just that with the right representation.
20952094
auto rep = getDeclRefRepresentation(constant);
@@ -2122,8 +2121,7 @@ const SILConstantInfo &TypeConverter::getConstantInfo(SILDeclRef constant) {
21222121
auto result = ::new (resultBuf) SILConstantInfo{formalInterfaceType,
21232122
bridgedTypes.Pattern,
21242123
loweredInterfaceType,
2125-
silFnType,
2126-
genericEnv};
2124+
silFnType};
21272125
if (DisableConstantInfoCache)
21282126
return *result;
21292127

@@ -2310,8 +2308,7 @@ TypeConverter::getConstantOverrideInfo(SILDeclRef derived, SILDeclRef base) {
23102308
derivedInterfaceTy,
23112309
bridgedTypes.Pattern,
23122310
overrideLoweredInterfaceTy,
2313-
fnTy,
2314-
derivedInfo.GenericEnv};
2311+
fnTy};
23152312

23162313
auto inserted = ConstantOverrideTypes.insert({{derived, base}, result});
23172314
assert(inserted.second);

lib/SIL/SILVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2527,7 +2527,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
25272527
assert(!methodTy->isCoroutine());
25282528

25292529
// Map interface types to archetypes.
2530-
if (auto *env = constantInfo.GenericEnv) {
2530+
if (auto *env = F.getModule().Types.getConstantGenericEnvironment(method)) {
25312531
auto subs = env->getForwardingSubstitutionMap();
25322532
methodTy = methodTy->substGenericArgs(F.getModule(), subs);
25332533
}

lib/SILGen/SILGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ void SILGenModule::preEmitFunction(SILDeclRef constant,
646646
assert(F->empty() && "already emitted function?!");
647647

648648
if (F->getLoweredFunctionType()->isPolymorphic())
649-
F->setGenericEnvironment(Types.getConstantInfo(constant).GenericEnv);
649+
F->setGenericEnvironment(Types.getConstantGenericEnvironment(constant));
650650

651651
// Create a debug scope for the function using astNode as source location.
652652
F->setDebugScope(new (M) SILDebugScope(Loc, F));

lib/SILGen/SILGenBridging.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,9 +1268,6 @@ static SILFunctionType *emitObjCThunkArguments(SILGenFunction &SGF,
12681268
auto swiftFormalFnTy = substGenericArgs(swiftInfo.LoweredType, subs);
12691269
SILFunctionConventions swiftConv(swiftFnTy, SGF.SGM.M);
12701270

1271-
// We must have the same context archetypes as the unthunked function.
1272-
assert(objcInfo.GenericEnv == swiftInfo.GenericEnv);
1273-
12741271
SmallVector<ManagedValue, 8> bridgedArgs;
12751272
bridgedArgs.reserve(objcFnTy->getParameters().size());
12761273

@@ -1399,7 +1396,7 @@ void SILGenFunction::emitNativeToForeignThunk(SILDeclRef thunk) {
13991396
SILFunctionConventions substConv(substTy, SGM.M);
14001397

14011398
// Use the same generic environment as the native entry point.
1402-
F.setGenericEnvironment(nativeInfo.GenericEnv);
1399+
F.setGenericEnvironment(SGM.Types.getConstantGenericEnvironment(native));
14031400

14041401
auto loc = thunk.getAsRegularLocation();
14051402
loc.markAutoGenerated();
@@ -1607,7 +1604,7 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
16071604
assert(nativeFnTy == nativeCI.SILFnType);
16081605

16091606
// Use the same generic environment as the native entry point.
1610-
F.setGenericEnvironment(nativeCI.GenericEnv);
1607+
F.setGenericEnvironment(SGM.Types.getConstantGenericEnvironment(thunk));
16111608

16121609
SILDeclRef foreignDeclRef = thunk.asForeign(true);
16131610
SILConstantInfo foreignCI = getConstantInfo(foreignDeclRef);

lib/SILGen/SILGenExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,7 +2871,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
28712871
// If the storage declaration is from a protocol, chase the override chain
28722872
// back to the declaration whose getter introduced the witness table
28732873
// entry.
2874-
if (auto origProto = dyn_cast<ProtocolDecl>(property->getDeclContext())) {
2874+
if (isa<ProtocolDecl>(property->getDeclContext())) {
28752875
auto getter = property->getGetter();
28762876
if (!SILDeclRef::requiresNewWitnessTableEntry(getter)) {
28772877
// Find the getter that does have a witness table entry.
@@ -3002,7 +3002,7 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
30023002
// If the storage declaration is from a protocol, chase the override chain
30033003
// back to the declaration whose setter introduced the witness table
30043004
// entry.
3005-
if (auto origProto = dyn_cast<ProtocolDecl>(property->getDeclContext())) {
3005+
if (isa<ProtocolDecl>(property->getDeclContext())) {
30063006
auto setter = property->getSetter();
30073007
if (!SILDeclRef::requiresNewWitnessTableEntry(setter)) {
30083008
// Find the setter that does have a witness table entry.

lib/Sema/ConstraintLocator.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ void ConstraintLocator::Profile(llvm::FoldingSetNodeID &id, Expr *anchor,
4545
id.AddPointer(elt.getWitness());
4646
break;
4747

48-
case AssociatedType:
49-
id.AddPointer(elt.getAssociatedType());
50-
break;
51-
5248
case ApplyArgument:
5349
case ApplyFunction:
5450
case FunctionArgument:
@@ -117,11 +113,6 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) {
117113
out << "archetype '" << elt.getArchetype()->getString() << "'";
118114
break;
119115

120-
case AssociatedType:
121-
out << "associated type '"
122-
<< elt.getAssociatedType()->getNameStr() << "'";
123-
break;
124-
125116
case ApplyArgument:
126117
out << "apply argument";
127118
break;

lib/Sema/ConstraintLocator.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ class ConstraintLocator : public llvm::FoldingSetNode {
6363
///
6464
/// Also contains the archetype itself.
6565
Archetype,
66-
/// An associated type reference.
67-
///
68-
/// Contains the associated type itself.
69-
AssociatedType,
7066
/// \brief The argument type of a function.
7167
FunctionArgument,
7268
/// \brief The result type of a function.
@@ -138,7 +134,6 @@ class ConstraintLocator : public llvm::FoldingSetNode {
138134
case ApplyArgument:
139135
case ApplyFunction:
140136
case Archetype:
141-
case AssociatedType:
142137
case FunctionArgument:
143138
case FunctionResult:
144139
case OptionalPayload:
@@ -211,7 +206,6 @@ class ConstraintLocator : public llvm::FoldingSetNode {
211206
case SubscriptMember:
212207
case OpenedGeneric:
213208
case Archetype:
214-
case AssociatedType:
215209
case GenericArgument:
216210
case NamedTupleElement:
217211
case TupleElement:
@@ -316,13 +310,6 @@ class ConstraintLocator : public llvm::FoldingSetNode {
316310
(kind == Witness && getWitness() == decl)));
317311
}
318312

319-
PathElement(AssociatedTypeDecl *decl)
320-
: storage((reinterpret_cast<uintptr_t>(decl) >> 2)),
321-
storedKind(StoredRequirement)
322-
{
323-
assert(getAssociatedType() == decl);
324-
}
325-
326313
/// \brief Retrieve a path element for a tuple element referred to by
327314
/// its position.
328315
static PathElement getTupleElement(unsigned position) {
@@ -370,8 +357,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
370357
return Archetype;
371358

372359
case StoredRequirement:
373-
return isa<AssociatedTypeDecl>(getRequirement()) ? AssociatedType
374-
: Requirement;
360+
return Requirement;
375361

376362
case StoredWitness:
377363
return Witness;
@@ -427,12 +413,6 @@ class ConstraintLocator : public llvm::FoldingSetNode {
427413
return reinterpret_cast<ValueDecl *>(storage << 2);
428414
}
429415

430-
/// Retrieve the declaration for an associated type path element.
431-
AssociatedTypeDecl *getAssociatedType() const {
432-
assert(getKind() == AssociatedType && "Is not an associated type");
433-
return reinterpret_cast<AssociatedTypeDecl *>(storage << 2);
434-
}
435-
436416
/// \brief Return the summary flags for this particular element.
437417
unsigned getNewSummaryFlags() const {
438418
return getSummaryFlagsForPathElement(getKind());

0 commit comments

Comments
 (0)