Skip to content

Commit cf27663

Browse files
committed
ASTMangler: Support closures whose types contain local archetypes
1 parent a40a6e2 commit cf27663

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
@@ -656,7 +656,8 @@ class ASTMangler : public Mangler {
656656
void appendClosureEntity(const AbstractClosureExpr *closure);
657657

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

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

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"
@@ -3733,29 +3734,48 @@ void ASTMangler::appendAssociatedTypeName(DependentMemberType *dmt,
37333734

37343735
void ASTMangler::appendClosureEntity(
37353736
const SerializedAbstractClosureExpr *closure) {
3737+
assert(!closure->getType()->hasLocalArchetype() &&
3738+
"Not enough information here to handle this case");
3739+
37363740
appendClosureComponents(closure->getType(), closure->getDiscriminator(),
3737-
closure->isImplicit(), closure->getParent());
3741+
closure->isImplicit(), closure->getParent(),
3742+
ArrayRef<GenericEnvironment *>());
37383743
}
37393744

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

37453763
void ASTMangler::appendClosureComponents(Type Ty, unsigned discriminator,
37463764
bool isImplicit,
3747-
const DeclContext *parentContext) {
3765+
const DeclContext *parentContext,
3766+
ArrayRef<GenericEnvironment *> capturedEnvs) {
37483767
assert(discriminator != AbstractClosureExpr::InvalidDiscriminator
37493768
&& "closure must be marked correctly with discriminator");
37503769

37513770
BaseEntitySignature base(parentContext->getInnermostDeclarationDeclContext());
37523771
appendContext(parentContext, base, StringRef());
37533772

3754-
if (!Ty)
3755-
Ty = ErrorType::get(parentContext->getASTContext());
3756-
37573773
auto Sig = parentContext->getGenericSignatureOfContext();
3758-
Ty = Ty->mapTypeOutOfContext();
3774+
3775+
Ty = Ty.subst(MapLocalArchetypesOutOfContext(Sig, capturedEnvs),
3776+
MakeAbstractConformanceForGenericType(),
3777+
SubstFlags::PreservePackExpansionLevel);
3778+
37593779
appendType(Ty->getCanonicalType(), Sig);
37603780
appendOperator(isImplicit ? "fu" : "fU", Index(discriminator));
37613781
}

0 commit comments

Comments
 (0)