Skip to content

Commit 0af0635

Browse files
committed
ManualOwnership: introduce 'SemanticCopies' diagnostic group
This includes documentation to explain how to understand these diagnostics.
1 parent 23474f9 commit 0af0635

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

include/swift/AST/DiagnosticGroups.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ GROUP(ErrorInFutureSwiftVersion, "error-in-future-swift-version")
5252
GROUP(ExclusivityViolation, "exclusivity-violation")
5353
GROUP(ExistentialAny, "existential-any")
5454
GROUP(ExistentialMemberAccess, "existential-member-access-limitations")
55+
GROUP(SemanticCopies, "semantic-copies")
5556
GROUP(ImplementationOnlyDeprecated, "implementation-only-deprecated")
5657
GROUP(IsolatedConformances, "isolated-conformances")
5758
GROUP(MemberImportVisibility, "member-import-visibility")

include/swift/AST/DiagnosticsSIL.def

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,13 @@ ERROR(wrong_linkage_for_serialized_function,none,
433433
"function has wrong linkage to be called from %0", (StringRef))
434434
NOTE(performance_called_from,none,
435435
"called from here", ())
436-
ERROR(manualownership_copy,none,
437-
"explicit 'copy' required here; please report this vague diagnostic as a bug", ())
438-
ERROR(manualownership_copy_happened,none,
436+
GROUPED_WARNING(manualownership_copy,SemanticCopies,none,
437+
"implicit 'copy' happens here; please report this vague diagnostic as a bug", ())
438+
GROUPED_WARNING(manualownership_copy_happened,SemanticCopies,none,
439439
"accessing %0 may produce a copy; write 'copy' to acknowledge or 'consume' to elide", (Identifier))
440-
ERROR(manualownership_copy_demanded,none,
440+
GROUPED_WARNING(manualownership_copy_demanded,SemanticCopies,none,
441441
"independent copy of %0 is required here; write 'copy' to acknowledge or 'consume' to elide", (Identifier))
442-
ERROR(manualownership_copy_captured,none,
442+
GROUPED_WARNING(manualownership_copy_captured,SemanticCopies,none,
443443
"closure capture of '%0' requires independent copy of it; write [%0 = copy %0] in the closure's capture list to acknowledge", (StringRef))
444444

445445
// 'transparent' diagnostics

test/SIL/manual_ownership.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend %s -emit-sil -verify \
2+
// RUN: -Werror SemanticCopies \
23
// RUN: -enable-experimental-feature ManualOwnership
34

45
// REQUIRES: swift_feature_ManualOwnership
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Semantic Copies
2+
3+
Values are implicitly copied for you in Swift, wherever they are needed to satisfy the language semantics.
4+
The Swift optimizer goes to great lengths to eliminate these copies.
5+
But for performance-oriented programmers, it's helpful to know where these copies happen so they can change their program's style to avoid copies entirely.
6+
7+
## Variable Bindings
8+
9+
TODO explain why variables require a copy.

0 commit comments

Comments
 (0)