Skip to content

Commit 7f97ce3

Browse files
committed
ASTMangler: Support closures whose types contain local archetypes
1 parent 0d9df46 commit 7f97ce3

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

include/swift/AST/ASTMangler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,8 @@ class ASTMangler : public Mangler {
657657
void appendClosureEntity(const AbstractClosureExpr *closure);
658658

659659
void appendClosureComponents(Type Ty, unsigned discriminator, bool isImplicit,
660-
const DeclContext *parentContext);
660+
const DeclContext *parentContext,
661+
ArrayRef<GenericEnvironment *> capturedEnvs);
661662

662663
void appendDefaultArgumentEntity(const DeclContext *ctx, unsigned index);
663664

lib/AST/ASTMangler.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "swift/AST/GenericSignature.h"
2626
#include "swift/AST/Initializer.h"
2727
#include "swift/AST/LazyResolver.h"
28+
#include "swift/AST/LocalArchetypeRequirementCollector.h"
2829
#include "swift/AST/MacroDiscriminatorContext.h"
2930
#include "swift/AST/Module.h"
3031
#include "swift/AST/Ownership.h"
@@ -3728,29 +3729,48 @@ void ASTMangler::appendAssociatedTypeName(DependentMemberType *dmt,
37283729

37293730
void ASTMangler::appendClosureEntity(
37303731
const SerializedAbstractClosureExpr *closure) {
3732+
assert(!closure->getType()->hasLocalArchetype() &&
3733+
"Not enough information here to handle this case");
3734+
37313735
appendClosureComponents(closure->getType(), closure->getDiscriminator(),
3732-
closure->isImplicit(), closure->getParent());
3736+
closure->isImplicit(), closure->getParent(),
3737+
ArrayRef<GenericEnvironment *>());
37333738
}
37343739

37353740
void ASTMangler::appendClosureEntity(const AbstractClosureExpr *closure) {
3736-
appendClosureComponents(closure->getType(), closure->getDiscriminator(),
3737-
isa<AutoClosureExpr>(closure), closure->getParent());
3741+
ArrayRef<GenericEnvironment *> capturedEnvs;
3742+
3743+
auto type = closure->getType();
3744+
3745+
// FIXME: CodeCompletionResultBuilder calls printValueDeclUSR() but the
3746+
// closure hasn't been type checked yet.
3747+
if (!type)
3748+
type = ErrorType::get(closure->getASTContext());
3749+
3750+
if (type->hasLocalArchetype())
3751+
capturedEnvs = closure->getCaptureInfo().getGenericEnvironments();
3752+
3753+
appendClosureComponents(type, closure->getDiscriminator(),
3754+
isa<AutoClosureExpr>(closure), closure->getParent(),
3755+
capturedEnvs);
37383756
}
37393757

37403758
void ASTMangler::appendClosureComponents(Type Ty, unsigned discriminator,
37413759
bool isImplicit,
3742-
const DeclContext *parentContext) {
3760+
const DeclContext *parentContext,
3761+
ArrayRef<GenericEnvironment *> capturedEnvs) {
37433762
assert(discriminator != AbstractClosureExpr::InvalidDiscriminator
37443763
&& "closure must be marked correctly with discriminator");
37453764

37463765
BaseEntitySignature base(parentContext->getInnermostDeclarationDeclContext());
37473766
appendContext(parentContext, base, StringRef());
37483767

3749-
if (!Ty)
3750-
Ty = ErrorType::get(parentContext->getASTContext());
3751-
37523768
auto Sig = parentContext->getGenericSignatureOfContext();
3753-
Ty = Ty->mapTypeOutOfContext();
3769+
3770+
Ty = Ty.subst(MapLocalArchetypesOutOfContext(Sig, capturedEnvs),
3771+
MakeAbstractConformanceForGenericType(),
3772+
SubstFlags::PreservePackExpansionLevel);
3773+
37543774
appendType(Ty->getCanonicalType(), Sig);
37553775
appendOperator(isImplicit ? "fu" : "fU", Index(discriminator));
37563776
}

0 commit comments

Comments
 (0)