Migrate "@unchecked Sendable" strict safety diagnostic to become a note associated with its type

This commit is contained in:
Doug Gregor
2024-12-20 11:21:53 -08:00
parent 192bb33409
commit a86d942e5b
5 changed files with 43 additions and 26 deletions

View File

@@ -8093,6 +8093,9 @@ NOTE(note_reference_to_nonisolated_unsafe,none,
(const ValueDecl *))
NOTE(note_reference_unowned_unsafe,none,
"reference to unowned(unsafe) %kind0 is unsafe", (const ValueDecl *))
NOTE(note_use_of_unchecked_conformance_is_unsafe,none,
"@unchecked conformance of %0 to %kind1 involves unsafe code",
(Type, const ValueDecl *))
GROUPED_WARNING(override_safe_withunsafe,Unsafe,none,
"override of safe %0 with unsafe %0", (DescriptiveDeclKind))
@@ -8102,8 +8105,9 @@ GROUPED_WARNING(witness_unsafe,Unsafe,none,
GROUPED_WARNING(type_witness_unsafe,Unsafe,none,
"unsafe type %0 cannot satisfy safe associated type %1",
(Type, DeclName))
GROUPED_WARNING(unchecked_conformance_is_unsafe,Unsafe,none,
"@unchecked conformance involves unsafe code", ())
GROUPED_WARNING(use_of_unchecked_conformance_is_unsafe,Unsafe,none,
"@unchecked conformance of %0 to %kind1 involves unsafe code",
(Type, const ValueDecl *))
GROUPED_WARNING(reference_unowned_unsafe,Unsafe,none,
"reference to unowned(unsafe) %kind0 is unsafe", (const ValueDecl *))
GROUPED_WARNING(reference_to_nonisolated_unsafe,Unsafe,none,

View File

@@ -15,14 +15,13 @@
#include "swift/AST/Decl.h"
#include "swift/AST/ProtocolConformance.h"
#include "swift/AST/ProtocolConformanceRef.h"
#include "swift/AST/Type.h"
#include "swift/Basic/SourceLoc.h"
#include "swift/Basic/Unreachable.h"
namespace swift {
class NormalProtocolConformance;
/// Describes a use of an unsafe construct.
///
/// Every use of an unsafe construct that should be diagnosed will be captured
@@ -66,7 +65,8 @@ private:
} typeWitness;
struct {
NormalProtocolConformance *conformance;
TypeBase *type;
void *conformanceRef;
DeclContext *declContext;
const void *location;
} conformance;
@@ -139,11 +139,13 @@ public:
return result;
}
static UnsafeUse forConformance(NormalProtocolConformance *conformance,
static UnsafeUse forConformance(Type subjectType,
ProtocolConformanceRef conformance,
SourceLoc location,
DeclContext *dc) {
UnsafeUse result(UnsafeConformance);
result.storage.conformance.conformance = conformance;
result.storage.conformance.type = subjectType.getPointer();
result.storage.conformance.conformanceRef = conformance.getOpaqueValue();
result.storage.conformance.declContext = dc;
result.storage.conformance.location = location.getOpaquePointerValue();
return result;
@@ -180,7 +182,9 @@ public:
return getDecl()->getLoc();
case UnsafeConformance:
return getConformance()->getLoc();
return SourceLoc(
llvm::SMLoc::getFromPointer(
(const char *)storage.conformance.location));
case TypeWitness:
return SourceLoc(
@@ -237,7 +241,7 @@ public:
case Witness:
case TypeWitness:
return getConformance()->getDeclContext();
return getConformance().getConcrete()->getDeclContext();
case UnsafeConformance:
return storage.conformance.declContext;
@@ -268,9 +272,11 @@ public:
switch (getKind()) {
case Override:
case Witness:
case UnsafeConformance:
return nullptr;
case UnsafeConformance:
return storage.conformance.type;
case TypeWitness:
return storage.typeWitness.type;
@@ -283,23 +289,24 @@ public:
}
/// Get the protocol conformance, if there is one.
NormalProtocolConformance *getConformance() const {
ProtocolConformanceRef getConformance() const {
switch (getKind()) {
case UnsafeConformance:
return storage.conformance.conformance;
return ProtocolConformanceRef::getFromOpaqueValue(
storage.conformance.conformanceRef);
case Witness:
return storage.polymorphic.conformance;
return ProtocolConformanceRef(storage.polymorphic.conformance);
case TypeWitness:
return storage.typeWitness.conformance;
return ProtocolConformanceRef(storage.typeWitness.conformance);
case Override:
case UnownedUnsafe:
case NonisolatedUnsafe:
case ReferenceToUnsafe:
case CallToUnsafe:
return nullptr;
return ProtocolConformanceRef::forInvalid();
}
}
};