Skip to content

Commit 4124693

Browse files
committed
[SPI Test] Extend and update SPI tests
1 parent 26c6a18 commit 4124693

File tree

5 files changed

+63
-19
lines changed

5 files changed

+63
-19
lines changed

test/SPI/Inputs/spi_helper.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,29 @@ func internalFunc() {}
1414
@_spi(HelperSPI) public init() { print("SPIStruct.init") }
1515
@_spi(HelperSPI) public func spiMethod() { print("SPIStruct.spiMethod") }
1616
@_spi(HelperSPI) public var spiVar = "text"
17-
//@_spi(HelperSPI) public subscript(index: Int) -> String { return spiVar } // TODO SPI support for subscripts
17+
18+
@_spi(HelperSPI) public var spiComputedVar: Int {
19+
get { return 42 }
20+
set {}
21+
}
22+
23+
@_spi(HelperSPI) public var spiComputedVarInherit: Int {
24+
@_spi(HelperSPI) get { return 42 }
25+
@_spi(HelperSPI) set {}
26+
}
27+
@_spi(HelperSPI) public subscript(index: Int) -> String { return spiVar }
28+
29+
public func spiInherit() {}
30+
@_spi(DifferentSPI) public func spiDontInherit() {}
31+
}
32+
33+
public extension SPIStruct {
34+
func spiExtensionHidden() {}
35+
@_spi(HelperSPI) func spiExtension() {}
36+
}
37+
38+
@_spi(HelperSPI) public extension SPIStruct {
39+
func spiExtensionInherited() {}
1840
}
1941

2042
@_spi(HelperSPI) public class SPIClass {

test/SPI/local_spi_decls.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,30 @@ private class PrivateClass {} // expected-note 2 {{type declared here}}
1818
@_spi(S) public protocol SPIProtocol {} // expected-note {{type declared here}}
1919

2020
@_spi(S) public func useOfSPITypeOk(_ p0: SPIProtocol, p1: SPIClass) -> SPIClass { fatalError() } // OK
21-
public func useOfSPITypeInvalid() -> SPIClass { fatalError() } // expected-error {{function cannot be declared public because its result uses an internal type}} // TODO misleading "internal" message
22-
@_spi(S) public func spiUseOfInternalType() -> InternalClass { fatalError() } // expected-error{{function cannot be declared '@_spi' because its result uses an internal type without a compatible '@_spi'}}
23-
@_spi(S) public func spiUseOfPrivateType(_ a: PrivateClass) { fatalError() } // expected-error{{function cannot be declared public because its parameter uses a private type}}
21+
public func useOfSPITypeInvalid() -> SPIClass { fatalError() } // expected-error {{function cannot be declared public because its result uses an '@_spi' type}}
22+
@_spi(S) public func spiUseOfInternalType() -> InternalClass { fatalError() } // expected-error{{function cannot be declared '@_spi' because its result uses an internal type}}
23+
@_spi(S) public func spiUseOfPrivateType(_ a: PrivateClass) { fatalError() } // expected-error{{function cannot be declared '@_spi' because its parameter uses a private type}}
2424

2525
@inlinable
26-
func inlinable() -> SPIClass { // expected-error {{class 'SPIClass' is internal and cannot be referenced from an '@inlinable' function}}
27-
spiFunc() // expected-error {{global function 'spiFunc()' is internal and cannot be referenced from an '@inlinable' function}}
28-
_ = SPIClass() // expected-error {{class 'SPIClass' is internal and cannot be referenced from an '@inlinable' function}}
26+
func inlinable() -> SPIClass { // expected-error {{class 'SPIClass' is '@_spi' and cannot be referenced from an '@inlinable' function}}
27+
spiFunc() // expected-error {{global function 'spiFunc()' is '@_spi' and cannot be referenced from an '@inlinable' function}}
28+
_ = SPIClass() // expected-error {{class 'SPIClass' is '@_spi' and cannot be referenced from an '@inlinable' function}}
2929
}
3030

3131
@_spi(S) public struct SPIStruct {} // expected-note 2 {{struct 'SPIStruct' is not '@usableFromInline' or public}}
3232

3333
@frozen public struct FrozenStruct {
34-
@_spi(S) public var asdf = SPIStruct() // expected-error {{struct 'SPIStruct' is internal and cannot be referenced from a property initializer in a '@frozen' type}}
35-
var asdf = SPIStruct() // expected-error {{struct 'SPIStruct' is internal and cannot be referenced from a property initializer in a '@frozen' type}}
34+
@_spi(S) public var asdf = SPIStruct() // expected-error {{struct 'SPIStruct' is '@_spi' and cannot be referenced from a property initializer in a '@frozen' type}}
35+
var asdf = SPIStruct() // expected-error {{struct 'SPIStruct' is '@_spi' and cannot be referenced from a property initializer in a '@frozen' type}}
3636
}
3737

3838
private protocol PrivateProtocol {} // expected-note {{type declared here}}
3939

4040
@_spi(S) public class BadSubclass : InternalClass {} // expected-error{{class cannot be declared public because its superclass is internal}}
4141
@_spi(S) public class OkSPISubclass : SPIClass {} // OK
42-
public class BadPublicClass : SPIClass {} // expected-error {{class cannot be declared public because its superclass is internal}}
42+
public class BadPublicClass : SPIClass {} // expected-error {{class cannot be declared public because its superclass is '@_spi'}}
4343
@_spi(S) public class BadSPIClass : PrivateClass {} // expected-error {{class cannot be declared public because its superclass is private}}
4444

4545
@_spi(s) public func genFunc<T: PrivateProtocol>(_ t: T) {} // expected-error {{global function cannot be declared public because its generic parameter uses a private type}}
46-
public func genFuncBad<T: SPIProtocol>(_ t: T) {} // expected-error {{global function cannot be declared public because its generic parameter uses an internal type}}
46+
public func genFuncBad<T: SPIProtocol>(_ t: T) {} // expected-error {{global function cannot be declared public because its generic parameter uses an '@_spi' type}}
4747
@_spi(S) public func genFuncSPI<T: SPIProtocol>(_ t: T) {} // OK

test/SPI/private_swiftinterface.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// RUN: %FileCheck -check-prefix=CHECK-HELPER %s < %t/SPIHelper.swiftinterface
99
// CHECK-HELPER-NOT: HelperSPI
1010
// CHECK-HELPER-NOT: @_spi
11+
// RUN: %target-swift-frontend -emit-module %t/SPIHelper.swiftinterface -emit-module-path %t/SPIHelper-from-public-swiftinterface.swiftmodule -swift-version 5 -module-name SPIHelper -enable-library-evolution
1112

1213
/// Test the textual interfaces generated from this test.
1314
// RUN: %target-swift-frontend -typecheck %s -emit-module-interface-path %t/main.swiftinterface -emit-private-module-interface-path %t/main.private.swiftinterface -enable-library-evolution -swift-version 5 -I %t
@@ -34,10 +35,13 @@ public func foo() {}
3435
// CHECK-PUBLIC-NOT: localSPIFunc()
3536

3637
// SPI declarations
37-
@_spi(MySPI) public class SPIClassLocal {}
38+
@_spi(MySPI) public class SPIClassLocal {
3839
// CHECK-PRIVATE: @_spi(MySPI) public class SPIClassLocal
3940
// CHECK-PUBLIC-NOT: class SPIClassLocal
4041

42+
public init() {}
43+
}
44+
4145
@_spi(MySPI) public extension SPIClassLocal {
4246
// CHECK-PRIVATE: @_spi(MySPI) extension SPIClassLocal
4347
// CHECK-PUBLIC-NOT: extension SPIClassLocal
@@ -46,9 +50,19 @@ public func foo() {}
4650
// CHECK-PRIVATE: @_spi(MySPI) public func extensionMethod
4751
// CHECK-PUBLIC-NOT: func extensionMethod
4852

49-
func internalExtensionMethod() {}
53+
internal func internalExtensionMethod() {}
5054
// CHECK-PRIVATE-NOT: internalExtensionMethod
5155
// CHECK-PUBLIC-NOT: internalExtensionMethod
56+
57+
func inheritedSPIExtensionMethod() {}
58+
// CHECK-PRIVATE: inheritedSPIExtensionMethod
59+
// CHECK-PUBLIC-NOT: inheritedSPIExtensionMethod
60+
}
61+
62+
public extension SPIClassLocal {
63+
internal func internalExtensionMethode1() {}
64+
// CHECK-PRIVATE-NOT: internalExtensionMethod1
65+
// CHECK-PUBLIC-NOT: internalExtensionMethod1
5266
}
5367

5468
class InternalClassLocal {}

test/SPI/public_client.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ SPIEnum().spiMethod() // expected-error {{use of unresolved identifier}}
2929

3030
var ps = PublicStruct()
3131
let _ = PublicStruct(alt_init: 1) // expected-error {{argument passed to call that takes no arguments}}
32-
ps.spiMethod() // expected-error {{'spiMethod' is inaccessible due to 'internal' protection level}} // TODO SPI specific diagnostics and suggest SPI to import
33-
ps.spiVar = "write" // expected-error {{'spiVar' is inaccessible due to 'internal' protection level}}
34-
print(ps.spiVar) // expected-error {{'spiVar' is inaccessible due to 'internal' protection level}}
32+
ps.spiMethod() // expected-error {{'spiMethod' is inaccessible due to '@_spi' protection level}} // TODO SPI specific diagnostics and suggest SPI to import
33+
ps.spiVar = "write" // expected-error {{'spiVar' is inaccessible due to '@_spi' protection level}}
34+
print(ps.spiVar) // expected-error {{'spiVar' is inaccessible due to '@_spi' protection level}}
3535

3636
otherApiFunc() // expected-error {{use of unresolved identifier}}
3737

test/SPI/spi_client.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ print(c.spiVar)
3030

3131
let s = SPIStruct()
3232
s.spiMethod()
33+
s.spiInherit()
34+
s.spiDontInherit() // expected-error {{'spiDontInherit' is inaccessible due to '@_spi' protection level}}
35+
s.spiExtensionHidden()
36+
s.spiExtension()
37+
s.spiExtensionInherited()
3338
s.spiVar = "write"
3439
print(s.spiVar)
3540

@@ -45,10 +50,13 @@ print(ps.spiVar)
4550
otherApiFunc() // expected-error {{use of unresolved identifier}}
4651

4752
public func publicUseOfSPI(param: SPIClass) -> SPIClass {} // expected-error 2{{cannot use class 'SPIClass' here; it is an SPI imported from 'SPIHelper'}}
53+
// expected-error@-1 {{function cannot be declared public because its parameter uses an '@_spi' type}}
4854
public func publicUseOfSPI2() -> [SPIClass] {} // expected-error {{cannot use class 'SPIClass' here; it is an SPI imported from 'SPIHelper'}}
55+
// expected-error@-1 {{function cannot be declared public because its result uses an '@_spi' type}}
4956

5057
@inlinable
51-
func inlinable() -> SPIClass { // expected-error {{class 'SPIClass' is imported as SPI; it cannot be referenced from an '@inlinable' function}}
52-
spiFunc() // expected-error {{global function 'spiFunc()' is imported as SPI; it cannot be referenced from an '@inlinable' function}}
53-
_ = SPIClass() // expected-error {{class 'SPIClass' is imported as SPI; it cannot be referenced from an '@inlinable' function}}
58+
func inlinable() -> SPIClass { // expected-error {{class 'SPIClass' is '@_spi' and cannot be referenced from an '@inlinable' function}}
59+
spiFunc() // expected-error {{global function 'spiFunc()' is '@_spi' and cannot be referenced from an '@inlinable' function}}
60+
_ = SPIClass() // expected-error {{class 'SPIClass' is '@_spi' and cannot be referenced from an '@inlinable' function}}
61+
_ = [SPIClass]() // expected-error {{class 'SPIClass' is '@_spi' and cannot be referenced from an '@inlinable' function}}
5462
}

0 commit comments

Comments
 (0)