Skip to content

[Serialization] Deal with ErrorTypes in specialized conformances #17523

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
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/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@ ModuleFile::maybeReadSubstitution(llvm::BitstreamCursor &cursor,
numConformances);

auto replacementTy = getType(replacementID);
if (!replacementTy)
replacementTy = ErrorType::get(getContext());
if (genericEnv) {
replacementTy = genericEnv->mapTypeIntoContext(replacementTy);
}
Expand Down
8 changes: 6 additions & 2 deletions lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,8 @@ Serializer::writeConformance(ProtocolConformanceRef conformanceRef,
abbrCode,
addTypeRef(type),
substitutions.size());
writeSubstitutions(substitutions, abbrCodes, genericEnv);
writeSubstitutions(substitutions, abbrCodes, genericEnv,
/*ignoreReplacementErrors*/true);

writeConformance(conf->getGenericConformance(), abbrCodes, genericEnv);
break;
Expand Down Expand Up @@ -1691,7 +1692,8 @@ Serializer::writeConformances(ArrayRef<ProtocolConformance*> conformances,
void
Serializer::writeSubstitutions(SubstitutionList substitutions,
const std::array<unsigned, 256> &abbrCodes,
GenericEnvironment *genericEnv) {
GenericEnvironment *genericEnv,
bool ignoreReplacementErrors) {
using namespace decls_block;
auto abbrCode = abbrCodes[BoundGenericSubstitutionLayout::Code];

Expand All @@ -1700,6 +1702,8 @@ Serializer::writeSubstitutions(SubstitutionList substitutions,
if (genericEnv && replacementType->hasArchetype()) {
replacementType = replacementType->mapTypeOutOfContext();
}
if (replacementType->hasError() && ignoreReplacementErrors)
replacementType = Type();

BoundGenericSubstitutionLayout::emitRecord(
Out, ScratchRecord, abbrCode,
Expand Down
3 changes: 2 additions & 1 deletion lib/Serialization/Serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ class Serializer {
/// being written.
void writeSubstitutions(SubstitutionList substitutions,
const std::array<unsigned, 256> &abbrCodes,
GenericEnvironment *genericEnv = nullptr);
GenericEnvironment *genericEnv = nullptr,
bool ignoreReplacementErrors = false);

/// Write a normal protocol conformance.
void writeNormalConformance(const NormalProtocolConformance *conformance);
Expand Down
20 changes: 20 additions & 0 deletions validation-test/Serialization/SR7337.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -emit-module -o %t/Lib.swiftmodule %s -DLIB
// RUN: %target-build-swift -emit-module -o %t/main.swiftmodule -I %t %s

#if LIB

protocol Proto {}

open class Base<T> {}
public struct ArbitraryStruct {}

extension Base: Proto where T: Proto {}

#else // LIB

import Lib

final class ConcreteSub: Base<ArbitraryStruct> {}

#endif // LIB