@@ -121,6 +121,22 @@ static void deriveBodyRawRepresentable_raw(AbstractFunctionDecl *toRawDecl) {
121
121
toRawDecl->setBody (body);
122
122
}
123
123
124
+ static void maybeMarkAsInlinable (DerivedConformance &derived,
125
+ AbstractFunctionDecl *afd) {
126
+ ASTContext &C = derived.TC .Context ;
127
+ auto parentDC = derived.getConformanceContext ();
128
+ if (parentDC->getParentModule ()->getResilienceStrategy () !=
129
+ ResilienceStrategy::Resilient) {
130
+ AccessScope access =
131
+ afd->getFormalAccessScope (nullptr ,
132
+ /* treatUsableFromInlineAsPublic*/ true );
133
+ if (auto *attr = afd->getAttrs ().getAttribute <UsableFromInlineAttr>())
134
+ attr->setInvalid ();
135
+ if (access.isPublic ())
136
+ afd->getAttrs ().add (new (C) InlinableAttr (/* implicit*/ false ));
137
+ }
138
+ }
139
+
124
140
static VarDecl *deriveRawRepresentable_raw (DerivedConformance &derived) {
125
141
ASTContext &C = derived.TC .Context ;
126
142
@@ -143,14 +159,7 @@ static VarDecl *deriveRawRepresentable_raw(DerivedConformance &derived) {
143
159
144
160
// If the containing module is not resilient, make sure clients can get at
145
161
// the raw value without function call overhead.
146
- if (parentDC->getParentModule ()->getResilienceStrategy () !=
147
- ResilienceStrategy::Resilient) {
148
- AccessScope access =
149
- enumDecl->getFormalAccessScope (nullptr ,
150
- /* treatUsableFromInlineAsPublic*/ true );
151
- if (access.isPublic ())
152
- getterDecl->getAttrs ().add (new (C) InlinableAttr (/* implicit*/ false ));
153
- }
162
+ maybeMarkAsInlinable (derived, getterDecl);
154
163
155
164
derived.addMembersToConformanceContext ({getterDecl, propDecl, pbDecl});
156
165
@@ -350,14 +359,7 @@ deriveRawRepresentable_init(DerivedConformance &derived) {
350
359
351
360
// If the containing module is not resilient, make sure clients can construct
352
361
// an instance without function call overhead.
353
- if (parentDC->getParentModule ()->getResilienceStrategy () !=
354
- ResilienceStrategy::Resilient) {
355
- AccessScope access =
356
- enumDecl->getFormalAccessScope (nullptr ,
357
- /* treatUsableFromInlineAsPublic*/ true );
358
- if (access.isPublic ())
359
- initDecl->getAttrs ().add (new (C) InlinableAttr (/* implicit*/ false ));
360
- }
362
+ maybeMarkAsInlinable (derived, initDecl);
361
363
362
364
C.addSynthesizedDecl (initDecl);
363
365
0 commit comments