Skip to content

Commit 76ef276

Browse files
authored
Merge pull request #16349 from jrose-apple/just-autolink-everything
Just autolink everything that's imported, publicly or privately. rdar://problem/39338239
2 parents 747e230 + fb59305 commit 76ef276

33 files changed

+136
-273
lines changed

include/swift/AST/Attr.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,6 @@ SIMPLE_DECL_ATTR(_frozen, Frozen,
372372
OnEnum |
373373
UserInaccessible,
374374
76)
375-
SIMPLE_DECL_ATTR(_usableFromInline, UsableFromInlineImport,
376-
OnImport | UserInaccessible,
377-
77)
378375

379376
#undef TYPE_ATTR
380377
#undef DECL_ATTR_ALIAS

include/swift/AST/Decl.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,19 +1549,10 @@ class ImportDecl final : public Decl,
15491549
return static_cast<ImportKind>(Bits.ImportDecl.ImportKind);
15501550
}
15511551

1552-
// An exported import is visible to name lookup from other modules, and is
1553-
// autolinked when the containing module is autolinked.
15541552
bool isExported() const {
15551553
return getAttrs().hasAttribute<ExportedAttr>();
15561554
}
15571555

1558-
// A usable from inline import is autolinked but not visible to name lookup.
1559-
// This attribute is inferred when type checking inlinable and default
1560-
// argument bodies.
1561-
bool isUsableFromInline() const {
1562-
return getAttrs().hasAttribute<UsableFromInlineImportAttr>();
1563-
}
1564-
15651556
ModuleDecl *getModule() const { return Mod; }
15661557
void setModule(ModuleDecl *M) { Mod = M; }
15671558

include/swift/AST/Module.h

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -353,17 +353,9 @@ class ModuleDecl : public DeclContext, public TypeDecl {
353353

354354
/// \sa getImportedModules
355355
enum class ImportFilter {
356-
// Everything.
357356
All,
358-
359-
// @_exported only.
360357
Public,
361-
362-
// Not @_exported only. Also includes @_usableFromInline.
363-
Private,
364-
365-
// @_usableFromInline and @_exported only.
366-
ForLinking
358+
Private
367359
};
368360

369361
/// Looks up which modules are imported by this module.
@@ -376,16 +368,11 @@ class ModuleDecl : public DeclContext, public TypeDecl {
376368
/// Looks up which modules are imported by this module, ignoring any that
377369
/// won't contain top-level decls.
378370
///
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.
381373
void
382374
getImportedModulesForLookup(SmallVectorImpl<ImportedModule> &imports) const;
383375

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-
389376
/// Finds all top-level decls of this module.
390377
///
391378
/// This does a simple local lookup, not recursively looking through imports.
@@ -423,16 +410,28 @@ class ModuleDecl : public DeclContext, public TypeDecl {
423410
/// results, with the given access path.
424411
/// \param fn A callback of type bool(ImportedModule) or void(ImportedModule).
425412
/// 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.
429413
///
430414
/// \return True if the traversal ran to completion, false if it ended early
431415
/// due to the callback.
432416
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+
}
435427

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+
}
436435

437436
/// @}
438437

@@ -664,12 +663,6 @@ class FileUnit : public DeclContext {
664663
return getImportedModules(imports, ModuleDecl::ImportFilter::Public);
665664
}
666665

667-
/// \see ModuleDecl::getImportedModulesForLinking
668-
virtual void getImportedModulesForLinking(
669-
SmallVectorImpl<ModuleDecl::ImportedModule> &imports) const {
670-
return getImportedModules(imports, ModuleDecl::ImportFilter::ForLinking);
671-
}
672-
673666
/// Generates the list of libraries needed to link this file, based on its
674667
/// imports.
675668
virtual void
@@ -681,15 +674,28 @@ class FileUnit : public DeclContext {
681674
///
682675
/// \param fn A callback of type bool(ImportedModule) or void(ImportedModule).
683676
/// 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.
687677
///
688678
/// \return True if the traversal ran to completion, false if it ended early
689679
/// due to the callback.
690680
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+
}
693699

694700
/// @}
695701

@@ -768,17 +774,13 @@ class SourceFile final : public FileUnit {
768774
};
769775

770776
/// Possible attributes for imports in source files.
771-
enum class ImportFlags : uint8_t {
777+
enum class ImportFlags {
772778
/// The imported module is exposed to anyone who imports the parent module.
773779
Exported = 0x1,
774780

775781
/// This source file has access to testable declarations in the imported
776782
/// 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
782784
};
783785

784786
/// \see ImportFlags
@@ -791,7 +793,7 @@ class SourceFile final : public FileUnit {
791793
/// This is the list of modules that are imported by this module.
792794
///
793795
/// 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;
795797

796798
/// A unique identifier representing this file; used to mark private decls
797799
/// within the file to keep them from conflicting with other files in the
@@ -897,8 +899,6 @@ class SourceFile final : public FileUnit {
897899

898900
bool hasTestableImport(const ModuleDecl *module) const;
899901

900-
void markUsableFromInlineImport(const ModuleDecl *module);
901-
902902
void clearLookupCache();
903903

904904
void cacheVisibleDecls(SmallVectorImpl<ValueDecl *> &&globals) const;

include/swift/ClangImporter/ClangModule.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ class ClangModuleUnit final : public LoadedFile {
9797
virtual void getImportedModulesForLookup(
9898
SmallVectorImpl<ModuleDecl::ImportedModule> &imports) const override;
9999

100-
virtual void getImportedModulesForLinking(
101-
SmallVectorImpl<ModuleDecl::ImportedModule> &imports) const override {
102-
// In C, anything that's linkable is visible to the source language.
103-
return getImportedModulesForLookup(imports);
104-
}
105-
106100
virtual void
107101
collectLinkLibraries(ModuleDecl::LinkLibraryCallback callback) const override;
108102

include/swift/Serialization/ModuleFile.h

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,40 +132,27 @@ class ModuleFile
132132
const StringRef RawPath;
133133

134134
private:
135+
unsigned IsExported : 1;
135136
const unsigned IsHeader : 1;
136-
const unsigned IsExported : 1;
137-
const unsigned IsUsableFromInline : 1;
138137
const unsigned IsScoped : 1;
139138

140-
Dependency(bool isHeader,
141-
StringRef path, bool exported,
142-
bool isUsableFromInline, bool isScoped)
143-
: RawPath(path),
144-
IsHeader(isHeader),
145-
IsExported(exported),
146-
IsUsableFromInline(isUsableFromInline),
147-
IsScoped(isScoped) {
148-
assert(!(IsExported && IsUsableFromInline));
149-
assert(!(IsHeader && IsScoped));
150-
}
139+
Dependency(StringRef path, bool isHeader, bool exported, bool isScoped)
140+
: RawPath(path), IsExported(exported), IsHeader(isHeader),
141+
IsScoped(isScoped) {}
151142

152143
public:
153-
Dependency(StringRef path, bool exported, bool isUsableFromInline,
154-
bool isScoped)
155-
: Dependency(false, path, exported, isUsableFromInline, isScoped) {}
144+
Dependency(StringRef path, bool exported, bool isScoped)
145+
: Dependency(path, false, exported, isScoped) {}
156146

157147
static Dependency forHeader(StringRef headerPath, bool exported) {
158-
return Dependency(true, headerPath, exported,
159-
/*isUsableFromInline=*/false,
160-
/*isScoped=*/false);
148+
return Dependency(headerPath, true, exported, false);
161149
}
162150

163151
bool isLoaded() const {
164152
return Import.second != nullptr;
165153
}
166154

167155
bool isExported() const { return IsExported; }
168-
bool isUsableFromInline() const { return IsUsableFromInline; }
169156
bool isHeader() const { return IsHeader; }
170157
bool isScoped() const { return IsScoped; }
171158

include/swift/Serialization/ModuleFormat.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const uint16_t VERSION_MAJOR = 0;
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
5757
/// Don't worry about adhering to the 80-column limit for this line.
58-
const uint16_t VERSION_MINOR = 416; // Last change: remove substitutions
58+
const uint16_t VERSION_MINOR = 417; // Last change: revert @usableFromInline imports
5959

6060
using DeclIDField = BCFixed<31>;
6161

@@ -595,7 +595,6 @@ namespace input_block {
595595
using ImportedModuleLayout = BCRecordLayout<
596596
IMPORTED_MODULE,
597597
BCFixed<1>, // exported?
598-
BCFixed<1>, // usable from inlinable functions?
599598
BCFixed<1>, // scoped?
600599
BCBlob // module name, with submodule path pieces separated by \0s.
601600
// If the 'scoped' flag is set, the final path piece is an access

lib/AST/ASTContext.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2331,7 +2331,6 @@ void ASTContext::diagnoseAttrsRequiringFoundation(SourceFile &SF) {
23312331
SF.forAllVisibleModules([&](ModuleDecl::ImportedModule import) {
23322332
if (import.second->getName() == Id_Foundation)
23332333
ImportsFoundationModule = true;
2334-
return true;
23352334
});
23362335

23372336
if (ImportsFoundationModule)

lib/AST/LookupVisibleDecls.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ static void doDynamicLookup(VisibleDeclConsumer &Consumer,
387387
CurrDC->getParentSourceFile()->forAllVisibleModules(
388388
[&](ModuleDecl::ImportedModule Import) {
389389
Import.second->lookupClassMembers(Import.first, ConsumerWrapper);
390-
return true;
391390
});
392391
}
393392

0 commit comments

Comments
 (0)