Skip to content

Commit efa5773

Browse files
[Prototype] Use nominal type decl instead of canonical type to compute GUID
This is necessary to support generic type reference
1 parent 20e3699 commit efa5773

File tree

4 files changed

+63
-28
lines changed

4 files changed

+63
-28
lines changed

lib/Serialization/ModuleSummaryIndexer.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ GUID modulesummary::getGUIDFromUniqueName(llvm::StringRef Name) {
1616
return llvm::MD5Hash(Name);
1717
}
1818

19-
static GUID getTypeGUID(Type type) {
19+
static GUID getTypeGUID(NominalTypeDecl *type) {
2020
Mangle::ASTMangler mangler;
21-
std::string mangled = mangler.mangleTypeWithoutPrefix(type);
21+
std::string mangled = mangler.mangleNominalType(type);
2222
return getGUIDFromUniqueName(mangled);
2323
}
2424

@@ -111,13 +111,11 @@ void FunctionSummaryIndexer::indexIndirectFunctionCall(
111111
void FunctionSummaryIndexer::indexUseOfType(CanType type) {
112112
Mangle::ASTMangler mangler;
113113
type.visit([&](Type t) {
114-
if (t.getPointer()->hasArchetype() ||
115-
t.getPointer()->hasOpaqueArchetype() ||
116-
t.getPointer()->getKind() == TypeKind::SILBlockStorage ||
117-
t.getPointer()->getKind() == TypeKind::SILFunction) {
114+
auto *decl = t->getAnyNominal();
115+
if (!decl) {
118116
return;
119117
}
120-
std::string mangled = mangler.mangleTypeWithoutPrefix(t);
118+
std::string mangled = mangler.mangleNominalType(decl);
121119
GUID guid = getGUIDFromUniqueName(mangled);
122120
if (RecordedTypes.insert(guid).second) {
123121
TheSummary->addTypeRef({guid, mangled});
@@ -384,7 +382,7 @@ void ModuleSummaryIndexer::indexWitnessTable(const SILWitnessTable &WT) {
384382
auto isPossibllyUsedExternally =
385383
WT.getDeclContext()->getParentModule() != Mod.getSwiftModule() ||
386384
WT.getProtocol()->getParentModule() != Mod.getSwiftModule();
387-
auto typeGUID = getTypeGUID(WT.getConformingType());
385+
auto typeGUID = getTypeGUID(WT.getConformingType()->getAnyNominal());
388386
for (auto entry : WT.getEntries()) {
389387
if (entry.getKind() != SILWitnessTable::Method)
390388
continue;
@@ -405,7 +403,7 @@ void ModuleSummaryIndexer::indexWitnessTable(const SILWitnessTable &WT) {
405403
}
406404

407405
void ModuleSummaryIndexer::indexVTable(const SILVTable &VT) {
408-
auto typeGUID = getTypeGUID(VT.getClass()->getDeclaredType()->getCanonicalType());
406+
auto typeGUID = getTypeGUID(VT.getClass());
409407
for (auto entry : VT.getEntries()) {
410408
auto Impl = entry.getImplementation();
411409
if (entry.getMethod().kind == SILDeclRef::Kind::Deallocator ||
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-sib -emit-module-summary-path %t/default_wt.swiftmodule.summary -module-name default_wt -Xllvm -module-summary-embed-debug-name %s
3+
// RUN: %swift_frontend_plain -cross-module-opt %t/default_wt.swiftmodule.summary -module-summary-embed-debug-name -o %t/default_wt.swiftmodule.merged-summary
4+
// RUN: %swift-module-summary-test --to-yaml %t/default_wt.swiftmodule.merged-summary -o %t/default_wt.merged-summary.yaml
5+
6+
// Ensure that optimizer won't eliminate PrimitiveSequenceType.getPrimitiveSequence
7+
// RUN: %target-swift-frontend -c -module-summary-path %t/default_wt.swiftmodule.merged-summary default_wt.sib -o %t/default_wt.o
8+
// RUN: %target-swiftc_driver %t/default_wt.o -o %t/default_wt
9+
// RUN: %t/default_wt
10+
11+
// RUN: cat %t/default_wt.merged-summary.yaml | %FileCheck %s
12+
// CHECK: 8732890044670327403:
13+
// CHECK-NEXT: name: '$s10default_wt11HappyStructV13requiredValueSiyF'
14+
// CHECK-NEXT: guid: 8732890044670327403
15+
// CHECK-NEXT: live: true
16+
17+
protocol HappyProtocol {
18+
func requiredValue() -> Int
19+
}
20+
21+
extension HappyProtocol {
22+
// Need to access requiredValue indirectly through wt
23+
@_optimize(none)
24+
func getRequiredValue() -> Int {
25+
return requiredValue()
26+
}
27+
}
28+
29+
struct HappyStruct<T> : HappyProtocol {
30+
func requiredValue() -> Int { 1 }
31+
}
32+
33+
func consume(_ v: HappyStruct<Int>) {
34+
_ = v.getRequiredValue()
35+
}
36+
37+
consume(HappyStruct<Int>())

test/Serialization/module_summary_tables.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
// CHECK: witness_tables:
1919
// CHECK-NEXT: 2682576275888919121:
2020
// CHECK-NEXT: - guid: 767048646313834908
21-
// CHECK-NEXT: type_guid: 16119760784751072103
21+
// CHECK-NEXT: type_guid: 16808374101942615301
2222
// `classMember` impls are recorded on the table
2323
// CHECK: vtables:
2424
// CHECK: 17602567966448237004:
2525
// CHECK-NEXT: - guid: 17602567966448237004
26-
// CHECK-NEXT: type_guid: 3703703597861618193
26+
// CHECK-NEXT: type_guid: 6261216615345887281
2727
// CHECK-NEXT: - guid: 11756327503593502600
28-
// CHECK-NEXT: type_guid: 9043091933214513226
28+
// CHECK-NEXT: type_guid: 1726984972356197982
2929

3030
protocol P {
3131
func protoMember()

test/Serialization/type_refs_summary.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@
1515
// SIMPLE-COERCE-NEXT: preserved: false
1616
// SIMPLE-COERCE-NEXT: calls: []
1717
// SIMPLE-COERCE-NEXT: type_refs:
18-
// SIMPLE-COERCE-NEXT: - name: 9type_refs1DC
19-
// SIMPLE-COERCE-NEXT: guid: 1332210649212571009
20-
21-
// SIMPLE-COERCE: name: '$s9type_refs11coerceToAnyyypAA1CCF'
22-
// SIMPLE-COERCE-NEXT: guid: 1940219073901329473
23-
// SIMPLE-COERCE-NEXT: live: false
24-
// SIMPLE-COERCE-NEXT: preserved: false
25-
// SIMPLE-COERCE-NEXT: calls: []
26-
// SIMPLE-COERCE-NEXT: type_refs:
27-
// SIMPLE-COERCE-NEXT: - name: 9type_refs1CC
28-
// SIMPLE-COERCE-NEXT: guid: 14053292587484144632
18+
// SIMPLE-COERCE-NEXT: - name: '$s9type_refs1DC'
19+
// SIMPLE-COERCE-NEXT: guid: 9126595621082655001
20+
21+
// SIMPLE-COERCE: name: '$s9type_refs11coerceToAnyyypAA1CCF'
22+
// SIMPLE-COERCE-NEXT: guid: 1940219073901329473
23+
// SIMPLE-COERCE-NEXT: live: false
24+
// SIMPLE-COERCE-NEXT: preserved: false
25+
// SIMPLE-COERCE-NEXT: calls: []
26+
// SIMPLE-COERCE-NEXT: type_refs:
27+
// SIMPLE-COERCE-NEXT: - name: '$s9type_refs1CC'
28+
// SIMPLE-COERCE-NEXT: guid: 3331627721515121492
2929

3030
// SIMPLE-COERCE: name: '$s9type_refs9coerceToPyAA1P_pAA1SVF'
3131
// SIMPLE-COERCE-NEXT: guid: 15452386893050095333
3232
// SIMPLE-COERCE-NEXT: live: false
3333
// SIMPLE-COERCE-NEXT: preserved: false
3434
// SIMPLE-COERCE-NEXT: calls: []
3535
// SIMPLE-COERCE-NEXT: type_refs:
36-
// SIMPLE-COERCE-NEXT: - name: 9type_refs1SV
37-
// SIMPLE-COERCE-NEXT: guid: 12736589225588998764
36+
// SIMPLE-COERCE-NEXT: - name: '$s9type_refs1SV'
37+
// SIMPLE-COERCE-NEXT: guid: 5397591673202260225
3838

3939

4040

@@ -47,7 +47,7 @@
4747
// WITNESS-IMPL: witness_tables:
4848
// WITNESS-IMPL-NEXT: 17891631795932606560:
4949
// WITNESS-IMPL-NEXT: - guid: 12925277474523063582
50-
// WITNESS-IMPL-NEXT: type_guid: 12736589225588998764
50+
// WITNESS-IMPL-NEXT: type_guid: 5397591673202260225
5151

5252

5353
// Ensure that vtable impl of C.bar and D.bar have type ref to C
@@ -61,9 +61,9 @@
6161

6262
// VTABLE-IMPL: 14897920476774525675:
6363
// VTABLE-IMPL-NEXT: - guid: 14897920476774525675
64-
// VTABLE-IMPL-NEXT: type_guid: 14053292587484144632
64+
// VTABLE-IMPL-NEXT: type_guid: 3331627721515121492
6565
// VTABLE-IMPL-NEXT: - guid: 16977749031506698911
66-
// VTABLE-IMPL-NEXT: type_guid: 1332210649212571009
66+
// VTABLE-IMPL-NEXT: type_guid: 9126595621082655001
6767

6868

6969
// RUN: %swift_frontend_plain -cross-module-opt %t/type_refs.swiftmodule.summary -module-summary-embed-debug-name -o %t/type_refs.swiftmodule.merged-summary

0 commit comments

Comments
 (0)