Skip to content

Commit 383b0ab

Browse files
authored
AST: Deep sugar type reconstitution should be optional. (swiftlang#8244)
Tentatively fixing a test failure in Sil parser.
1 parent 9e4a769 commit 383b0ab

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

include/swift/AST/Types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ class alignas(1 << TypeAlignInBits) TypeBase {
367367

368368
/// Reconstitute type sugar, e.g., for array types, dictionary
369369
/// types, optionals, etc.
370-
TypeBase *reconstituteSugar();
370+
TypeBase *reconstituteSugar(bool Recursive);
371371

372372
/// getASTContext - Return the ASTContext that this type belongs to.
373373
ASTContext &getASTContext() {

lib/AST/Type.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,8 +1168,8 @@ CanType TypeBase::getCanonicalType() {
11681168
return CanType(Result);
11691169
}
11701170

1171-
TypeBase *TypeBase::reconstituteSugar() {
1172-
return Type(this).transform([](Type Ty) -> Type {
1171+
TypeBase *TypeBase::reconstituteSugar(bool Recursive) {
1172+
auto Func = [](Type Ty) -> Type {
11731173
if (auto boundGeneric = dyn_cast<BoundGenericType>(Ty.getPointer())) {
11741174
auto &ctx = boundGeneric->getASTContext();
11751175
if (boundGeneric->getDecl() == ctx.getArrayDecl())
@@ -1184,7 +1184,11 @@ TypeBase *TypeBase::reconstituteSugar() {
11841184
get(boundGeneric->getGenericArgs()[0]);
11851185
}
11861186
return Ty;
1187-
}).getPointer();
1187+
};
1188+
if (Recursive)
1189+
return Type(this).transform(Func).getPointer();
1190+
else
1191+
return Func(this).getPointer();
11881192
}
11891193

11901194
TypeBase *TypeBase::getDesugaredType() {

lib/Sema/CSSolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Solution ConstraintSystem::finalize(
141141

142142
// For each of the type variables, get its fixed type.
143143
for (auto tv : TypeVariables) {
144-
solution.typeBindings[tv] = simplifyType(tv)->reconstituteSugar();
144+
solution.typeBindings[tv] = simplifyType(tv)->reconstituteSugar(false);
145145
}
146146

147147
// For each of the overload sets, get its overload choice.

0 commit comments

Comments
 (0)