Skip to content

Commit e1f50b2

Browse files
committed
SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline
1 parent a00f252 commit e1f50b2

File tree

240 files changed

+6262
-6258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

240 files changed

+6262
-6258
lines changed

benchmark/single-source/PopFrontGeneric.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let arrayCount = 1024
2222

2323
// This test case exposes rdar://17440222 which caused rdar://17974483 (popFront
2424
// being really slow).
25-
@_versioned
25+
@usableFromInline
2626
protocol MyArrayBufferProtocol : MutableCollection, RandomAccessCollection {
2727
mutating func myReplace<C>(
2828
_ subRange: Range<Int>,

benchmark/single-source/Queue.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public let QueueConcrete = BenchmarkInfo(
2828

2929
// TODO: remove when there is a native equivalent in the std lib
3030
extension RangeReplaceableCollection where Self: BidirectionalCollection {
31-
@_inlineable
31+
@inlinable
3232
public mutating func popLast() -> Element? {
3333
if isEmpty { return nil}
3434
else { return removeLast() }

docs/StandardLibraryProgrammersManual.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ TODO: Should this subsume or link to [AccessControlInStdlib.rst](https://github.
2424
1. Customization hooks
2525
1. Use of classes, COW implementation, buffers, etc
2626
1. Compatibility, `@available`, etc.
27-
1. Resilience, ABI stability, `@_inlineable`, `@_versioned`, etc
27+
1. Resilience, ABI stability, `@inlinable`, `@usableFromInline`, etc
2828
1. Strings and ICU
2929
1. Lifetimes
3030
1. withExtendedLifetime, withUnsafe...,

include/swift/AST/Attr.def

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ SIMPLE_DECL_ATTR(nonobjc, NonObjC,
166166
SIMPLE_DECL_ATTR(_fixed_layout, FixedLayout,
167167
OnVar | OnClass | OnStruct | UserInaccessible, 31)
168168

169-
SIMPLE_DECL_ATTR(_inlineable, Inlineable,
169+
SIMPLE_DECL_ATTR(inlinable, Inlinable,
170170
OnVar | OnSubscript | OnFunc | OnConstructor | OnDestructor |
171171
UserInaccessible, 32)
172172

@@ -259,9 +259,7 @@ SIMPLE_DECL_ATTR(_show_in_interface, ShowInInterface,
259259
DECL_ATTR(_cdecl, CDecl,
260260
OnFunc | LongAttribute | UserInaccessible, 63)
261261

262-
// A testing attribute for Library Evolution ("resilience").
263-
// FIXME: Replace with improved @available attribute.
264-
SIMPLE_DECL_ATTR(_versioned, Versioned,
262+
SIMPLE_DECL_ATTR(usableFromInline, UsableFromInline,
265263
OnFunc | OnVar | OnSubscript | OnConstructor |
266264
OnDestructor | OnStruct | OnEnum | OnClass |
267265
OnProtocol | LongAttribute | UserInaccessible,

include/swift/AST/Decl.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,6 +2147,9 @@ class ValueDecl : public Decl {
21472147
SourceLoc NameLoc;
21482148
llvm::PointerIntPair<Type, 3, OptionalEnum<AccessLevel>> TypeAndAccess;
21492149

2150+
private:
2151+
bool isUsableFromInline() const;
2152+
21502153
protected:
21512154
ValueDecl(DeclKind K,
21522155
llvm::PointerUnion<DeclContext *, ASTContext *> context,
@@ -2232,8 +2235,6 @@ class ValueDecl : public Decl {
22322235
/// \see getFormalAccess
22332236
AccessLevel getFormalAccessImpl(const DeclContext *useDC) const;
22342237

2235-
bool isVersionedInternalDecl() const;
2236-
22372238
/// Returns the access level specified explicitly by the user, or provided by
22382239
/// default according to language rules.
22392240
///
@@ -2242,14 +2243,19 @@ class ValueDecl : public Decl {
22422243
/// being used), features that affect formal access such as \c \@testable are
22432244
/// taken into account.
22442245
///
2246+
/// If \p isUsageFromInline is true, the presence of the \c @usableFromInline
2247+
/// attribute will treat internal declarations as public. This is normally
2248+
/// false for name lookup and other source language concerns, but true when
2249+
/// computing the linkage of generated functions.
2250+
///
22452251
/// \sa getFormalAccessScope
22462252
AccessLevel getFormalAccess(const DeclContext *useDC = nullptr,
2247-
bool respectVersionedAttr = false) const {
2253+
bool isUsageFromInline = false) const {
22482254
assert(hasAccess() && "access not computed yet");
22492255
AccessLevel result = TypeAndAccess.getInt().getValue();
2250-
if (respectVersionedAttr &&
2256+
if (isUsageFromInline &&
22512257
result == AccessLevel::Internal &&
2252-
isVersionedInternalDecl()) {
2258+
isUsableFromInline()) {
22532259
assert(!useDC);
22542260
return AccessLevel::Public;
22552261
}
@@ -2280,8 +2286,8 @@ class ValueDecl : public Decl {
22802286
bool respectVersionedAttr = false) const;
22812287

22822288

2283-
/// Copy the formal access level and @_versioned attribute from source.
2284-
void copyFormalAccessAndVersionedAttrFrom(ValueDecl *source);
2289+
/// Copy the formal access level and @usableFromInline attribute from source.
2290+
void copyFormalAccessFrom(ValueDecl *source);
22852291

22862292
/// Returns the access level that actually controls how a declaration should
22872293
/// be emitted and may be used.
@@ -5283,7 +5289,7 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
52835289
/// The ResilienceExpansion for default arguments.
52845290
///
52855291
/// In Swift 4 mode, default argument expressions are serialized, and must
5286-
/// obey the restrictions imposed upon inlineable function bodies.
5292+
/// obey the restrictions imposed upon inlinable function bodies.
52875293
ResilienceExpansion getDefaultArgumentResilienceExpansion() const {
52885294
return ResilienceExpansion(
52895295
Bits.AbstractFunctionDecl.DefaultArgumentResilienceExpansion);
@@ -5835,7 +5841,7 @@ class EnumElementDecl : public ValueDecl {
58355841
/// The ResilienceExpansion for default arguments.
58365842
///
58375843
/// In Swift 4 mode, default argument expressions are serialized, and must
5838-
/// obey the restrictions imposed upon inlineable function bodies.
5844+
/// obey the restrictions imposed upon inlinable function bodies.
58395845
ResilienceExpansion getDefaultArgumentResilienceExpansion() const {
58405846
return ResilienceExpansion(
58415847
Bits.EnumElementDecl.DefaultArgumentResilienceExpansion);

include/swift/AST/DiagnosticsSema.def

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3712,30 +3712,30 @@ WARNING(discardable_result_on_void_never_function, none,
37123712
//------------------------------------------------------------------------------
37133713

37143714
ERROR(fixed_layout_attr_on_internal_type,
3715-
none, "'@_fixed_layout' attribute can only be applied to '@_versioned' "
3715+
none, "'@_fixed_layout' attribute can only be applied to '@usableFromInline' "
37163716
"or public declarations, but %0 is "
37173717
"%select{private|fileprivate|internal|%error|%error}1",
37183718
(DeclName, AccessLevel))
37193719

37203720
ERROR(versioned_attr_with_explicit_access,
3721-
none, "'@_versioned' attribute can only be applied to internal "
3721+
none, "'@usableFromInline' attribute can only be applied to internal "
37223722
"declarations, but %0 is %select{private|fileprivate|%error|public|open}1",
37233723
(DeclName, AccessLevel))
37243724

37253725
ERROR(versioned_attr_in_protocol,none,
3726-
"'@_versioned' attribute cannot be used in protocols", ())
3726+
"'@usableFromInline' attribute cannot be used in protocols", ())
37273727

37283728
ERROR(versioned_dynamic_not_supported,none,
3729-
"'@_versioned' attribute cannot be applied to 'dynamic' declarations", ())
3729+
"'@usableFromInline' attribute cannot be applied to 'dynamic' declarations", ())
37303730

37313731
#define FRAGILE_FUNC_KIND \
37323732
"%select{a '@_transparent' function|" \
37333733
"an '@inline(__always)' function|" \
3734-
"an '@_inlineable' function|" \
3734+
"an '@inlinable' function|" \
37353735
"a default argument value|" \
37363736
"a property initializer in a '@_fixed_layout' type}"
37373737

3738-
ERROR(local_type_in_inlineable_function,
3738+
ERROR(local_type_in_inlinable_function,
37393739
none, "type %0 cannot be nested inside " FRAGILE_FUNC_KIND "1",
37403740
(DeclName, unsigned))
37413741

@@ -3750,21 +3750,21 @@ NOTE(resilience_decl_declared_here,
37503750
none, "%0 %1 is not public", (DescriptiveDeclKind, DeclName))
37513751

37523752
NOTE(resilience_decl_declared_here_versioned,
3753-
none, "%0 %1 is not '@_versioned' or public", (DescriptiveDeclKind, DeclName))
3753+
none, "%0 %1 is not '@usableFromInline' or public", (DescriptiveDeclKind, DeclName))
37543754

3755-
ERROR(class_designated_init_inlineable_resilient,none,
3755+
ERROR(class_designated_init_inlinable_resilient,none,
37563756
"initializer for class %0 is "
3757-
"'%select{@_transparent|@inline(__always)|@_inlineable|%error}1' and must "
3757+
"'%select{@_transparent|@inline(__always)|@inlinable|%error}1' and must "
37583758
"delegate to another initializer", (Type, unsigned))
37593759

37603760
ERROR(attribute_invalid_on_stored_property,
37613761
none, "'@%0' attribute cannot be applied to stored properties", (StringRef))
37623762

3763-
ERROR(inlineable_dynamic_not_supported,
3764-
none, "'@_inlineable' attribute cannot be applied to 'dynamic' declarations", ())
3763+
ERROR(inlinable_dynamic_not_supported,
3764+
none, "'@inlinable' attribute cannot be applied to 'dynamic' declarations", ())
37653765

3766-
ERROR(inlineable_decl_not_public,
3767-
none, "'@_inlineable' attribute can only be applied to public declarations, "
3766+
ERROR(inlinable_decl_not_public,
3767+
none, "'@inlinable' attribute can only be applied to public declarations, "
37683768
"but %0 is %select{private|fileprivate|internal|%error|%error}1",
37693769
(DeclBaseName, AccessLevel))
37703770

include/swift/AST/Module.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ enum class SourceFileKind {
107107
/// Discriminator for resilience strategy.
108108
enum class ResilienceStrategy : unsigned {
109109
/// Public nominal types: fragile
110-
/// Non-inlineable function bodies: resilient
110+
/// Non-inlinable function bodies: resilient
111111
///
112112
/// This is the default behavior without any flags.
113113
Default,
114114

115115
/// Public nominal types: resilient
116-
/// Non-inlineable function bodies: resilient
116+
/// Non-inlinable function bodies: resilient
117117
///
118118
/// This is the behavior with -enable-resilience.
119119
Resilient

include/swift/SILOptimizer/Utils/PerformanceInlinerUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ enum class InlineSelection {
3737
NoSemanticsAndGlobalInit
3838
};
3939

40-
// Returns the callee of an apply_inst if it is basically inlineable.
40+
// Returns the callee of an apply_inst if it is basically inlinable.
4141
SILFunction *getEligibleFunction(FullApplySite AI,
4242
InlineSelection WhatToInline);
4343

lib/AST/Decl.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,19 +2102,19 @@ SourceLoc ValueDecl::getAttributeInsertionLoc(bool forModifier) const {
21022102
}
21032103

21042104
/// Returns true if \p VD needs to be treated as publicly-accessible
2105-
/// at the SIL, LLVM, and machine levels due to being versioned.
2106-
bool ValueDecl::isVersionedInternalDecl() const {
2105+
/// at the SIL, LLVM, and machine levels due to being @usableFromInline.
2106+
bool ValueDecl::isUsableFromInline() const {
21072107
assert(getFormalAccess() == AccessLevel::Internal);
21082108

2109-
if (getAttrs().hasAttribute<VersionedAttr>())
2109+
if (getAttrs().hasAttribute<UsableFromInlineAttr>())
21102110
return true;
21112111

21122112
if (auto *accessor = dyn_cast<AccessorDecl>(this))
2113-
if (accessor->getStorage()->getAttrs().hasAttribute<VersionedAttr>())
2113+
if (accessor->getStorage()->getAttrs().hasAttribute<UsableFromInlineAttr>())
21142114
return true;
21152115

21162116
if (auto *EED = dyn_cast<EnumElementDecl>(this))
2117-
if (EED->getParentEnum()->getAttrs().hasAttribute<VersionedAttr>())
2117+
if (EED->getParentEnum()->getAttrs().hasAttribute<UsableFromInlineAttr>())
21182118
return true;
21192119

21202120
return false;
@@ -2251,15 +2251,15 @@ AccessScope ValueDecl::getFormalAccessScope(const DeclContext *useDC,
22512251
llvm_unreachable("unknown access level");
22522252
}
22532253

2254-
void ValueDecl::copyFormalAccessAndVersionedAttrFrom(ValueDecl *source) {
2254+
void ValueDecl::copyFormalAccessFrom(ValueDecl *source) {
22552255
if (!hasAccess()) {
22562256
setAccess(source->getFormalAccess());
22572257
}
22582258

2259-
// Inherit the @_versioned attribute.
2260-
if (source->getAttrs().hasAttribute<VersionedAttr>()) {
2259+
// Inherit the @usableFromInline attribute.
2260+
if (source->getAttrs().hasAttribute<UsableFromInlineAttr>()) {
22612261
auto &ctx = getASTContext();
2262-
auto *clonedAttr = new (ctx) VersionedAttr(/*implicit=*/true);
2262+
auto *clonedAttr = new (ctx) UsableFromInlineAttr(/*implicit=*/true);
22632263
getAttrs().add(clonedAttr);
22642264
}
22652265
}
@@ -2806,7 +2806,7 @@ void ClassDecl::addImplicitDestructor() {
28062806
setHasDestructor();
28072807

28082808
// Propagate access control and versioned-ness.
2809-
DD->copyFormalAccessAndVersionedAttrFrom(this);
2809+
DD->copyFormalAccessFrom(this);
28102810

28112811
// Wire up generic environment of DD.
28122812
DD->setGenericEnvironment(getGenericEnvironmentOfContext());

lib/AST/DeclContext.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,17 +397,17 @@ ResilienceExpansion DeclContext::getResilienceExpansion() const {
397397
if (AFD->isTransparent())
398398
return ResilienceExpansion::Minimal;
399399

400-
if (AFD->getAttrs().hasAttribute<InlineableAttr>())
400+
if (AFD->getAttrs().hasAttribute<InlinableAttr>())
401401
return ResilienceExpansion::Minimal;
402402

403403
if (auto attr = AFD->getAttrs().getAttribute<InlineAttr>())
404404
if (attr->getKind() == InlineKind::Always)
405405
return ResilienceExpansion::Minimal;
406406

407-
// If a property or subscript is @_inlineable, the accessors are
408-
// @_inlineable also.
407+
// If a property or subscript is @inlinable, the accessors are
408+
// @inlinable also.
409409
if (auto accessor = dyn_cast<AccessorDecl>(AFD))
410-
if (accessor->getStorage()->getAttrs().getAttribute<InlineableAttr>())
410+
if (accessor->getStorage()->getAttrs().getAttribute<InlinableAttr>())
411411
return ResilienceExpansion::Minimal;
412412
}
413413
}

lib/Demangling/OldDemangler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ class OldDemangler {
675675
Node::Kind::GenericSpecializationNotReAbstracted :
676676
Node::Kind::GenericSpecialization);
677677

678-
// Create a node if the specialization is externally inlineable.
678+
// Create a node if the specialization is externally inlinable.
679679
if (Mangled.nextIf("q")) {
680680
auto kind = Node::Kind::SpecializationIsFragile;
681681
spec->addChild(Factory.createNode(kind), Factory);
@@ -692,7 +692,7 @@ class OldDemangler {
692692
auto spec =
693693
Factory.createNode(Node::Kind::FunctionSignatureSpecialization);
694694

695-
// Create a node if the specialization is externally inlineable.
695+
// Create a node if the specialization is externally inlinable.
696696
if (Mangled.nextIf("q")) {
697697
auto kind = Node::Kind::SpecializationIsFragile;
698698
spec->addChild(Factory.createNode(kind), Factory);

lib/SIL/SILDeclRef.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,15 @@ SILLinkage SILDeclRef::getLinkage(ForDefinition_t forDefinition) const {
288288
// Three cases:
289289
//
290290
// 1) Type is formally @_fixed_layout. Root initializers can be declared
291-
// @_inlineable. The property initializer must only reference
291+
// @inlinable. The property initializer must only reference
292292
// public symbols, and is serialized, so we give it PublicNonABI linkage.
293293
//
294294
// 2) Type is not formally @_fixed_layout and the module is not resilient.
295-
// Root initializers can be declared @_inlineable. This is the annoying
295+
// Root initializers can be declared @inlinable. This is the annoying
296296
// case. We give the initializer public linkage if the type is public.
297297
//
298298
// 3) Type is resilient. The property initializer is never public because
299-
// root initializers cannot be @_inlineable.
299+
// root initializers cannot be @inlinable.
300300
//
301301
// FIXME: Get rid of case 2 somehow.
302302
if (isSerialized())
@@ -424,7 +424,7 @@ IsSerialized_t SILDeclRef::isSerialized() const {
424424
dc = getDecl()->getInnermostDeclContext();
425425

426426
// Enum element constructors are serialized if the enum is
427-
// @_versioned or public.
427+
// @usableFromInline or public.
428428
if (isEnumElement())
429429
if (d->getEffectiveAccess() >= AccessLevel::Public)
430430
return IsSerialized;
@@ -441,7 +441,7 @@ IsSerialized_t SILDeclRef::isSerialized() const {
441441
return IsSerializable;
442442

443443
// The allocating entry point for designated initializers are serialized
444-
// if the class is @_versioned or public.
444+
// if the class is @usableFromInline or public.
445445
if (kind == SILDeclRef::Kind::Allocator) {
446446
auto *ctor = cast<ConstructorDecl>(d);
447447
if (ctor->isDesignatedInit() &&
@@ -467,11 +467,11 @@ IsSerialized_t SILDeclRef::isSerialized() const {
467467
}
468468

469469
// Declarations imported from Clang modules are serialized if
470-
// referenced from an inlineable context.
470+
// referenced from an inlinable context.
471471
if (isClangImported())
472472
return IsSerializable;
473473

474-
// Otherwise, ask the AST if we're inside an @_inlineable context.
474+
// Otherwise, ask the AST if we're inside an @inlinable context.
475475
if (dc->getResilienceExpansion() == ResilienceExpansion::Minimal)
476476
return IsSerialized;
477477

lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static bool canAndShouldUnrollLoop(SILLoop *Loop, uint64_t TripCount) {
198198
if (auto AI = FullApplySite::isa(&Inst)) {
199199
auto Callee = AI.getCalleeFunction();
200200
if (Callee && getEligibleFunction(AI, InlineSelection::Everything)) {
201-
// If callee is rather big and potentialy inlineable, it may be better
201+
// If callee is rather big and potentialy inlinable, it may be better
202202
// not to unroll, so that the body of the calle can be inlined later.
203203
Cost += Callee->size() * InsnsPerBB;
204204
}

lib/SILOptimizer/Utils/PerformanceInlinerUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ static bool isCallerAndCalleeLayoutConstraintsCompatible(FullApplySite AI) {
657657
return true;
658658
}
659659

660-
// Returns the callee of an apply_inst if it is basically inlineable.
660+
// Returns the callee of an apply_inst if it is basically inlinable.
661661
SILFunction *swift::getEligibleFunction(FullApplySite AI,
662662
InlineSelection WhatToInline) {
663663
// For now, we cannot inline begin_apply at all.

lib/Sema/CodeSynthesis.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,15 +2105,15 @@ swift::createDesignatedInitOverride(TypeChecker &tc,
21052105
access = std::min(access, superclassCtor->getFormalAccess());
21062106
ctor->setAccess(access);
21072107

2108-
// Inherit the @_versioned attribute.
2109-
if (superclassCtor->getAttrs().hasAttribute<VersionedAttr>()) {
2110-
auto *clonedAttr = new (ctx) VersionedAttr(/*implicit=*/true);
2108+
// Inherit the @usableFromInline attribute.
2109+
if (superclassCtor->getAttrs().hasAttribute<UsableFromInlineAttr>()) {
2110+
auto *clonedAttr = new (ctx) UsableFromInlineAttr(/*implicit=*/true);
21112111
ctor->getAttrs().add(clonedAttr);
21122112
}
21132113

2114-
// Inherit the @_inlineable attribute.
2115-
if (superclassCtor->getAttrs().hasAttribute<InlineableAttr>()) {
2116-
auto *clonedAttr = new (ctx) InlineableAttr(/*implicit=*/true);
2114+
// Inherit the @inlinable attribute.
2115+
if (superclassCtor->getAttrs().hasAttribute<InlinableAttr>()) {
2116+
auto *clonedAttr = new (ctx) InlinableAttr(/*implicit=*/true);
21172117
ctor->getAttrs().add(clonedAttr);
21182118
}
21192119

0 commit comments

Comments
 (0)