Skip to content

Commit 4714fcd

Browse files
committed
Revert "Merge pull request #16211 from slavapestov/fix-inlinable-vs-autolinking"
This reverts commit bb16ee0, reversing changes made to a8d831f. It's not sufficient to solve the problem, and the choices were to do something more complicated, or just take a simple brute force approach. We're going with the latter.
1 parent e432971 commit 4714fcd

21 files changed

+26
-196
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: 7 additions & 39 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,11 @@ 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);
435-
417+
llvm::function_ref<bool(ImportedModule)> fn);
436418

437419
/// @}
438420

@@ -664,12 +646,6 @@ class FileUnit : public DeclContext {
664646
return getImportedModules(imports, ModuleDecl::ImportFilter::Public);
665647
}
666648

667-
/// \see ModuleDecl::getImportedModulesForLinking
668-
virtual void getImportedModulesForLinking(
669-
SmallVectorImpl<ModuleDecl::ImportedModule> &imports) const {
670-
return getImportedModules(imports, ModuleDecl::ImportFilter::ForLinking);
671-
}
672-
673649
/// Generates the list of libraries needed to link this file, based on its
674650
/// imports.
675651
virtual void
@@ -681,15 +657,11 @@ class FileUnit : public DeclContext {
681657
///
682658
/// \param fn A callback of type bool(ImportedModule) or void(ImportedModule).
683659
/// 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.
687660
///
688661
/// \return True if the traversal ran to completion, false if it ended early
689662
/// due to the callback.
690663
bool
691-
forAllVisibleModules(llvm::function_ref<bool(ModuleDecl::ImportedModule)> fn,
692-
bool includeLinkOnlyModules = false);
664+
forAllVisibleModules(llvm::function_ref<bool(ModuleDecl::ImportedModule)> fn);
693665

694666
/// @}
695667

@@ -768,17 +740,13 @@ class SourceFile final : public FileUnit {
768740
};
769741

770742
/// Possible attributes for imports in source files.
771-
enum class ImportFlags : uint8_t {
743+
enum class ImportFlags {
772744
/// The imported module is exposed to anyone who imports the parent module.
773745
Exported = 0x1,
774746

775747
/// This source file has access to testable declarations in the imported
776748
/// module.
777-
Testable = 0x2,
778-
779-
/// Modules that depend on the module containing this source file will
780-
/// autolink this dependency.
781-
UsableFromInline = 0x4,
749+
Testable = 0x2
782750
};
783751

784752
/// \see ImportFlags

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/Module.cpp

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -974,11 +974,6 @@ SourceFile::getImportedModules(SmallVectorImpl<ModuleDecl::ImportedModule> &modu
974974
if (importPair.second.contains(ImportFlags::Exported))
975975
continue;
976976
break;
977-
case ModuleDecl::ImportFilter::ForLinking:
978-
if (!importPair.second.contains(ImportFlags::UsableFromInline) &&
979-
!importPair.second.contains(ImportFlags::Exported))
980-
continue;
981-
break;
982977
}
983978

984979
modules.push_back(importPair.first);
@@ -990,11 +985,6 @@ void ModuleDecl::getImportedModulesForLookup(
990985
FORWARD(getImportedModulesForLookup, (modules));
991986
}
992987

993-
void ModuleDecl::getImportedModulesForLinking(
994-
SmallVectorImpl<ImportedModule> &modules) const {
995-
FORWARD(getImportedModulesForLinking, (modules));
996-
}
997-
998988
bool ModuleDecl::isSameAccessPath(AccessPathTy lhs, AccessPathTy rhs) {
999989
using AccessPathElem = std::pair<Identifier, SourceLoc>;
1000990
if (lhs.size() != rhs.size())
@@ -1138,15 +1128,11 @@ bool ModuleDecl::isSystemModule() const {
11381128
}
11391129

11401130
bool ModuleDecl::forAllVisibleModules(AccessPathTy thisPath,
1141-
llvm::function_ref<bool(ImportedModule)> fn,
1142-
bool includeLinkOnlyModules) {
1131+
llvm::function_ref<bool(ImportedModule)> fn) {
11431132
llvm::SmallSet<ImportedModule, 32, ModuleDecl::OrderImportedModules> visited;
11441133
SmallVector<ImportedModule, 32> stack;
11451134

1146-
if (includeLinkOnlyModules)
1147-
getImportedModules(stack, ModuleDecl::ImportFilter::ForLinking);
1148-
else
1149-
getImportedModules(stack, ModuleDecl::ImportFilter::Public);
1135+
getImportedModules(stack, ModuleDecl::ImportFilter::Public);
11501136

11511137
// Make sure the top-level module is first; we want pre-order-ish traversal.
11521138
stack.push_back(ImportedModule(thisPath, this));
@@ -1172,20 +1158,15 @@ bool ModuleDecl::forAllVisibleModules(AccessPathTy thisPath,
11721158
if (!fn(next))
11731159
return false;
11741160

1175-
if (includeLinkOnlyModules)
1176-
next.second->getImportedModulesForLinking(stack);
1177-
else
1178-
next.second->getImportedModulesForLookup(stack);
1161+
next.second->getImportedModulesForLookup(stack);
11791162
}
11801163

11811164
return true;
11821165
}
11831166

11841167
bool FileUnit::forAllVisibleModules(
1185-
llvm::function_ref<bool(ModuleDecl::ImportedModule)> fn,
1186-
bool includeLinkOnlyModules) {
1187-
if (!getParentModule()->forAllVisibleModules(ModuleDecl::AccessPathTy(), fn,
1188-
includeLinkOnlyModules))
1168+
llvm::function_ref<bool(ModuleDecl::ImportedModule)> fn) {
1169+
if (!getParentModule()->forAllVisibleModules(ModuleDecl::AccessPathTy(), fn))
11891170
return false;
11901171

11911172
if (auto SF = dyn_cast<SourceFile>(this)) {
@@ -1194,8 +1175,7 @@ bool FileUnit::forAllVisibleModules(
11941175
SmallVector<ModuleDecl::ImportedModule, 4> imports;
11951176
SF->getImportedModules(imports, ModuleDecl::ImportFilter::Private);
11961177
for (auto importPair : imports)
1197-
if (!importPair.second->forAllVisibleModules(importPair.first, fn,
1198-
includeLinkOnlyModules))
1178+
if (!importPair.second->forAllVisibleModules(importPair.first, fn))
11991179
return false;
12001180
}
12011181

@@ -1218,8 +1198,7 @@ SourceFile::collectLinkLibraries(ModuleDecl::LinkLibraryCallback callback) const
12181198

12191199
next->collectLinkLibraries(callback);
12201200
return true;
1221-
},
1222-
/*includeLinkOnlyModules=*/true);
1201+
});
12231202
}
12241203

12251204
bool ModuleDecl::walk(ASTWalker &Walker) {

lib/ClangImporter/ClangImporter.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,7 +3055,6 @@ void ClangModuleUnit::getImportedModules(
30553055
imports.push_back({ModuleDecl::AccessPathTy(), owner.getStdlibModule()});
30563056
break;
30573057
case ModuleDecl::ImportFilter::Public:
3058-
case ModuleDecl::ImportFilter::ForLinking:
30593058
break;
30603059
}
30613060

@@ -3065,7 +3064,6 @@ void ClangModuleUnit::getImportedModules(
30653064
switch (filter) {
30663065
case ModuleDecl::ImportFilter::All:
30673066
case ModuleDecl::ImportFilter::Public:
3068-
case ModuleDecl::ImportFilter::ForLinking:
30693067
imported.append(owner.ImportedHeaderExports.begin(),
30703068
owner.ImportedHeaderExports.end());
30713069
break;
@@ -3114,7 +3112,6 @@ void ClangModuleUnit::getImportedModules(
31143112
}
31153113

31163114
case ModuleDecl::ImportFilter::Public:
3117-
case ModuleDecl::ImportFilter::ForLinking:
31183115
break;
31193116
}
31203117
}

lib/Sema/NameBinding.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,6 @@ void NameBinder::addImport(
235235
ImportOptions options;
236236
if (ID->isExported())
237237
options |= SourceFile::ImportFlags::Exported;
238-
if (ID->isUsableFromInline())
239-
options |= SourceFile::ImportFlags::UsableFromInline;
240238
if (testableAttr)
241239
options |= SourceFile::ImportFlags::Testable;
242240
imports.push_back({ { ID->getDeclPath(), M }, options });

lib/Sema/TypeCheckAttr.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ class AttributeEarlyChecker : public AttributeVisitor<AttributeEarlyChecker> {
113113
IGNORED_ATTR(UIApplicationMain)
114114
IGNORED_ATTR(UnsafeNoObjCTaggedPointer)
115115
IGNORED_ATTR(UsableFromInline)
116-
IGNORED_ATTR(UsableFromInlineImport)
117116
IGNORED_ATTR(WeakLinked)
118117
#undef IGNORED_ATTR
119118

@@ -834,7 +833,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
834833
IGNORED_ATTR(SynthesizedProtocol)
835834
IGNORED_ATTR(Testable)
836835
IGNORED_ATTR(Transparent)
837-
IGNORED_ATTR(UsableFromInlineImport)
838836
IGNORED_ATTR(WarnUnqualifiedAccess)
839837
IGNORED_ATTR(WeakLinked)
840838
#undef IGNORED_ATTR

lib/Sema/TypeCheckDecl.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5794,8 +5794,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
57945794
UNINTERESTING_ATTR(ClangImporterSynthesizedType)
57955795
UNINTERESTING_ATTR(WeakLinked)
57965796
UNINTERESTING_ATTR(Frozen)
5797-
UNINTERESTING_ATTR(UsableFromInlineImport)
5798-
57995797
#undef UNINTERESTING_ATTR
58005798

58015799
void visitAvailableAttr(AvailableAttr *attr) {

lib/Serialization/ModuleFile.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,12 +1140,10 @@ ModuleFile::ModuleFile(
11401140
unsigned kind = cursor.readRecord(next.ID, scratch, &blobData);
11411141
switch (kind) {
11421142
case input_block::IMPORTED_MODULE: {
1143-
bool exported, usableFromInline, scoped;
1143+
bool exported, scoped;
11441144
input_block::ImportedModuleLayout::readRecord(scratch,
1145-
exported,
1146-
usableFromInline,
1147-
scoped);
1148-
Dependencies.push_back({blobData, exported, usableFromInline, scoped});
1145+
exported, scoped);
1146+
Dependencies.push_back({blobData, exported, scoped});
11491147
break;
11501148
}
11511149
case input_block::LINK_LIBRARY: {
@@ -1607,13 +1605,6 @@ void ModuleFile::getImportedModules(
16071605
continue;
16081606

16091607
break;
1610-
1611-
case ModuleDecl::ImportFilter::ForLinking:
1612-
// Only include @_exported and @usableFromInline imports.
1613-
if (!dep.isExported() && !dep.isUsableFromInline())
1614-
continue;
1615-
1616-
break;
16171608
}
16181609

16191610
assert(dep.isLoaded());
@@ -1682,9 +1673,6 @@ void ModuleFile::getImportDecls(SmallVectorImpl<Decl *> &Results) {
16821673
if (Dep.isExported())
16831674
ID->getAttrs().add(
16841675
new (Ctx) ExportedAttr(/*IsImplicit=*/false));
1685-
if (Dep.isUsableFromInline())
1686-
ID->getAttrs().add(
1687-
new (Ctx) UsableFromInlineImportAttr(/*IsImplicit=*/true));
16881676
ImportDecls.push_back(ID);
16891677
}
16901678
Bits.ComputedImportDecls = true;

0 commit comments

Comments
 (0)