Skip to content

Commit c60b8fa

Browse files
committed
[Serialization] Ensure we run InheritedTypeRequest before serializing inherited type
When using `-experimental-skip-all-function-bodies` we don’t run the `TypeCheckSourceFileRequest` and thus don’t go through the decl checker, which calls `InheritedTypeRequest` on all inheritance clauses. This means that the inherited entries are not populated by the time we serialize the module. Trigger the computation of inherited entries by calling `InheritedTypeRequest` during serialization. Unfortunately, we can’t use the type returned by `getResolvedType` for the serialization because `getResolvedType` returns an inverted protocol type for suppressed conformances but during serialization, we want to serialize the suppressed type with a `isSuppressedBit`. We thus need to call `getEntry(i).getType()` again to get the type to serialize. rdar://141440011
1 parent 33eab01 commit c60b8fa

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4080,7 +4080,15 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
40804080
/// \returns the number of entries added.
40814081
size_t addInherited(InheritedTypes inheritedEntries,
40824082
SmallVectorImpl<uint64_t> &result) {
4083-
for (const auto &inherited : inheritedEntries.getEntries()) {
4083+
for (size_t i = 0; i < inheritedEntries.size(); ++i) {
4084+
// Ensure that we run the `InheritedTypeRequest` before getting the
4085+
// inherited type. We serialize the inherited type into the module
4086+
// because we serialize whether the conformance is suppressed as a
4087+
// separate bit instead of inside the inherited type itself. We thus need
4088+
// to get the type to serialize using a subsequent call to
4089+
// `getEntry(i).getType()` (see `InheritedTypeRequest::cacheResult`).
4090+
(void)inheritedEntries.getResolvedType(i);
4091+
const InheritedEntry &inherited = inheritedEntries.getEntry(i);
40844092
assert(!inherited.getType() || !inherited.getType()->hasArchetype());
40854093
uint64_t typeRef = S.addTypeRef(inherited.getType());
40864094
uint64_t originalTypeRef = typeRef;

test/IDE/rdar141440011.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public protocol MyProto {}
2+
public struct MyStruct: MyProto {}
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: %swift -emit-module -o %t/swift_mod.swiftmodule %s -parse-as-library -experimental-skip-all-function-bodies -experimental-skip-non-exportable-decls -experimental-lazy-typecheck -target arm64-apple-macosx13.0
6+
// RUN: %target-swift-synthesize-interface -module-name swift_mod -I %t -o - -target arm64-apple-macosx13.0 | %FileCheck %s
7+
8+
// CHECK: public struct MyStruct : swift_mod.MyProto

0 commit comments

Comments
 (0)