Skip to content

Commit 6a9540f

Browse files
committed
[APINotes] Protocols cannot use import-as-member.
We could support this in the future but right now it's causing problems. There's also a potential ambiguity issue here where a protocol and class could have the same name. In addition to updating the importer, remove the two entries from the CryptoTokenKit API notes that were trying to use this feature. rdar://problem/27990168
1 parent d5d9d82 commit 6a9540f

File tree

10 files changed

+2
-128
lines changed

10 files changed

+2
-128
lines changed

apinotes/CryptoTokenKit.apinotes

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ Classes:
3333
SwiftPrivate: true
3434
- Name: TKSmartCardATRInterfaceGroup
3535
SwiftName: TKSmartCardATR.InterfaceGroup
36-
- Name: TKTokenKeyAlgorithm
37-
SwiftName: TKTokenSessionDelegate.KeyAlgorithm
38-
- Name: TKTokenKeyExchangeParameters
39-
SwiftName: TKTokenSessionDelegate.KeyExchangeParameters
4036
Protocols:
4137
- Name: TKTokenSessionDelegate
4238
Methods:

lib/ClangImporter/SwiftLookupTable.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ clang::NamedDecl *SwiftLookupTable::resolveContext(StringRef unresolvedName) {
216216
if (auto decl = entry.dyn_cast<clang::NamedDecl *>()) {
217217
if (isa<clang::TagDecl>(decl) ||
218218
isa<clang::ObjCInterfaceDecl>(decl) ||
219-
isa<clang::ObjCProtocolDecl>(decl) ||
220219
isa<clang::TypedefNameDecl>(decl))
221220
return decl;
222221
}

test/IDE/Inputs/custom-modules/ImportAsMemberError.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@ struct __attribute__((swift_name("ErrorStruct"))) IAMStruct {
1212
@end
1313
typedef NSObject<ImportedProtocolBase> *ImportedProtocolBase_t;
1414

15-
@protocol ErrorProto;
16-
@protocol ErrorProto <ImportedProtocolBase>
17-
@end
18-
19-
typedef NSObject<ErrorProto> *ErrorProto_t;
20-
21-
// Instance and static member onto protocol
22-
void mutateSomeStaticState(void)
23-
__attribute__((swift_name("ErrorProto.mutateSomeStaticState()"))); // ok
24-
void mutateSomeInstanceState(ErrorProto_t self) __attribute__((
25-
swift_name("ErrorProto.mutateSomeInstanceState(self:)"))); // error
26-
2715
// Non-prototype declaration
2816
extern void IAMErrorStructHasPrototype(void)
2917
__attribute__((swift_name("ErrorStruct.hasPrototype()"))); // ok

test/IDE/Inputs/custom-modules/ImportAsMemberProto.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

test/IDE/Inputs/custom-modules/module.map

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ module ImportAsMember {
3737
header "ImportAsMemberC.h"
3838
}
3939

40-
module Proto {
41-
requires objc
42-
header "ImportAsMemberProto.h"
43-
}
44-
4540
module Class {
4641
requires objc
4742
header "ImportAsMemberClass.h"

test/IDE/import_as_member_objc.swift

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -I %t -I %S/Inputs/custom-modules -print-module -source-filename %s -module-to-print=ImportAsMember.Proto -always-argument-labels > %t.printed.Proto.txt
2-
3-
// RUN: %FileCheck %s -check-prefix=PRINT-PROTO -strict-whitespace < %t.printed.Proto.txt
4-
5-
// PRINT-PROTO-LABEL: protocol ImportedProtocolBase : NSObjectProtocol {
6-
// PRINT-PROTO-NEXT: }
7-
// PRINT-PROTO-NEXT: typealias ImportedProtocolBase_t = ImportedProtocolBase
8-
// PRINT-PROTO-NEXT: protocol IAMProto : ImportedProtocolBase {
9-
// PRINT-PROTO-NEXT: }
10-
// PRINT-PROTO-NEXT: typealias IAMProto_t = IAMProto
11-
// PRINT-PROTO-NEXT: extension IAMProto {
12-
// PRINT-PROTO-NEXT: func mutateSomeState()
13-
// PRINT-PROTO-NEXT: func mutateSomeState(withParameter _: Int)
14-
// PRINT-PROTO-NEXT: func mutateSomeState(withFirstParameter _: Int)
15-
// PRINT-PROTO-NEXT: var someValue: Int32
16-
// PRINT-PROTO-NEXT: }
17-
181
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -I %t -I %S/Inputs/custom-modules -print-module -source-filename %s -module-to-print=ImportAsMember.Class -always-argument-labels > %t.printed.Class.txt
192

203
// RUN: %FileCheck %s -check-prefix=PRINT-CLASS -strict-whitespace < %t.printed.Class.txt
@@ -37,32 +20,12 @@
3720
// REQUIRES: objc_interop
3821

3922
import Foundation
40-
import ImportAsMember.Proto
4123
import ImportAsMember.Class
4224
import IAMError
4325

4426
// Errors
4527
ErrorStruct.hasPrototype();
4628

47-
// Protocols
48-
@objc class Foo : NSObject, IAMProto {}
49-
50-
struct Bar : IAMProto {}
51-
// expected-error@-1{{non-class type 'Bar' cannot conform to class protocol 'IAMProto'}}
52-
// expected-error@-2{{non-class type 'Bar' cannot conform to class protocol 'ImportedProtocolBase'}}
53-
// expected-error@-3{{non-class type 'Bar' cannot conform to class protocol 'NSObjectProtocol'}}
54-
55-
@objc class FooErr : NSObject, ErrorProto {}
56-
57-
let foo = Foo()
58-
foo.mutateSomeState()
59-
60-
let fooErr = FooErr()
61-
fooErr.mutateSomeInstanceState()
62-
FooErr.mutateSomeStaticState()
63-
// expected-error@-1{{type 'FooErr' has no member 'mutateSomeStaticState'}}
64-
65-
6629
// Import into members of an imported, renamed class.
6730
let someClassOpts: SomeClass.Options = .fuzzyDice
6831
let someClass = SomeClass(value: 3.14159)

test/IRGen/cf_members.sil

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import ImportAsMember
1010
sil @IAMStruct1CreateSimple : $@convention(c) () -> Struct1
1111
sil @IAMStruct1Rotate : $@convention(c) (@in Struct1, Double) -> Struct1
1212
sil @IAMStruct1SetAltitude : $@convention(c) (@inout Struct1, Double) -> ()
13-
sil @mutateSomeState : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (τ_0_0) -> ()
1413

1514
sil @invoke_methods : $@convention(thin) (Double) -> () {
1615
entry(%z : $Double):
@@ -25,14 +24,3 @@ entry(%z : $Double):
2524
dealloc_stack %c : $*Struct1
2625
return undef : $()
2726
}
28-
29-
// CHECK-LABEL: define void @invoke_protocol_methods(%objc_object*)
30-
sil @invoke_protocol_methods : $@convention(thin) (IAMProto) -> () {
31-
entry(%z : $IAMProto):
32-
%a = open_existential_ref %z : $IAMProto to $@opened("01234567-89AB-CDEF-0123-000000000000") IAMProto
33-
%b = function_ref @mutateSomeState : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (τ_0_0) -> ()
34-
// CHECK: [[CAST:%.*]] = bitcast %objc_object* %0 to i8*
35-
// CHECK: call void @mutateSomeState(i8* [[CAST]])
36-
apply %b<@opened("01234567-89AB-CDEF-0123-000000000000") IAMProto>(%a) : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (τ_0_0) -> ()
37-
return undef : $()
38-
}

test/SILGen/cf_members.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,6 @@ public func bar(_ x: Double) {
245245
c()
246246
}
247247

248-
// CHECK-LABEL: sil @_TF10cf_members16importAsProtocolFPSo8IAMProto_T_
249-
public func importAsProtocol(_ x: IAMProto_t) {
250-
// CHECK: function_ref @mutateSomeState : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (τ_0_0) -> ()
251-
x.mutateSomeState()
252-
// CHECK: function_ref @mutateSomeStateWithParameter : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (τ_0_0, Int) -> ()
253-
x.mutateSomeState(withParameter: 0)
254-
// CHECK: function_ref @mutateSomeStateWithFirstParameter : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (Int, τ_0_0) -> ()
255-
x.mutateSomeState(withFirstParameter: 0)
256-
257-
// CHECK: function_ref @getSomeValue : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (τ_0_0) -> Int32
258-
let y = x.someValue
259-
// CHECK: function_ref @setSomeValue : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (τ_0_0, Int32) -> Int32
260-
x.someValue = y
261-
}
262-
263248
// CHECK-LABEL: sil @_TF10cf_members28importGlobalVarsAsProperties
264249
public func importGlobalVarsAsProperties()
265250
-> (Double, CCPowerSupply, CCPowerSupply?) {

test/SILGen/import_as_member.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// RUN: %target-swift-frontend -emit-silgen -I %S/../IDE/Inputs/custom-modules %s 2>&1 | %FileCheck --check-prefix=SIL %s
22
// REQUIRES: objc_interop
33
import ImportAsMember.A
4-
import ImportAsMember.Proto
54
import ImportAsMember.Class
65

76
public func returnGlobalVar() -> Double {
@@ -13,14 +12,6 @@ public func returnGlobalVar() -> Double {
1312
// SIL: return %2 : $Double
1413
// SIL-NEXT: }
1514

16-
// SIL-LABEL: sil {{.*}}useProto{{.*}} (@owned IAMProto) -> () {
17-
// TODO: Add in body checks
18-
public func useProto(p: IAMProto) {
19-
p.mutateSomeState()
20-
let v = p.someValue
21-
p.someValue = v+1
22-
}
23-
2415
// SIL-LABEL: sil {{.*}}anchor{{.*}} () -> () {
2516
func anchor() {}
2617

validation-test/stdlib/CryptoTokenKitTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ if #available(OSX 10.12, *) {
6969

7070
struct TKTokenTest {
7171
func f1(session: TKTokenSession, sessionDelegate: TKTokenSessionDelegate,
72-
algorithm: TKTokenSessionDelegate.KeyAlgorithm,
73-
parameters: TKTokenSessionDelegate.KeyExchangeParameters) throws {
72+
algorithm: TKTokenKeyAlgorithm,
73+
parameters: TKTokenKeyExchangeParameters) throws {
7474
let _: Bool = sessionDelegate.tokenSession!(session, supports: .none,
7575
keyObjectID: "", algorithm: algorithm)
7676
let _: Data = try sessionDelegate.tokenSession!(session, sign: Data(),

0 commit comments

Comments
 (0)