@@ -353,17 +353,9 @@ class ModuleDecl : public DeclContext, public TypeDecl {
353
353
354
354
// / \sa getImportedModules
355
355
enum class ImportFilter {
356
- // Everything.
357
356
All,
358
-
359
- // @_exported only.
360
357
Public,
361
-
362
- // Not @_exported only. Also includes @_usableFromInline.
363
- Private,
364
-
365
- // @_usableFromInline and @_exported only.
366
- ForLinking
358
+ Private
367
359
};
368
360
369
361
// / Looks up which modules are imported by this module.
@@ -376,16 +368,11 @@ class ModuleDecl : public DeclContext, public TypeDecl {
376
368
// / Looks up which modules are imported by this module, ignoring any that
377
369
// / won't contain top-level decls.
378
370
// /
379
- // / This is a performance hack for the ClangImporter . Do not use for
380
- // / anything but name lookup. May go away in the future.
371
+ // / This is a performance hack. Do not use for anything but name lookup.
372
+ // / May go away in the future.
381
373
void
382
374
getImportedModulesForLookup (SmallVectorImpl<ImportedModule> &imports) const ;
383
375
384
- // / Extension of the above hack. Identical to getImportedModulesForLookup()
385
- // / for imported modules, otherwise also includes @usableFromInline imports.
386
- void
387
- getImportedModulesForLinking (SmallVectorImpl<ImportedModule> &imports) const ;
388
-
389
376
// / Finds all top-level decls of this module.
390
377
// /
391
378
// / This does a simple local lookup, not recursively looking through imports.
@@ -423,16 +410,28 @@ class ModuleDecl : public DeclContext, public TypeDecl {
423
410
// / results, with the given access path.
424
411
// / \param fn A callback of type bool(ImportedModule) or void(ImportedModule).
425
412
// / Return \c false to abort iteration.
426
- // / \param includeLinkOnlyModules Include modules that are not visible to
427
- // / name lookup but must be linked in because inlinable code can
428
- // / reference their symbols.
429
413
// /
430
414
// / \return True if the traversal ran to completion, false if it ended early
431
415
// / due to the callback.
432
416
bool forAllVisibleModules (AccessPathTy topLevelAccessPath,
433
- llvm::function_ref<bool (ImportedModule)> fn,
434
- bool includeLinkOnlyModules = false);
417
+ llvm::function_ref<bool (ImportedModule)> fn);
418
+
419
+ bool forAllVisibleModules (AccessPathTy topLevelAccessPath,
420
+ llvm::function_ref<void (ImportedModule)> fn) {
421
+ return forAllVisibleModules (topLevelAccessPath,
422
+ [=](const ImportedModule &import ) -> bool {
423
+ fn (import );
424
+ return true ;
425
+ });
426
+ }
435
427
428
+ template <typename Fn>
429
+ bool forAllVisibleModules (AccessPathTy topLevelAccessPath,
430
+ Fn &&fn) {
431
+ using RetTy = typename std::result_of<Fn (ImportedModule)>::type;
432
+ llvm::function_ref<RetTy (ImportedModule)> wrapped{std::forward<Fn>(fn)};
433
+ return forAllVisibleModules (topLevelAccessPath, wrapped);
434
+ }
436
435
437
436
// / @}
438
437
@@ -664,12 +663,6 @@ class FileUnit : public DeclContext {
664
663
return getImportedModules (imports, ModuleDecl::ImportFilter::Public);
665
664
}
666
665
667
- // / \see ModuleDecl::getImportedModulesForLinking
668
- virtual void getImportedModulesForLinking (
669
- SmallVectorImpl<ModuleDecl::ImportedModule> &imports) const {
670
- return getImportedModules (imports, ModuleDecl::ImportFilter::ForLinking);
671
- }
672
-
673
666
// / Generates the list of libraries needed to link this file, based on its
674
667
// / imports.
675
668
virtual void
@@ -681,15 +674,28 @@ class FileUnit : public DeclContext {
681
674
// /
682
675
// / \param fn A callback of type bool(ImportedModule) or void(ImportedModule).
683
676
// / Return \c false to abort iteration.
684
- // / \param includeLinkOnlyModules Include modules that are not visible to
685
- // / name lookup but must be linked in because inlinable code can
686
- // / reference their symbols.
687
677
// /
688
678
// / \return True if the traversal ran to completion, false if it ended early
689
679
// / due to the callback.
690
680
bool
691
- forAllVisibleModules (llvm::function_ref<bool (ModuleDecl::ImportedModule)> fn,
692
- bool includeLinkOnlyModules = false);
681
+ forAllVisibleModules (llvm::function_ref<bool (ModuleDecl::ImportedModule)> fn);
682
+
683
+ bool
684
+ forAllVisibleModules (llvm::function_ref<void (ModuleDecl::ImportedModule)> fn) {
685
+ return forAllVisibleModules ([=](ModuleDecl::ImportedModule import ) -> bool {
686
+ fn (import );
687
+ return true ;
688
+ });
689
+ }
690
+
691
+ template <typename Fn>
692
+ bool forAllVisibleModules (Fn &&fn) {
693
+ using RetTy = typename std::result_of<Fn (ModuleDecl::ImportedModule)>::type;
694
+ llvm::function_ref<RetTy (ModuleDecl::ImportedModule)> wrapped{
695
+ std::forward<Fn>(fn)
696
+ };
697
+ return forAllVisibleModules (wrapped);
698
+ }
693
699
694
700
// / @}
695
701
@@ -768,17 +774,13 @@ class SourceFile final : public FileUnit {
768
774
};
769
775
770
776
// / Possible attributes for imports in source files.
771
- enum class ImportFlags : uint8_t {
777
+ enum class ImportFlags {
772
778
// / The imported module is exposed to anyone who imports the parent module.
773
779
Exported = 0x1 ,
774
780
775
781
// / This source file has access to testable declarations in the imported
776
782
// / module.
777
- Testable = 0x2 ,
778
-
779
- // / Modules that depend on the module containing this source file will
780
- // / autolink this dependency.
781
- UsableFromInline = 0x4 ,
783
+ Testable = 0x2
782
784
};
783
785
784
786
// / \see ImportFlags
@@ -791,7 +793,7 @@ class SourceFile final : public FileUnit {
791
793
// / This is the list of modules that are imported by this module.
792
794
// /
793
795
// / This is filled in by the Name Binding phase.
794
- MutableArrayRef <std::pair<ModuleDecl::ImportedModule, ImportOptions>> Imports;
796
+ ArrayRef <std::pair<ModuleDecl::ImportedModule, ImportOptions>> Imports;
795
797
796
798
// / A unique identifier representing this file; used to mark private decls
797
799
// / within the file to keep them from conflicting with other files in the
@@ -897,8 +899,6 @@ class SourceFile final : public FileUnit {
897
899
898
900
bool hasTestableImport (const ModuleDecl *module ) const ;
899
901
900
- void markUsableFromInlineImport (const ModuleDecl *module );
901
-
902
902
void clearLookupCache ();
903
903
904
904
void cacheVisibleDecls (SmallVectorImpl<ValueDecl *> &&globals) const ;
0 commit comments