@@ -1071,20 +1071,7 @@ bool LinkEntity::isWeakImported(ModuleDecl *module) const {
1071
1071
llvm_unreachable (" Bad link entity kind" );
1072
1072
}
1073
1073
1074
- const SourceFile *LinkEntity::getSourceFileForEmission () const {
1075
- const SourceFile *sf;
1076
-
1077
- // Shared-linkage entities don't get emitted with any particular file.
1078
- if (hasSharedVisibility (getLinkage (NotForDefinition)))
1079
- return nullptr ;
1080
-
1081
- auto getSourceFileForDeclContext =
1082
- [](const DeclContext *dc) -> const SourceFile * {
1083
- if (!dc)
1084
- return nullptr ;
1085
- return dc->getParentSourceFile ();
1086
- };
1087
-
1074
+ DeclContext *LinkEntity::getDeclContextForEmission () const {
1088
1075
switch (getKind ()) {
1089
1076
case Kind::DispatchThunk:
1090
1077
case Kind::DispatchThunkInitializer:
@@ -1122,60 +1109,39 @@ const SourceFile *LinkEntity::getSourceFileForEmission() const {
1122
1109
case Kind::OpaqueTypeDescriptorAccessorImpl:
1123
1110
case Kind::OpaqueTypeDescriptorAccessorKey:
1124
1111
case Kind::OpaqueTypeDescriptorAccessorVar:
1125
- sf = getSourceFileForDeclContext (getDecl ()->getDeclContext ());
1126
- if (!sf)
1127
- return nullptr ;
1128
- break ;
1112
+ return getDecl ()->getDeclContext ();
1129
1113
1130
1114
case Kind::SILFunction:
1131
1115
case Kind::DynamicallyReplaceableFunctionVariable:
1132
1116
case Kind::DynamicallyReplaceableFunctionKey:
1133
- sf = getSourceFileForDeclContext (getSILFunction ()->getDeclContext ());
1134
- if (!sf)
1135
- return nullptr ;
1136
- break ;
1117
+ return getSILFunction ()->getDeclContext ();
1137
1118
1138
1119
case Kind::SILGlobalVariable:
1139
- if (auto decl = getSILGlobalVariable ()->getDecl ()) {
1140
- sf = getSourceFileForDeclContext (decl->getDeclContext ());
1141
- if (!sf)
1142
- return nullptr ;
1143
- } else {
1144
- return nullptr ;
1145
- }
1146
- break ;
1120
+ if (auto decl = getSILGlobalVariable ()->getDecl ())
1121
+ return decl->getDeclContext ();
1122
+
1123
+ return nullptr ;
1147
1124
1148
1125
case Kind::ProtocolWitnessTable:
1149
1126
case Kind::ProtocolConformanceDescriptor:
1150
- sf = getSourceFileForDeclContext (
1151
- getRootProtocolConformance ()->getDeclContext ());
1152
- if (!sf)
1153
- return nullptr ;
1154
- break ;
1127
+ return getRootProtocolConformance ()->getDeclContext ();
1155
1128
1156
1129
case Kind::ProtocolWitnessTablePattern:
1157
1130
case Kind::GenericProtocolWitnessTableInstantiationFunction:
1158
1131
case Kind::AssociatedTypeWitnessTableAccessFunction:
1159
1132
case Kind::ReflectionAssociatedTypeDescriptor:
1160
1133
case Kind::ProtocolWitnessTableLazyCacheVariable:
1161
1134
case Kind::ProtocolWitnessTableLazyAccessFunction:
1162
- sf = getSourceFileForDeclContext (
1163
- getProtocolConformance ()->getRootConformance ()->getDeclContext ());
1164
- if (!sf)
1165
- return nullptr ;
1166
- break ;
1135
+ return getRootProtocolConformance ()->getDeclContext ();
1167
1136
1168
1137
case Kind::TypeMetadata: {
1169
1138
auto ty = getType ();
1170
1139
// Only fully concrete nominal type metadata gets emitted eagerly.
1171
1140
auto nom = ty->getAnyNominal ();
1172
- if (! nom || nom-> isGenericContext () )
1173
- return nullptr ;
1141
+ if (nom)
1142
+ return nom-> getDeclContext () ;
1174
1143
1175
- sf = getSourceFileForDeclContext (nom);
1176
- if (!sf)
1177
- return nullptr ;
1178
- break ;
1144
+ return nullptr ;
1179
1145
}
1180
1146
1181
1147
// Always shared linkage
@@ -1197,6 +1163,4 @@ const SourceFile *LinkEntity::getSourceFileForEmission() const {
1197
1163
case Kind::DifferentiabilityWitness:
1198
1164
return nullptr ;
1199
1165
}
1200
-
1201
- return sf;
1202
1166
}
0 commit comments