@@ -2246,6 +2246,53 @@ SPIGroupsRequest::evaluate(Evaluator &evaluator, const Decl *decl) const {
2246
2246
return ctx.AllocateCopy (spiGroups.getArrayRef ());
2247
2247
}
2248
2248
2249
+ LibraryLevel ModuleDecl::getLibraryLevel () const {
2250
+ return evaluateOrDefault (getASTContext ().evaluator ,
2251
+ ModuleLibraryLevelRequest{this },
2252
+ LibraryLevel::Other);
2253
+ }
2254
+
2255
+ LibraryLevel
2256
+ ModuleLibraryLevelRequest::evaluate (Evaluator &evaluator,
2257
+ const ModuleDecl *module ) const {
2258
+ auto &ctx = module ->getASTContext ();
2259
+
2260
+ // / Is \p modulePath from System/Library/PrivateFrameworks/?
2261
+ auto fromPrivateFrameworks = [&](StringRef modulePath) -> bool {
2262
+ if (!ctx.LangOpts .Target .isOSDarwin ()) return false ;
2263
+
2264
+ namespace path = llvm::sys::path;
2265
+ SmallString<128 > scratch;
2266
+ scratch = ctx.SearchPathOpts .SDKPath ;
2267
+ path::append (scratch, " System" , " Library" , " PrivateFrameworks" );
2268
+ return hasPrefix (path::begin (modulePath), path::end (modulePath),
2269
+ path::begin (scratch), path::end (scratch));
2270
+ };
2271
+
2272
+ if (module ->isNonSwiftModule ()) {
2273
+ if (auto *underlying = module ->findUnderlyingClangModule ()) {
2274
+ // Imported clangmodules are SPI if they are defined by a private
2275
+ // modulemap or from the PrivateFrameworks folder in the SDK.
2276
+ bool moduleIsSPI = underlying->ModuleMapIsPrivate ||
2277
+ (underlying->isPartOfFramework () &&
2278
+ fromPrivateFrameworks (underlying->PresumedModuleMapFile ));
2279
+ return moduleIsSPI ? LibraryLevel::SPI : LibraryLevel::API;
2280
+ }
2281
+ return LibraryLevel::Other;
2282
+
2283
+ } else if (module ->isMainModule ()) {
2284
+ // The current compilation target.
2285
+ return ctx.LangOpts .LibraryLevel ;
2286
+
2287
+ } else {
2288
+ // Other Swift modules are SPI if they are from the PrivateFrameworks
2289
+ // folder in the SDK.
2290
+ auto modulePath = module ->getModuleFilename ();
2291
+ return fromPrivateFrameworks (modulePath) ?
2292
+ LibraryLevel::SPI : LibraryLevel::API;
2293
+ }
2294
+ }
2295
+
2249
2296
bool SourceFile::shouldCrossImport () const {
2250
2297
return Kind != SourceFileKind::SIL && Kind != SourceFileKind::Interface &&
2251
2298
getASTContext ().LangOpts .EnableCrossImportOverlays ;
0 commit comments