Skip to content

[NFC] Address review feedback from #27172 #27241

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
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
13 changes: 7 additions & 6 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3786,12 +3786,13 @@ PotentialArchetype *GenericSignatureBuilder::realizePotentialArchetype(

static Type getStructuralType(TypeDecl *typeDecl) {
if (auto typealias = dyn_cast<TypeAliasDecl>(typeDecl)) {
// When we're computing requirement signatures, the structural type
// suffices. Otherwise we'll potentially try to validate incomplete
// requirements.
auto *proto = dyn_cast_or_null<ProtocolDecl>(typealias->getDeclContext()->getAsDecl());
if (proto && proto->isComputingRequirementSignature())
return typealias->getStructuralType();
// When we're computing requirement signatures, the structural type
// suffices. Otherwise we'll potentially try to validate incomplete
// requirements.
auto *proto = dyn_cast_or_null<ProtocolDecl>(
typealias->getDeclContext()->getAsDecl());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more nitpick: This should be dyn_cast<ProtocolDecl>(typealias->getDeclContext())

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or typealias->getSelfProtocolDecl() :)

if (proto && proto->isComputingRequirementSignature())
return typealias->getStructuralType();
return typealias->getUnderlyingType();
}

Expand Down
20 changes: 12 additions & 8 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4302,16 +4302,20 @@ ExtendedTypeRequest::evaluate(Evaluator &eval, ExtensionDecl *ext) const {
// Nested Hack to break cycles if this is called before validation has
// finished.
if (aliasDecl->hasInterfaceType()) {
auto extendedNominal = aliasDecl->getDeclaredInterfaceType()->getAnyNominal();
auto extendedNominal =
aliasDecl->getDeclaredInterfaceType()->getAnyNominal();
if (extendedNominal)
return TypeChecker::isPassThroughTypealias(aliasDecl, aliasDecl->getUnderlyingType(), extendedNominal)
? extendedType
: extendedNominal->getDeclaredType();
return TypeChecker::isPassThroughTypealias(
aliasDecl, aliasDecl->getUnderlyingType(), extendedNominal)
? extendedType
: extendedNominal->getDeclaredType();
} else {
if (auto ty = aliasDecl->getStructuralType()->getAs<NominalOrBoundGenericNominalType>())
return TypeChecker::isPassThroughTypealias(aliasDecl, ty, ty->getDecl())
? extendedType
: ty->getDecl()->getDeclaredType();
if (auto ty = aliasDecl->getStructuralType()
->getAs<NominalOrBoundGenericNominalType>())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getNominalOrBoundGenericNominal()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That canonicalizes the type. I only want to desugar it.

return TypeChecker::isPassThroughTypealias(aliasDecl, ty,
ty->getDecl())
? extendedType
: ty->getDecl()->getDeclaredType();
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions lib/Sema/TypeCheckGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,8 @@ static Type formExtensionInterfaceType(
}

// If we have a typealias, try to form type sugar.
if (typealias && TypeChecker::isPassThroughTypealias(typealias, typealias->getUnderlyingType(), nominal)) {
if (typealias && TypeChecker::isPassThroughTypealias(
typealias, typealias->getUnderlyingType(), nominal)) {
auto typealiasSig = typealias->getGenericSignature();
SubstitutionMap subMap;
if (typealiasSig) {
Expand All @@ -565,10 +566,10 @@ static Type formExtensionInterfaceType(
mustInferRequirements = true;
}

resultType = TypeAliasType::get(typealias, parentType, subMap,
resultType);
resultType = TypeAliasType::get(typealias, parentType, subMap, resultType);
}


return resultType;
}

Expand Down
10 changes: 1 addition & 9 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2292,15 +2292,7 @@ class swift::DeclDeserializer {

auto underlying = MF.getType(underlyingTypeID);
alias->setUnderlyingType(underlying);
SubstitutionMap subs;
if (genericSig) {
subs = genericSig->getIdentitySubstitutionMap();
}
Type parent;
if (DC->isTypeContext())
parent = DC->getDeclaredInterfaceType();
auto sugaredType = TypeAliasType::get(alias, parent, subs, underlying);
alias->setInterfaceType(MetatypeType::get(sugaredType, ctx));
alias->computeType();
alias->setValidationToChecked();

if (auto accessLevel = getActualAccessLevel(rawAccessLevel))
Expand Down