Skip to content

Commit f7a82ac

Browse files
committed
[Type Reconstruction] For now, reconstruct existential types without
explicit ExistentialType. The ASTDemangler needs to produce ExistentialType based on context, not unconditionally when producing a protocol composition. This is tricky because existential types are mangled the same way as other protocol references, e.g. in conformance requirements. For now, drop the explicit existentials when reconstructing types.
1 parent 1d56338 commit f7a82ac

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/AST/ASTDemangler.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,11 +584,15 @@ Type ASTBuilder::createProtocolCompositionType(
584584
members.push_back(protocol->getDeclaredInterfaceType());
585585
if (superclass && superclass->getClassOrBoundGenericClass())
586586
members.push_back(superclass);
587+
588+
// FIXME: When explicit existential types are enabled, protocol
589+
// compositions should be wrapped in ExistentialType based on
590+
// context, similar to how protocol compositions are resolved
591+
// during type resolution. For example, protocol compositions
592+
// in parameter types should be wrapped in ExistentialType, but
593+
// protocol compositions on the right side of a conformance
594+
// requirement should not.
587595
Type composition = ProtocolCompositionType::get(Ctx, members, isClassBound);
588-
if (Ctx.LangOpts.EnableExplicitExistentialTypes &&
589-
!(composition->isAny() || composition->isAnyObject())) {
590-
composition = ExistentialType::get(composition);
591-
}
592596
return composition;
593597
}
594598

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,14 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
900900
Ty->dump(llvm::errs());
901901
abort();
902902
} else if (!Reconstructed->isEqual(Ty) &&
903+
// FIXME: Existential types are reconstructed without
904+
// an explicit ExistentialType wrapping the constraint.
905+
!(Ty->getASTContext().LangOpts.EnableExplicitExistentialTypes &&
906+
Ty.transform([](Type type) -> Type {
907+
if (auto existential = type->getAs<ExistentialType>())
908+
return existential->getConstraintType();
909+
return type;
910+
})->isEqual(Reconstructed)) &&
903911
!EqualUpToClangTypes().check(Reconstructed, Ty)) {
904912
// [FIXME: Include-Clang-type-in-mangling] Remove second check
905913
llvm::errs() << "Incorrect reconstructed type for " << Result << "\n";

0 commit comments

Comments
 (0)