@@ -235,6 +235,30 @@ class ModuleWriter {
235
235
});
236
236
}
237
237
238
+ void forwardDeclareType (const TypeDecl *TD) {
239
+ if (auto CD = dyn_cast<ClassDecl>(TD)) {
240
+ if (!forwardDeclare (CD)) {
241
+ (void )addImport (CD);
242
+ }
243
+ } else if (auto PD = dyn_cast<ProtocolDecl>(TD)) {
244
+ forwardDeclare (PD);
245
+ } else if (auto TAD = dyn_cast<TypeAliasDecl>(TD)) {
246
+ bool imported = false ;
247
+ if (TAD->hasClangNode ())
248
+ imported = addImport (TD);
249
+ assert ((imported || !TAD->isGeneric ()) &&
250
+ " referencing non-imported generic typealias?" );
251
+ } else if (addImport (TD)) {
252
+ return ;
253
+ } else if (auto ED = dyn_cast<EnumDecl>(TD)) {
254
+ forwardDeclare (ED);
255
+ } else if (isa<AbstractTypeParamDecl>(TD)) {
256
+ llvm_unreachable (" should not see type params here" );
257
+ } else {
258
+ assert (false && " unknown local type decl" );
259
+ }
260
+ }
261
+
238
262
bool forwardDeclareMemberTypes (DeclRange members, const Decl *container) {
239
263
PrettyStackTraceDecl
240
264
entry (" printing forward declarations needed by members of" , container);
@@ -312,26 +336,7 @@ class ModuleWriter {
312
336
// FIXME: It would be nice to diagnose this.
313
337
}
314
338
315
- if (auto CD = dyn_cast<ClassDecl>(TD)) {
316
- if (!forwardDeclare (CD)) {
317
- (void )addImport (CD);
318
- }
319
- } else if (auto PD = dyn_cast<ProtocolDecl>(TD)) {
320
- forwardDeclare (PD);
321
- } else if (auto TAD = dyn_cast<TypeAliasDecl>(TD)) {
322
- bool imported = false ;
323
- if (TAD->hasClangNode ())
324
- imported = addImport (TD);
325
- assert ((imported || !TAD->isGeneric ()) && " referencing non-imported generic typealias?" );
326
- } else if (addImport (TD)) {
327
- return ;
328
- } else if (auto ED = dyn_cast<EnumDecl>(TD)) {
329
- forwardDeclare (ED);
330
- } else if (isa<AbstractTypeParamDecl>(TD)) {
331
- llvm_unreachable (" should not see type params here" );
332
- } else {
333
- assert (false && " unknown local type decl" );
334
- }
339
+ forwardDeclareType (TD);
335
340
});
336
341
337
342
if (needsToBeIndividuallyDelayed) {
@@ -374,11 +379,22 @@ class ModuleWriter {
374
379
printer.print (CD);
375
380
return true ;
376
381
}
377
-
382
+
378
383
bool writeFunc (const FuncDecl *FD) {
379
384
if (addImport (FD))
380
385
return true ;
381
386
387
+ PrettyStackTraceDecl entry (
388
+ " printing forward declarations needed by function" , FD);
389
+ ReferencedTypeFinder::walk (
390
+ FD->getInterfaceType (),
391
+ [&](ReferencedTypeFinder &finder, const TypeDecl *TD) {
392
+ PrettyStackTraceDecl entry (" walking its interface type, currently at" ,
393
+ TD);
394
+ forwardDeclareType (TD);
395
+ });
396
+
397
+ os << ' \n ' ;
382
398
printer.print (FD);
383
399
return true ;
384
400
}
0 commit comments