Skip to content

Commit 0b424e2

Browse files
authored
Merge pull request #40982 from slavapestov/fix-rdar86861522
Sema: Back out #36752 entirely
2 parents be20cfa + f89e805 commit 0b424e2

File tree

6 files changed

+9
-127
lines changed

6 files changed

+9
-127
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4157,35 +4157,6 @@ void ConformanceChecker::checkNonFinalClassWitness(ValueDecl *requirement,
41574157
}
41584158
}
41594159

4160-
static bool isSwiftRawRepresentableEnum(Type adoptee) {
4161-
auto *enumDecl = dyn_cast<EnumDecl>(adoptee->getAnyNominal());
4162-
return (enumDecl && enumDecl->hasRawType() && !enumDecl->isObjC());
4163-
}
4164-
4165-
// If the given witness matches a generic RawRepresentable function conforming
4166-
// with a given protocol e.g. `func == <T : RawRepresentable>(lhs: T, rhs: T) ->
4167-
// Bool where T.RawValue : Equatable`
4168-
static bool isRawRepresentableGenericFunction(
4169-
ASTContext &ctx, const ValueDecl *witness,
4170-
const NormalProtocolConformance *conformance) {
4171-
auto *fnDecl = dyn_cast<AbstractFunctionDecl>(witness);
4172-
if (!fnDecl || !fnDecl->isStdlibDecl())
4173-
return false;
4174-
4175-
return fnDecl->isGeneric() && fnDecl->getGenericParams()->size() == 1 &&
4176-
fnDecl->getGenericRequirements().size() == 2 &&
4177-
llvm::all_of(
4178-
fnDecl->getGenericRequirements(), [&](Requirement genericReq) {
4179-
if (genericReq.getKind() != RequirementKind::Conformance)
4180-
return false;
4181-
return genericReq.getProtocolDecl() ==
4182-
ctx.getProtocol(
4183-
KnownProtocolKind::RawRepresentable) ||
4184-
genericReq.getProtocolDecl() ==
4185-
conformance->getProtocol();
4186-
});
4187-
}
4188-
41894160
ResolveWitnessResult
41904161
ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
41914162
assert(!isa<AssociatedTypeDecl>(requirement) && "Use resolveTypeWitnessVia*");
@@ -4238,9 +4209,6 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
42384209
!canDerive && !requirement->getAttrs().hasAttribute<OptionalAttr>() &&
42394210
!requirement->getAttrs().isUnavailable(getASTContext());
42404211

4241-
auto &ctx = getASTContext();
4242-
bool isEquatableConformance = (Conformance->getProtocol() ==
4243-
ctx.getProtocol(KnownProtocolKind::Equatable));
42444212
if (findBestWitness(requirement,
42454213
considerRenames ? &ignoringNames : nullptr,
42464214
Conformance,
@@ -4249,28 +4217,6 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
42494217
const auto &best = matches[bestIdx];
42504218
auto witness = best.Witness;
42514219

4252-
if (canDerive &&
4253-
isEquatableConformance &&
4254-
isSwiftRawRepresentableEnum(Adoptee) &&
4255-
!Conformance->getDeclContext()->getParentModule()->isResilient()) {
4256-
// For swift enum types that can derive an Equatable conformance,
4257-
// if the best witness is the default implementation
4258-
//
4259-
// func == <T : RawRepresentable>(lhs: T, rhs: T) -> Bool
4260-
// where T.RawValue : Equatable
4261-
//
4262-
// let's return as missing and derive the conformance, since it will be
4263-
// more efficient than comparing rawValues.
4264-
//
4265-
// However, we only do this if the module is non-resilient. If it is
4266-
// resilient, this change can break ABI by publishing a synthesized ==
4267-
// declaration that may not exist in versions of the framework built
4268-
// with an older compiler.
4269-
if (isRawRepresentableGenericFunction(ctx, witness, Conformance)) {
4270-
return ResolveWitnessResult::Missing;
4271-
}
4272-
}
4273-
42744220
// If the name didn't actually line up, complain.
42754221
if (ignoringNames &&
42764222
requirement->getName() != best.Witness->getName() &&

test/DebugInfo/debug_scope_propagate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %target-swift-frontend -primary-file %s -g -O -emit-sil | %FileCheck %s
22

3-
public enum BenchmarkCategory : String {
3+
public enum BenchmarkCategory {
44
case validation
55
case api, Array, String, Dictionary, Codable, Set, Data, IndexPath, SIMD
66
}

test/SILGen/enum_equatable_witness.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public enum MyState : String {
99

1010
// CHECK-LABEL: sil [ossa] @$s4main11check_stateySiAA7MyStateOF : $@convention(thin) (MyState) -> Int {
1111
public func check_state(_ state : MyState) -> Int {
12-
// FRAGILE: function_ref @$s4main7MyStateO21__derived_enum_equalsySbAC_ACtFZ
12+
// FRAGILE: function_ref @$ss2eeoiySbx_xtSYRzSQ8RawValueRpzlF
1313
// RESILIENT: function_ref @$ss2eeoiySbx_xtSYRzSQ8RawValueRpzlF
1414
return state == .opened ? 1 : 0
1515
}
@@ -22,7 +22,7 @@ public enum GenericMyState<T> : String {
2222

2323
// CHECK-LABEL: sil [ossa] @$s4main19check_generic_stateySiAA14GenericMyStateOySiGF : $@convention(thin) (GenericMyState<Int>) -> Int {
2424
public func check_generic_state(_ state : GenericMyState<Int>) -> Int {
25-
// FRAGILE: function_ref @$s4main14GenericMyStateO21__derived_enum_equalsySbACyxG_AEtFZ
25+
// FRAGILE: function_ref @$ss2eeoiySbx_xtSYRzSQ8RawValueRpzlF
2626
// RESILIENT: function_ref @$ss2eeoiySbx_xtSYRzSQ8RawValueRpzlF
2727
return state == .opened ? 1 : 0
2828
}
@@ -35,7 +35,7 @@ public enum Regular {
3535

3636
// CHECK-LABEL: sil [ossa] @$s4main13check_regularySiAA7RegularOF : $@convention(thin) (Regular) -> Int {
3737
public func check_regular(_ state : Regular) -> Int {
38-
// FRAGILE: function_ref @$s4main7RegularO21__derived_enum_equalsySbAC_ACtFZ
38+
// FRAGILE: function_ref @$ss2eeoiySbx_xtSYRzSQ8RawValueRpzlF
3939
// RESILIENT: function_ref @$ss2eeoiySbx_xtSYRzSQ8RawValueRpzlF
4040
return state == .closed ? 1 : 0
4141
}
@@ -47,14 +47,14 @@ public enum Alphabet : String {
4747

4848
// CHECK-LABEL: sil [ossa] @$s4main14check_alphabetySiAA8AlphabetOF : $@convention(thin) (Alphabet) -> Int {
4949
public func check_alphabet(_ state : Alphabet) -> Int {
50-
// FRAGILE: function_ref @$s4main8AlphabetO21__derived_enum_equalsySbAC_ACtFZ
50+
// FRAGILE: function_ref @$ss2eeoiySbx_xtSYRzSQ8RawValueRpzlF
5151
// RESILIENT: function_ref @$ss2eeoiySbx_xtSYRzSQ8RawValueRpzlF
5252
return state == .E ? 1 : 0
5353
}
5454

5555
// CHECK-LABEL: sil [ossa] @$s4main9compareItySbAA8AlphabetO_ADtF : $@convention(thin) (Alphabet, Alphabet) -> Bool {
5656
public func compareIt(_ state : Alphabet, _ rhs: Alphabet) -> Bool {
57-
// FRAGILE: function_ref @$s4main8AlphabetO21__derived_enum_equalsySbAC_ACtFZ
57+
// FRAGILE: function_ref @$ss2eeoiySbx_xtSYRzSQ8RawValueRpzlF
5858
// RESILIENT: function_ref @$ss2eeoiySbx_xtSYRzSQ8RawValueRpzlF
5959
return state == rhs
6060
}
@@ -66,14 +66,14 @@ public enum AlphabetInt : Int {
6666

6767
// CHECK-LABEL: sil [ossa] @$s4main18check_alphabet_intySiAA11AlphabetIntOF : $@convention(thin) (AlphabetInt) -> Int {
6868
public func check_alphabet_int(_ state : AlphabetInt) -> Int {
69-
// FRAGILE: function_ref @$s4main11AlphabetIntO21__derived_enum_equalsySbAC_ACtFZ
69+
// FRAGILE: function_ref @$ss2eeoiySbx_xtSYRzSQ8RawValueRpzlF
7070
// RESILIENT: function_ref @$ss2eeoiySbx_xtSYRzSQ8RawValueRpzlF
7171
return state == .E ? 1 : 0
7272
}
7373

7474
// CHECK-LABEL: sil [ossa] @$s4main9compareItySbAA11AlphabetIntO_ADtF : $@convention(thin) (AlphabetInt, AlphabetInt) -> Bool {
7575
public func compareIt(_ state : AlphabetInt, _ rhs: AlphabetInt) -> Bool {
76-
// FRAGILE: function_ref @$s4main11AlphabetIntO21__derived_enum_equalsySbAC_ACtFZ
76+
// FRAGILE: function_ref @$ss2eeoiySbx_xtSYRzSQ8RawValueRpzlF
7777
// RESILIENT: function_ref @$ss2eeoiySbx_xtSYRzSQ8RawValueRpzlF
7878
return state == rhs
7979
}

test/SILGen/opaque_ownership.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public struct Int : _ExpressibleByBuiltinIntegerLiteral, ExpressibleByIntegerLit
178178
// CHECK: %5 = apply %4(%0, %1, %3) : $@convention(method) (FloatingPointSign, FloatingPointSign, @thin FloatingPointSign.Type) -> Bool // user: %6
179179
// CHECK: return %5 : $Bool
180180
// CHECK-LABEL: } // end sil function '$ss17FloatingPointSignOSQsSQ2eeoiySbx_xtFZTW'
181-
public enum FloatingPointSign: Int64 {
181+
public enum FloatingPointSign {
182182
/// The sign for a positive value.
183183
case plus
184184

test/api-digester/Outputs/cake-abi.json

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -594,38 +594,6 @@
594594
"moduleName": "cake",
595595
"fixedbinaryorder": 0
596596
},
597-
{
598-
"kind": "Function",
599-
"name": "__derived_enum_equals",
600-
"printedName": "__derived_enum_equals(_:_:)",
601-
"children": [
602-
{
603-
"kind": "TypeNominal",
604-
"name": "Bool",
605-
"printedName": "Swift.Bool",
606-
"usr": "s:Sb"
607-
},
608-
{
609-
"kind": "TypeNominal",
610-
"name": "Number",
611-
"printedName": "cake.Number",
612-
"usr": "s:4cake6NumberO"
613-
},
614-
{
615-
"kind": "TypeNominal",
616-
"name": "Number",
617-
"printedName": "cake.Number",
618-
"usr": "s:4cake6NumberO"
619-
}
620-
],
621-
"declKind": "Func",
622-
"usr": "s:4cake6NumberO21__derived_enum_equalsySbAC_ACtFZ",
623-
"mangledName": "$s4cake6NumberO21__derived_enum_equalsySbAC_ACtFZ",
624-
"moduleName": "cake",
625-
"static": true,
626-
"implicit": true,
627-
"funcSelfKind": "NonMutating"
628-
},
629597
{
630598
"kind": "Constructor",
631599
"name": "init",

test/api-digester/Outputs/cake.json

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -596,38 +596,6 @@
596596
"mangledName": "$s4cake6NumberO3oneyA2CmF",
597597
"moduleName": "cake"
598598
},
599-
{
600-
"kind": "Function",
601-
"name": "__derived_enum_equals",
602-
"printedName": "__derived_enum_equals(_:_:)",
603-
"children": [
604-
{
605-
"kind": "TypeNominal",
606-
"name": "Bool",
607-
"printedName": "Swift.Bool",
608-
"usr": "s:Sb"
609-
},
610-
{
611-
"kind": "TypeNominal",
612-
"name": "Number",
613-
"printedName": "cake.Number",
614-
"usr": "s:4cake6NumberO"
615-
},
616-
{
617-
"kind": "TypeNominal",
618-
"name": "Number",
619-
"printedName": "cake.Number",
620-
"usr": "s:4cake6NumberO"
621-
}
622-
],
623-
"declKind": "Func",
624-
"usr": "s:4cake6NumberO21__derived_enum_equalsySbAC_ACtFZ",
625-
"mangledName": "$s4cake6NumberO21__derived_enum_equalsySbAC_ACtFZ",
626-
"moduleName": "cake",
627-
"static": true,
628-
"implicit": true,
629-
"funcSelfKind": "NonMutating"
630-
},
631599
{
632600
"kind": "Constructor",
633601
"name": "init",

0 commit comments

Comments
 (0)