From a031c0ca055c0266275aef9471a838edbf74a70a Mon Sep 17 00:00:00 2001 From: Nate Chandler Date: Mon, 20 May 2024 15:11:07 -0700 Subject: [PATCH] [TypeCheckAttr] Frozen is valid without resilience Even when building not for library evolution, @frozen is a valid attribute on enums. rdar://128358780 --- lib/Sema/TypeCheckAttr.cpp | 5 --- .../moveonly_generics_complex.swift | 2 -- test/Sema/bitwise_copyable_nonresilient.swift | 6 ++-- .../{attr-invalid.swift => attr-frozen.swift} | 2 +- .../inferred_nonfrozen_conformance.swift | 36 +++++++++++++++++++ .../Outputs/Cake-binary-vs-interface.txt | 2 -- test/decl/enum/frozen-nonresilient.swift | 4 +-- 7 files changed, 41 insertions(+), 16 deletions(-) rename test/Serialization/{attr-invalid.swift => attr-frozen.swift} (93%) create mode 100644 test/Serialization/inferred_nonfrozen_conformance.swift diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index bbf5659923401..be7901e2e5acb 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -3940,11 +3940,6 @@ void AttributeChecker::visitImplementsAttr(ImplementsAttr *attr) { void AttributeChecker::visitFrozenAttr(FrozenAttr *attr) { if (auto *ED = dyn_cast(D)) { - if (!ED->getModuleContext()->isResilient()) { - attr->setInvalid(); - return; - } - if (ED->getFormalAccess() < AccessLevel::Package && !ED->getAttrs().hasAttribute()) { diagnoseAndRemoveAttr(attr, diag::enum_frozen_nonpublic, attr); diff --git a/test/SILOptimizer/moveonly_generics_complex.swift b/test/SILOptimizer/moveonly_generics_complex.swift index 938340c2b31bc..da507494be353 100644 --- a/test/SILOptimizer/moveonly_generics_complex.swift +++ b/test/SILOptimizer/moveonly_generics_complex.swift @@ -8,7 +8,6 @@ import Builtin -@frozen enum MyLittleLayout { @_transparent static var size: Int { @@ -20,7 +19,6 @@ enum MyLittleLayout { } } -@frozen enum MyLittleResult : ~Copyable { case success(Success) case failure(Failure) diff --git a/test/Sema/bitwise_copyable_nonresilient.swift b/test/Sema/bitwise_copyable_nonresilient.swift index e0a8f74887326..58cfcafa14e2e 100644 --- a/test/Sema/bitwise_copyable_nonresilient.swift +++ b/test/Sema/bitwise_copyable_nonresilient.swift @@ -38,9 +38,7 @@ func passOopsional(_ t: Oopsional) { take(t) } // expected-error{{type_doe struct S_Explicit_With_Woopsional : BitwiseCopyable { - var o: Woopsional // expected-error{{non_bitwise_copyable_type_member}} + var o: Woopsional } -func passWoopsional(_ t: Woopsional) { take(t) } // expected-error{{type_does_not_conform_decl_owner}} - // expected-note@-15{{where_requirement_failure_one_subst}} - +func passWoopsional(_ t: Woopsional) { take(t) } diff --git a/test/Serialization/attr-invalid.swift b/test/Serialization/attr-frozen.swift similarity index 93% rename from test/Serialization/attr-invalid.swift rename to test/Serialization/attr-frozen.swift index 5c32dd9974f49..17eacd129cf24 100644 --- a/test/Serialization/attr-invalid.swift +++ b/test/Serialization/attr-frozen.swift @@ -6,7 +6,7 @@ // These two should be checking for the same thing. // CHECK-RESILIENT: Frozen_DECL_ATTR -// CHECK-NON-RESILIENT-NOT: Frozen_DECL_ATTR +// CHECK-NON-RESILIENT: Frozen_DECL_ATTR @frozen // expected-no-warning public enum SomeEnum { diff --git a/test/Serialization/inferred_nonfrozen_conformance.swift b/test/Serialization/inferred_nonfrozen_conformance.swift new file mode 100644 index 0000000000000..68cbbc2c5fafc --- /dev/null +++ b/test/Serialization/inferred_nonfrozen_conformance.swift @@ -0,0 +1,36 @@ +// RUN: %empty-directory(%t) +// RUN: split-file %s %t +// RUN: %target-swift-frontend -emit-module %t/Library.swift -emit-module-path %t/Library.swiftmodule -module-name Library +// RUN: %target-swift-frontend -typecheck -verify -strict-concurrency=complete -swift-version 6 %s -I %t + +//--- Library.swift + +@frozen public enum Numquam {} + +@_fixed_layout public struct Nunca {} // expected-warning {{}} + +//--- Client.swift + +public protocol WithSendable { + associatedtype AssocSendable : Sendable +} + +extension Numquam : WithSendable { + public typealias AssocSendable = Numquam +} + +extension Nunca : WithSendable { + public typealias AssocSendable = Nunca +} + +public protocol WithBitwiseCopyable { + associatedtype AssocBitwiseCopyable : BitwiseCopyable +} + +extension Numquam : WithBitwiseCopyable { + public typealias AssocBitwiseCopyable = Numquam +} + +extension Nunca : WithBitwiseCopyable { + public typealias AssocBitwiseCopyable = Nunca +} diff --git a/test/api-digester/Outputs/Cake-binary-vs-interface.txt b/test/api-digester/Outputs/Cake-binary-vs-interface.txt index e09f822f7b441..a4653d5a8dc32 100644 --- a/test/api-digester/Outputs/Cake-binary-vs-interface.txt +++ b/test/api-digester/Outputs/Cake-binary-vs-interface.txt @@ -3,8 +3,6 @@ cake: Accessor GlobalLetChangedToVar.Get() is a new API without @available attri cake: Accessor GlobalVarChangedToLet.Get() is a new API without @available attribute cake: Accessor GlobalVarChangedToLet.Modify() is a new API without @available attribute cake: Accessor GlobalVarChangedToLet.Set() is a new API without @available attribute -cake: Enum FrozenKind is now with @frozen -cake: Enum IceKind is now with @frozen cake: Func FrozenKind.==(_:_:) is a new API without @available attribute cake: Var C1.CIIns1 is no longer a stored property cake: Var C1.CIIns2 is no longer a stored property diff --git a/test/decl/enum/frozen-nonresilient.swift b/test/decl/enum/frozen-nonresilient.swift index 34312ec89b3c7..7e33adc28fa04 100644 --- a/test/decl/enum/frozen-nonresilient.swift +++ b/test/decl/enum/frozen-nonresilient.swift @@ -1,5 +1,5 @@ -// RUN: %target-typecheck-verify-swift -warnings-as-errors +// RUN: %target-typecheck-verify-swift @frozen public enum Exhaustive {} // expected-no-warning -@frozen enum NotPublic {} // expected-no-warning +@frozen enum NotPublic {} // expected-warning{{@frozen has no effect on non-public enums}}