mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #16268 from DougGregor/substitution-map-ast-adoption
[AST] Adopt SubstitutionMap as the storage mechanism for substitutions
This commit is contained in:
@@ -568,6 +568,19 @@ GenericEnvironmentID Serializer::addGenericEnvironmentRef(
|
||||
return id;
|
||||
}
|
||||
|
||||
SubstitutionMapID Serializer::addSubstitutionMapRef(
|
||||
SubstitutionMap substitutions) {
|
||||
if (!substitutions) return 0;
|
||||
|
||||
auto &id = SubstitutionMapIDs[substitutions];
|
||||
if (id != 0)
|
||||
return id;
|
||||
|
||||
id = ++LastSubstitutionMapID;
|
||||
SubstitutionMapsToWrite.push(substitutions);
|
||||
return id;
|
||||
}
|
||||
|
||||
DeclContextID Serializer::addDeclContextRef(const DeclContext *DC) {
|
||||
switch (DC->getContextKind()) {
|
||||
case DeclContextKind::Module:
|
||||
@@ -787,6 +800,7 @@ void Serializer::writeBlockInfoBlock() {
|
||||
BLOCK_RECORD(index_block, LOCAL_DECL_CONTEXT_OFFSETS);
|
||||
BLOCK_RECORD(index_block, GENERIC_SIGNATURE_OFFSETS);
|
||||
BLOCK_RECORD(index_block, GENERIC_ENVIRONMENT_OFFSETS);
|
||||
BLOCK_RECORD(index_block, SUBSTITUTION_MAP_OFFSETS);
|
||||
BLOCK_RECORD(index_block, DECL_CONTEXT_OFFSETS);
|
||||
BLOCK_RECORD(index_block, LOCAL_TYPE_DECLS);
|
||||
BLOCK_RECORD(index_block, NORMAL_CONFORMANCE_OFFSETS);
|
||||
@@ -1459,6 +1473,34 @@ void Serializer::writeGenericEnvironment(const GenericEnvironment *env) {
|
||||
DeclTypeAbbrCodes);
|
||||
}
|
||||
|
||||
void Serializer::writeSubstitutionMap(const SubstitutionMap substitutions) {
|
||||
using namespace decls_block;
|
||||
assert(substitutions);
|
||||
|
||||
// Record the offset of this substitution map.
|
||||
auto id = SubstitutionMapIDs[substitutions];
|
||||
assert(id != 0 && "generic environment not referenced properly");
|
||||
(void)id;
|
||||
|
||||
// Record the current bit.
|
||||
assert((id - 1) == SubstitutionMapOffsets.size());
|
||||
SubstitutionMapOffsets.push_back(Out.GetCurrentBitNo());
|
||||
|
||||
// Collect the replacement types.
|
||||
SmallVector<uint64_t, 4> rawReplacementTypes;
|
||||
for (auto type : substitutions.getReplacementTypes())
|
||||
rawReplacementTypes.push_back(addTypeRef(type));
|
||||
|
||||
auto substitutionsAbbrCode = DeclTypeAbbrCodes[SubstitutionMapLayout::Code];
|
||||
SubstitutionMapLayout::emitRecord(Out, ScratchRecord, substitutionsAbbrCode,
|
||||
addGenericSignatureRef(
|
||||
substitutions.getGenericSignature()),
|
||||
substitutions.getConformances().size(),
|
||||
rawReplacementTypes);
|
||||
|
||||
writeConformances(substitutions.getConformances(), DeclTypeAbbrCodes);
|
||||
}
|
||||
|
||||
void Serializer::writeSILLayout(SILLayout *layout) {
|
||||
using namespace decls_block;
|
||||
auto foundLayoutID = SILLayouts.find(layout);
|
||||
@@ -3623,14 +3665,13 @@ void Serializer::writeType(Type ty) {
|
||||
|
||||
unsigned abbrCode = DeclTypeAbbrCodes[NameAliasTypeLayout::Code];
|
||||
NameAliasTypeLayout::emitRecord(
|
||||
Out, ScratchRecord, abbrCode,
|
||||
addDeclRef(typeAlias,
|
||||
/*forceSerialization*/false,
|
||||
/*allowTypeAliasXRef*/true),
|
||||
addTypeRef(alias->getParent()),
|
||||
addTypeRef(alias->getSinglyDesugaredType()));
|
||||
// Write the set of substitutions.
|
||||
writeSubstitutions(alias->getSubstitutionList(), DeclTypeAbbrCodes);
|
||||
Out, ScratchRecord, abbrCode,
|
||||
addDeclRef(typeAlias,
|
||||
/*forceSerialization*/false,
|
||||
/*allowTypeAliasXRef*/true),
|
||||
addTypeRef(alias->getParent()),
|
||||
addTypeRef(alias->getSinglyDesugaredType()),
|
||||
addSubstitutionMapRef(alias->getSubstitutionMap()));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -4053,6 +4094,7 @@ void Serializer::writeAllDeclsAndTypes() {
|
||||
registerDeclTypeAbbr<LayoutRequirementLayout>();
|
||||
registerDeclTypeAbbr<GenericSignatureLayout>();
|
||||
registerDeclTypeAbbr<SILGenericEnvironmentLayout>();
|
||||
registerDeclTypeAbbr<SubstitutionMapLayout>();
|
||||
|
||||
registerDeclTypeAbbr<ForeignErrorConventionLayout>();
|
||||
registerDeclTypeAbbr<DeclContextLayout>();
|
||||
@@ -4123,6 +4165,12 @@ void Serializer::writeAllDeclsAndTypes() {
|
||||
writeGenericEnvironment(next);
|
||||
}
|
||||
|
||||
while (!SubstitutionMapsToWrite.empty()) {
|
||||
auto next = SubstitutionMapsToWrite.front();
|
||||
SubstitutionMapsToWrite.pop();
|
||||
writeSubstitutionMap(next);
|
||||
}
|
||||
|
||||
while (!NormalConformancesToWrite.empty()) {
|
||||
auto next = NormalConformancesToWrite.front();
|
||||
NormalConformancesToWrite.pop();
|
||||
@@ -4140,6 +4188,7 @@ void Serializer::writeAllDeclsAndTypes() {
|
||||
!SILLayoutsToWrite.empty() ||
|
||||
!GenericSignaturesToWrite.empty() ||
|
||||
!GenericEnvironmentsToWrite.empty() ||
|
||||
!SubstitutionMapsToWrite.empty() ||
|
||||
!NormalConformancesToWrite.empty());
|
||||
}
|
||||
|
||||
@@ -4938,6 +4987,7 @@ void Serializer::writeAST(ModuleOrSourceFile DC,
|
||||
writeOffsets(Offsets, LocalDeclContextOffsets);
|
||||
writeOffsets(Offsets, GenericSignatureOffsets);
|
||||
writeOffsets(Offsets, GenericEnvironmentOffsets);
|
||||
writeOffsets(Offsets, SubstitutionMapOffsets);
|
||||
writeOffsets(Offsets, NormalConformanceOffsets);
|
||||
writeOffsets(Offsets, SILLayoutOffsets);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user