Skip to content

Commit 73cef18

Browse files
committed
Make inlinability non-ABI for @abi
Inlinability doesn’t affect the mangling except in function specializations, which are applied after the fact and should never mangle in information from an ABI-only decl. That means we can simply ban these from `@abi` instead of inferring them. Also adds some assertions to help double-check that SIL never tries to directly mangle or retrieve inlinability info from an ABI-only decl.
1 parent a07ec12 commit 73cef18

File tree

3 files changed

+43
-27
lines changed

3 files changed

+43
-27
lines changed

Diff for: include/swift/AST/DeclAttr.def

+4-4
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ SIMPLE_DECL_ATTR(unsafe_no_objc_tagged_pointer, UnsafeNoObjCTaggedPointer,
163163

164164
DECL_ATTR(inline, Inline,
165165
OnVar | OnSubscript | OnAbstractFunction,
166-
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | InferredInABIAttr,
166+
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | ForbiddenInABIAttr,
167167
20)
168168

169169
DECL_ATTR(_semantics, Semantics,
@@ -193,7 +193,7 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(postfix, Postfix,
193193

194194
SIMPLE_DECL_ATTR(_transparent, Transparent,
195195
OnFunc | OnAccessor | OnConstructor | OnVar | OnDestructor,
196-
UserInaccessible | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | InferredInABIAttr,
196+
UserInaccessible | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | ForbiddenInABIAttr,
197197
26)
198198

199199
SIMPLE_DECL_ATTR(requires_stored_property_inits, RequiresStoredPropertyInits,
@@ -216,7 +216,7 @@ SIMPLE_DECL_ATTR(_fixed_layout, FixedLayout,
216216

217217
SIMPLE_DECL_ATTR(inlinable, Inlinable,
218218
OnVar | OnSubscript | OnAbstractFunction,
219-
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | InferredInABIAttr,
219+
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | ForbiddenInABIAttr,
220220
32)
221221

222222
DECL_ATTR(_specialize, Specialize,
@@ -465,7 +465,7 @@ DECL_ATTR(_private, PrivateImport,
465465

466466
SIMPLE_DECL_ATTR(_alwaysEmitIntoClient, AlwaysEmitIntoClient,
467467
OnVar | OnSubscript | OnAbstractFunction,
468-
UserInaccessible | ABIBreakingToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | InferredInABIAttr,
468+
UserInaccessible | ABIBreakingToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | ForbiddenInABIAttr,
469469
83)
470470

471471
SIMPLE_DECL_ATTR(_implementationOnly, ImplementationOnly,

Diff for: lib/SIL/IR/SILDeclRef.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,9 @@ SerializedKind_t SILDeclRef::getSerializedKind() const {
883883

884884
auto *d = getDecl();
885885

886+
ASSERT(ABIRoleInfo(d).providesAPI()
887+
&& "should not get serialization info from ABI-only decl");
888+
886889
// Default and property wrapper argument generators are serialized if the
887890
// containing declaration is public.
888891
if (isDefaultArgGenerator() || (isPropertyWrapperBackingInitializer() &&
@@ -1021,6 +1024,9 @@ bool SILDeclRef::isNoinline() const {
10211024
return false;
10221025

10231026
auto *decl = getDecl();
1027+
ASSERT(ABIRoleInfo(decl).providesAPI()
1028+
&& "should not get inline attr from ABI-only decl");
1029+
10241030
if (auto *attr = decl->getAttrs().getAttribute<InlineAttr>())
10251031
if (attr->getKind() == InlineKind::Never)
10261032
return true;
@@ -1051,6 +1057,9 @@ bool SILDeclRef::isAlwaysInline() const {
10511057
return false;
10521058
}
10531059

1060+
ASSERT(ABIRoleInfo(decl).providesAPI()
1061+
&& "should not get inline attr from ABI-only decl");
1062+
10541063
if (auto attr = decl->getAttrs().getAttribute<InlineAttr>())
10551064
if (attr->getKind() == InlineKind::Always)
10561065
return true;
@@ -1070,6 +1079,10 @@ bool SILDeclRef::isBackDeployed() const {
10701079
return false;
10711080

10721081
auto *decl = getDecl();
1082+
1083+
ASSERT(ABIRoleInfo(decl).providesAPI()
1084+
&& "should not get backDeployed from ABI-only decl");
1085+
10731086
if (auto afd = dyn_cast<AbstractFunctionDecl>(decl))
10741087
return afd->isBackDeployed(getASTContext());
10751088

@@ -1198,6 +1211,9 @@ static std::string mangleClangDecl(Decl *decl, bool isForeign) {
11981211
}
11991212

12001213
std::string SILDeclRef::mangle(ManglingKind MKind) const {
1214+
ASSERT(!hasDecl() || ABIRoleInfo(getDecl()).providesAPI()
1215+
&& "SILDeclRef mangling ABI decl directly?");
1216+
12011217
using namespace Mangle;
12021218
ASTMangler mangler(getASTContext());
12031219

@@ -1268,9 +1284,6 @@ std::string SILDeclRef::mangle(ManglingKind MKind) const {
12681284
if (auto *ACE = getAbstractClosureExpr())
12691285
return mangler.mangleClosureEntity(ACE, SKind);
12701286

1271-
ASSERT(ABIRoleInfo(getDecl()).providesAPI()
1272-
&& "SILDeclRef mangling ABI decl directly?");
1273-
12741287
// As a special case, functions can have manually mangled names.
12751288
// Use the SILGen name only for the original non-thunked, non-curried entry
12761289
// point.

Diff for: test/attr/attr_abi.swift

+23-20
Original file line numberDiff line numberDiff line change
@@ -1869,45 +1869,48 @@ func section2() {}
18691869
@abi(func section3())
18701870
@_section("fnord") func section3() {}
18711871

1872-
// @inlinable -- automatically cloned into @abi
1873-
@abi(@inlinable func inlinable1())
1872+
// @inlinable -- banned in @abi
1873+
// Although the inlining *does* occasionally get mangled, it's only done in the
1874+
// SpecializationManglers, which shouldn't get their serialization from an ABI
1875+
// attribute.
1876+
@abi(@inlinable func inlinable1()) // expected-error {{unused 'inlinable' attribute in '@abi'}} {{6-16=}}
18741877
@inlinable func inlinable1() {}
18751878

1876-
@abi(@inlinable func inlinable2()) // expected-error {{extra 'inlinable' attribute in '@abi'}} {{6-16=}}
1879+
@abi(@inlinable func inlinable2()) // expected-error {{unused 'inlinable' attribute in '@abi'}} {{6-16=}}
18771880
func inlinable2() {}
18781881

1879-
@abi(func inlinable3()) // expected-remark {{inferred '@inlinable' in '@abi' to match attribute on API}}
1880-
@inlinable func inlinable3() {} // expected-note {{matches attribute here}}
1882+
@abi(func inlinable3())
1883+
@inlinable func inlinable3() {}
18811884

1882-
// @inline -- automatically cloned into @abi
1883-
@abi(@inline(never) func inline1())
1885+
// @inlinable -- banned in @abi
1886+
@abi(@inline(never) func inline1()) // expected-error {{unused 'inline(never)' attribute in '@abi'}} {{6-20=}}
18841887
@inline(never) func inline1() {}
18851888

1886-
@abi(@inline(never) func inline2()) // expected-error {{extra 'inline(never)' attribute in '@abi'}} {{6-20=}}
1889+
@abi(@inline(never) func inline2()) // expected-error {{unused 'inline(never)' attribute in '@abi'}} {{6-20=}}
18871890
func inline2() {}
18881891

1889-
@abi(func inline3()) // expected-remark {{inferred '@inline(never)' in '@abi' to match attribute on API}}
1890-
@inline(never) func inline3() {} // expected-note {{matches attribute here}}
1892+
@abi(func inline3())
1893+
@inline(never) func inline3() {}
18911894

1892-
// @_transparent -- automatically cloned into @abi
1893-
@abi(@_transparent func transparent1())
1895+
// @_transparent -- banned in @abi
1896+
@abi(@_transparent func transparent1()) // expected-error {{unused '_transparent' attribute in '@abi'}} {{6-19=}}
18941897
@_transparent func transparent1() {}
18951898

1896-
@abi(@_transparent func transparent2()) // expected-error {{extra '_transparent' attribute in '@abi'}} {{6-19=}}
1899+
@abi(@_transparent func transparent2()) // expected-error {{unused '_transparent' attribute in '@abi'}} {{6-19=}}
18971900
func transparent2() {}
18981901

1899-
@abi(func transparent3()) // expected-remark {{inferred '@_transparent' in '@abi' to match attribute on API}}
1900-
@_transparent func transparent3() {} // expected-note {{matches attribute here}}
1902+
@abi(func transparent3())
1903+
@_transparent func transparent3() {}
19011904

1902-
// @_alwaysEmitIntoClient -- automatically cloned into @abi
1903-
@abi(@_alwaysEmitIntoClient func alwaysEmitIntoClient1())
1905+
// @_alwaysEmitIntoClient -- banned in @abi
1906+
@abi(@_alwaysEmitIntoClient func alwaysEmitIntoClient1()) // expected-error {{unused '_alwaysEmitIntoClient' attribute in '@abi'}} {{6-28=}}
19041907
@_alwaysEmitIntoClient func alwaysEmitIntoClient1() {}
19051908

1906-
@abi(@_alwaysEmitIntoClient func alwaysEmitIntoClient2()) // expected-error {{extra '_alwaysEmitIntoClient' attribute in '@abi'}} {{6-28=}}
1909+
@abi(@_alwaysEmitIntoClient func alwaysEmitIntoClient2()) // expected-error {{unused '_alwaysEmitIntoClient' attribute in '@abi'}} {{6-28=}}
19071910
func alwaysEmitIntoClient2() {}
19081911

1909-
@abi(func alwaysEmitIntoClient3()) // expected-remark {{inferred '@_alwaysEmitIntoClient' in '@abi' to match attribute on API}}
1910-
@_alwaysEmitIntoClient func alwaysEmitIntoClient3() {} // expected-note {{matches attribute here}}
1912+
@abi(func alwaysEmitIntoClient3())
1913+
@_alwaysEmitIntoClient func alwaysEmitIntoClient3() {}
19111914

19121915
// @_optimize(none) -- banned in @abi
19131916
@abi(@_optimize(none) func optimize1()) // expected-error {{unused '_optimize(none)' attribute in '@abi'}} {{6-22=}}

0 commit comments

Comments
 (0)