|
20 | 20 | #include "PrintSwiftToClangCoreScaffold.h"
|
21 | 21 | #include "SwiftToClangInteropContext.h"
|
22 | 22 |
|
| 23 | +#include "swift/AST/Decl.h" |
23 | 24 | #include "swift/AST/DiagnosticsSema.h"
|
24 | 25 | #include "swift/AST/ExistentialLayout.h"
|
25 | 26 | #include "swift/AST/Module.h"
|
@@ -671,6 +672,15 @@ class ModuleWriter {
|
671 | 672 | llvm_unreachable("unknown top-level ObjC decl");
|
672 | 673 | };
|
673 | 674 |
|
| 675 | + // When we visit a function, we might also generate a thunk that calls into the |
| 676 | + // implementation of structs/enums to get the opaque pointers. To avoid |
| 677 | + // referencing these methods before we see the definition for the generated |
| 678 | + // classes, we want to visit function definitions last. |
| 679 | + if (isa<AbstractFunctionDecl>(*rhs) && isa<NominalTypeDecl>(*lhs)) |
| 680 | + return Descending; |
| 681 | + if (isa<AbstractFunctionDecl>(*lhs) && isa<NominalTypeDecl>(*rhs)) |
| 682 | + return Ascending; |
| 683 | + |
674 | 684 | // Sort by names.
|
675 | 685 | int result = getSortName(*rhs).compare(getSortName(*lhs));
|
676 | 686 | if (result != 0)
|
@@ -700,9 +710,9 @@ class ModuleWriter {
|
700 | 710 | // even when the variable might not actually be emitted by the emitter.
|
701 | 711 | // In that case, order the function before the variable.
|
702 | 712 | if (isa<AbstractFunctionDecl>(*rhs) && isa<VarDecl>(*lhs))
|
703 |
| - return 1; |
| 713 | + return Descending; |
704 | 714 | if (isa<AbstractFunctionDecl>(*lhs) && isa<VarDecl>(*rhs))
|
705 |
| - return -1; |
| 715 | + return Ascending; |
706 | 716 |
|
707 | 717 | // Prefer value decls to extensions.
|
708 | 718 | assert(!(isa<ValueDecl>(*lhs) && isa<ValueDecl>(*rhs)));
|
|
0 commit comments