Skip to content

Commit 6198f30

Browse files
authored
Merge pull request #15762 from slavapestov/versioned-is-gone
Versioned is gone
2 parents c8ab588 + 61280ef commit 6198f30

File tree

5 files changed

+34
-25
lines changed

5 files changed

+34
-25
lines changed

include/swift/AST/Decl.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,17 +2243,17 @@ class ValueDecl : public Decl {
22432243
/// being used), features that affect formal access such as \c \@testable are
22442244
/// taken into account.
22452245
///
2246-
/// If \p isUsageFromInline is true, the presence of the \c @usableFromInline
2247-
/// attribute will treat internal declarations as public. This is normally
2246+
/// If \p treatUsableFromInlineAsPublic is true, declarations marked with the
2247+
/// \c @usableFromInline attribute are treated as public. This is normally
22482248
/// false for name lookup and other source language concerns, but true when
22492249
/// computing the linkage of generated functions.
22502250
///
22512251
/// \sa getFormalAccessScope
22522252
AccessLevel getFormalAccess(const DeclContext *useDC = nullptr,
2253-
bool isUsageFromInline = false) const {
2253+
bool treatUsableFromInlineAsPublic = false) const {
22542254
assert(hasAccess() && "access not computed yet");
22552255
AccessLevel result = TypeAndAccess.getInt().getValue();
2256-
if (isUsageFromInline &&
2256+
if (treatUsableFromInlineAsPublic &&
22572257
result == AccessLevel::Internal &&
22582258
isUsableFromInline()) {
22592259
assert(!useDC);
@@ -2277,13 +2277,19 @@ class ValueDecl : public Decl {
22772277
/// taken into account.
22782278
///
22792279
/// \invariant
2280-
/// <code>value.isAccessibleFrom(value.getFormalAccessScope())</code>
2280+
/// <code>value.isAccessibleFrom(
2281+
/// value.getFormalAccessScope().getDeclContext())</code>
2282+
///
2283+
/// If \p treatUsableFromInlineAsPublic is true, declarations marked with the
2284+
/// \c @usableFromInline attribute are treated as public. This is normally
2285+
/// false for name lookup and other source language concerns, but true when
2286+
/// computing the linkage of generated functions.
22812287
///
22822288
/// \sa getFormalAccess
22832289
/// \sa isAccessibleFrom
22842290
AccessScope
22852291
getFormalAccessScope(const DeclContext *useDC = nullptr,
2286-
bool respectVersionedAttr = false) const;
2292+
bool treatUsableFromInlineAsPublic = false) const;
22872293

22882294

22892295
/// Copy the formal access level and @usableFromInline attribute from source.

lib/AST/Decl.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ bool AbstractStorageDecl::isFormallyResilient() const {
15191519
// Private and (unversioned) internal variables always have a
15201520
// fixed layout.
15211521
if (!getFormalAccessScope(/*useDC=*/nullptr,
1522-
/*respectVersionedAttr=*/true).isPublic())
1522+
/*treatUsableFromInlineAsPublic=*/true).isPublic())
15231523
return false;
15241524

15251525
// If we're an instance property of a nominal type, query the type.
@@ -2204,28 +2204,31 @@ AccessLevel ValueDecl::getFormalAccessImpl(const DeclContext *useDC) const {
22042204
return getFormalAccess();
22052205
}
22062206

2207-
AccessScope ValueDecl::getFormalAccessScope(const DeclContext *useDC,
2208-
bool respectVersionedAttr) const {
2207+
AccessScope
2208+
ValueDecl::getFormalAccessScope(const DeclContext *useDC,
2209+
bool treatUsableFromInlineAsPublic) const {
22092210
const DeclContext *result = getDeclContext();
2210-
AccessLevel access = getFormalAccess(useDC, respectVersionedAttr);
2211+
AccessLevel access = getFormalAccess(useDC, treatUsableFromInlineAsPublic);
22112212

22122213
while (!result->isModuleScopeContext()) {
22132214
if (result->isLocalContext() || access == AccessLevel::Private)
22142215
return AccessScope(result, true);
22152216

22162217
if (auto enclosingNominal = dyn_cast<NominalTypeDecl>(result)) {
2217-
access = std::min(access,
2218-
enclosingNominal->getFormalAccess(useDC,
2219-
respectVersionedAttr));
2218+
auto enclosingAccess =
2219+
enclosingNominal->getFormalAccess(useDC,
2220+
treatUsableFromInlineAsPublic);
2221+
access = std::min(access, enclosingAccess);
22202222

22212223
} else if (auto enclosingExt = dyn_cast<ExtensionDecl>(result)) {
22222224
// Just check the base type. If it's a constrained extension, Sema should
22232225
// have already enforced access more strictly.
22242226
if (auto extendedTy = enclosingExt->getExtendedType()) {
22252227
if (auto nominal = extendedTy->getAnyNominal()) {
2226-
access = std::min(access,
2227-
nominal->getFormalAccess(useDC,
2228-
respectVersionedAttr));
2228+
auto nominalAccess =
2229+
nominal->getFormalAccess(useDC,
2230+
treatUsableFromInlineAsPublic);
2231+
access = std::min(access, nominalAccess);
22292232
}
22302233
}
22312234

@@ -2332,7 +2335,7 @@ bool NominalTypeDecl::isFormallyResilient() const {
23322335
// Private and (unversioned) internal types always have a
23332336
// fixed layout.
23342337
if (!getFormalAccessScope(/*useDC=*/nullptr,
2335-
/*respectVersionedAttr=*/true).isPublic())
2338+
/*treatUsableFromInlineAsPublic=*/true).isPublic())
23362339
return false;
23372340

23382341
// Check for an explicit @_fixed_layout or @_frozen attribute.

lib/Sema/CodeSynthesis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,7 +2091,7 @@ swift::createDesignatedInitOverride(TypeChecker &tc,
20912091
// This is really painful. We need better abstractions for dealing with
20922092
// @usableFromInline.
20932093
if (superclassCtor->getFormalAccess(/*useDC=*/nullptr,
2094-
/*isUsableFromInline=*/true)
2094+
/*treatUsableFromInlineAsPublic=*/true)
20952095
>= AccessLevel::Public) {
20962096
if (access == AccessLevel::Internal &&
20972097
!superclassCtor->isDynamic()) {
@@ -2102,7 +2102,7 @@ swift::createDesignatedInitOverride(TypeChecker &tc,
21022102

21032103
// Inherit the @inlinable attribute.
21042104
if (ctor->getFormalAccess(/*useDC=*/nullptr,
2105-
/*isUsableFromInline=*/true)
2105+
/*treatUsableFromInlineAsPublic=*/true)
21062106
>= AccessLevel::Public) {
21072107
if (superclassCtor->getAttrs().hasAttribute<InlinableAttr>()) {
21082108
auto *clonedAttr = new (ctx) InlinableAttr(/*implicit=*/true);

lib/Sema/TypeCheckAttr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,7 @@ void AttributeChecker::visitFixedLayoutAttr(FixedLayoutAttr *attr) {
19461946
auto *VD = cast<ValueDecl>(D);
19471947

19481948
auto access = VD->getFormalAccess(/*useDC=*/nullptr,
1949-
/*isUsageFromInline=*/true);
1949+
/*treatUsableFromInlineAsPublic=*/true);
19501950
if (access < AccessLevel::Public) {
19511951
diagnoseAndRemoveAttr(attr, diag::fixed_layout_attr_on_internal_type,
19521952
VD->getFullName(), access);
@@ -2006,7 +2006,7 @@ void AttributeChecker::visitInlinableAttr(InlinableAttr *attr) {
20062006
// @inlinable can only be applied to public or @usableFromInline
20072007
// declarations.
20082008
auto access = VD->getFormalAccess(/*useDC=*/nullptr,
2009-
/*isUsageFromInline=*/true);
2009+
/*treatUsableFromInlineAsPublic=*/true);
20102010
if (access < AccessLevel::Public) {
20112011
diagnoseAndRemoveAttr(attr, diag::inlinable_decl_not_public,
20122012
VD->getBaseName(),
@@ -2096,7 +2096,7 @@ void AttributeChecker::visitFrozenAttr(FrozenAttr *attr) {
20962096
}
20972097

20982098
auto access = ED->getFormalAccess(/*useDC=*/nullptr,
2099-
/*isUsageFromInline=*/true);
2099+
/*treatUsableFromInlineAsPublic=*/true);
21002100
if (access < AccessLevel::Public) {
21012101
diagnoseAndRemoveAttr(attr, diag::enum_frozen_nonpublic, attr);
21022102
}

stdlib/public/core/AssertCommon.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ internal func _assertionFailure(
142142
///
143143
/// This function should not be inlined because it is cold and inlining just
144144
/// bloats code.
145-
@_versioned // FIXME(sil-serialize-all)
145+
@usableFromInline // FIXME(sil-serialize-all)
146146
@inline(never)
147147
internal func _assertionFailure(
148148
_ prefix: StaticString, _ message: String,
@@ -271,7 +271,7 @@ func _undefined<T>(
271271
/// bloats code. It doesn't take a source location because it's most important
272272
/// in release builds anyway (old apps that are run on new OSs).
273273
@inline(never)
274-
@_versioned // COMPILER_INTRINSIC
274+
@usableFromInline // COMPILER_INTRINSIC
275275
internal func _diagnoseUnexpectedEnumCaseValue<SwitchedValue, RawValue>(
276276
type: SwitchedValue.Type,
277277
rawValue: RawValue
@@ -288,7 +288,7 @@ internal func _diagnoseUnexpectedEnumCaseValue<SwitchedValue, RawValue>(
288288
/// bloats code. It doesn't take a source location because it's most important
289289
/// in release builds anyway (old apps that are run on new OSs).
290290
@inline(never)
291-
@_versioned // COMPILER_INTRINSIC
291+
@usableFromInline // COMPILER_INTRINSIC
292292
internal func _diagnoseUnexpectedEnumCase<SwitchedValue>(
293293
type: SwitchedValue.Type
294294
) -> Never {

0 commit comments

Comments
 (0)