Skip to content

Commit 393f3f8

Browse files
committed
ManualOwnership: provide ability to apply to entire compilation unit
With this radar, we're flipping the polarity of things. The flag `-enable-experimental-feature ManualOwnership` now turns on the diagnostics, but they're all silenced by default. So, you need to add -Wwarning or -Werror to your build settings to turn on the specific diagnostics you care about. These are the diagnostic groups relevant to the feature: - SemanticCopies aka "explicit copies mode" - DynamicExclusivity For example, the build setting `-Werror SemanticCopies` now gives you errors about explicit copies, just as before, but now you can make them just warnings with -Wwarning. To opt-out a declaration from everything when using the feature, use @_noManualOwnership. @_manualOwnership is no longer an attribute as a result. resolves rdar://163372569
1 parent 4c5cf50 commit 393f3f8

File tree

13 files changed

+45
-103
lines changed

13 files changed

+45
-103
lines changed

include/swift/AST/DeclAttr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ SIMPLE_DECL_ATTR(_noObjCBridging, NoObjCBridging,
815815
UserInaccessible | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | ForbiddenInABIAttr,
816816
155)
817817

818-
SIMPLE_DECL_ATTR(_manualOwnership, ManualOwnership,
818+
SIMPLE_DECL_ATTR(_noManualOwnership, NoManualOwnership,
819819
OnAbstractFunction | OnSubscript,
820820
UserInaccessible | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | ForbiddenInABIAttr,
821821
156)

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,9 +2140,7 @@ ERROR(attr_static_exclusive_only_mutating,none,
21402140
ERROR(attr_static_exclusive_no_setters,none,
21412141
"variable of type %0 must not have a setter", (Type))
21422142

2143-
// @_manualOwnership
2144-
ERROR(attr_manual_ownership_experimental,none,
2145-
"'@_manualOwnership' requires '-enable-experimental-feature ManualOwnership'", ())
2143+
// ManualOwnership
21462144
ERROR(attr_manual_ownership_noimplicitcopy,none,
21472145
"'@_noImplicitCopy' cannot be used with ManualOwnership", ())
21482146

include/swift/Basic/Features.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,9 @@ EXPERIMENTAL_FEATURE(LifetimeDependence, true)
452452
/// Enable the `@_staticExclusiveOnly` attribute.
453453
EXPERIMENTAL_FEATURE(StaticExclusiveOnly, true)
454454

455-
/// Enable the `@_manualOwnership` attribute.
455+
/// Enable the ManualOwnership diagnostic groups:
456+
/// * -Wwarning SemanticCopies
457+
/// * -Wwarning DynamicExclusivity
456458
EXPERIMENTAL_FEATURE(ManualOwnership, false)
457459

458460
/// Enable the @extractConstantsFromMembers attribute.

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5024,7 +5024,7 @@ class PrintAttribute : public AttributeVisitor<PrintAttribute, void, Label>,
50245024
TRIVIAL_ATTR_PRINTER(NoLocks, no_locks)
50255025
TRIVIAL_ATTR_PRINTER(NoMetadata, no_metadata)
50265026
TRIVIAL_ATTR_PRINTER(NoObjCBridging, no_objc_bridging)
5027-
TRIVIAL_ATTR_PRINTER(ManualOwnership, manual_ownership)
5027+
TRIVIAL_ATTR_PRINTER(NoManualOwnership, no_manual_ownership)
50285028
TRIVIAL_ATTR_PRINTER(NoRuntime, no_runtime)
50295029
TRIVIAL_ATTR_PRINTER(NonEphemeral, non_ephemeral)
50305030
TRIVIAL_ATTR_PRINTER(NonEscapable, non_escapable)

lib/ASTGen/Sources/ASTGen/DeclAttrs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ extension ASTGenVisitor {
265265
.LexicalLifetimes,
266266
.LLDBDebuggerFunction,
267267
.MainType,
268-
.ManualOwnership,
269268
.Marker,
270269
.MoveOnly,
271270
.NeverEmitIntoClient,
@@ -276,6 +275,7 @@ extension ASTGenVisitor {
276275
.NoRuntime,
277276
.NoImplicitCopy,
278277
.NoLocks,
278+
.NoManualOwnership,
279279
.NoMetadata,
280280
.NoObjCBridging,
281281
.NonEphemeral,

lib/SIL/IR/SILFunctionBuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ void SILFunctionBuilder::addFunctionAttributes(
204204
F->setPerfConstraints(PerformanceConstraints::NoExistentials);
205205
} else if (Attrs.hasAttribute<NoObjCBridgingAttr>()) {
206206
F->setPerfConstraints(PerformanceConstraints::NoObjCBridging);
207-
} else if (Attrs.hasAttribute<ManualOwnershipAttr>()) {
207+
} else if (constant && constant.hasDecl() && !constant.isImplicit() &&
208+
!Attrs.hasAttribute<NoManualOwnershipAttr>()) {
208209
F->setPerfConstraints(PerformanceConstraints::ManualOwnership);
209210
}
210211

lib/SILGen/SILGen.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,15 +1368,15 @@ void SILGenModule::preEmitFunction(SILDeclRef constant, SILFunction *F,
13681368
//
13691369
// If ManualOwnership ends up subsuming those prior mechanisms for an
13701370
// explicit-copy mode, we can move this somewhere else, like postEmitFunction.
1371-
if (auto *ace = constant.getAbstractClosureExpr()) {
1372-
if (auto *dc = ace->getOutermostFunctionContext()) {
1373-
if (auto *decl = dc->getAsDecl()) {
1374-
if (decl->getAttrs().hasAttribute<ManualOwnershipAttr>()) {
1375-
F->setPerfConstraints(PerformanceConstraints::ManualOwnership);
1376-
}
1377-
}
1378-
}
1379-
}
1371+
//
1372+
// FIXME: maybe this should happen in SILFunctionBuilder::getOrCreateFunction
1373+
if (getASTContext().LangOpts.hasFeature(Feature::ManualOwnership))
1374+
if (auto *ace = constant.getAbstractClosureExpr())
1375+
if (auto *dc = ace->getOutermostFunctionContext())
1376+
if (auto *decl = dc->getAsDecl())
1377+
if (!decl->isImplicit() &&
1378+
!decl->getAttrs().hasAttribute<NoManualOwnershipAttr>())
1379+
F->setPerfConstraints(PerformanceConstraints::ManualOwnership);
13801380

13811381
LLVM_DEBUG(llvm::dbgs() << "lowering ";
13821382
F->printName(llvm::dbgs());

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
183183
IGNORED_ATTR(NoAllocation)
184184
IGNORED_ATTR(NoRuntime)
185185
IGNORED_ATTR(NoExistentials)
186+
IGNORED_ATTR(NoManualOwnership)
186187
IGNORED_ATTR(NoObjCBridging)
187188
IGNORED_ATTR(EmitAssemblyVisionRemarks)
188189
IGNORED_ATTR(ShowInInterface)
@@ -476,7 +477,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
476477
void visitUnsafeNonEscapableResultAttr(UnsafeNonEscapableResultAttr *attr);
477478

478479
void visitStaticExclusiveOnlyAttr(StaticExclusiveOnlyAttr *attr);
479-
void visitManualOwnershipAttr(ManualOwnershipAttr *attr);
480480
void visitWeakLinkedAttr(WeakLinkedAttr *attr);
481481
void visitSILGenNameAttr(SILGenNameAttr *attr);
482482
void visitLifetimeAttr(LifetimeAttr *attr);
@@ -8424,13 +8424,6 @@ void AttributeChecker::visitStaticExclusiveOnlyAttr(
84248424
}
84258425
}
84268426

8427-
void AttributeChecker::visitManualOwnershipAttr(ManualOwnershipAttr *attr) {
8428-
if (Ctx.LangOpts.hasFeature(Feature::ManualOwnership))
8429-
return;
8430-
8431-
diagnoseAndRemoveAttr(attr, diag::attr_manual_ownership_experimental);
8432-
}
8433-
84348427
void AttributeChecker::visitWeakLinkedAttr(WeakLinkedAttr *attr) {
84358428
if (!Ctx.LangOpts.Target.isOSBinFormatCOFF())
84368429
return;

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1620,8 +1620,8 @@ namespace {
16201620
UNINTERESTING_ATTR(NoAllocation)
16211621
UNINTERESTING_ATTR(NoRuntime)
16221622
UNINTERESTING_ATTR(NoExistentials)
1623+
UNINTERESTING_ATTR(NoManualOwnership)
16231624
UNINTERESTING_ATTR(NoObjCBridging)
1624-
UNINTERESTING_ATTR(ManualOwnership)
16251625
UNINTERESTING_ATTR(Inlinable)
16261626
UNINTERESTING_ATTR(Effects)
16271627
UNINTERESTING_ATTR(Expose)

0 commit comments

Comments
 (0)