Skip to content

Commit 7815b82

Browse files
committed
Forbid @_borrowed in @abi
It has indirect effects on the accessors, so it shouldn’t matter, but we can defensively redirect the query to the API counterpart anyway. This was the last `InferredInABIAttr` attribute, so we can now remove all of the infrastructure involved in supporting attribute inference.
1 parent 73cef18 commit 7815b82

11 files changed

+15
-50
lines changed

include/swift/AST/Attr.h

+2-9
Original file line numberDiff line numberDiff line change
@@ -384,21 +384,14 @@ class DeclAttribute : public AttributeBase {
384384
/// valid if they match.
385385
EquivalentInABIAttr = 1ull << 18,
386386

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

398392
enum : uint64_t {
399393
InABIAttrMask = ForbiddenInABIAttr | UnconstrainedInABIAttr
400-
| EquivalentInABIAttr | InferredInABIAttr
401-
| UnreachableInABIAttr
394+
| EquivalentInABIAttr | UnreachableInABIAttr
402395
};
403396

404397
LLVM_READNONE

include/swift/AST/DeclAttr.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -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,

include/swift/AST/DiagnosticsSema.def

-3
Original file line numberDiff line numberDiff line change
@@ -8385,9 +8385,6 @@ ERROR(attr_abi_extra_attr,none,
83858385
ERROR(attr_abi_forbidden_attr,none,
83868386
"unused '%0' %select{attribute|modifier}1 in '@abi'",
83878387
(StringRef, bool))
8388-
REMARK(abi_attr_inferred_attribute,none,
8389-
"inferred '%0' in '@abi' to match %select{attribute|modifier}1 on API",
8390-
(StringRef, bool))
83918388

83928389
ERROR(attr_abi_mismatched_attr,none,
83938390
"'%0' %select{attribute|modifier}1 in '@abi' should match '%2'",

include/swift/Basic/LangOptions.h

-3
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

-4
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/Attr.cpp

+1-1
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/Frontend/CompilerInvocation.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1422,8 +1422,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
14221422

14231423
Opts.EnableSkipExplicitInterfaceModuleBuildRemarks = Args.hasArg(OPT_remark_skip_explicit_interface_build);
14241424

1425-
Opts.EnableABIInferenceRemarks = Args.hasArg(OPT_remark_abi_inference);
1426-
14271425
if (Args.hasArg(OPT_experimental_skip_non_exportable_decls)) {
14281426
// Only allow -experimental-skip-non-exportable-decls if either library
14291427
// evolution is enabled (in which case the module's ABI is independent of

lib/Sema/TypeCheckAttrABI.cpp

-20
Original file line numberDiff line numberDiff line change
@@ -881,26 +881,6 @@ class ABIDeclChecker : public ASTComparisonVisitor<ABIDeclChecker> {
881881

882882
return false;
883883

884-
case DeclAttribute::InferredInABIAttr:
885-
if (!abi && api->canClone()) {
886-
// Infer an identical attribute.
887-
abi = api->clone(ctx);
888-
abi->setImplicit(true);
889-
abiDecl->getAttrs().add(abi);
890-
891-
if (ctx.LangOpts.EnableABIInferenceRemarks) {
892-
SmallString<64> scratch;
893-
auto abiAttrAsString = printAttr(abi, abiDecl, scratch);
894-
895-
abiDecl->diagnose(diag::abi_attr_inferred_attribute,
896-
abiAttrAsString, api->isDeclModifier());
897-
noteAttrHere(api, apiDecl, /*isMatch=*/true);
898-
}
899-
}
900-
901-
// Other than the cloning behavior, Inferred behaves like Equivalent.
902-
LLVM_FALLTHROUGH;
903-
904884
case DeclAttribute::EquivalentInABIAttr:
905885
// Diagnose if API doesn't have attribute.
906886
if (!api) {

lib/Sema/TypeCheckStorage.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,10 @@ IsSetterMutatingRequest::evaluate(Evaluator &evaluator,
846846
OpaqueReadOwnership
847847
OpaqueReadOwnershipRequest::evaluate(Evaluator &evaluator,
848848
AbstractStorageDecl *storage) const {
849+
auto abiRole = ABIRoleInfo(storage);
850+
if (!abiRole.providesAPI() && abiRole.getCounterpart())
851+
return abiRole.getCounterpart()->getOpaqueReadOwnership();
852+
849853
enum class DiagKind {
850854
BorrowedAttr,
851855
NoncopyableType

test/attr/attr_abi.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Extern -enable-experimental-feature ABIAttribute -enable-experimental-feature AddressableParameters -enable-experimental-feature NoImplicitCopy -enable-experimental-feature SymbolLinkageMarkers -enable-experimental-feature StrictMemorySafety -enable-experimental-feature LifetimeDependence -enable-experimental-feature CImplementation -enable-experimental-feature ExecutionAttribute -import-bridging-header %S/Inputs/attr_abi.h -parse-as-library -Rabi-inference -debugger-support
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Extern -enable-experimental-feature ABIAttribute -enable-experimental-feature AddressableParameters -enable-experimental-feature NoImplicitCopy -enable-experimental-feature SymbolLinkageMarkers -enable-experimental-feature StrictMemorySafety -enable-experimental-feature LifetimeDependence -enable-experimental-feature CImplementation -enable-experimental-feature ExecutionAttribute -import-bridging-header %S/Inputs/attr_abi.h -parse-as-library -debugger-support
22

33
// REQUIRES: swift_feature_ABIAttribute
44
// REQUIRES: swift_feature_AddressableParameters
@@ -2035,15 +2035,15 @@ extension DynamicReplacement {
20352035

20362036
// @_weakLinked -- tested in attr/attr_weaklinked.swift
20372037

2038-
// @_borrowed -- automatically cloned into @abi
2038+
// @_borrowed -- banned in @abi
20392039
protocol BorrowedAttr {
2040-
@abi(@_borrowed var v1: Int)
2040+
@abi(@_borrowed var v1: Int) // expected-error {{unused '_borrowed' attribute in '@abi'}} {{8-18=}}
20412041
@_borrowed var v1: Int { get set }
20422042

2043-
@abi(var v2: Int) // expected-remark {{inferred '@_borrowed' in '@abi' to match attribute on API}}
2044-
@_borrowed var v2: Int { get set } // expected-note {{matches attribute here}}
2043+
@abi(var v2: Int)
2044+
@_borrowed var v2: Int { get set }
20452045

2046-
@abi(@_borrowed var v3: Int) // expected-error {{extra '_borrowed' attribute in '@abi'}} {{8-18=}}
2046+
@abi(@_borrowed var v3: Int) // expected-error {{unused '_borrowed' attribute in '@abi'}} {{8-18=}}
20472047
var v3: Int { get set }
20482048
}
20492049

test/attr/attr_abi_objc.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ABIAttribute -parse-as-library -Rabi-inference
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ABIAttribute -parse-as-library
22

33
// REQUIRES: swift_feature_ABIAttribute
44
// REQUIRES: objc_interop

0 commit comments

Comments
 (0)