From a8fec6f39ba162e41cd6caf212e9b80b0f0ab3b3 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Mon, 13 Oct 2025 19:03:06 -0700 Subject: [PATCH] [Swiftify] Always skip safe wrappers when building the stdlib _SwiftifyImport assumes types like Swift.Int, Swift.UnsafePointer and Swift.Span are available. This is not the case when building the stdlib itself. Disable safe interop in the stdlib to prevent errors. This currently has no effect, but will when this feature is enabled by default, which I have manually tested. --- include/swift/Basic/LangOptions.h | 4 ++++ lib/ClangImporter/ImportDecl.cpp | 3 ++- lib/Frontend/CompilerInvocation.cpp | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/swift/Basic/LangOptions.h b/include/swift/Basic/LangOptions.h index 4687beea7d70d..3e89fc1062711 100644 --- a/include/swift/Basic/LangOptions.h +++ b/include/swift/Basic/LangOptions.h @@ -1148,6 +1148,10 @@ namespace swift { /// ones to apply. bool LoadVersionIndependentAPINotes = false; + /// Whether the importer should skip SafeInteropWrappers, even though the + /// feature is enabled. + bool DisableSafeInteropWrappers = false; + /// Return a hash code of any components from these options that should /// contribute to a Swift Bridging PCH hash. llvm::hash_code getPCHHashComponents() const { diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index f2db92c2f1100..a0bf7db57b502 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -9484,7 +9484,8 @@ static StringRef getAttributeName(const clang::CountAttributedType *CAT) { } void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) { - if (!SwiftContext.LangOpts.hasFeature(Feature::SafeInteropWrappers)) + if (!SwiftContext.LangOpts.hasFeature(Feature::SafeInteropWrappers) || + SwiftContext.ClangImporterOpts.DisableSafeInteropWrappers) return; auto ClangDecl = dyn_cast_or_null(MappedDecl->getClangDecl()); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 773c30ffd3f84..6672844e2f809 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -2175,6 +2175,8 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts, ArgList &Args, Opts.LoadVersionIndependentAPINotes |= Args.hasArg(OPT_version_independent_apinotes); + Opts.DisableSafeInteropWrappers |= FrontendOpts.ParseStdlib; + if (FrontendOpts.DisableImplicitModules) Opts.DisableImplicitClangModules = true;