Skip to content

Commit 1f1b75a

Browse files
committed
[AST] Eliminate ModuleDecl parameters from GenericSignature.
1 parent 936a701 commit 1f1b75a

24 files changed

+96
-130
lines changed

include/swift/AST/GenericSignature.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,46 +264,47 @@ class alignas(1 << TypeAlignInBits) GenericSignature final
264264
}
265265

266266
/// Determine whether the given dependent type is required to be a class.
267-
bool requiresClass(Type type, ModuleDecl &mod);
267+
bool requiresClass(Type type);
268268

269269
/// Determine the superclass bound on the given dependent type.
270-
Type getSuperclassBound(Type type, ModuleDecl &mod);
270+
Type getSuperclassBound(Type type);
271271

272272
using ConformsToArray = SmallVector<ProtocolDecl *, 2>;
273273
/// Determine the set of protocols to which the given dependent type
274274
/// must conform.
275-
ConformsToArray getConformsTo(Type type, ModuleDecl &mod);
275+
ConformsToArray getConformsTo(Type type);
276276

277277
/// Determine whether the given dependent type conforms to this protocol.
278-
bool conformsToProtocol(Type type, ProtocolDecl *proto, ModuleDecl &mod);
278+
bool conformsToProtocol(Type type, ProtocolDecl *proto);
279279

280280
/// Determine whether the given dependent type is equal to a concrete type.
281-
bool isConcreteType(Type type, ModuleDecl &mod);
281+
bool isConcreteType(Type type);
282282

283283
/// Return the concrete type that the given dependent type is constrained to,
284284
/// or the null Type if it is not the subject of a concrete same-type
285285
/// constraint.
286-
Type getConcreteType(Type type, ModuleDecl &mod);
286+
Type getConcreteType(Type type);
287287

288288
/// Return the layout constraint that the given dependent type is constrained
289289
/// to, or the null LayoutConstraint if it is not the subject of layout
290290
/// constraint.
291-
LayoutConstraint getLayoutConstraint(Type type, ModuleDecl &mod);
291+
LayoutConstraint getLayoutConstraint(Type type);
292292

293293
/// Return whether two type parameters represent the same type under this
294294
/// generic signature.
295295
///
296296
/// The type parameters must be known to not be concrete within the context.
297-
bool areSameTypeParameterInContext(Type type1, Type type2, ModuleDecl &mod);
297+
bool areSameTypeParameterInContext(Type type1, Type type2);
298298

299299
/// Return the canonical version of the given type under this generic
300300
/// signature.
301-
CanType getCanonicalTypeInContext(Type type, ModuleDecl &mod);
302-
bool isCanonicalTypeInContext(Type type, ModuleDecl &mod);
301+
CanType getCanonicalTypeInContext(Type type);
302+
bool isCanonicalTypeInContext(Type type);
303303

304304
/// Return the canonical version of the given type under this generic
305305
/// signature.
306-
CanType getCanonicalTypeInContext(Type type, GenericSignatureBuilder &builder);
306+
CanType getCanonicalTypeInContext(Type type,
307+
GenericSignatureBuilder &builder);
307308
bool isCanonicalTypeInContext(Type type, GenericSignatureBuilder &builder);
308309

309310
/// Retrieve the conformance access path used to extract the conformance of
@@ -319,8 +320,7 @@ class alignas(1 << TypeAlignInBits) GenericSignature final
319320
///
320321
/// \seealso ConformanceAccessPath
321322
ConformanceAccessPath getConformanceAccessPath(Type type,
322-
ProtocolDecl *protocol,
323-
ModuleDecl &mod);
323+
ProtocolDecl *protocol);
324324

325325
static void Profile(llvm::FoldingSetNodeID &ID,
326326
ArrayRef<GenericTypeParamType *> genericParams,

include/swift/AST/Type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ class CanGenericSignature {
577577

578578
/// Retrieve the canonical generic environment associated with this
579579
/// generic signature.
580-
GenericEnvironment *getGenericEnvironment(ModuleDecl &module) const;
580+
GenericEnvironment *getGenericEnvironment() const;
581581

582582
GenericSignature *operator->() const {
583583
return Signature;

include/swift/AST/Types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3523,7 +3523,7 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
35233523
/// If this is a @convention(witness_method) function with a protocol
35243524
/// constrained self parameter, return the protocol constraint for
35253525
/// the Self type.
3526-
ProtocolDecl *getDefaultWitnessMethodProtocol(ModuleDecl &M) const;
3526+
ProtocolDecl *getDefaultWitnessMethodProtocol() const;
35273527

35283528
/// If this is a @convention(witness_method) function with a class
35293529
/// constrained self parameter, return the class constraint for the

include/swift/SIL/AbstractionPattern.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,14 +705,14 @@ class AbstractionPattern {
705705

706706
/// Is this an interface type that is subject to a concrete
707707
/// same-type constraint?
708-
bool isConcreteType(ModuleDecl &module) const {
708+
bool isConcreteType() const {
709709
assert(isTypeParameter());
710710
return (getKind() != Kind::Opaque &&
711711
GenericSig != nullptr &&
712-
GenericSig->isConcreteType(getType(), module));
712+
GenericSig->isConcreteType(getType()));
713713
}
714714

715-
bool requiresClass(ModuleDecl &module) {
715+
bool requiresClass() {
716716
switch (getKind()) {
717717
case Kind::Opaque:
718718
return false;
@@ -725,7 +725,7 @@ class AbstractionPattern {
725725
isa<GenericTypeParamType>(type)) {
726726
assert(GenericSig &&
727727
"Dependent type in pattern without generic signature?");
728-
return GenericSig->requiresClass(type, module);
728+
return GenericSig->requiresClass(type);
729729
}
730730
return false;
731731
}

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3632,12 +3632,10 @@ GenericFunctionType::get(GenericSignature *sig,
36323632
// it's canonical. Unfortunately, isCanonicalTypeInContext can cause
36333633
// new GenericFunctionTypes to be created and thus invalidate our insertion
36343634
// point.
3635-
auto &moduleForCanonicality = *ctx.TheBuiltinModule;
36363635
bool isCanonical = sig->isCanonical()
36373636
&& isCanonicalFunctionInputType(input)
3638-
&& sig->isCanonicalTypeInContext(unwrapParenType(input),
3639-
moduleForCanonicality)
3640-
&& sig->isCanonicalTypeInContext(output, moduleForCanonicality);
3637+
&& sig->isCanonicalTypeInContext(unwrapParenType(input))
3638+
&& sig->isCanonicalTypeInContext(output);
36413639

36423640
if (auto result
36433641
= ctx.Impl.GenericFunctionTypes.FindNodeOrInsertPos(id, insertPos)) {

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,8 +1680,8 @@ void ASTMangler::appendAssociatedTypeName(DependentMemberType *dmt) {
16801680
// dependent type, but can't yet. Shouldn't need this side channel.
16811681

16821682
appendIdentifier(assocTy->getName().str());
1683-
if (!OptimizeProtocolNames || !CurGenericSignature || !Mod
1684-
|| CurGenericSignature->getConformsTo(dmt->getBase(), *Mod).size() > 1) {
1683+
if (!OptimizeProtocolNames || !CurGenericSignature
1684+
|| CurGenericSignature->getConformsTo(dmt->getBase()).size() > 1) {
16851685
appendAnyGenericType(assocTy->getProtocol());
16861686
}
16871687
}

lib/AST/GenericSignature.cpp

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ getSubstitutions(const SubstitutionMap &subMap,
479479
});
480480
}
481481

482-
bool GenericSignature::requiresClass(Type type, ModuleDecl &mod) {
482+
bool GenericSignature::requiresClass(Type type) {
483483
if (!type->isTypeParameter()) return false;
484484

485485
auto &builder = *getGenericSignatureBuilder();
@@ -510,7 +510,7 @@ bool GenericSignature::requiresClass(Type type, ModuleDecl &mod) {
510510
}
511511

512512
/// Determine the superclass bound on the given dependent type.
513-
Type GenericSignature::getSuperclassBound(Type type, ModuleDecl &mod) {
513+
Type GenericSignature::getSuperclassBound(Type type) {
514514
if (!type->isTypeParameter()) return nullptr;
515515

516516
auto &builder = *getGenericSignatureBuilder();
@@ -531,7 +531,7 @@ Type GenericSignature::getSuperclassBound(Type type, ModuleDecl &mod) {
531531
/// Determine the set of protocols to which the given dependent type
532532
/// must conform.
533533
SmallVector<ProtocolDecl *, 2>
534-
GenericSignature::getConformsTo(Type type, ModuleDecl &mod) {
534+
GenericSignature::getConformsTo(Type type) {
535535
if (!type->isTypeParameter()) return { };
536536

537537
auto &builder = *getGenericSignatureBuilder();
@@ -556,8 +556,7 @@ GenericSignature::getConformsTo(Type type, ModuleDecl &mod) {
556556
return result;
557557
}
558558

559-
bool GenericSignature::conformsToProtocol(Type type, ProtocolDecl *proto,
560-
ModuleDecl &mod) {
559+
bool GenericSignature::conformsToProtocol(Type type, ProtocolDecl *proto) {
561560
// FIXME: Deal with concrete conformances here?
562561
if (!type->isTypeParameter()) return false;
563562

@@ -576,14 +575,14 @@ bool GenericSignature::conformsToProtocol(Type type, ProtocolDecl *proto,
576575
}
577576

578577
/// Determine whether the given dependent type is equal to a concrete type.
579-
bool GenericSignature::isConcreteType(Type type, ModuleDecl &mod) {
580-
return bool(getConcreteType(type, mod));
578+
bool GenericSignature::isConcreteType(Type type) {
579+
return bool(getConcreteType(type));
581580
}
582581

583582
/// Return the concrete type that the given dependent type is constrained to,
584583
/// or the null Type if it is not the subject of a concrete same-type
585584
/// constraint.
586-
Type GenericSignature::getConcreteType(Type type, ModuleDecl &mod) {
585+
Type GenericSignature::getConcreteType(Type type) {
587586
if (!type->isTypeParameter()) return Type();
588587

589588
auto &builder = *getGenericSignatureBuilder();
@@ -596,8 +595,7 @@ Type GenericSignature::getConcreteType(Type type, ModuleDecl &mod) {
596595
return equivClass->concreteType;
597596
}
598597

599-
LayoutConstraint GenericSignature::getLayoutConstraint(Type type,
600-
ModuleDecl &mod) {
598+
LayoutConstraint GenericSignature::getLayoutConstraint(Type type) {
601599
if (!type->isTypeParameter()) return LayoutConstraint();
602600

603601
auto &builder = *getGenericSignatureBuilder();
@@ -610,8 +608,7 @@ LayoutConstraint GenericSignature::getLayoutConstraint(Type type,
610608
return equivClass->layout;
611609
}
612610

613-
bool GenericSignature::areSameTypeParameterInContext(Type type1, Type type2,
614-
ModuleDecl &mod) {
611+
bool GenericSignature::areSameTypeParameterInContext(Type type1, Type type2) {
615612
assert(type1->isTypeParameter());
616613
assert(type2->isTypeParameter());
617614

@@ -636,7 +633,7 @@ bool GenericSignature::areSameTypeParameterInContext(Type type1, Type type2,
636633
return equivClass1 == equivClass2;
637634
}
638635

639-
bool GenericSignature::isCanonicalTypeInContext(Type type, ModuleDecl &mod) {
636+
bool GenericSignature::isCanonicalTypeInContext(Type type) {
640637
// If the type isn't independently canonical, it's certainly not canonical
641638
// in this context.
642639
if (!type->isCanonical())
@@ -713,8 +710,7 @@ CanType GenericSignature::getCanonicalTypeInContext(Type type,
713710
return result;
714711
}
715712

716-
CanType GenericSignature::getCanonicalTypeInContext(Type type,
717-
ModuleDecl &mod) {
713+
CanType GenericSignature::getCanonicalTypeInContext(Type type) {
718714
type = type->getCanonicalType();
719715

720716
// All the contextual canonicality rules apply to type parameters, so if the
@@ -726,11 +722,11 @@ CanType GenericSignature::getCanonicalTypeInContext(Type type,
726722
return getCanonicalTypeInContext(type, builder);
727723
}
728724

729-
GenericEnvironment *CanGenericSignature::getGenericEnvironment(
730-
ModuleDecl &module) const {
725+
GenericEnvironment *CanGenericSignature::getGenericEnvironment() const {
731726
// generic signature builders are stored on the ASTContext.
732-
return module.getASTContext().getOrCreateCanonicalGenericEnvironment(
733-
module.getASTContext().getOrCreateGenericSignatureBuilder(*this),
727+
auto &ctx = getGenericParams()[0]->getASTContext();
728+
return ctx.getOrCreateCanonicalGenericEnvironment(
729+
ctx.getOrCreateGenericSignatureBuilder(*this),
734730
*this);
735731
}
736732

@@ -766,8 +762,7 @@ getBestRequirementSource(ArrayRef<GSBConstraint<ProtocolDecl *>> constraints) {
766762

767763
ConformanceAccessPath GenericSignature::getConformanceAccessPath(
768764
Type type,
769-
ProtocolDecl *protocol,
770-
ModuleDecl &mod) {
765+
ProtocolDecl *protocol) {
771766
assert(type->isTypeParameter() && "not a type parameter");
772767

773768
// Resolve this type to a potential archetype.
@@ -844,8 +839,7 @@ ConformanceAccessPath GenericSignature::getConformanceAccessPath(
844839
// signature.
845840
Type subjectType = source->getStoredType();
846841
subjectType = inProtocol->getGenericSignature()
847-
->getCanonicalTypeInContext(subjectType,
848-
*inProtocol->getParentModule());
842+
->getCanonicalTypeInContext(subjectType);
849843

850844
assert(hasConformanceInSignature(inProtocol->getRequirementSignature(),
851845
subjectType, conformingProto) &&
@@ -888,9 +882,7 @@ ConformanceAccessPath GenericSignature::getConformanceAccessPath(
888882
assert(conformsSource != source || !requirementSignatureProto);
889883
Type localRootType = conformsSource->getRootPotentialArchetype()
890884
->getDependentType(inProtoSig->getGenericParams());
891-
localRootType = inProtoSig->getCanonicalTypeInContext(
892-
localRootType,
893-
*inProtocol->getModuleContext());
885+
localRootType = inProtoSig->getCanonicalTypeInContext(localRootType);
894886

895887
// Build the path according to the requirement signature.
896888
buildPath(inProtocol->getRequirementSignature(), conformsSource,

lib/AST/SubstitutionMap.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ Type SubstitutionMap::lookupSubstitution(CanSubstitutableType type) const {
133133

134134
// The generic parameter may have been made concrete by the generic signature,
135135
// substitute into the concrete type.
136-
ModuleDecl &anyModule = *genericParam->getASTContext().getStdlibModule();
137-
if (auto concreteType = genericSig->getConcreteType(genericParam, anyModule)){
136+
if (auto concreteType = genericSig->getConcreteType(genericParam)){
138137
// Set the replacement type to an error, to block infinite recursion.
139138
replacementType = ErrorType::get(concreteType);
140139

@@ -191,14 +190,13 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
191190
};
192191

193192
auto genericSig = getGenericSignature();
194-
auto &mod = *proto->getModuleContext();
195193

196194
// If the type doesn't conform to this protocol, fail.
197-
if (!genericSig->conformsToProtocol(type, proto, mod))
195+
if (!genericSig->conformsToProtocol(type, proto))
198196
return None;
199197

200198
auto accessPath =
201-
genericSig->getConformanceAccessPath(type, proto, mod);
199+
genericSig->getConformanceAccessPath(type, proto);
202200

203201
// Fall through because we cannot yet evaluate an access path.
204202
Optional<ProtocolConformanceRef> conformance;

lib/AST/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ CanType TypeBase::getCanonicalType(GenericSignature *sig,
12391239
if (!sig)
12401240
return getCanonicalType();
12411241

1242-
return sig->getCanonicalTypeInContext(this, mod);
1242+
return sig->getCanonicalTypeInContext(this);
12431243
}
12441244

12451245
TypeBase *TypeBase::reconstituteSugar(bool Recursive) {

lib/IDE/CodeCompletion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
19561956
}
19571957

19581958
if (t->isTypeParameter()) {
1959-
auto protos = genericSig->getConformsTo(t, *M);
1959+
auto protos = genericSig->getConformsTo(t);
19601960
if (!protos.empty())
19611961
return buildProtocolComposition(protos);
19621962
}

0 commit comments

Comments
 (0)