Skip to content

[6.1] [Serialization] Ensure we run InheritedTypeRequest before serializing inherited type #78956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4031,7 +4031,16 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
/// \returns the number of entries added.
size_t addInherited(InheritedTypes inheritedEntries,
SmallVectorImpl<TypeID> &result) {
for (const auto &inherited : inheritedEntries.getEntries()) {
for (size_t i : inheritedEntries.getIndices()) {
// Ensure that we run the `InheritedTypeRequest` before getting the
// inherited type. We serialize the inherited type from `getEntry` rather
// than `getResolvedType` since the former represents a suppressed
// conformance as a separate bit distinct from the type, which is how we
// want to serialize it. We thus need to get the type to serialize using a
// subsequent call to `getEntry(i).getType()` (see
// `InheritedTypeRequest::cacheResult`).
(void)inheritedEntries.getResolvedType(i);
const InheritedEntry &inherited = inheritedEntries.getEntry(i);
assert(!inherited.getType() || !inherited.getType()->hasArchetype());
TypeID typeRef = S.addTypeRef(inherited.getType());

Expand Down
8 changes: 8 additions & 0 deletions test/IDE/rdar141440011.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public protocol MyProto {}
public struct MyStruct: MyProto {}

// RUN: %empty-directory(%t)
// 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
// RUN: %target-swift-synthesize-interface -module-name swift_mod -I %t -o - -target %target-triple | %FileCheck %s

// CHECK: public struct MyStruct : swift_mod.MyProto
6 changes: 3 additions & 3 deletions test/Serialization/AllowErrors/invalid-inheritance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ extension SomeStruct: undefined {} // expected-error {{cannot find type 'undefin
extension SomeEnum: undefined {} // expected-error {{cannot find type 'undefined'}}

extension undefined {} // expected-error {{cannot find type 'undefined'}}
extension undefined: undefined {} // expected-error {{cannot find type 'undefined'}}
extension undefined: undefined {} // expected-error 2 {{cannot find type 'undefined'}}
extension undefined: SomeProto {} // expected-error {{cannot find type 'undefined'}}

public extension undefined { // expected-error {{cannot find type 'undefined' in scope}}
protocol SomeProtoInner: undefined {} // expected-error {{cannot find type 'undefined' in scope}}
class SomeClassInner: undefined {}
struct SomeStructInner: undefined {}
class SomeClassInner: undefined {} // expected-error {{cannot find type 'undefined' in scope}}
struct SomeStructInner: undefined {} // expected-error {{cannot find type 'undefined' in scope}}
enum SomeEnumInner: undefined { // expected-error {{cannot find type 'undefined' in scope}}
case a
}
Expand Down