Skip to content

[5.5][Serialization] Skip MissingMembers when allowing errors #37560

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
May 21, 2021
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
2 changes: 2 additions & 0 deletions lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,8 @@ static bool shouldSerializeMember(Decl *D) {
llvm_unreachable("decl should never be a member");

case DeclKind::MissingMember:
if (D->getASTContext().LangOpts.AllowModuleWithCompilerErrors)
return false;
llvm_unreachable("should never need to reserialize a member placeholder");

case DeclKind::IfConfig:
Expand Down
41 changes: 41 additions & 0 deletions test/Serialization/AllowErrors/invalid-xref.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/mods)

// RUN: touch %t/empty.swift
// RUN: %{python} %utils/split_file.py -o %t %s

// We're going to swap A and B around to cause an invalid xref
// RUN: %target-swift-frontend -emit-module -o %t/mods/A.swiftmodule -module-name A %t/lib.swift
// RUN: %target-swift-frontend -emit-module -o %t/mods/B.swiftmodule -module-name B %t/empty.swift

// Compile using SomeType from A
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errorsmain.partial.swiftmodule -I %t/mods %t/errors.swift
// Empty module so we can do a merge modules step
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errorsempty.partial.swiftmodule %t/empty.swift

// Swap A and B
// RUN: %target-swift-frontend -emit-module -o %t/mods/A.swiftmodule -module-name A %t/empty.swift
// RUN: %target-swift-frontend -emit-module -o %t/mods/B.swiftmodule -module-name B %t/lib.swift

// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errors.swiftmodule -experimental-allow-module-with-compiler-errors %t/mods/errorsmain.partial.swiftmodule %t/mods/errorsempty.partial.swiftmodule

// Expect this to crash without allowing errors (we should never get into a
// situation where merge modules is run with MissingMemberDecls)
// RUN: not --crash %target-swift-frontend -module-name errors -emit-module -o %t/mods/errors.swiftmodule %t/mods/errorsmain.partial.swiftmodule %t/mods/errorsempty.partial.swiftmodule

// BEGIN lib.swift
public struct SomeType {
public init() {}
}


// BEGIN errors.swift
import A
import B

public class SomeClass {
public let member: SomeType
public init(member: SomeType) {
self.member = member
}
}