Skip to content

Commit 637412c

Browse files
committed
[Mangling] Consider overlays when determining retroactive conformances.
When determining whether a given normal protocol conformance is “retroactive”, consider an overlay module to be equivalent to its underlying Clang module. Therefore, don’t classify conformances within the overlay as “retroactive”, simplifying some common manglings (e.g., NSObject’s Hashable conformance is no longer considered retroactive) and better capturing the intent.
1 parent 5e232de commit 637412c

File tree

6 files changed

+37
-12
lines changed

6 files changed

+37
-12
lines changed

lib/AST/ProtocolConformance.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,19 @@ bool NormalProtocolConformance::isRetroactive() const {
363363
// If the conformance occurs in the same module as the conforming type
364364
// definition, this is not a retroactive conformance.
365365
if (auto nominal = getType()->getAnyNominal()) {
366-
if (module == nominal->getParentModule())
366+
auto nominalModule = nominal->getParentModule();
367+
368+
// Consider the overlay module to be the "home" of a nominal type
369+
// defined in a Clang module.
370+
if (auto nominalClangModule =
371+
dyn_cast<ClangModuleUnit>(nominal->getModuleScopeContext())) {
372+
if (auto clangLoader = nominal->getASTContext().getClangModuleLoader()) {
373+
if (auto overlayModule = nominalClangModule->getAdapterModule())
374+
nominalModule = overlayModule;
375+
}
376+
}
377+
378+
if (module == nominalModule)
367379
return false;
368380
}
369381

test/IRGen/objc_bridge.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ import Foundation
8888
// CHECK: { i8*, i8*, i8* } {
8989
// CHECK: i8* getelementptr inbounds ([11 x i8], [11 x i8]* @"\01L_selector_data(acceptSet:)", i64 0, i64 0),
9090
// CHECK: i8* getelementptr inbounds ([11 x i8], [11 x i8]* @{{[0-9]+}}, i64 0, i64 0),
91-
// CHECK: i8* bitcast (void (%3*, i8*, %4*)* @"$s11objc_bridge3BasC9acceptSetyyShyA2CSH10ObjectiveCyHCg_GFTo" to i8*)
91+
// CHECK: i8* bitcast (void (%3*, i8*, %4*)* @"$s11objc_bridge3BasC9acceptSetyyShyACGFTo" to i8*)
9292
// CHECK: }
9393
// CHECK: { i8*, i8*, i8* } {
9494
// CHECK: i8* getelementptr inbounds ([14 x i8], [14 x i8]* @"\01L_selector_data(.cxx_destruct)", i64 0, i64 0),

test/SILGen/Inputs/Foundation.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,6 @@ extension Set : _ObjectiveCBridgeable {
113113
}
114114
}
115115

116-
extension NSObject : Hashable {
117-
public var hashValue: Int { return 0 }
118-
}
119-
120-
public func == (x: NSObject, y: NSObject) -> Bool { return true }
121-
122116
extension NSError : Error {
123117
public var _domain: String { return domain }
124118
public var _code: Int { return code }

test/SILGen/Inputs/ObjectiveC.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ public struct Selector : ExpressibleByStringLiteral {
3333
self = sel_registerName(value)
3434
}
3535
}
36+
37+
extension NSObject : Hashable {
38+
public var hashValue: Int { return 0 }
39+
public static func == (x: NSObject, y: NSObject) -> Bool { return true }
40+
}
41+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %build-silgen-test-overlays
3+
// RUN: %target-swift-emit-silgen(mock-sdk: -sdk %S/Inputs -I %t) %s -enable-sil-ownership | %FileCheck %s
4+
5+
import ObjectiveC
6+
7+
struct RequiresEq<T: Equatable> { }
8+
9+
// Note: the NSObject: Equatable conformance from the overlay is not considered
10+
// to be a "retroactive" conformance, so ensure that it isn't mangled as such.
11+
// CHECK: sil hidden @$s28mangling_retroactive_overlay4testyyAA10RequiresEqVySo8NSObjectCGF
12+
func test(_: RequiresEq<NSObject>) { }
13+

test/SILGen/objc_dictionary_bridging.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ import gizmo
5353
@objc var property: Dictionary<Foo, Foo> = [:]
5454

5555
// Property getter
56-
// CHECK-LABEL: sil hidden [thunk] @$s24objc_dictionary_bridging3FooC8propertySDyA3CSH10FoundationyHCg_GvgTo : $@convention(objc_method) (Foo) -> @autoreleased NSDictionary
56+
// CHECK-LABEL: sil hidden [thunk] @$s24objc_dictionary_bridging3FooC8propertySDyA2CGvgTo : $@convention(objc_method) (Foo) -> @autoreleased NSDictionary
5757
// @$s24objc_dictionary_bridging3FooC8propertySDyA2CSo8NSObjectCSH10Foundationg_Gvpfi
5858
// CHECK: bb0([[SELF:%[0-9]+]] : @unowned $Foo):
5959
// CHECK: [[SELF_COPY:%.*]] = copy_value [[SELF]]
6060
// CHECK: [[BORROWED_SELF_COPY:%.*]] = begin_borrow [[SELF_COPY]]
61-
// CHECK: [[GETTER:%[0-9]+]] = function_ref @$s24objc_dictionary_bridging3FooC8propertySDyA3CSH10FoundationyHCg_Gvg : $@convention(method) (@guaranteed Foo) -> @owned Dictionary<Foo, Foo>
61+
// CHECK: [[GETTER:%[0-9]+]] = function_ref @$s24objc_dictionary_bridging3FooC8propertySDyA2CGvg : $@convention(method) (@guaranteed Foo) -> @owned Dictionary<Foo, Foo>
6262
// CHECK: [[DICT:%[0-9]+]] = apply [[GETTER]]([[BORROWED_SELF_COPY]]) : $@convention(method) (@guaranteed Foo) -> @owned Dictionary<Foo, Foo>
6363
// CHECK: end_borrow [[BORROWED_SELF_COPY]]
6464
// CHECK: destroy_value [[SELF_COPY]]
@@ -71,7 +71,7 @@ import gizmo
7171
// CHECK: } // end sil function
7272

7373
// Property setter
74-
// CHECK-LABEL: sil hidden [thunk] @$s24objc_dictionary_bridging3FooC8propertySDyA3CSH10FoundationyHCg_GvsTo : $@convention(objc_method) (NSDictionary, Foo) -> ()
74+
// CHECK-LABEL: sil hidden [thunk] @$s24objc_dictionary_bridging3FooC8propertySDyA2CGvsTo : $@convention(objc_method) (NSDictionary, Foo) -> ()
7575
// CHECK: bb0([[NSDICT:%[0-9]+]] : @unowned $NSDictionary, [[SELF:%[0-9]+]] : @unowned $Foo):
7676
// CHECK: [[NSDICT_COPY:%.*]] = copy_value [[NSDICT]]
7777
// CHECK: [[SELF_COPY:%.*]] = copy_value [[SELF]]
@@ -81,7 +81,7 @@ import gizmo
8181
// CHECK: [[DICT:%[0-9]+]] = apply [[CONVERTER]]<Foo, Foo>([[OPT_NSDICT]], [[DICT_META]])
8282

8383
// CHECK: [[BORROWED_SELF_COPY:%.*]] = begin_borrow [[SELF_COPY]]
84-
// CHECK: [[SETTER:%[0-9]+]] = function_ref @$s24objc_dictionary_bridging3FooC8propertySDyA3CSH10FoundationyHCg_Gvs : $@convention(method) (@owned Dictionary<Foo, Foo>, @guaranteed Foo) -> ()
84+
// CHECK: [[SETTER:%[0-9]+]] = function_ref @$s24objc_dictionary_bridging3FooC8propertySDyA2CGvs : $@convention(method) (@owned Dictionary<Foo, Foo>, @guaranteed Foo) -> ()
8585
// CHECK: [[RESULT:%[0-9]+]] = apply [[SETTER]]([[DICT]], [[BORROWED_SELF_COPY]]) : $@convention(method) (@owned Dictionary<Foo, Foo>, @guaranteed Foo) -> ()
8686
// CHECK: end_borrow [[BORROWED_SELF_COPY]]
8787
// CHECK: destroy_value [[SELF_COPY]]

0 commit comments

Comments
 (0)