Skip to content

AST: Minor generics changes #60505

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
merged 4 commits into from
Aug 11, 2022
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/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1343,8 +1343,8 @@ class ASTContext final {
/// particular, the opened archetype signature does not have requirements for
/// conformances inherited from superclass constraints while existential
/// values do.
CanGenericSignature getOpenedArchetypeSignature(Type type,
GenericSignature parentSig);
CanGenericSignature getOpenedExistentialSignature(Type type,
GenericSignature parentSig);

GenericSignature getOverrideGenericSignature(const ValueDecl *base,
const ValueDecl *derived);
Expand Down
4 changes: 1 addition & 3 deletions include/swift/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,11 @@ class Type {
/// Transform the given type by recursively applying the user-provided
/// function to each node.
///
/// If the function returns \c None, the transform operation will
///
/// \param fn A function object which accepts a type pointer and returns a
/// transformed type, a null type (which will propagate out the null type),
/// or None (to indicate that the transform operation should recursively
/// transform the children). The function object should use \c dyn_cast rather
/// than \c getAs when the transform is intended to preserve sugar
/// than \c getAs when the transform is intended to preserve sugar.
///
/// \returns the result of transforming the type.
Type transformRec(llvm::function_ref<Optional<Type>(TypeBase *)> fn) const;
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4655,7 +4655,7 @@ GenericEnvironment *
GenericEnvironment::forOpenedExistential(
Type existential, GenericSignature parentSig, UUID uuid) {
auto &ctx = existential->getASTContext();
auto signature = ctx.getOpenedArchetypeSignature(existential, parentSig);
auto signature = ctx.getOpenedExistentialSignature(existential, parentSig);
return GenericEnvironment::forOpenedArchetypeSignature(existential, signature, uuid);
}

Expand Down Expand Up @@ -5199,7 +5199,7 @@ Type OpenedArchetypeType::getSelfInterfaceTypeFromContext(GenericSignature paren
}

CanGenericSignature
ASTContext::getOpenedArchetypeSignature(Type type, GenericSignature parentSig) {
ASTContext::getOpenedExistentialSignature(Type type, GenericSignature parentSig) {
assert(type->isExistentialType());

if (auto existential = type->getAs<ExistentialType>())
Expand Down
5 changes: 5 additions & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,9 @@ void PrintAST::printSingleDepthOfGenericSignature(
llvm::interleave(
genericParams,
[&](GenericTypeParamType *param) {
if (param->isTypeSequence())
Printer.printAttrName("@_typeSequence ");

if (!subMap.empty()) {
printType(substParam(param));
} else if (auto *GP = param->getDecl()) {
Expand Down Expand Up @@ -3473,6 +3476,8 @@ void PrintAST::visitTypeAliasDecl(TypeAliasDecl *decl) {

void PrintAST::visitGenericTypeParamDecl(GenericTypeParamDecl *decl) {
recordDeclLoc(decl, [&] {
if (decl->isTypeSequence())
Printer.printAttrName("@_typeSequence ");
Printer.printName(decl->getName(), PrintNameContext::GenericParameter);
});

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4168,7 +4168,7 @@ GenericParameterReferenceInfo ValueDecl::findExistentialSelfReferences(
// Note: a non-null GenericSignature would violate the invariant that
// the protocol 'Self' type referenced from the requirement's interface
// type is the same as the existential 'Self' type.
auto sig = getASTContext().getOpenedArchetypeSignature(baseTy,
auto sig = getASTContext().getOpenedExistentialSignature(baseTy,
GenericSignature());

auto genericParam = sig.getGenericParams().front();
Expand Down
7 changes: 5 additions & 2 deletions lib/AST/RequirementMachine/RequirementMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,11 @@ void RequirementMachine::dump(llvm::raw_ostream &out) const {
out << " ]";
} else {
out << "fresh signature <";
for (auto paramTy : Params)
out << " " << Type(paramTy);
for (auto paramTy : Params) {
out << " " << paramTy;
if (paramTy->castTo<GenericTypeParamType>()->isTypeSequence())
out << "…";
}
out << " >";
}
out << "\n";
Expand Down
10 changes: 8 additions & 2 deletions lib/AST/RequirementMachine/Symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,15 @@ void Symbol::dump(llvm::raw_ostream &out) const {
return;
}

case Kind::GenericParam:
out << Type(getGenericParam());
case Kind::GenericParam: {
auto *gp = getGenericParam();
if (gp->isTypeSequence()) {
out << "(" << Type(gp) << "…)";
} else {
out << Type(gp);
}
return;
}

case Kind::Layout:
out << "[layout: ";
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ Type TypeBase::typeEraseOpenedArchetypesWithRoot(
if (!hasOpenedExistential())
return type;

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

unsigned metatypeDepth = 0;
Expand Down Expand Up @@ -4163,7 +4163,7 @@ CanType ProtocolCompositionType::getMinimalCanonicalType(
// Use generic signature minimization: the requirements of the signature will
// represent the minimal composition.
auto sig = useDC->getGenericSignatureOfContext();
const auto Sig = Ctx.getOpenedArchetypeSignature(CanTy, sig);
const auto Sig = Ctx.getOpenedExistentialSignature(CanTy, sig);
const auto &Reqs = Sig.getRequirements();
if (Reqs.size() == 1) {
return Reqs.front().getSecondType()->getCanonicalType();
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6168,7 +6168,7 @@ irgen::emitExtendedExistentialTypeShape(IRGenModule &IGM,
}

CanGenericSignature reqSig =
IGM.Context.getOpenedArchetypeSignature(existentialType, genSig);
IGM.Context.getOpenedExistentialSignature(existentialType, genSig);

CanType typeExpression;
if (metatypeDepth > 0) {
Expand Down
6 changes: 3 additions & 3 deletions lib/SILOptimizer/Utils/Existential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ void ConcreteExistentialInfo::initializeSubstitutionMap(
// Construct a single-generic-parameter substitution map directly to the
// ConcreteType with this existential's full list of conformances.
//
// NOTE: getOpenedArchetypeSignature() generates the signature for passing an
// NOTE: getOpenedExistentialSignature() generates the signature for passing an
// opened existential as a generic parameter. No opened archetypes are
// actually involved here--the API is only used as a convenient way to create
// a substitution map. Since opened archetypes have different conformances
// than their corresponding existential, ExistentialConformances needs to be
// filtered when using it with this (phony) generic signature.
CanGenericSignature ExistentialSig =
M->getASTContext().getOpenedArchetypeSignature(ExistentialType,
GenericSignature());
M->getASTContext().getOpenedExistentialSignature(ExistentialType,
GenericSignature());
ExistentialSubs = SubstitutionMap::get(
ExistentialSig, [&](SubstitutableType *type) { return ConcreteType; },
[&](CanType /*depType*/, Type /*replaceType*/,
Expand Down
6 changes: 3 additions & 3 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1924,8 +1924,8 @@ typeEraseExistentialSelfReferences(
}

const auto existentialSig =
baseTy->getASTContext().getOpenedArchetypeSignature(baseTy,
GenericSignature());
baseTy->getASTContext().getOpenedExistentialSignature(baseTy,
GenericSignature());

unsigned metatypeDepth = 0;

Expand Down Expand Up @@ -6561,7 +6561,7 @@ static bool doesMemberHaveUnfulfillableConstraintsWithExistentialBase(

return Action::Stop;
}
} isDependentOnSelfWalker(member->getASTContext().getOpenedArchetypeSignature(
} isDependentOnSelfWalker(member->getASTContext().getOpenedExistentialSignature(
baseTy, GenericSignature()));

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