@@ -2617,6 +2617,14 @@ loadIndexValuesForKeyPathComponent(SILGenFunction &SGF, SILLocation loc,
26172617 return indexValues;
26182618}
26192619
2620+ static AccessorDecl *
2621+ getRepresentativeAccessorForKeyPath (AbstractStorageDecl *storage) {
2622+ if (storage->requiresOpaqueGetter ())
2623+ return storage->getGetter ();
2624+ assert (storage->requiresOpaqueReadCoroutine ());
2625+ return storage->getReadCoroutine ();
2626+ }
2627+
26202628static SILFunction *getOrCreateKeyPathGetter (SILGenModule &SGM,
26212629 SILLocation loc,
26222630 AbstractStorageDecl *property,
@@ -2629,16 +2637,16 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
26292637 // back to the declaration whose getter introduced the witness table
26302638 // entry.
26312639 if (isa<ProtocolDecl>(property->getDeclContext ())) {
2632- auto getter = property-> getGetter ( );
2633- if (!SILDeclRef::requiresNewWitnessTableEntry (getter )) {
2640+ auto accessor = getRepresentativeAccessorForKeyPath (property );
2641+ if (!SILDeclRef::requiresNewWitnessTableEntry (accessor )) {
26342642 // Find the getter that does have a witness table entry.
2635- auto wtableGetter =
2636- cast<AccessorDecl>(SILDeclRef::getOverriddenWitnessTableEntry (getter ));
2643+ auto wtableAccessor =
2644+ cast<AccessorDecl>(SILDeclRef::getOverriddenWitnessTableEntry (accessor ));
26372645
26382646 // Substitute the 'Self' type of the base protocol.
26392647 subs = SILGenModule::mapSubstitutionsForWitnessOverride (
2640- getter, wtableGetter , subs);
2641- property = wtableGetter ->getStorage ();
2648+ accessor, wtableAccessor , subs);
2649+ property = wtableAccessor ->getStorage ();
26422650 }
26432651 }
26442652
@@ -3239,7 +3247,7 @@ getIdForKeyPathComponentComputedProperty(SILGenModule &SGM,
32393247 // observed property into a stored property.
32403248 strategy = strategy.getReadStrategy ();
32413249 if (strategy.getKind () != AccessStrategy::Storage ||
3242- !storage-> getGetter ( )) {
3250+ !getRepresentativeAccessorForKeyPath (storage )) {
32433251 return getIdForKeyPathComponentComputedProperty (SGM, storage, strategy);
32443252 }
32453253 LLVM_FALLTHROUGH;
@@ -3250,12 +3258,13 @@ getIdForKeyPathComponentComputedProperty(SILGenModule &SGM,
32503258 // TODO: If the getter has shared linkage (say it's synthesized for a
32513259 // Clang-imported thing), we'll need some other sort of
32523260 // stable identifier.
3253- auto getterRef = SILDeclRef (storage->getGetter (), SILDeclRef::Kind::Func);
3261+ auto getterRef = SILDeclRef (getRepresentativeAccessorForKeyPath (storage),
3262+ SILDeclRef::Kind::Func);
32543263 return SGM.getFunction (getterRef, NotForDefinition);
32553264 }
32563265 case AccessStrategy::DispatchToAccessor: {
32573266 // Identify the property by its vtable or wtable slot.
3258- return SGM.getAccessorDeclRef (storage-> getGetter ( ));
3267+ return SGM.getAccessorDeclRef (getRepresentativeAccessorForKeyPath (storage ));
32593268 }
32603269 case AccessStrategy::BehaviorStorage:
32613270 llvm_unreachable (" unpossible" );
@@ -3336,7 +3345,8 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
33363345 // Properties that only dispatch via ObjC lookup do not have nor need
33373346 // property descriptors, since the selector identifies the storage.
33383347 && (!storage->hasAnyAccessors ()
3339- || !getAccessorDeclRef (storage->getGetter ()).isForeign );
3348+ || !getAccessorDeclRef (getRepresentativeAccessorForKeyPath (storage))
3349+ .isForeign );
33403350 };
33413351
33423352 auto strategy = storage->getAccessStrategy (AccessSemantics::Ordinary,
0 commit comments