Skip to content

Revert "Make Error and CodingKey conform to ConcurrentValue." #36088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -4323,38 +4323,20 @@ ERROR(non_concurrent_type_member,none,
"%select{stored property %1|associated value %1}0 of "
"'ConcurrentValue'-conforming %2 %3 has non-concurrent-value type %4",
(bool, DeclName, DescriptiveDeclKind, DeclName, Type))
WARNING(non_concurrent_type_member_warn,none,
"%select{stored property %1|associated value %1}0 of "
"'ConcurrentValue'-conforming %2 %3 has non-concurrent-value type %4",
(bool, DeclName, DescriptiveDeclKind, DeclName, Type))
ERROR(concurrent_value_class_mutable_property,none,
"stored property %0 of 'ConcurrentValue'-conforming %1 %2 is mutable",
(DeclName, DescriptiveDeclKind, DeclName))
WARNING(concurrent_value_class_mutable_property_warn,none,
"stored property %0 of 'ConcurrentValue'-conforming %1 %2 is mutable",
(DeclName, DescriptiveDeclKind, DeclName))
ERROR(concurrent_value_outside_source_file,none,
"conformance to 'ConcurrentValue' must occur in the same source file as "
"%0 %1; use 'UnsafeConcurrentValue' for retroactive conformance",
(DescriptiveDeclKind, DeclName))
WARNING(concurrent_value_outside_source_file_warn,none,
"conformance to 'ConcurrentValue' must occur in the same source file as "
"conformance 'ConcurrentValue' must occur in the same source file as "
"%0 %1; use 'UnsafeConcurrentValue' for retroactive conformance",
(DescriptiveDeclKind, DeclName))
ERROR(concurrent_value_open_class,none,
"open class %0 cannot conform to `ConcurrentValue`; "
"use `UnsafeConcurrentValue`", (DeclName))
WARNING(concurrent_value_open_class_warn,none,
"open class %0 cannot conform to `ConcurrentValue`; "
"use `UnsafeConcurrentValue`", (DeclName))
ERROR(concurrent_value_inherit,none,
"`ConcurrentValue` class %1 cannot inherit from another class"
"%select{| other than 'NSObject'}0",
(bool, DeclName))
WARNING(concurrent_value_inherit_warn,none,
"`ConcurrentValue` class %1 cannot inherit from another class"
"%select{| other than 'NSObject'}0",
(bool, DeclName))

ERROR(actorindependent_let,none,
"'@actorIndependent' is meaningless on 'let' declarations because "
Expand Down
33 changes: 9 additions & 24 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2259,8 +2259,7 @@ static bool shouldDiagnoseExistingDataRaces(const DeclContext *dc) {
return false;
}

void swift::checkConcurrentValueConformance(
ProtocolConformance *conformance, bool asWarning) {
void swift::checkConcurrentValueConformance(ProtocolConformance *conformance) {
auto conformanceDC = conformance->getDeclContext();
auto nominal = conformance->getType()->getAnyNominal();
if (!nominal)
Expand All @@ -2278,9 +2277,7 @@ void swift::checkConcurrentValueConformance(
if (!conformanceDC->getParentSourceFile() ||
conformanceDC->getParentSourceFile() != nominal->getParentSourceFile()) {
conformanceDecl->diagnose(
asWarning
? diag::concurrent_value_outside_source_file_warn
: diag::concurrent_value_outside_source_file,
diag::concurrent_value_outside_source_file,
nominal->getDescriptiveKind(), nominal->getName());
return;
}
Expand All @@ -2289,11 +2286,8 @@ void swift::checkConcurrentValueConformance(
// An open class cannot conform to `ConcurrentValue`.
if (classDecl->getFormalAccess() == AccessLevel::Open) {
classDecl->diagnose(
asWarning ? diag::concurrent_value_open_class_warn
: diag::concurrent_value_open_class,
classDecl->getName());
if (!asWarning)
return;
diag::concurrent_value_open_class, classDecl->getName());
return;
}

// A 'ConcurrentValue' class cannot inherit from another class, although
Expand All @@ -2302,12 +2296,10 @@ void swift::checkConcurrentValueConformance(
if (auto superclassDecl = classDecl->getSuperclassDecl()) {
if (!superclassDecl->isNSObject()) {
classDecl->diagnose(
asWarning ? diag::concurrent_value_inherit_warn
: diag::concurrent_value_inherit,
diag::concurrent_value_inherit,
nominal->getASTContext().LangOpts.EnableObjCInterop,
classDecl->getName());
if (!asWarning)
return;
return;
}
}
}
Expand All @@ -2318,10 +2310,7 @@ void swift::checkConcurrentValueConformance(
if (isa<StructDecl>(nominal) || classDecl) {
for (auto property : nominal->getStoredProperties()) {
if (classDecl && property->supportsMutation()) {
property->diagnose(
asWarning ? diag::concurrent_value_class_mutable_property_warn
: diag::concurrent_value_class_mutable_property,
property->getName(), nominal->getDescriptiveKind(),
property->diagnose(diag::concurrent_value_class_mutable_property, property->getName(), nominal->getDescriptiveKind(),
nominal->getName());
continue;
}
Expand All @@ -2330,9 +2319,7 @@ void swift::checkConcurrentValueConformance(
conformanceDC->mapTypeIntoContext(property->getInterfaceType());
if (!isConcurrentValueType(conformanceDC, propertyType)) {
property->diagnose(
asWarning ? diag::non_concurrent_type_member_warn
: diag::non_concurrent_type_member,
false, property->getName(),
diag::non_concurrent_type_member, false, property->getName(),
nominal->getDescriptiveKind(), nominal->getName(), propertyType);
continue;
}
Expand All @@ -2353,9 +2340,7 @@ void swift::checkConcurrentValueConformance(
element->getArgumentInterfaceType());
if (!isConcurrentValueType(conformanceDC, elementType)) {
element->diagnose(
asWarning ? diag::non_concurrent_type_member_warn
: diag::non_concurrent_type_member,
true, element->getName(),
diag::non_concurrent_type_member, true, element->getName(),
nominal->getDescriptiveKind(), nominal->getName(), elementType);
continue;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/Sema/TypeCheckConcurrency.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ bool diagnoseNonConcurrentTypesInReference(
ConcurrentReferenceKind refKind);

/// Check the correctness of the given ConcurrentValue conformance.
void checkConcurrentValueConformance(
ProtocolConformance *conformance, bool asWarning);
void checkConcurrentValueConformance(ProtocolConformance *conformance);

} // end namespace swift

Expand Down
12 changes: 2 additions & 10 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5660,8 +5660,6 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {

ProtocolConformance *concurrentValueConformance = nullptr;
ProtocolConformance *unsafeConcurrentValueConformance = nullptr;
ProtocolConformance *errorConformance = nullptr;
ProtocolConformance *codingKeyConformance = nullptr;
bool anyInvalid = false;
for (auto conformance : conformances) {
// Check and record normal conformances.
Expand Down Expand Up @@ -5693,18 +5691,12 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
} else if (proto->isSpecificProtocol(
KnownProtocolKind::UnsafeConcurrentValue)) {
unsafeConcurrentValueConformance = conformance;
} else if (proto->isSpecificProtocol(KnownProtocolKind::Error)) {
errorConformance = conformance;
} else if (proto->isSpecificProtocol(KnownProtocolKind::CodingKey)) {
codingKeyConformance = conformance;
}
}

// Check constraints of ConcurrentValue.
if (concurrentValueConformance && !unsafeConcurrentValueConformance) {
bool asWarning = errorConformance || codingKeyConformance;
checkConcurrentValueConformance(concurrentValueConformance, asWarning);
}
if (concurrentValueConformance && !unsafeConcurrentValueConformance)
checkConcurrentValueConformance(concurrentValueConformance);

// Check all conformances.
groupChecker.checkAllConformances();
Expand Down
7 changes: 3 additions & 4 deletions stdlib/public/core/Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public typealias Codable = Encodable & Decodable
//===----------------------------------------------------------------------===//

/// A type that can be used as a key for encoding and decoding.
public protocol CodingKey: ConcurrentValue,
CustomStringConvertible,
public protocol CodingKey: CustomStringConvertible,
CustomDebugStringConvertible {
/// The string to use in a named collection (e.g. a string-keyed dictionary).
var stringValue: String { get }
Expand Down Expand Up @@ -3180,7 +3179,7 @@ public struct CodingUserInfoKey: RawRepresentable, Equatable, Hashable, Concurre
/// An error that occurs during the encoding of a value.
public enum EncodingError: Error {
/// The context in which the error occurred.
public struct Context: ConcurrentValue {
public struct Context {
/// The path of coding keys taken to get to the point of the failing encode
/// call.
public let codingPath: [CodingKey]
Expand Down Expand Up @@ -3263,7 +3262,7 @@ public enum EncodingError: Error {
/// An error that occurs during the decoding of a value.
public enum DecodingError: Error {
/// The context in which the error occurred.
public struct Context: ConcurrentValue {
public struct Context {
/// The path of coding keys taken to get to the point of the failing decode
/// call.
public let codingPath: [CodingKey]
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/ErrorType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ import SwiftShims
/// print("Other error: \(error)")
/// }
/// // Prints "Parsing error: mismatchedTag [19:5]"
public protocol Error: ConcurrentValue {
public protocol Error {
var _domain: String { get }
var _code: Int { get }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public struct URL : _ObjectiveCBridgeable {
}
}

extension NSError : Error, UnsafeConcurrentValue {
extension NSError : Error {
public var _domain: String { return domain }
public var _code: Int { return code }
}
Expand Down
4 changes: 2 additions & 2 deletions test/SILGen/errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class Cat {}
enum HomeworkError : Error {
case TooHard
case TooMuch
case CatAteIt(Cat) // expected-warning{{associated value 'CatAteIt' of 'ConcurrentValue'-conforming enum 'HomeworkError' has non-concurrent-value type 'Cat'}}
case CatHidIt(Cat) // expected-warning{{associated value 'CatHidIt' of 'ConcurrentValue'-conforming enum 'HomeworkError' has non-concurrent-value type 'Cat'}}
case CatAteIt(Cat)
case CatHidIt(Cat)
}

func someValidPointer<T>() -> UnsafePointer<T> { fatalError() }
Expand Down
2 changes: 1 addition & 1 deletion test/Sema/existential_nested_type.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protocol HasAssoc {
}

enum MyError : Error {
case bad(Any) // expected-warning{{associated value 'bad' of 'ConcurrentValue'-conforming enum 'MyError' has non-concurrent-value type 'Any'}}
case bad(Any)
}

func checkIt(_ js: Any) throws {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
Protocol CodingKey has added inherited protocol ConcurrentValue
Protocol CodingKey has generic signature change from <Self : Swift.CustomDebugStringConvertible, Self : Swift.CustomStringConvertible> to <Self : Swift.ConcurrentValue, Self : Swift.CustomDebugStringConvertible, Self : Swift.CustomStringConvertible>
Protocol Error has added inherited protocol ConcurrentValue
Protocol Error has generic signature change from to <Self : Swift.ConcurrentValue>
4 changes: 0 additions & 4 deletions test/api-digester/stability-stdlib-abi-with-asserts.test
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,4 @@ Func _measureRuntimeFunctionCountersDiffs(objects:_:) is a new API without @avai
Protocol _RuntimeFunctionCountersStats is a new API without @available attribute
Struct _GlobalRuntimeFunctionCountersState is a new API without @available attribute
Struct _ObjectRuntimeFunctionCountersState is a new API without @available attribute
Protocol CodingKey has added inherited protocol ConcurrentValue
Protocol CodingKey has generic signature change from <Self : Swift.CustomDebugStringConvertible, Self : Swift.CustomStringConvertible> to <Self : Swift.ConcurrentValue, Self : Swift.CustomDebugStringConvertible, Self : Swift.CustomStringConvertible>
Protocol Error has added inherited protocol ConcurrentValue
Protocol Error has generic signature change from to <Self : Swift.ConcurrentValue>
Struct _RuntimeFunctionCounters is a new API without @available attribute
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
extension NoRawTypeKey : CodingKey, UnsafeConcurrentValue {}
extension StringKey : CodingKey, UnsafeConcurrentValue {}
extension IntKey : CodingKey, UnsafeConcurrentValue {}
extension NoRawTypeKey : CodingKey {}
extension StringKey : CodingKey {}
extension IntKey : CodingKey {}