File: local_spi_decls.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (134 lines) | stat: -rw-r--r-- 6,887 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Checks for SPI declarations and limited exportability.

// RUN: %empty-directory(%t)
// RUN: %target-typecheck-verify-swift -I %t -verify-ignore-unknown -enable-library-evolution -swift-version 5 -package-name myPkg

// Without -enable-library-evolution the exportability check looks at struct internal properties.
// RUN: %target-typecheck-verify-swift -I %t -verify-ignore-unknown -swift-version 5 -package-name myPkg

// SPI declarations
@_spi(MySPI) public func spiFunc() {}
@_spi(+) public func invalidSPIName() {} // expected-error {{expected an SPI identifier as subject of the '@_spi' attribute}}
@_spi(🤔) public func emojiNamedSPI() {} // OK
@_spi(_) public func underscoreNamedSPI() {} // OK
@_spi() public func emptyParensSPI() {} // expected-error {{expected an SPI identifier as subject of the '@_spi' attribute}}
@_spi(set) public func keywordSPI() {} // expected-error {{expected an SPI identifier as subject of the '@_spi' attribute}}

@_spi(S) public class SPIClass { // expected-note 6 {{type declared here}}
  public init() {}
}
class InternalClass {} // expected-note 2 {{type declared here}}
private class PrivateClass {} // expected-note 2 {{type declared here}}

@_spi(S) public protocol SPIProtocol {} // expected-note {{type declared here}}

@_spi(S) public func useOfSPITypeOk(_ p0: SPIProtocol, p1: SPIClass) -> SPIClass { fatalError() } // OK
public func useOfSPITypeInvalid() -> SPIClass { fatalError() } // expected-error {{cannot use class 'SPIClass' here; it is SPI}}
@_spi(S) public func spiUseOfInternalType() -> InternalClass { fatalError() } // expected-error{{function cannot be declared public because its result uses an internal type}}
@_spi(S) public func spiUseOfPrivateType(_ a: PrivateClass)  { fatalError() } // expected-error{{function cannot be declared public because its parameter uses a private type}}

public var globalArrayWithSPISetter: [Int] {
  get { fatalError() }
  @_spi(S) set {}
}

@inlinable
func inlinable() -> SPIClass { // expected-error {{class 'SPIClass' cannot be used in an '@inlinable' function because it is SPI}}
  spiFunc() // expected-error {{global function 'spiFunc()' cannot be used in an '@inlinable' function because it is SPI}}
  _ = SPIClass() // expected-error {{class 'SPIClass' cannot be used in an '@inlinable' function because it is SPI}}
  // expected-error@-1 {{initializer 'init()' cannot be used in an '@inlinable' function because it is SPI}}
  globalArrayWithSPISetter = [] // expected-error {{setter for var 'globalArrayWithSPISetter' cannot be used in an '@inlinable' function because it is SPI}}
  globalArrayWithSPISetter.append(0) // expected-error {{setter for var 'globalArrayWithSPISetter' cannot be used in an '@inlinable' function because it is SPI}}
}

@_spi(S) public struct SPIStruct {
// expected-note@-1 {{type declared here}}
  public init() {}
}

@frozen public struct FrozenStruct {
  @_spi(S) public var spiInFrozen = SPIStruct()
  // expected-error@-1 {{stored property 'spiInFrozen' cannot be declared '@_spi' in a '@frozen' struct}}

  var spiTypeInFrozen = SPIStruct() // expected-error {{struct 'SPIStruct' cannot be used in a property initializer in a '@frozen' type because it is SPI}}
  // expected-error@-1 {{cannot use struct 'SPIStruct' here; it is SPI}}
  // expected-error@-2 {{initializer 'init()' cannot be used in a property initializer in a '@frozen' type because it is SPI}}

  private var spiTypeInFrozen1: SPIClass // expected-error {{cannot use class 'SPIClass' here; it is SPI}}
}

@_spi(S)
@frozen public struct SPIFrozenStruct {
  var spiTypeInFrozen = SPIStruct()
  private var spiTypeInFrozen1: SPIClass

  @_spi(S)
  private var privateSPIInFrozenSPI = SPIStruct()
}

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

@_spi(S) public class BadSubclass : InternalClass {} // expected-error{{class cannot be declared public because its superclass is internal}}
@_spi(S) public class OkSPISubclass : SPIClass {} // OK
public class BadPublicClass : SPIClass {} // expected-error {{cannot use class 'SPIClass' in a public or '@usableFromInline' conformance; it is SPI}}
@_spi(S) public class BadSPIClass : PrivateClass {} // expected-error {{class cannot be declared public because its superclass is private}}

@_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}}
public func genFuncBad<T: SPIProtocol>(_ t: T) {} // expected-error {{cannot use protocol 'SPIProtocol' here; it is SPI}}
@_spi(S) public func genFuncSPI<T: SPIProtocol>(_ t: T) {} // OK

@_spi(S) private func privateCantBeSPI() {} // expected-error{{private global function cannot be declared '@_spi' because only public and open declarations can be '@_spi'}} {{1-10=}}
@_spi(S) func internalCantBeSPI() {} // expected-error{{internal global function cannot be declared '@_spi' because only public and open declarations can be '@_spi'}} {{1-10=}}

public struct PublicStructWithProperties {
  public var a: SPIClass // expected-error {{cannot use class 'SPIClass' here; it is SPI}}
  public var b = SPIClass() // expected-error {{cannot use class 'SPIClass' here; it is SPI}}
}

@_spi(S)
@usableFromInline
func usableFromInlineFunc(_ a: SPIStruct) -> SPIStruct {
  fatalError()
}

@_spi(S)
public final class ClassWithUsables {
    @usableFromInline
    var usableFromInlineVar = SPIClass()

    @usableFromInline
    func usableFromInlineFunc(_ a: SPIStruct) -> SPIStruct {
      fatalError()
    }
}

@_spi(S)
public struct NestedParent {
    public struct Nested { }
    let nested: Nested
}

public func publicFuncWithDefaultValue(_ p: SPIClass = SPIClass()) {} // expected-error {{cannot use class 'SPIClass' here; it is SPI}}
// expected-error@-1 {{class 'SPIClass' cannot be used in a default argument value because it is SPI}}
// expected-error@-2 {{initializer 'init()' cannot be used in a default argument value because it is SPI}}

@_spi(S)
public func spiFuncWithDefaultValue(_ p: SPIClass = SPIClass()) {}

@inlinable
public func inlinablePublic() {
  spiFunc() // expected-error {{global function 'spiFunc()' cannot be used in an '@inlinable' function because it is SPI}}
  let _ = SPIClass() // expected-error {{class 'SPIClass' cannot be used in an '@inlinable' function because it is SPI}}
  // expected-error@-1 {{initializer 'init()' cannot be used in an '@inlinable' function because it is SPI}}
}

@_spi(S)
@inlinable
public func inlinableSPI() {
  spiFunc()
  let _ = SPIClass()
}

@_spi(S) func internalFunc() {} // expected-error {{internal global function cannot be declared '@_spi' because only public and open declarations can be '@_spi'}}

@_spi(S) package func packageFunc() {} // expected-error {{package global function cannot be declared '@_spi' because only public and open declarations can be '@_spi'}}