Skip to content

Commit bf755cc

Browse files
authored
Merge pull request #60505 from slavapestov/misc-variadic-crap
AST: Minor generics changes
2 parents 93417d9 + 0c497c9 commit bf755cc

File tree

11 files changed

+33
-21
lines changed

11 files changed

+33
-21
lines changed

include/swift/AST/ASTContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,8 +1343,8 @@ class ASTContext final {
13431343
/// particular, the opened archetype signature does not have requirements for
13441344
/// conformances inherited from superclass constraints while existential
13451345
/// values do.
1346-
CanGenericSignature getOpenedArchetypeSignature(Type type,
1347-
GenericSignature parentSig);
1346+
CanGenericSignature getOpenedExistentialSignature(Type type,
1347+
GenericSignature parentSig);
13481348

13491349
GenericSignature getOverrideGenericSignature(const ValueDecl *base,
13501350
const ValueDecl *derived);

include/swift/AST/Type.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,11 @@ class Type {
282282
/// Transform the given type by recursively applying the user-provided
283283
/// function to each node.
284284
///
285-
/// If the function returns \c None, the transform operation will
286-
///
287285
/// \param fn A function object which accepts a type pointer and returns a
288286
/// transformed type, a null type (which will propagate out the null type),
289287
/// or None (to indicate that the transform operation should recursively
290288
/// transform the children). The function object should use \c dyn_cast rather
291-
/// than \c getAs when the transform is intended to preserve sugar
289+
/// than \c getAs when the transform is intended to preserve sugar.
292290
///
293291
/// \returns the result of transforming the type.
294292
Type transformRec(llvm::function_ref<Optional<Type>(TypeBase *)> fn) const;

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4655,7 +4655,7 @@ GenericEnvironment *
46554655
GenericEnvironment::forOpenedExistential(
46564656
Type existential, GenericSignature parentSig, UUID uuid) {
46574657
auto &ctx = existential->getASTContext();
4658-
auto signature = ctx.getOpenedArchetypeSignature(existential, parentSig);
4658+
auto signature = ctx.getOpenedExistentialSignature(existential, parentSig);
46594659
return GenericEnvironment::forOpenedArchetypeSignature(existential, signature, uuid);
46604660
}
46614661

@@ -5199,7 +5199,7 @@ Type OpenedArchetypeType::getSelfInterfaceTypeFromContext(GenericSignature paren
51995199
}
52005200

52015201
CanGenericSignature
5202-
ASTContext::getOpenedArchetypeSignature(Type type, GenericSignature parentSig) {
5202+
ASTContext::getOpenedExistentialSignature(Type type, GenericSignature parentSig) {
52035203
assert(type->isExistentialType());
52045204

52055205
if (auto existential = type->getAs<ExistentialType>())

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,9 @@ void PrintAST::printSingleDepthOfGenericSignature(
16791679
llvm::interleave(
16801680
genericParams,
16811681
[&](GenericTypeParamType *param) {
1682+
if (param->isTypeSequence())
1683+
Printer.printAttrName("@_typeSequence ");
1684+
16821685
if (!subMap.empty()) {
16831686
printType(substParam(param));
16841687
} else if (auto *GP = param->getDecl()) {
@@ -3473,6 +3476,8 @@ void PrintAST::visitTypeAliasDecl(TypeAliasDecl *decl) {
34733476

34743477
void PrintAST::visitGenericTypeParamDecl(GenericTypeParamDecl *decl) {
34753478
recordDeclLoc(decl, [&] {
3479+
if (decl->isTypeSequence())
3480+
Printer.printAttrName("@_typeSequence ");
34763481
Printer.printName(decl->getName(), PrintNameContext::GenericParameter);
34773482
});
34783483

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4168,7 +4168,7 @@ GenericParameterReferenceInfo ValueDecl::findExistentialSelfReferences(
41684168
// Note: a non-null GenericSignature would violate the invariant that
41694169
// the protocol 'Self' type referenced from the requirement's interface
41704170
// type is the same as the existential 'Self' type.
4171-
auto sig = getASTContext().getOpenedArchetypeSignature(baseTy,
4171+
auto sig = getASTContext().getOpenedExistentialSignature(baseTy,
41724172
GenericSignature());
41734173

41744174
auto genericParam = sig.getGenericParams().front();

lib/AST/RequirementMachine/RequirementMachine.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,11 @@ void RequirementMachine::dump(llvm::raw_ostream &out) const {
556556
out << " ]";
557557
} else {
558558
out << "fresh signature <";
559-
for (auto paramTy : Params)
560-
out << " " << Type(paramTy);
559+
for (auto paramTy : Params) {
560+
out << " " << paramTy;
561+
if (paramTy->castTo<GenericTypeParamType>()->isTypeSequence())
562+
out << "";
563+
}
561564
out << " >";
562565
}
563566
out << "\n";

lib/AST/RequirementMachine/Symbol.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,9 +675,15 @@ void Symbol::dump(llvm::raw_ostream &out) const {
675675
return;
676676
}
677677

678-
case Kind::GenericParam:
679-
out << Type(getGenericParam());
678+
case Kind::GenericParam: {
679+
auto *gp = getGenericParam();
680+
if (gp->isTypeSequence()) {
681+
out << "(" << Type(gp) << "…)";
682+
} else {
683+
out << Type(gp);
684+
}
680685
return;
686+
}
681687

682688
case Kind::Layout:
683689
out << "[layout: ";

lib/AST/Type.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ Type TypeBase::typeEraseOpenedArchetypesWithRoot(
511511
if (!hasOpenedExistential())
512512
return type;
513513

514-
const auto sig = root->getASTContext().getOpenedArchetypeSignature(
514+
const auto sig = root->getASTContext().getOpenedExistentialSignature(
515515
root->getExistentialType(), useDC->getGenericSignatureOfContext());
516516

517517
unsigned metatypeDepth = 0;
@@ -4163,7 +4163,7 @@ CanType ProtocolCompositionType::getMinimalCanonicalType(
41634163
// Use generic signature minimization: the requirements of the signature will
41644164
// represent the minimal composition.
41654165
auto sig = useDC->getGenericSignatureOfContext();
4166-
const auto Sig = Ctx.getOpenedArchetypeSignature(CanTy, sig);
4166+
const auto Sig = Ctx.getOpenedExistentialSignature(CanTy, sig);
41674167
const auto &Reqs = Sig.getRequirements();
41684168
if (Reqs.size() == 1) {
41694169
return Reqs.front().getSecondType()->getCanonicalType();

lib/IRGen/GenMeta.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6168,7 +6168,7 @@ irgen::emitExtendedExistentialTypeShape(IRGenModule &IGM,
61686168
}
61696169

61706170
CanGenericSignature reqSig =
6171-
IGM.Context.getOpenedArchetypeSignature(existentialType, genSig);
6171+
IGM.Context.getOpenedExistentialSignature(existentialType, genSig);
61726172

61736173
CanType typeExpression;
61746174
if (metatypeDepth > 0) {

lib/SILOptimizer/Utils/Existential.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,15 @@ void ConcreteExistentialInfo::initializeSubstitutionMap(
249249
// Construct a single-generic-parameter substitution map directly to the
250250
// ConcreteType with this existential's full list of conformances.
251251
//
252-
// NOTE: getOpenedArchetypeSignature() generates the signature for passing an
252+
// NOTE: getOpenedExistentialSignature() generates the signature for passing an
253253
// opened existential as a generic parameter. No opened archetypes are
254254
// actually involved here--the API is only used as a convenient way to create
255255
// a substitution map. Since opened archetypes have different conformances
256256
// than their corresponding existential, ExistentialConformances needs to be
257257
// filtered when using it with this (phony) generic signature.
258258
CanGenericSignature ExistentialSig =
259-
M->getASTContext().getOpenedArchetypeSignature(ExistentialType,
260-
GenericSignature());
259+
M->getASTContext().getOpenedExistentialSignature(ExistentialType,
260+
GenericSignature());
261261
ExistentialSubs = SubstitutionMap::get(
262262
ExistentialSig, [&](SubstitutableType *type) { return ConcreteType; },
263263
[&](CanType /*depType*/, Type /*replaceType*/,

lib/Sema/ConstraintSystem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,8 +1924,8 @@ typeEraseExistentialSelfReferences(
19241924
}
19251925

19261926
const auto existentialSig =
1927-
baseTy->getASTContext().getOpenedArchetypeSignature(baseTy,
1928-
GenericSignature());
1927+
baseTy->getASTContext().getOpenedExistentialSignature(baseTy,
1928+
GenericSignature());
19291929

19301930
unsigned metatypeDepth = 0;
19311931

@@ -6561,7 +6561,7 @@ static bool doesMemberHaveUnfulfillableConstraintsWithExistentialBase(
65616561

65626562
return Action::Stop;
65636563
}
6564-
} isDependentOnSelfWalker(member->getASTContext().getOpenedArchetypeSignature(
6564+
} isDependentOnSelfWalker(member->getASTContext().getOpenedExistentialSignature(
65656565
baseTy, GenericSignature()));
65666566

65676567
for (const auto &req : sig.getRequirements()) {

0 commit comments

Comments
 (0)