Skip to content

Commit be56e43

Browse files
committed
ASTMangler: Compute canonical type earlier
1 parent 715b4c0 commit be56e43

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

include/swift/AST/ASTMangler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ class ASTMangler : public Mangler {
680680

681681
void appendClosureEntity(const AbstractClosureExpr *closure);
682682

683-
void appendClosureComponents(Type Ty, unsigned discriminator, bool isImplicit,
683+
void appendClosureComponents(CanType Ty, unsigned discriminator, bool isImplicit,
684684
const DeclContext *parentContext,
685685
ArrayRef<GenericEnvironment *> capturedEnvs);
686686

lib/AST/ASTMangler.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3752,10 +3752,12 @@ void ASTMangler::appendAssociatedTypeName(DependentMemberType *dmt,
37523752

37533753
void ASTMangler::appendClosureEntity(
37543754
const SerializedAbstractClosureExpr *closure) {
3755-
assert(!closure->getType()->hasLocalArchetype() &&
3755+
auto canType = closure->getType()->getCanonicalType();
3756+
assert(!canType->hasLocalArchetype() &&
37563757
"Not enough information here to handle this case");
37573758

3758-
appendClosureComponents(closure->getType(), closure->getDiscriminator(),
3759+
appendClosureComponents(canType,
3760+
closure->getDiscriminator(),
37593761
closure->isImplicit(), closure->getParent(),
37603762
ArrayRef<GenericEnvironment *>());
37613763
}
@@ -3769,17 +3771,18 @@ void ASTMangler::appendClosureEntity(const AbstractClosureExpr *closure) {
37693771
// code; the type-checker currently isn't strict about producing typed
37703772
// expression nodes when it fails. Once we enforce that, we can remove this.
37713773
if (!type)
3772-
type = ErrorType::get(closure->getASTContext());
3774+
type = CanType(ErrorType::get(closure->getASTContext()));
37733775

3774-
if (type->hasLocalArchetype())
3776+
auto canType = type->getCanonicalType();
3777+
if (canType->hasLocalArchetype())
37753778
capturedEnvs = closure->getCaptureInfo().getGenericEnvironments();
37763779

3777-
appendClosureComponents(type, closure->getDiscriminator(),
3780+
appendClosureComponents(canType, closure->getDiscriminator(),
37783781
isa<AutoClosureExpr>(closure), closure->getParent(),
37793782
capturedEnvs);
37803783
}
37813784

3782-
void ASTMangler::appendClosureComponents(Type Ty, unsigned discriminator,
3785+
void ASTMangler::appendClosureComponents(CanType Ty, unsigned discriminator,
37833786
bool isImplicit,
37843787
const DeclContext *parentContext,
37853788
ArrayRef<GenericEnvironment *> capturedEnvs) {
@@ -3793,9 +3796,9 @@ void ASTMangler::appendClosureComponents(Type Ty, unsigned discriminator,
37933796

37943797
Ty = Ty.subst(MapLocalArchetypesOutOfContext(Sig, capturedEnvs),
37953798
MakeAbstractConformanceForGenericType(),
3796-
SubstFlags::PreservePackExpansionLevel);
3799+
SubstFlags::PreservePackExpansionLevel)->getCanonicalType();
37973800

3798-
appendType(Ty->getCanonicalType(), Sig);
3801+
appendType(Ty, Sig);
37993802
appendOperator(isImplicit ? "fu" : "fU", Index(discriminator));
38003803
}
38013804

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
2+
3+
struct S {
4+
var y: Int { fatalError() }
5+
}
6+
7+
struct G<Element> {
8+
func f<T>(_: (Element) -> T) -> [T] { fatalError() }
9+
}
10+
11+
protocol P {
12+
typealias A = S
13+
var x: G<A> { get }
14+
}
15+
16+
// CHECK-LABEL: sil private [ossa] @$s29phantom_existential_typealias5test11pSaySiGAA1P_p_tFSiAA1SVXEfU_ : $@convention(thin) @substituted <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0) -> @out τ_0_1 for <S, Int> {
17+
18+
func test1(p: any P) -> [Int] {
19+
return p.x.f { $0.y }
20+
}

0 commit comments

Comments
 (0)