Skip to content

Commit 408d745

Browse files
committed
Serialization: Don't serialize RequirementReprs
RequirementReprs stored serialized references to archetypes, which do not have enough information to reconstruct same-type requirements. For this reason, we would serialize the 'as written' requirement string as well as the actual types, which is a horrible hack. Now that the ASTPrinter and SourceKit use GenericSignatures, none of this is needed anymore.
1 parent 354416f commit 408d745

File tree

7 files changed

+4
-139
lines changed

7 files changed

+4
-139
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,20 +1025,6 @@ class RequirementRepr {
10251025
return SeparatorLoc;
10261026
}
10271027

1028-
/// Set during deserialization; used to print out the requirements accurately
1029-
/// for the generated interface.
1030-
StringRef getAsWrittenString() const {
1031-
return AsWrittenString;
1032-
}
1033-
void setAsWrittenString(StringRef Str) {
1034-
AsWrittenString = Str;
1035-
}
1036-
1037-
/// Further analyze the written string, if it's not empty, to collect the first
1038-
/// type, the second type and the requirement kind.
1039-
Optional<std::tuple<StringRef, StringRef, RequirementReprKind>>
1040-
getAsAnalyzedWrittenString() const;
1041-
10421028
SourceRange getSourceRange() const {
10431029
return SourceRange(Types[0].getSourceRange().Start,
10441030
Types[1].getSourceRange().End);
@@ -1048,7 +1034,6 @@ class RequirementRepr {
10481034
void dump() const LLVM_ATTRIBUTE_USED,
10491035
"only for use within the debugger");
10501036
void print(raw_ostream &OS) const;
1051-
void printAsWritten(raw_ostream &OS) const;
10521037
};
10531038

10541039
/// GenericParamList - A list of generic parameters that is part of a generic

include/swift/Serialization/DeclTypeRecordNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ OTHER(TOP_LEVEL_CODE_DECL_CONTEXT, 239)
168168
OTHER(GENERIC_PARAM_LIST, 240)
169169
TRAILING_INFO(GENERIC_PARAM)
170170
TRAILING_INFO(GENERIC_REQUIREMENT)
171-
TRAILING_INFO(LAST_GENERIC_REQUIREMENT)
172171
TRAILING_INFO(GENERIC_ENVIRONMENT)
173172

174173
OTHER(LOCAL_DISCRIMINATOR, 248)

include/swift/Serialization/ModuleFormat.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
5454
/// in source control, you should also update the comment to briefly
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
57-
const uint16_t VERSION_MINOR = 270; // Last change: parameter type flags
57+
const uint16_t VERSION_MINOR = 271; // Stop serializing RequirementReprs
5858

5959
using DeclID = PointerEmbeddedInt<unsigned, 31>;
6060
using DeclIDField = BCFixed<31>;
@@ -1117,19 +1117,7 @@ namespace decls_block {
11171117
GENERIC_REQUIREMENT,
11181118
GenericRequirementKindField, // requirement kind
11191119
TypeIDField, // types involved (two for conformance,
1120-
TypeIDField, // same-type; one for value witness marker)
1121-
BCBlob // as written string
1122-
>;
1123-
1124-
/// Placeholder that marks the last generic requirement in the generic
1125-
/// parameters list.
1126-
///
1127-
/// Used as a buffer between the generic parameter list's requirements and
1128-
/// the generic signature's requirements for nominal type declarations.
1129-
/// FIXME: Expected to go away once the latter is no longer serialized.
1130-
using LastGenericRequirementLayout = BCRecordLayout<
1131-
LAST_GENERIC_REQUIREMENT,
1132-
BCFixed<1> // dummy
1120+
TypeIDField // same-type; one for value witness marker)
11331121
>;
11341122

11351123
/// Specifies the private discriminator string for a private declaration. This

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,6 @@ void RequirementRepr::dump() const {
9090
llvm::errs() << "\n";
9191
}
9292

93-
Optional<std::tuple<StringRef, StringRef, RequirementReprKind>>
94-
RequirementRepr::getAsAnalyzedWrittenString() const {
95-
if (AsWrittenString.empty())
96-
return None;
97-
auto Pair = AsWrittenString.split("==");
98-
auto Kind = RequirementReprKind::SameType;
99-
if (Pair.second.empty()) {
100-
Pair = AsWrittenString.split(":");
101-
Kind = RequirementReprKind::TypeConstraint;
102-
}
103-
assert(!Pair.second.empty() && "cannot get second type.");
104-
return std::make_tuple(Pair.first.trim(), Pair.second.trim(), Kind);
105-
}
106-
10793
void RequirementRepr::printImpl(raw_ostream &out, bool AsWritten) const {
10894
auto printTy = [&](const TypeLoc &TyLoc) {
10995
if (AsWritten && TyLoc.getTypeRepr()) {
@@ -132,14 +118,6 @@ void RequirementRepr::print(raw_ostream &out) const {
132118
printImpl(out, /*AsWritten=*/false);
133119
}
134120

135-
void RequirementRepr::printAsWritten(raw_ostream &out) const {
136-
if (!AsWrittenString.empty()) {
137-
out << AsWrittenString;
138-
} else {
139-
printImpl(out, /*AsWritten=*/true);
140-
}
141-
}
142-
143121
void GenericParamList::print(llvm::raw_ostream &OS) {
144122
OS << '<';
145123
bool First = true;

lib/Serialization/Deserialization.cpp

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -705,57 +705,6 @@ GenericParamList *ModuleFile::maybeReadGenericParams(DeclContext *DC,
705705
params.push_back(genericParam);
706706
break;
707707
}
708-
case GENERIC_REQUIREMENT: {
709-
uint8_t rawKind;
710-
uint64_t rawTypeIDs[2];
711-
GenericRequirementLayout::readRecord(scratch, rawKind,
712-
rawTypeIDs[0], rawTypeIDs[1]);
713-
714-
switch (rawKind) {
715-
case GenericRequirementKind::Conformance: {
716-
auto subject = TypeLoc::withoutLoc(getType(rawTypeIDs[0]));
717-
auto constraint = TypeLoc::withoutLoc(getType(rawTypeIDs[1]));
718-
719-
requirements.push_back(RequirementRepr::getTypeConstraint(subject,
720-
SourceLoc(),
721-
constraint));
722-
break;
723-
}
724-
case GenericRequirementKind::SameType: {
725-
auto first = TypeLoc::withoutLoc(getType(rawTypeIDs[0]));
726-
auto second = TypeLoc::withoutLoc(getType(rawTypeIDs[1]));
727-
728-
requirements.push_back(RequirementRepr::getSameType(first,
729-
SourceLoc(),
730-
second));
731-
break;
732-
}
733-
734-
case GenericRequirementKind::Superclass:
735-
case WitnessMarker: {
736-
// Shouldn't happen where we have requirement representations.
737-
error();
738-
break;
739-
}
740-
741-
default:
742-
// Unknown requirement kind. Drop the requirement and continue, but log
743-
// an error so that we don't actually try to generate code.
744-
error();
745-
}
746-
747-
requirements.back().setAsWrittenString(blobData);
748-
749-
break;
750-
}
751-
case LAST_GENERIC_REQUIREMENT:
752-
// Read the end-of-requirements record.
753-
uint8_t dummy;
754-
LastGenericRequirementLayout::readRecord(scratch, dummy);
755-
lastRecordOffset.reset();
756-
shouldContinue = false;
757-
break;
758-
759708
default:
760709
// This record is not part of the GenericParamList.
761710
shouldContinue = false;
@@ -767,7 +716,7 @@ GenericParamList *ModuleFile::maybeReadGenericParams(DeclContext *DC,
767716
}
768717

769718
auto paramList = GenericParamList::create(getContext(), SourceLoc(),
770-
params, SourceLoc(), requirements,
719+
params, SourceLoc(), { },
771720
SourceLoc());
772721
paramList->setOuterParameters(outerParams ? outerParams :
773722
DC->getGenericParamsOfContext());

lib/Serialization/SILFormat.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ namespace sil_block {
157157
GENERIC_PARAM_LIST = decls_block::GENERIC_PARAM_LIST,
158158
GENERIC_PARAM = decls_block::GENERIC_PARAM,
159159
GENERIC_REQUIREMENT = decls_block::GENERIC_REQUIREMENT,
160-
LAST_GENERIC_REQUIREMENT = decls_block::LAST_GENERIC_REQUIREMENT,
161160
};
162161

163162
using SILInstNoOperandLayout = BCRecordLayout<

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,6 @@ void Serializer::writeBlockInfoBlock() {
527527
decls_block::GENERIC_PARAM);
528528
BLOCK_RECORD_WITH_NAMESPACE(sil_block,
529529
decls_block::GENERIC_REQUIREMENT);
530-
BLOCK_RECORD_WITH_NAMESPACE(sil_block,
531-
decls_block::LAST_GENERIC_REQUIREMENT);
532530
BLOCK_RECORD_WITH_NAMESPACE(sil_block,
533531
decls_block::GENERIC_ENVIRONMENT);
534532

@@ -950,8 +948,7 @@ void Serializer::writeGenericRequirements(ArrayRef<Requirement> requirements) {
950948
Out, ScratchRecord, reqAbbrCode,
951949
getRawStableRequirementKind(req.getKind()),
952950
addTypeRef(req.getFirstType()),
953-
addTypeRef(req.getSecondType()),
954-
StringRef());
951+
addTypeRef(req.getSecondType()));
955952
}
956953
}
957954

@@ -971,35 +968,6 @@ bool Serializer::writeGenericParams(const GenericParamList *genericParams) {
971968
addDeclRef(next));
972969
}
973970

974-
abbrCode = DeclTypeAbbrCodes[GenericRequirementLayout::Code];
975-
SmallString<64> ReqStr;
976-
for (auto next : genericParams->getRequirements()) {
977-
ReqStr.clear();
978-
llvm::raw_svector_ostream ReqOS(ReqStr);
979-
next.printAsWritten(ReqOS);
980-
switch (next.getKind()) {
981-
case RequirementReprKind::TypeConstraint:
982-
GenericRequirementLayout::emitRecord(
983-
Out, ScratchRecord, abbrCode,
984-
GenericRequirementKind::Conformance,
985-
addTypeRef(next.getSubject()),
986-
addTypeRef(next.getConstraint()),
987-
ReqOS.str());
988-
break;
989-
case RequirementReprKind::SameType:
990-
GenericRequirementLayout::emitRecord(
991-
Out, ScratchRecord, abbrCode,
992-
GenericRequirementKind::SameType,
993-
addTypeRef(next.getFirstType()),
994-
addTypeRef(next.getSecondType()),
995-
ReqOS.str());
996-
break;
997-
}
998-
}
999-
1000-
abbrCode = DeclTypeAbbrCodes[LastGenericRequirementLayout::Code];
1001-
uint8_t dummy = 0;
1002-
LastGenericRequirementLayout::emitRecord(Out, ScratchRecord, abbrCode, dummy);
1003971
return true;
1004972
}
1005973

@@ -3303,7 +3271,6 @@ void Serializer::writeAllDeclsAndTypes() {
33033271
registerDeclTypeAbbr<GenericParamListLayout>();
33043272
registerDeclTypeAbbr<GenericParamLayout>();
33053273
registerDeclTypeAbbr<GenericRequirementLayout>();
3306-
registerDeclTypeAbbr<LastGenericRequirementLayout>();
33073274
registerDeclTypeAbbr<GenericEnvironmentLayout>();
33083275

33093276
registerDeclTypeAbbr<ForeignErrorConventionLayout>();

0 commit comments

Comments
 (0)