Merge pull request #79424 from DougGregor/se-0458-match-proposal

[SE-0458] Bring implementation in line with the latest proposal revision
This commit is contained in:
Doug Gregor
2025-02-16 19:15:27 -08:00
committed by GitHub
22 changed files with 397 additions and 119 deletions

View File

@@ -8149,15 +8149,22 @@ NOTE(note_reference_exclusivity_unchecked,none,
NOTE(note_use_of_unsafe_conformance_is_unsafe,none,
"@unsafe conformance of %0 to %kind1 involves unsafe code",
(Type, const ValueDecl *))
NOTE(note_unsafe_storage,none,
"%kindbase1 involves unsafe type %2", (bool, const ValueDecl *, Type))
GROUPED_WARNING(decl_signature_involves_unsafe,Unsafe,none,
"%kindbase0 has an interface that involves unsafe types",
GROUPED_WARNING(decl_unsafe_storage,Unsafe,none,
"%kindbase0 has storage involving unsafe types",
(const Decl *))
NOTE(decl_signature_mark_unsafe,none,
"add '@unsafe' to indicate that this declaration is unsafe to use",
NOTE(decl_storage_mark_unsafe,none,
"add '@unsafe' if this type is also unsafe to use",
())
NOTE(decl_signature_mark_safe,none,
"add '@safe' to indicate that this declaration is memory-safe to use", ())
NOTE(decl_storage_mark_safe,none,
"add '@safe' if this type encapsulates the unsafe storage in "
"a safe interface", ())
GROUPED_WARNING(unsafe_superclass,Unsafe,none,
"%kindbase0 has superclass involving unsafe type %1",
(const ValueDecl *, Type))
GROUPED_WARNING(conformance_involves_unsafe,Unsafe,none,
"conformance of %0 to %kind1 involves unsafe code; use '@unsafe' to "

View File

@@ -45,6 +45,8 @@ public:
NonisolatedUnsafe,
/// A reference to an unsafe declaration.
ReferenceToUnsafe,
/// A reference to an unsafe storage.
ReferenceToUnsafeStorage,
/// A reference to a typealias that is not itself unsafe, but has
/// an unsafe underlying type.
ReferenceToUnsafeThroughTypealias,
@@ -113,6 +115,7 @@ private:
kind == ExclusivityUnchecked ||
kind == NonisolatedUnsafe ||
kind == ReferenceToUnsafe ||
kind == ReferenceToUnsafeStorage ||
kind == ReferenceToUnsafeThroughTypealias ||
kind == CallToUnsafe);
@@ -179,6 +182,12 @@ public:
decl, type, location);
}
static UnsafeUse forReferenceToUnsafeStorage(const Decl *decl,
Type type,
SourceLoc location) {
return forReference(ReferenceToUnsafeStorage, decl, type, location);
}
static UnsafeUse forReferenceToUnsafeThroughTypealias(const Decl *decl,
Type type,
SourceLoc location) {
@@ -215,6 +224,7 @@ public:
case ExclusivityUnchecked:
case NonisolatedUnsafe:
case ReferenceToUnsafe:
case ReferenceToUnsafeStorage:
case ReferenceToUnsafeThroughTypealias:
case CallToUnsafe:
return SourceLoc(
@@ -246,6 +256,7 @@ public:
case ExclusivityUnchecked:
case NonisolatedUnsafe:
case ReferenceToUnsafe:
case ReferenceToUnsafeStorage:
case ReferenceToUnsafeThroughTypealias:
case CallToUnsafe:
storage.entity.location = loc.getOpaquePointerValue();
@@ -266,6 +277,7 @@ public:
case ExclusivityUnchecked:
case NonisolatedUnsafe:
case ReferenceToUnsafe:
case ReferenceToUnsafeStorage:
case ReferenceToUnsafeThroughTypealias:
case CallToUnsafe:
return storage.entity.decl;
@@ -299,6 +311,7 @@ public:
case NonisolatedUnsafe:
case ReferenceToUnsafe:
case ReferenceToUnsafeThroughTypealias:
case ReferenceToUnsafeStorage:
case CallToUnsafe:
case UnsafeConformance:
case PreconcurrencyImport:
@@ -324,6 +337,7 @@ public:
case ExclusivityUnchecked:
case NonisolatedUnsafe:
case ReferenceToUnsafe:
case ReferenceToUnsafeStorage:
case ReferenceToUnsafeThroughTypealias:
case CallToUnsafe:
return storage.entity.type;
@@ -348,6 +362,7 @@ public:
case ExclusivityUnchecked:
case NonisolatedUnsafe:
case ReferenceToUnsafe:
case ReferenceToUnsafeStorage:
case ReferenceToUnsafeThroughTypealias:
case CallToUnsafe:
case PreconcurrencyImport:

View File

@@ -31,6 +31,7 @@ namespace swift {
class Decl;
class DeclName;
class EnumDecl;
enum class ExplicitSafety;
/// The input type for a clang direct lookup request.
struct ClangDirectLookupDescriptor final {
@@ -564,6 +565,25 @@ private:
void simple_display(llvm::raw_ostream &out, EscapabilityLookupDescriptor desc);
SourceLoc extractNearestSourceLoc(EscapabilityLookupDescriptor desc);
/// Determine the safety of the given Clang declaration.
class ClangDeclExplicitSafety
: public SimpleRequest<ClangDeclExplicitSafety,
ExplicitSafety(SafeUseOfCxxDeclDescriptor),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;
// Source location
SourceLoc getNearestLoc() const { return SourceLoc(); };
bool isCached() const;
private:
friend SimpleRequest;
// Evaluation.
ExplicitSafety evaluate(Evaluator &evaluator, SafeUseOfCxxDeclDescriptor desc) const;
};
#define SWIFT_TYPEID_ZONE ClangImporter
#define SWIFT_TYPEID_HEADER "swift/ClangImporter/ClangImporterTypeIDZone.def"
#include "swift/Basic/DefineTypeIDZone.h"

View File

@@ -45,3 +45,6 @@ SWIFT_REQUEST(ClangImporter, CustomRefCountingOperation,
SWIFT_REQUEST(ClangImporter, ClangTypeEscapability,
CxxEscapability(EscapabilityLookupDescriptor), Cached,
NoLocationInfo)
SWIFT_REQUEST(ClangImporter, ClangDeclExplicitSafety,
ExplicitSafety(SafeUseOfCxxDeclDescriptor), Cached,
NoLocationInfo)