@@ -34,6 +34,7 @@ namespace swift {
34
34
class Type ;
35
35
class TypeRepr ;
36
36
class ValueDecl ;
37
+
37
38
enum class DeclAvailabilityFlag : uint8_t {
38
39
// / Do not diagnose uses of protocols in versions before they were introduced.
39
40
// / Used when type-checking protocol conformances, since conforming to a
@@ -68,6 +69,29 @@ enum class ExportabilityReason : unsigned {
68
69
ExtensionWithConditionalConformances
69
70
};
70
71
72
+ // / A description of the restrictions on what declarations can be referenced
73
+ // / from a the signature or body of a declaration.
74
+ // /
75
+ // / We say a declaration is "exported" if it is `public` or
76
+ // / `@usableFromInline`, not `_@spi`, and not visible via an
77
+ // / `@_implementationOnly` import.
78
+ // /
79
+ // / The "signature" of a declaration is the set of all types written in the
80
+ // / declaration (such as function parameter and return types), but not
81
+ // / including the function body.
82
+ // /
83
+ // / The signature of an exported declaration can only reference other
84
+ // / exported types.
85
+ // /
86
+ // / The body of an inlinable function can only reference other `public` and
87
+ // / `@usableFromInline` declarations; furthermore, if the inlinable
88
+ // / function is also exported, its body is restricted to referencing other
89
+ // / exported declarations.
90
+ // /
91
+ // / The ExportContext also stores if the location in the program is inside
92
+ // / of a function or type body with deprecated or unavailable availability.
93
+ // / This allows referencing other deprecated and unavailable declarations,
94
+ // / without producing a warning or error, respectively.
71
95
class ExportContext {
72
96
DeclContext *DC;
73
97
FragileFunctionKind FragileKind;
@@ -78,20 +102,54 @@ class ExportContext {
78
102
ExportContext (DeclContext *DC, FragileFunctionKind kind, bool spi, bool exported);
79
103
80
104
public:
105
+
106
+ // / Create an instance describing the types that can be referenced from the
107
+ // / given declaration's signature.
108
+ // /
109
+ // / If the declaration is exported, the resulting context is restricted to
110
+ // / referencing exported types only. Otherwise it can reference anything.
81
111
static ExportContext forDeclSignature (Decl *D);
112
+
113
+ // / Create an instance describing the declarations that can be referenced
114
+ // / from the given function's body.
115
+ // /
116
+ // / If the function is inlinable, the resulting context is restricted to
117
+ // / referencing ABI-public declarations only. Furthermore, if the function
118
+ // / is exported, referenced declarations must also be exported. Otherwise
119
+ // / it can reference anything.
82
120
static ExportContext forFunctionBody (DeclContext *DC);
83
121
122
+ // / Produce a new context with the same properties as this one, except
123
+ // / changing the ExportabilityReason. This only affects diagnostics.
84
124
ExportContext forReason (ExportabilityReason reason) const ;
125
+
126
+ // / Produce a new context with the same properties as this one, except
127
+ // / that if 'exported' is false, the resulting context can reference
128
+ // / declarations that are not exported. If 'exported' is true, the
129
+ // / resulting context is indentical to this one.
130
+ // /
131
+ // / That is, this will perform a 'bitwise and' on the 'exported' bit.
85
132
ExportContext forExported (bool exported) const ;
86
133
87
134
DeclContext *getDeclContext () const { return DC; }
135
+
136
+ // / If not 'None', the context has the inlinable function body restriction.
88
137
FragileFunctionKind getFragileFunctionKind () const { return FragileKind; }
89
138
139
+ // / If true, the context is SPI and can reference SPI declarations.
90
140
bool isSPI () const { return SPI; }
141
+
142
+ // / If true, the context is exported and cannot reference SPI declarations
143
+ // / or declarations from `@_implementationOnly` imports.
91
144
bool isExported () const { return Exported; }
92
145
146
+ // / If true, the context can only reference exported declarations, either
147
+ // / because it is the signature context of an exported declaration, or
148
+ // / because it is the function body context of an inlinable function.
93
149
bool mustOnlyReferenceExportedDecls () const ;
94
150
151
+ // / Get the ExportabilityReason for diagnostics. If this is 'None', there
152
+ // / are no restrictions on referencing unexported declarations.
95
153
Optional<ExportabilityReason> getExportabilityReason () const ;
96
154
};
97
155
0 commit comments