Skip to content

Commit 3a8399d

Browse files
authored
Merge pull request #83900 from eeckstein/fix-sil-printer
SIL: fix printing of dependent existential archetypes
2 parents f9394ad + 833560f commit 3a8399d

File tree

4 files changed

+62
-42
lines changed

4 files changed

+62
-42
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7221,6 +7221,9 @@ class TypePrinter : public TypeVisitor<TypePrinter, void, NonRecursivePrintOptio
72217221
if (Options.PrintForSIL) {
72227222
auto *env = T->getGenericEnvironment();
72237223

7224+
if (!T->isRoot())
7225+
Printer << '(';
7226+
72247227
Printer << "@opened(\"" << env->getOpenedExistentialUUID() << "\", ";
72257228
auto existentialTy = env->maybeApplyOuterContextSubstitutions(
72267229
env->getOpenedExistentialType());
@@ -7232,7 +7235,8 @@ class TypePrinter : public TypeVisitor<TypePrinter, void, NonRecursivePrintOptio
72327235
auto interfaceTy = T->getInterfaceType();
72337236
auto selfTy = interfaceTy->getRootGenericParam();
72347237
auto &ctx = selfTy->getASTContext();
7235-
newAlternativeTypeNames[selfTy->getCanonicalType()] = ctx.Id_Self;
7238+
Identifier selfId = (T->isRoot() ? ctx.Id_Self : ctx.getIdentifier("Self)"));
7239+
newAlternativeTypeNames[selfTy->getCanonicalType()] = selfId;
72367240

72377241
PrintOptions::OverrideScope scope(Options);
72387242
OVERRIDE_PRINT_OPTION(scope, AlternativeTypeNames, &newAlternativeTypeNames);

test/SIL/Parser/basic.sil

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,22 @@ bb0:
17441744
return %1 : $()
17451745
}
17461746

1747+
protocol P2 {
1748+
associatedtype A
1749+
}
1750+
1751+
// CHECK-LABEL: sil [ossa] @test_dependent_existential_archetype :
1752+
// CHECK: %2 = alloc_stack $(@opened("0B7C132E-8010-11F0-8526-0EA13E3AABB4", any P2) Self).A
1753+
// CHECK-LABEL: } // end sil function 'test_dependent_existential_archetype'
1754+
sil [ossa] @test_dependent_existential_archetype : $@convention(thin) (@thick any P2.Type) -> () {
1755+
bb0(%0 : $@thick any P2.Type):
1756+
%1 = open_existential_metatype %0 to $@thick (@opened("0B7C132E-8010-11F0-8526-0EA13E3AABB4", any P2) Self).Type
1757+
%2 = alloc_stack $(@opened("0B7C132E-8010-11F0-8526-0EA13E3AABB4", any P2) Self).A
1758+
dealloc_stack %2
1759+
%r = tuple ()
1760+
return %r
1761+
}
1762+
17471763
class Foo2: Foo {}
17481764

17491765
// CHECK-LABEL: sil_vtable Foo {

0 commit comments

Comments
 (0)