@@ -556,8 +556,6 @@ void Serializer::writeBlockInfoBlock() {
556556 decls_block::GENERIC_PARAM);
557557 BLOCK_RECORD_WITH_NAMESPACE (sil_block,
558558 decls_block::GENERIC_REQUIREMENT);
559- BLOCK_RECORD_WITH_NAMESPACE (sil_block,
560- decls_block::SIL_GENERIC_ENVIRONMENT);
561559
562560 BLOCK (SIL_INDEX_BLOCK);
563561 BLOCK_RECORD (sil_index_block, SIL_FUNC_NAMES);
@@ -1011,25 +1009,32 @@ bool Serializer::writeGenericParams(const GenericParamList *genericParams) {
10111009 return true ;
10121010}
10131011
1014- void Serializer::writeGenericEnvironment (
1015- const GenericEnvironment *env,
1016- const std::array<unsigned , 256 > &abbrCodes,
1017- bool SILMode) {
1012+ void Serializer::writeGenericEnvironment (const GenericEnvironment *env) {
10181013 using namespace decls_block ;
10191014
10201015 // Record the offset of this generic environment.
1021- if (!SILMode) {
1022- auto id = GenericEnvironmentIDs[env];
1023- assert (id != 0 && " generic environment not referenced properly" );
1024- (void )id;
1016+ auto id = GenericEnvironmentIDs[env];
1017+ assert (id != 0 && " generic environment not referenced properly" );
1018+ (void )id;
10251019
1026- assert ((id - 1 ) == GenericEnvironmentOffsets.size ());
1027- GenericEnvironmentOffsets.push_back (Out.GetCurrentBitNo ());
1028- }
1020+ assert ((id - 1 ) == GenericEnvironmentOffsets.size ());
1021+ GenericEnvironmentOffsets.push_back (Out.GetCurrentBitNo ());
10291022
10301023 if (env == nullptr )
10311024 return ;
10321025
1026+ // Determine whether we must use SIL mode, because one of the generic
1027+ // parameters has a declaration with module context.
1028+ bool SILMode = false ;
1029+ for (auto *paramTy : env->getGenericParams ()) {
1030+ if (auto *decl = paramTy->getDecl ()) {
1031+ if (decl->getDeclContext ()->isModuleScopeContext ()) {
1032+ SILMode = true ;
1033+ break ;
1034+ }
1035+ }
1036+ }
1037+
10331038 // Record the generic parameters.
10341039 SmallVector<uint64_t , 4 > rawParamIDs;
10351040 for (auto *paramTy : env->getGenericParams ()) {
@@ -1050,20 +1055,17 @@ void Serializer::writeGenericEnvironment(
10501055 }
10511056
10521057 if (SILMode) {
1053- assert (&abbrCodes != &DeclTypeAbbrCodes);
1054- auto envAbbrCode = abbrCodes[SILGenericEnvironmentLayout::Code];
1058+ auto envAbbrCode = DeclTypeAbbrCodes[SILGenericEnvironmentLayout::Code];
10551059 SILGenericEnvironmentLayout::emitRecord (Out, ScratchRecord, envAbbrCode,
10561060 rawParamIDs);
1057- return ;
1061+ } else {
1062+ auto envAbbrCode = DeclTypeAbbrCodes[GenericEnvironmentLayout::Code];
1063+ GenericEnvironmentLayout::emitRecord (Out, ScratchRecord, envAbbrCode,
1064+ rawParamIDs);
10581065 }
10591066
1060- assert (&abbrCodes == &DeclTypeAbbrCodes);
1061- auto envAbbrCode = abbrCodes[GenericEnvironmentLayout::Code];
1062- GenericEnvironmentLayout::emitRecord (Out, ScratchRecord, envAbbrCode,
1063- rawParamIDs);
1064-
10651067 writeGenericRequirements (env->getGenericSignature ()->getRequirements (),
1066- abbrCodes );
1068+ DeclTypeAbbrCodes );
10671069}
10681070
10691071void Serializer::writeSILLayout (SILLayout *layout) {
@@ -3437,6 +3439,7 @@ void Serializer::writeAllDeclsAndTypes() {
34373439 registerDeclTypeAbbr<GenericParamLayout>();
34383440 registerDeclTypeAbbr<GenericRequirementLayout>();
34393441 registerDeclTypeAbbr<GenericEnvironmentLayout>();
3442+ registerDeclTypeAbbr<SILGenericEnvironmentLayout>();
34403443
34413444 registerDeclTypeAbbr<ForeignErrorConventionLayout>();
34423445 registerDeclTypeAbbr<DeclContextLayout>();
@@ -3498,7 +3501,7 @@ void Serializer::writeAllDeclsAndTypes() {
34983501 while (!GenericEnvironmentsToWrite.empty ()) {
34993502 auto next = GenericEnvironmentsToWrite.front ();
35003503 GenericEnvironmentsToWrite.pop ();
3501- writeGenericEnvironment (next, DeclTypeAbbrCodes, /* SILMode= */ false );
3504+ writeGenericEnvironment (next);
35023505 }
35033506
35043507 while (!NormalConformancesToWrite.empty ()) {
0 commit comments