1010//
1111// ===----------------------------------------------------------------------===//
1212
13+ #include " swift/Frontend/ModuleInterfaceSupport.h"
1314#include " swift/AST/ASTContext.h"
1415#include " swift/AST/ASTPrinter.h"
1516#include " swift/AST/Decl.h"
2021#include " swift/AST/Module.h"
2122#include " swift/AST/ModuleNameLookup.h"
2223#include " swift/AST/NameLookupRequests.h"
24+ #include " swift/AST/PrettyStackTrace.h"
2325#include " swift/AST/ProtocolConformance.h"
2426#include " swift/AST/TypeCheckRequests.h"
2527#include " swift/AST/TypeRepr.h"
2628#include " swift/Basic/Assertions.h"
2729#include " swift/Basic/STLExtras.h"
2830#include " swift/Frontend/Frontend.h"
29- #include " swift/Frontend/ModuleInterfaceSupport.h"
3031#include " swift/Frontend/PrintingDiagnosticConsumer.h"
3132#include " swift/SILOptimizer/PassManager/Passes.h"
3233#include " swift/Serialization/SerializationOptions.h"
@@ -530,6 +531,7 @@ class InheritedProtocolCollector {
530531 // / protocols.
531532 void recordProtocols (InheritedTypes directlyInherited, const Decl *D,
532533 bool skipExtra = false ) {
534+ PrettyStackTraceDecl stackTrace (" recording protocols for" , D);
533535 std::optional<AvailableAttrList> availableAttrs;
534536
535537 for (int i : directlyInherited.getIndices ()) {
@@ -602,11 +604,19 @@ class InheritedProtocolCollector {
602604 // /
603605 // / \sa recordProtocols
604606 static void collectProtocols (PerTypeMap &map, const Decl *D) {
607+ PrettyStackTraceDecl stackTrace (" collecting protocols for" , D);
605608 InheritedTypes directlyInherited = InheritedTypes (D);
606609 const NominalTypeDecl *nominal;
607610 const IterableDeclContext *memberContext;
608611
609612 auto shouldInclude = [](const ExtensionDecl *extension) {
613+ // In lazy typechecking mode we may be resolving the extended type for the
614+ // first time here, so we need to call getExtendedType() to cause
615+ // diagnostics to be emitted if necessary.
616+ (void )extension->getExtendedType ();
617+ if (extension->isInvalid ())
618+ return false ;
619+
610620 if (extension->isConstrainedExtension ()) {
611621 // Conditional conformances never apply to inherited protocols, nor
612622 // can they provide unconditional conformances that might be used in
@@ -615,9 +625,9 @@ class InheritedProtocolCollector {
615625 }
616626 return true ;
617627 };
628+
618629 if ((nominal = dyn_cast<NominalTypeDecl>(D))) {
619630 memberContext = nominal;
620-
621631 } else if (auto *extension = dyn_cast<ExtensionDecl>(D)) {
622632 if (!shouldInclude (extension)) {
623633 return ;
@@ -697,6 +707,9 @@ class InheritedProtocolCollector {
697707 const PrintOptions &printOptions,
698708 ModuleDecl *M,
699709 const NominalTypeDecl *nominal) const {
710+ PrettyStackTraceDecl stackTrace (" printing synthesized extensions for" ,
711+ nominal);
712+
700713 if (ExtraProtocols.empty ())
701714 return ;
702715
@@ -881,6 +894,8 @@ const StringLiteral InheritedProtocolCollector::DummyProtocolName =
881894bool swift::emitSwiftInterface (raw_ostream &out,
882895 ModuleInterfaceOptions const &Opts,
883896 ModuleDecl *M) {
897+ PrettyStackTraceDecl stackTrace (" emitting swiftinterface for" , M);
898+
884899 assert (M);
885900
886901 llvm::SmallSet<StringRef, 4 > aliasModuleNamesTargets;
0 commit comments