Skip to content

Commit 7539674

Browse files
committed
AST: Support '@_usableFromInline import'
1 parent e2f3e6d commit 7539674

File tree

6 files changed

+24
-2
lines changed

6 files changed

+24
-2
lines changed

include/swift/AST/Attr.def

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

376379
#undef TYPE_ATTR
377380
#undef DECL_ATTR_ALIAS

include/swift/AST/Decl.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,10 +1549,19 @@ 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.
15521554
bool isExported() const {
15531555
return getAttrs().hasAttribute<ExportedAttr>();
15541556
}
15551557

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+
15561565
ModuleDecl *getModule() const { return Mod; }
15571566
void setModule(ModuleDecl *M) { Mod = M; }
15581567

include/swift/AST/Module.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,17 @@ class SourceFile final : public FileUnit {
732732
};
733733

734734
/// Possible attributes for imports in source files.
735-
enum class ImportFlags {
735+
enum class ImportFlags : uint8_t {
736736
/// The imported module is exposed to anyone who imports the parent module.
737737
Exported = 0x1,
738738

739739
/// This source file has access to testable declarations in the imported
740740
/// module.
741-
Testable = 0x2
741+
Testable = 0x2,
742+
743+
/// Modules that depend on the module containing this source file will
744+
/// autolink this dependency.
745+
UsableFromInline = 0x4,
742746
};
743747

744748
/// \see ImportFlags

lib/Sema/NameBinding.cpp

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

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class AttributeEarlyChecker : public AttributeVisitor<AttributeEarlyChecker> {
112112
IGNORED_ATTR(UIApplicationMain)
113113
IGNORED_ATTR(UnsafeNoObjCTaggedPointer)
114114
IGNORED_ATTR(UsableFromInline)
115+
IGNORED_ATTR(UsableFromInlineImport)
115116
IGNORED_ATTR(WeakLinked)
116117
#undef IGNORED_ATTR
117118

@@ -840,6 +841,7 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
840841
IGNORED_ATTR(SynthesizedProtocol)
841842
IGNORED_ATTR(Testable)
842843
IGNORED_ATTR(Transparent)
844+
IGNORED_ATTR(UsableFromInlineImport)
843845
IGNORED_ATTR(WarnUnqualifiedAccess)
844846
IGNORED_ATTR(WeakLinked)
845847
#undef IGNORED_ATTR

lib/Sema/TypeCheckDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5775,6 +5775,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
57755775
UNINTERESTING_ATTR(ClangImporterSynthesizedType)
57765776
UNINTERESTING_ATTR(WeakLinked)
57775777
UNINTERESTING_ATTR(Frozen)
5778+
UNINTERESTING_ATTR(UsableFromInlineImport)
5779+
57785780
#undef UNINTERESTING_ATTR
57795781

57805782
void visitAvailableAttr(AvailableAttr *attr) {

0 commit comments

Comments
 (0)