Skip to content

Commit e7607e1

Browse files
authored
Merge pull request #81393 from beccadax/abi-let-you-graduate-6.2
2 parents 97c5fbf + e831274 commit e7607e1

33 files changed

+360
-188
lines changed

include/swift/AST/Attr.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -380,21 +380,14 @@ class DeclAttribute : public AttributeBase {
380380
/// valid if they match.
381381
EquivalentInABIAttr = 1ull << 18,
382382

383-
/// Attribute can be used in an \c \@abi attribute, but must match
384-
/// equivalent on API decl; if omitted, API decl's attribute will be
385-
/// cloned. Use where you would want to use \c EquivalentInABIAttr but
386-
/// repeating the attribute is judged too burdensome.
387-
InferredInABIAttr = 1ull << 19,
388-
389383
/// Use for attributes which are \em only valid on declarations that cannot
390384
/// have an \c @abi attribute, such as \c ImportDecl .
391-
UnreachableInABIAttr = 1ull << 20,
385+
UnreachableInABIAttr = 1ull << 19,
392386
};
393387

394388
enum : uint64_t {
395389
InABIAttrMask = ForbiddenInABIAttr | UnconstrainedInABIAttr
396-
| EquivalentInABIAttr | InferredInABIAttr
397-
| UnreachableInABIAttr
390+
| EquivalentInABIAttr | UnreachableInABIAttr
398391
};
399392

400393
LLVM_READNONE

include/swift/AST/DeclAttr.def

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ SIMPLE_DECL_ATTR(NSManaged, NSManaged,
143143

144144
CONTEXTUAL_SIMPLE_DECL_ATTR(lazy, Lazy,
145145
OnVar,
146-
DeclModifier | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | InferredInABIAttr,
146+
DeclModifier | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | UnconstrainedInABIAttr,
147147
16)
148148

149149
SIMPLE_DECL_ATTR(LLDBDebuggerFunction, LLDBDebuggerFunction,
@@ -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,
@@ -455,7 +455,7 @@ DECL_ATTR(_dynamicReplacement, DynamicReplacement,
455455

456456
SIMPLE_DECL_ATTR(_borrowed, Borrowed,
457457
OnVar | OnSubscript,
458-
UserInaccessible | NotSerialized | ABIBreakingToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove | InferredInABIAttr,
458+
UserInaccessible | NotSerialized | ABIBreakingToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove | ForbiddenInABIAttr,
459459
81)
460460

461461
DECL_ATTR(_private, PrivateImport,
@@ -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,
@@ -860,7 +860,6 @@ DECL_ATTR(abi, ABI,
860860
OnConstructor | OnFunc | OnSubscript | OnVar,
861861
LongAttribute | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | ForbiddenInABIAttr,
862862
165)
863-
DECL_ATTR_FEATURE_REQUIREMENT(ABI, ABIAttribute)
864863

865864
// Unused '166': Used to be `@execution(caller | concurrent)` replaced with `@concurrent` and `nonisolated(nonsending)`
866865

include/swift/AST/DiagnosticsParse.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,11 @@ ERROR(attr_unsupported_on_target, none,
15681568
ERROR(attr_name_unsupported_on_target, none,
15691569
"attribute '%0' is unsupported on target '%1'", (StringRef, StringRef))
15701570

1571+
// abi attribute
1572+
ERROR(attr_abi_incompatible_kind,none,
1573+
"cannot use %0 in '@abi'",
1574+
(DescriptiveDeclKind))
1575+
15711576
// availability
15721577
ERROR(attr_availability_platform,none,
15731578
"expected platform name or '*' for '%0' attribute", (StringRef))

include/swift/AST/DiagnosticsSema.def

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7439,7 +7439,7 @@ ERROR(property_wrapper_effectful,none,
74397439

74407440
ERROR(property_with_wrapper_conflict_attribute,none,
74417441
"property %0 with a wrapper cannot also be "
7442-
"%select{lazy|'@NSCopying'|'@NSManaged'|weak|unowned|unmanaged}1",
7442+
"%select{lazy|'@NSCopying'|'@NSManaged'|'@abi'|weak|unowned|unmanaged}1",
74437443
(Identifier, int))
74447444
ERROR(property_wrapper_not_single_var, none,
74457445
"property wrapper can only apply to a single variable", ())
@@ -8436,14 +8436,10 @@ ERROR(attr_abi_mismatched_async,none,
84368436
"cannot give %0 the ABI of %select{a non-async|an async}1 %kindonly0",
84378437
(Decl *, /*abiIsAsync=*/bool))
84388438

8439-
ERROR(attr_abi_mismatched_pbd_size,none,
8440-
"cannot give pattern binding the ABI of a binding with "
8441-
"%select{more|fewer}0 patterns",
8442-
(/*abiHasExtra=*/bool))
8443-
8444-
ERROR(attr_abi_mismatched_var,none,
8445-
"no match for %select{%kind0 in the ABI|ABI %kind0}1",
8446-
(Decl *, /*isABI=*/bool))
8439+
ERROR(attr_abi_multiple_vars,none,
8440+
"'abi' attribute can only be applied to a single %0; declare each "
8441+
"%0 separately",
8442+
(DescriptiveDeclKind))
84478443

84488444
ERROR(attr_abi_incompatible_with_silgen_name,none,
84498445
"cannot use '@_silgen_name' and '@abi' on the same %0 because they serve "
@@ -8459,9 +8455,6 @@ ERROR(attr_abi_extra_attr,none,
84598455
ERROR(attr_abi_forbidden_attr,none,
84608456
"unused '%0' %select{attribute|modifier}1 in '@abi'",
84618457
(StringRef, bool))
8462-
REMARK(abi_attr_inferred_attribute,none,
8463-
"inferred '%0' in '@abi' to match %select{attribute|modifier}1 on API",
8464-
(StringRef, bool))
84658458

84668459
ERROR(attr_abi_mismatched_attr,none,
84678460
"'%0' %select{attribute|modifier}1 in '@abi' should match '%2'",
@@ -8501,6 +8494,13 @@ ERROR(attr_abi_no_default_arguments,none,
85018494
"affect the parameter's ABI",
85028495
(Decl *))
85038496
8497+
ERROR(attr_abi_no_macros,none,
8498+
"%kind0 cannot be expanded in '@abi' attribute",
8499+
(Decl *))
8500+
ERROR(attr_abi_no_lazy,none,
8501+
"'lazy' is not compatible with '@abi' attribute",
8502+
())
8503+
85048504
// These macros insert 'final', 'non-final', or nothing depending on both the
85058505
// current decl and its counterpart, such that 'non-final' is used if the
85068506
// counterpart would be described as 'final' or 'static'. They must be kept in

include/swift/Basic/Features.def

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ LANGUAGE_FEATURE(IsolatedConformances, 470, "Global-actor isolated conformances"
258258
LANGUAGE_FEATURE(AsyncExecutionBehaviorAttributes, 0, "@concurrent and nonisolated(nonsending)")
259259
LANGUAGE_FEATURE(GeneralizedIsSameMetaTypeBuiltin, 465, "Builtin.is_same_metatype with support for noncopyable/nonescapable types")
260260
LANGUAGE_FEATURE(ValueGenericsNameLookup, 452, "Value generics appearing as static members for namelookup")
261+
SUPPRESSIBLE_LANGUAGE_FEATURE(ABIAttributeSE0479, 479, "@abi attribute on functions, initializers, properties, and subscripts")
261262

262263
// Swift 6
263264
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
@@ -488,9 +489,6 @@ EXPERIMENTAL_FEATURE(CoroutineAccessorsUnwindOnCallerError, false)
488489
EXPERIMENTAL_FEATURE(AddressableParameters, true)
489490
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(AddressableTypes, true)
490491

491-
/// Allow the @abi attribute.
492-
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(ABIAttribute, true)
493-
494492
/// Allow custom availability domains to be defined and referenced.
495493
EXPERIMENTAL_FEATURE(CustomAvailability, true)
496494

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,6 @@ namespace swift {
269269
/// Emit a remark on early exit in explicit interface build
270270
bool EnableSkipExplicitInterfaceModuleBuildRemarks = false;
271271

272-
/// Emit a remark when \c \@abi infers an attribute or modifier.
273-
bool EnableABIInferenceRemarks = false;
274-
275272
///
276273
/// Support for alternate usage modes
277274
///

include/swift/Option/Options.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,6 @@ def remark_module_serialization : Flag<["-"], "Rmodule-serialization">,
468468
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
469469
HelpText<"Emit remarks about module serialization">;
470470

471-
def remark_abi_inference : Flag<["-"], "Rabi-inference">,
472-
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
473-
HelpText<"Emit a remark when an '@abi' attribute adds an attribute or modifier to the ABI declaration based on its presence in the API">;
474-
475471
def emit_tbd : Flag<["-"], "emit-tbd">,
476472
HelpText<"Emit a TBD file">,
477473
Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput]>;

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3289,8 +3289,8 @@ suppressingFeatureCoroutineAccessors(PrintOptions &options,
32893289
}
32903290

32913291
static void
3292-
suppressingFeatureABIAttribute(PrintOptions &options,
3293-
llvm::function_ref<void()> action) {
3292+
suppressingFeatureABIAttributeSE0479(PrintOptions &options,
3293+
llvm::function_ref<void()> action) {
32943294
llvm::SaveAndRestore<bool> scope1(options.PrintSyntheticSILGenName, true);
32953295
ExcludeAttrRAII scope2(options.ExcludeAttrList, DeclAttrKind::ABI);
32963296
action();

lib/AST/Attr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static_assert(IsTriviallyDestructible<DeclAttributes>::value,
6161
DeclAttribute::APIBreakingToRemove | DeclAttribute::APIStableToRemove), \
6262
#Name " needs to specify either APIBreakingToRemove or APIStableToRemove"); \
6363
static_assert(DeclAttribute::hasOneBehaviorFor##Id(DeclAttribute::InABIAttrMask), \
64-
#Name " needs to specify exactly one of ForbiddenInABIAttr, UnconstrainedInABIAttr, EquivalentInABIAttr, InferredInABIAttr, or UnreachableInABIAttr");
64+
#Name " needs to specify exactly one of ForbiddenInABIAttr, UnconstrainedInABIAttr, EquivalentInABIAttr, or UnreachableInABIAttr");
6565
#include "swift/AST/DeclAttr.def"
6666

6767
#define TYPE_ATTR(_, Id) \

lib/AST/FeatureSet.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ static ABIAttr *getABIAttr(Decl *decl) {
389389
return decl->getAttrs().getAttribute<ABIAttr>();
390390
}
391391

392-
static bool usesFeatureABIAttribute(Decl *decl) {
392+
static bool usesFeatureABIAttributeSE0479(Decl *decl) {
393393
return getABIAttr(decl) != nullptr;
394394
}
395395

@@ -700,8 +700,12 @@ FeatureSet swift::getUniqueFeaturesUsed(Decl *decl) {
700700
// Remove all the features used by all enclosing declarations.
701701
Decl *enclosingDecl = decl;
702702
while (!features.empty()) {
703+
// If we were in an @abi attribute, collect from the API counterpart.
704+
auto abiRole = ABIRoleInfo(enclosingDecl);
705+
if (!abiRole.providesAPI() && abiRole.getCounterpart())
706+
enclosingDecl = abiRole.getCounterpart();
703707
// Find the next outermost enclosing declaration.
704-
if (auto accessor = dyn_cast<AccessorDecl>(enclosingDecl))
708+
else if (auto accessor = dyn_cast<AccessorDecl>(enclosingDecl))
705709
enclosingDecl = accessor->getStorage();
706710
else
707711
enclosingDecl = enclosingDecl->getDeclContext()->getAsDecl();

0 commit comments

Comments
 (0)