mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
AST: Re-baseline MemorySafetyAttributes feature.
This commit is contained in:
@@ -254,8 +254,8 @@ CONDITIONALLY_SUPPRESSIBLE_LANGUAGE_FEATURE(IsolatedAny, 431, "@isolated(any) fu
|
||||
LANGUAGE_FEATURE(IsolatedAny2, 431, "@isolated(any) function types")
|
||||
LANGUAGE_FEATURE(ObjCImplementation, 436, "@objc @implementation extensions")
|
||||
LANGUAGE_FEATURE(NonescapableTypes, 446, "Nonescapable types")
|
||||
SUPPRESSIBLE_LANGUAGE_FEATURE(MemorySafetyAttributes, 458, "@unsafe attribute")
|
||||
BASELINE_LANGUAGE_FEATURE(BuiltinEmplaceTypedThrows, 0, "Builtin.emplace typed throws")
|
||||
BASELINE_LANGUAGE_FEATURE(MemorySafetyAttributes, 458, "@unsafe attribute")
|
||||
BASELINE_LANGUAGE_FEATURE(ValueGenerics, 452, "Value generics feature (integer generics)")
|
||||
LANGUAGE_FEATURE(RawIdentifiers, 451, "Raw identifiers")
|
||||
LANGUAGE_FEATURE(SendableCompletionHandlers, 463, "Objective-C completion handler parameters are imported as @Sendable")
|
||||
|
||||
@@ -3280,20 +3280,6 @@ struct ExcludeAttrRAII {
|
||||
};
|
||||
}
|
||||
|
||||
static void
|
||||
suppressingFeatureMemorySafetyAttributes(PrintOptions &options,
|
||||
llvm::function_ref<void()> action) {
|
||||
ExcludeAttrRAII scope(options.ExcludeAttrList, DeclAttrKind::Unsafe);
|
||||
ExcludeAttrRAII scope2(options.ExcludeAttrList, DeclAttrKind::Safe);
|
||||
options.ExcludeAttrList.push_back(TypeAttrKind::Unsafe);
|
||||
SWIFT_DEFER {
|
||||
assert(options.ExcludeAttrList.back() == TypeAttrKind::Unsafe);
|
||||
options.ExcludeAttrList.pop_back();
|
||||
};
|
||||
|
||||
action();
|
||||
}
|
||||
|
||||
static void
|
||||
suppressingFeatureCoroutineAccessors(PrintOptions &options,
|
||||
llvm::function_ref<void()> action) {
|
||||
|
||||
@@ -451,35 +451,6 @@ static bool usesFeatureCDecl(Decl *decl) {
|
||||
return attr && !attr->Underscored;
|
||||
}
|
||||
|
||||
static bool usesFeatureMemorySafetyAttributes(Decl *decl) {
|
||||
if (decl->getAttrs().hasAttribute<SafeAttr>() ||
|
||||
decl->getAttrs().hasAttribute<UnsafeAttr>())
|
||||
return true;
|
||||
|
||||
IterableDeclContext *idc;
|
||||
if (auto nominal = dyn_cast<NominalTypeDecl>(decl))
|
||||
idc = nominal;
|
||||
else if (auto ext = dyn_cast<ExtensionDecl>(decl))
|
||||
idc = ext;
|
||||
else
|
||||
idc = nullptr;
|
||||
|
||||
// Look for an @unsafe conformance ascribed to this declaration.
|
||||
if (idc) {
|
||||
auto conformances = idc->getLocalConformances();
|
||||
for (auto conformance : conformances) {
|
||||
auto rootConformance = conformance->getRootConformance();
|
||||
if (auto rootNormalConformance =
|
||||
dyn_cast<NormalProtocolConformance>(rootConformance)) {
|
||||
if (rootNormalConformance->getExplicitSafety() == ExplicitSafety::Unsafe)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
UNINTERESTING_FEATURE(StrictMemorySafety)
|
||||
UNINTERESTING_FEATURE(SafeInteropWrappers)
|
||||
UNINTERESTING_FEATURE(AssumeResilientCxxTypes)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
|
||||
// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution -module-name unsafe -emit-module -o %t/unsafe.swiftmodule -emit-module-interface-path - %s | %FileCheck %s
|
||||
|
||||
// CHECK: #if compiler(>=5.3) && $MemorySafetyAttributes
|
||||
// CHECK: @unsafe public func testFunction()
|
||||
// CHECK: #else
|
||||
// CHECK: public func testFunction()
|
||||
// CHECK: #endif
|
||||
@unsafe public func testFunction() { }
|
||||
@@ -2,11 +2,7 @@
|
||||
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -module-name UserModule
|
||||
// RUN: %FileCheck %s < %t.swiftinterface
|
||||
|
||||
// CHECK: #if compiler(>=5.3) && $MemorySafetyAttributes
|
||||
// CHECK: @unsafe public func getIntUnsafely() -> Swift.Int
|
||||
// CHECK: #else
|
||||
// CHECK: public func getIntUnsafely() -> Swift.Int
|
||||
// CHECK: #endif
|
||||
@unsafe public func getIntUnsafely() -> Int { 0 }
|
||||
|
||||
public struct UnsafeIterator: @unsafe IteratorProtocol {
|
||||
@@ -33,13 +29,8 @@ public protocol P {
|
||||
func f()
|
||||
}
|
||||
|
||||
// CHECK: #if compiler(>=5.3) && $MemorySafetyAttributes
|
||||
// CHECK: public struct X : @unsafe UserModule.P
|
||||
public struct X: @unsafe P {
|
||||
// CHECK: @unsafe public func f()
|
||||
// CHECK: #else
|
||||
// CHECK: public struct X : UserModule.P
|
||||
// CHECK: public func f()
|
||||
// CHECK: #endif
|
||||
@unsafe public func f() { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user