Skip to content

Commit 3fa61e3

Browse files
authored
Merge pull request swiftlang#78956 from ahoppen/6.1/rdar141440011
[6.1] [Serialization] Ensure we run `InheritedTypeRequest` before serializing inherited type
2 parents ea69594 + c75df7c commit 3fa61e3

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4031,7 +4031,16 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
40314031
/// \returns the number of entries added.
40324032
size_t addInherited(InheritedTypes inheritedEntries,
40334033
SmallVectorImpl<TypeID> &result) {
4034-
for (const auto &inherited : inheritedEntries.getEntries()) {
4034+
for (size_t i : inheritedEntries.getIndices()) {
4035+
// Ensure that we run the `InheritedTypeRequest` before getting the
4036+
// inherited type. We serialize the inherited type from `getEntry` rather
4037+
// than `getResolvedType` since the former represents a suppressed
4038+
// conformance as a separate bit distinct from the type, which is how we
4039+
// want to serialize it. We thus need to get the type to serialize using a
4040+
// subsequent call to `getEntry(i).getType()` (see
4041+
// `InheritedTypeRequest::cacheResult`).
4042+
(void)inheritedEntries.getResolvedType(i);
4043+
const InheritedEntry &inherited = inheritedEntries.getEntry(i);
40354044
assert(!inherited.getType() || !inherited.getType()->hasArchetype());
40364045
TypeID typeRef = S.addTypeRef(inherited.getType());
40374046

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 %target-triple
6+
// RUN: %target-swift-synthesize-interface -module-name swift_mod -I %t -o - -target %target-triple | %FileCheck %s
7+
8+
// CHECK: public struct MyStruct : swift_mod.MyProto

test/Serialization/AllowErrors/invalid-inheritance.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ extension SomeStruct: undefined {} // expected-error {{cannot find type 'undefin
2727
extension SomeEnum: undefined {} // expected-error {{cannot find type 'undefined'}}
2828

2929
extension undefined {} // expected-error {{cannot find type 'undefined'}}
30-
extension undefined: undefined {} // expected-error {{cannot find type 'undefined'}}
30+
extension undefined: undefined {} // expected-error 2 {{cannot find type 'undefined'}}
3131
extension undefined: SomeProto {} // expected-error {{cannot find type 'undefined'}}
3232

3333
public extension undefined { // expected-error {{cannot find type 'undefined' in scope}}
3434
protocol SomeProtoInner: undefined {} // expected-error {{cannot find type 'undefined' in scope}}
35-
class SomeClassInner: undefined {}
36-
struct SomeStructInner: undefined {}
35+
class SomeClassInner: undefined {} // expected-error {{cannot find type 'undefined' in scope}}
36+
struct SomeStructInner: undefined {} // expected-error {{cannot find type 'undefined' in scope}}
3737
enum SomeEnumInner: undefined { // expected-error {{cannot find type 'undefined' in scope}}
3838
case a
3939
}

0 commit comments

Comments
 (0)