Skip to content

Commit a7ff0da

Browse files
authored
Merge pull request #15594 from slavapestov/se-0193
Implement SE-0193 - part 1
2 parents a00f252 + de4c319 commit a7ff0da

File tree

246 files changed

+6359
-6320
lines changed

Some content is hidden

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

246 files changed

+6359
-6320
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/DiagnosticsParse.def

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,12 @@ ERROR(attr_only_on_parameters_parse, none,
13111311
ERROR(attr_access_expected_set,none,
13121312
"expected 'set' as subject of '%0' modifier", (StringRef))
13131313

1314+
// Attributes
1315+
ERROR(attr_renamed, none,
1316+
"'@%0' has been renamed to '@%1'", (StringRef, StringRef))
1317+
WARNING(attr_renamed_warning, none,
1318+
"'@%0' has been renamed to '@%1'", (StringRef, StringRef))
1319+
13141320
// availability
13151321
ERROR(attr_availability_platform,none,
13161322
"expected platform name or '*' for '%0' attribute", (StringRef))
@@ -1319,7 +1325,7 @@ ERROR(attr_availability_unavailable_deprecated,none,
13191325
"'deprecated'", (StringRef))
13201326

13211327
WARNING(attr_availability_unknown_platform,none,
1322-
"unknown platform '%0' for attribute '%1'", (StringRef, StringRef))
1328+
"unknown platform '%0' for attribute '%1'", (StringRef, StringRef))
13231329
ERROR(attr_availability_invalid_renamed,none,
13241330
"'renamed' argument of '%0' attribute must be an operator, identifier, "
13251331
"or full function name, optionally prefixed by a type name", (StringRef))
@@ -1334,9 +1340,6 @@ ERROR(attr_availability_expected_equal,none,
13341340
ERROR(attr_availability_expected_version,none,
13351341
"expected version number in '%0' attribute", (StringRef))
13361342

1337-
ERROR(attr_availability_renamed, none,
1338-
"@availability has been renamed to @available", ())
1339-
13401343
// autoclosure
13411344
ERROR(attr_autoclosure_expected_r_paren,PointsToFirstBadToken,
13421345
"expected ')' in @autoclosure", ())

include/swift/AST/DiagnosticsSema.def

Lines changed: 14 additions & 14 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,
3761-
none, "'@%0' attribute cannot be applied to stored properties", (StringRef))
3761+
none, "'%0' attribute cannot be applied to stored properties", (DeclAttribute))
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);

0 commit comments

Comments
 (0)