Skip to content

Commit 9fbc6f7

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 a26ee74 commit 9fbc6f7

File tree

11 files changed

+15
-50
lines changed

11 files changed

+15
-50
lines changed

include/swift/AST/Attr.h

+2-9
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

+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
@@ -8456,9 +8456,6 @@ ERROR(attr_abi_extra_attr,none,
84568456
ERROR(attr_abi_forbidden_attr,none,
84578457
"unused '%0' %select{attribute|modifier}1 in '@abi'",
84588458
(StringRef, bool))
8459-
REMARK(abi_attr_inferred_attribute,none,
8460-
"inferred '%0' in '@abi' to match %select{attribute|modifier}1 on API",
8461-
(StringRef, bool))
84628459

84638460
ERROR(attr_abi_mismatched_attr,none,
84648461
"'%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
@@ -880,26 +880,6 @@ class ABIDeclChecker : public ASTComparisonVisitor<ABIDeclChecker> {
880880

881881
return false;
882882

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

lib/Sema/TypeCheckStorage.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,10 @@ IsSetterMutatingRequest::evaluate(Evaluator &evaluator,
849849
OpaqueReadOwnership
850850
OpaqueReadOwnershipRequest::evaluate(Evaluator &evaluator,
851851
AbstractStorageDecl *storage) const {
852+
auto abiRole = ABIRoleInfo(storage);
853+
if (!abiRole.providesAPI() && abiRole.getCounterpart())
854+
return abiRole.getCounterpart()->getOpaqueReadOwnership();
855+
852856
enum class DiagKind {
853857
BorrowedAttr,
854858
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 -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 -import-bridging-header %S/Inputs/attr_abi.h -parse-as-library -debugger-support
22

33
// REQUIRES: swift_feature_ABIAttribute
44
// REQUIRES: swift_feature_AddressableParameters
@@ -2034,15 +2034,15 @@ extension DynamicReplacement {
20342034

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

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

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

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

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)