Skip to content

[APINotes] Protocols cannot use import-as-member. #4484

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

Merged
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
4 changes: 0 additions & 4 deletions apinotes/CryptoTokenKit.apinotes
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ Classes:
SwiftPrivate: true
- Name: TKSmartCardATRInterfaceGroup
SwiftName: TKSmartCardATR.InterfaceGroup
- Name: TKTokenKeyAlgorithm
SwiftName: TKTokenSessionDelegate.KeyAlgorithm
- Name: TKTokenKeyExchangeParameters
SwiftName: TKTokenSessionDelegate.KeyExchangeParameters
Protocols:
- Name: TKTokenSessionDelegate
Methods:
Expand Down
1 change: 0 additions & 1 deletion lib/ClangImporter/SwiftLookupTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ clang::NamedDecl *SwiftLookupTable::resolveContext(StringRef unresolvedName) {
if (auto decl = entry.dyn_cast<clang::NamedDecl *>()) {
if (isa<clang::TagDecl>(decl) ||
isa<clang::ObjCInterfaceDecl>(decl) ||
isa<clang::ObjCProtocolDecl>(decl) ||
isa<clang::TypedefNameDecl>(decl))
return decl;
}
Expand Down
12 changes: 0 additions & 12 deletions test/IDE/Inputs/custom-modules/ImportAsMemberError.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ struct __attribute__((swift_name("ErrorStruct"))) IAMStruct {
@end
typedef NSObject<ImportedProtocolBase> *ImportedProtocolBase_t;

@protocol ErrorProto;
@protocol ErrorProto <ImportedProtocolBase>
@end

typedef NSObject<ErrorProto> *ErrorProto_t;

// Instance and static member onto protocol
void mutateSomeStaticState(void)
__attribute__((swift_name("ErrorProto.mutateSomeStaticState()"))); // ok
void mutateSomeInstanceState(ErrorProto_t self) __attribute__((
swift_name("ErrorProto.mutateSomeInstanceState(self:)"))); // error

// Non-prototype declaration
extern void IAMErrorStructHasPrototype(void)
__attribute__((swift_name("ErrorStruct.hasPrototype()"))); // ok
Expand Down
31 changes: 0 additions & 31 deletions test/IDE/Inputs/custom-modules/ImportAsMemberProto.h

This file was deleted.

5 changes: 0 additions & 5 deletions test/IDE/Inputs/custom-modules/module.map
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ module ImportAsMember {
header "ImportAsMemberC.h"
}

module Proto {
requires objc
header "ImportAsMemberProto.h"
}

module Class {
requires objc
header "ImportAsMemberClass.h"
Expand Down
37 changes: 0 additions & 37 deletions test/IDE/import_as_member_objc.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
// 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

// RUN: %FileCheck %s -check-prefix=PRINT-PROTO -strict-whitespace < %t.printed.Proto.txt

// PRINT-PROTO-LABEL: protocol ImportedProtocolBase : NSObjectProtocol {
// PRINT-PROTO-NEXT: }
// PRINT-PROTO-NEXT: typealias ImportedProtocolBase_t = ImportedProtocolBase
// PRINT-PROTO-NEXT: protocol IAMProto : ImportedProtocolBase {
// PRINT-PROTO-NEXT: }
// PRINT-PROTO-NEXT: typealias IAMProto_t = IAMProto
// PRINT-PROTO-NEXT: extension IAMProto {
// PRINT-PROTO-NEXT: func mutateSomeState()
// PRINT-PROTO-NEXT: func mutateSomeState(withParameter _: Int)
// PRINT-PROTO-NEXT: func mutateSomeState(withFirstParameter _: Int)
// PRINT-PROTO-NEXT: var someValue: Int32
// PRINT-PROTO-NEXT: }

// 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

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

import Foundation
import ImportAsMember.Proto
import ImportAsMember.Class
import IAMError

// Errors
ErrorStruct.hasPrototype();

// Protocols
@objc class Foo : NSObject, IAMProto {}

struct Bar : IAMProto {}
// expected-error@-1{{non-class type 'Bar' cannot conform to class protocol 'IAMProto'}}
// expected-error@-2{{non-class type 'Bar' cannot conform to class protocol 'ImportedProtocolBase'}}
// expected-error@-3{{non-class type 'Bar' cannot conform to class protocol 'NSObjectProtocol'}}

@objc class FooErr : NSObject, ErrorProto {}

let foo = Foo()
foo.mutateSomeState()

let fooErr = FooErr()
fooErr.mutateSomeInstanceState()
FooErr.mutateSomeStaticState()
// expected-error@-1{{type 'FooErr' has no member 'mutateSomeStaticState'}}


// Import into members of an imported, renamed class.
let someClassOpts: SomeClass.Options = .fuzzyDice
let someClass = SomeClass(value: 3.14159)
Expand Down
12 changes: 0 additions & 12 deletions test/IRGen/cf_members.sil
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import ImportAsMember
sil @IAMStruct1CreateSimple : $@convention(c) () -> Struct1
sil @IAMStruct1Rotate : $@convention(c) (@in Struct1, Double) -> Struct1
sil @IAMStruct1SetAltitude : $@convention(c) (@inout Struct1, Double) -> ()
sil @mutateSomeState : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (τ_0_0) -> ()

sil @invoke_methods : $@convention(thin) (Double) -> () {
entry(%z : $Double):
Expand All @@ -25,14 +24,3 @@ entry(%z : $Double):
dealloc_stack %c : $*Struct1
return undef : $()
}

// CHECK-LABEL: define void @invoke_protocol_methods(%objc_object*)
sil @invoke_protocol_methods : $@convention(thin) (IAMProto) -> () {
entry(%z : $IAMProto):
%a = open_existential_ref %z : $IAMProto to $@opened("01234567-89AB-CDEF-0123-000000000000") IAMProto
%b = function_ref @mutateSomeState : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (τ_0_0) -> ()
// CHECK: [[CAST:%.*]] = bitcast %objc_object* %0 to i8*
// CHECK: call void @mutateSomeState(i8* [[CAST]])
apply %b<@opened("01234567-89AB-CDEF-0123-000000000000") IAMProto>(%a) : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (τ_0_0) -> ()
return undef : $()
}
15 changes: 0 additions & 15 deletions test/SILGen/cf_members.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,6 @@ public func bar(_ x: Double) {
c()
}

// CHECK-LABEL: sil @_TF10cf_members16importAsProtocolFPSo8IAMProto_T_
public func importAsProtocol(_ x: IAMProto_t) {
// CHECK: function_ref @mutateSomeState : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (τ_0_0) -> ()
x.mutateSomeState()
// CHECK: function_ref @mutateSomeStateWithParameter : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (τ_0_0, Int) -> ()
x.mutateSomeState(withParameter: 0)
// CHECK: function_ref @mutateSomeStateWithFirstParameter : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (Int, τ_0_0) -> ()
x.mutateSomeState(withFirstParameter: 0)

// CHECK: function_ref @getSomeValue : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (τ_0_0) -> Int32
let y = x.someValue
// CHECK: function_ref @setSomeValue : $@convention(c) <τ_0_0 where τ_0_0 : IAMProto> (τ_0_0, Int32) -> Int32
x.someValue = y
}

// CHECK-LABEL: sil @_TF10cf_members28importGlobalVarsAsProperties
public func importGlobalVarsAsProperties()
-> (Double, CCPowerSupply, CCPowerSupply?) {
Expand Down
9 changes: 0 additions & 9 deletions test/SILGen/import_as_member.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// RUN: %target-swift-frontend -emit-silgen -I %S/../IDE/Inputs/custom-modules %s 2>&1 | %FileCheck --check-prefix=SIL %s
// REQUIRES: objc_interop
import ImportAsMember.A
import ImportAsMember.Proto
import ImportAsMember.Class

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

// SIL-LABEL: sil {{.*}}useProto{{.*}} (@owned IAMProto) -> () {
// TODO: Add in body checks
public func useProto(p: IAMProto) {
p.mutateSomeState()
let v = p.someValue
p.someValue = v+1
}

// SIL-LABEL: sil {{.*}}anchor{{.*}} () -> () {
func anchor() {}

Expand Down
4 changes: 2 additions & 2 deletions validation-test/stdlib/CryptoTokenKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ if #available(OSX 10.12, *) {

struct TKTokenTest {
func f1(session: TKTokenSession, sessionDelegate: TKTokenSessionDelegate,
algorithm: TKTokenSessionDelegate.KeyAlgorithm,
parameters: TKTokenSessionDelegate.KeyExchangeParameters) throws {
algorithm: TKTokenKeyAlgorithm,
parameters: TKTokenKeyExchangeParameters) throws {
let _: Bool = sessionDelegate.tokenSession!(session, supports: .none,
keyObjectID: "", algorithm: algorithm)
let _: Data = try sessionDelegate.tokenSession!(session, sign: Data(),
Expand Down