@@ -255,6 +255,9 @@ static AccessorDecl *createGetterPrototype(TypeChecker &TC,
255255 if (storage->isStatic ())
256256 getter->setStatic ();
257257
258+ if (!storage->requiresOpaqueAccessor (AccessorKind::Get))
259+ getter->setForcedStaticDispatch (true );
260+
258261 // Always add the getter to the context immediately after the storage.
259262 addMemberToContextIfNeeded (getter, storage->getDeclContext (), storage);
260263
@@ -298,6 +301,9 @@ static AccessorDecl *createSetterPrototype(TypeChecker &TC,
298301 if (isStatic)
299302 setter->setStatic ();
300303
304+ // All mutable storage requires a setter.
305+ assert (storage->requiresOpaqueAccessor (AccessorKind::Set));
306+
301307 // Always add the setter to the context immediately after the getter.
302308 if (!getter) getter = storage->getGetter ();
303309 if (!getter) getter = storage->getReadCoroutine ();
@@ -307,14 +313,6 @@ static AccessorDecl *createSetterPrototype(TypeChecker &TC,
307313 return setter;
308314}
309315
310- // True if the storage is dynamic or imported from Objective-C. In these cases,
311- // we need to emit static coroutine accessors that dynamically dispatch
312- // to 'get' and 'set', rather than the normal dynamically dispatched
313- // opaque accessors that peer dispatch to 'get' and 'set'.
314- static bool needsDynamicCoroutineAccessors (AbstractStorageDecl *storage) {
315- return storage->isObjCDynamic () || storage->hasClangNode ();
316- }
317-
318316// / Mark the accessor as transparent if we can.
319317// /
320318// / If the storage is inside a fixed-layout nominal type, we can mark the
@@ -418,11 +416,11 @@ createCoroutineAccessorPrototype(TypeChecker &TC,
418416 if (storage->isFinal ())
419417 makeFinal (ctx, accessor);
420418
421- // If the storage is dynamic or ObjC-native, we can't add a dynamically-
422- // dispatched method entry for the accessor, so force it to be
423- // statically dispatched. ("final" would be inappropriate because the
424- // property can still be overridden.)
425- if (needsDynamicCoroutineAccessors ( storage))
419+ // If the storage does not provide this accessor as an opaque accessor,
420+ // we can't add a dynamically- dispatched method entry for the accessor,
421+ // so force it to be statically dispatched. ("final" would be inappropriate
422+ // because the property can still be overridden.)
423+ if (! storage-> requiresOpaqueAccessor (kind ))
426424 accessor->setForcedStaticDispatch (true );
427425
428426 // Make sure the coroutine is available enough to access
@@ -2093,6 +2091,11 @@ void swift::maybeAddAccessorsToStorage(TypeChecker &TC,
20932091}
20942092
20952093static void synthesizeGetterBody (TypeChecker &TC, AccessorDecl *getter) {
2094+ if (getter->hasForcedStaticDispatch ()) {
2095+ synthesizeTrivialGetterBody (TC, getter, TargetImpl::Ordinary);
2096+ return ;
2097+ }
2098+
20962099 switch (getter->getStorage ()->getReadImpl ()) {
20972100 case ReadImplKind::Stored:
20982101 synthesizeTrivialGetterBody (TC, getter);
0 commit comments