From f0a32d104db7254b81bdabe401a7742d0a212b61 Mon Sep 17 00:00:00 2001 From: Egor Zhdan Date: Fri, 18 Jul 2025 20:19:30 +0100 Subject: [PATCH] [cxx-interop] Prevent protocol conformance table from being prematurely populated We've started seeing build failures where the conformance of a `std::vector` instantiation to `CxxVector` is missing. This was because the LifetimeDependenceInfoRequest triggers the protocol conformance table for the instantiation to be built before the synthesized conformance gets added. This works around the issue by preventing LifetimeDependenceInfoRequest from running for the synthesized default argument generator function, which was the culprit of this particular failure. rdar://155977071 --- lib/ClangImporter/SwiftDeclSynthesizer.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/ClangImporter/SwiftDeclSynthesizer.cpp b/lib/ClangImporter/SwiftDeclSynthesizer.cpp index 617aee360edf4..d1c8535d7e9a3 100644 --- a/lib/ClangImporter/SwiftDeclSynthesizer.cpp +++ b/lib/ClangImporter/SwiftDeclSynthesizer.cpp @@ -21,6 +21,7 @@ #include "swift/AST/ParameterList.h" #include "swift/AST/Pattern.h" #include "swift/AST/Stmt.h" +#include "swift/AST/TypeCheckRequests.h" #include "swift/Basic/Assertions.h" #include "clang/AST/Mangle.h" #include "clang/Sema/DelayedDiagnostic.h" @@ -2532,6 +2533,11 @@ SwiftDeclSynthesizer::makeDefaultArgument(const clang::ParmVarDecl *param, funcDecl->setAccess(AccessLevel::Public); funcDecl->getAttrs().add(new (ctx) AlwaysEmitIntoClientAttr(/*IsImplicit=*/true)); + // At this point, the parameter/return types of funcDecl might not be imported + // into Swift completely, meaning that their protocol conformances might not + // be populated yet. Prevent LifetimeDependenceInfoRequest from prematurely + // populating the conformance table for the types involved. + ctx.evaluator.cacheOutput(LifetimeDependenceInfoRequest{funcDecl}, {}); ImporterImpl.defaultArgGenerators[param] = funcDecl;