@@ -2506,60 +2506,52 @@ struct SortedFuncList {
25062506} // end namespace
25072507
25082508ArrayRef<Decl *>
2509- EmittedMembersRequest::evaluate (Evaluator &evaluator,
2510- ClassDecl *CD) const {
2511- auto &Context = CD->getASTContext ();
2509+ SemanticMembersRequest::evaluate (Evaluator &evaluator,
2510+ IterableDeclContext *idc) const {
2511+ auto dc = cast<DeclContext>(idc->getDecl ());
2512+ auto &Context = dc->getASTContext ();
25122513 SmallVector<Decl *, 8 > result;
25132514
2514- if (!CD ->getParentSourceFile ()) {
2515- auto members = CD ->getMembers ();
2515+ if (!dc ->getParentSourceFile ()) {
2516+ auto members = idc ->getMembers ();
25162517 result.append (members.begin (), members.end ());
25172518 return Context.AllocateCopy (result);
25182519 }
25192520
2520- // We need to add implicit initializers because they
2521- // affect vtable layout.
2522- TypeChecker::addImplicitConstructors (CD);
2521+ auto nominal = dyn_cast<NominalTypeDecl>(idc);
25232522
2524- auto forceConformance = [&](ProtocolDecl *protocol) {
2525- auto ref = CD->getParentModule ()->lookupConformance (
2526- CD->getDeclaredInterfaceType (), protocol);
2527- if (ref.isInvalid ()) {
2528- return ;
2529- }
2523+ if (nominal) {
2524+ // We need to add implicit initializers because they
2525+ // affect vtable layout.
2526+ TypeChecker::addImplicitConstructors (nominal);
2527+ }
25302528
2531- auto conformance = ref.getConcrete ();
2532- if (conformance->getDeclContext () == CD &&
2533- conformance->getState () == ProtocolConformanceState::Incomplete) {
2529+ // Force any derivable conformances in this context. This ensures that any
2530+ // synthesized members will approach in the member list.
2531+ for (auto conformance : idc->getLocalConformances ()) {
2532+ if (conformance->getState () == ProtocolConformanceState::Incomplete &&
2533+ conformance->getProtocol ()->getKnownDerivableProtocolKind ())
25342534 TypeChecker::checkConformance (conformance->getRootNormalConformance ());
2535- }
2536- };
2535+ }
25372536
2538- // If the class is Encodable, Decodable or Hashable, force those
2539- // conformances to ensure that the synthesized members appear in the vtable.
2540- //
2541- // FIXME: Generalize this to other protocols for which
2542- // we can derive conformances.
2543- forceConformance (Context.getProtocol (KnownProtocolKind::Decodable));
2544- forceConformance (Context.getProtocol (KnownProtocolKind::Encodable));
2545- forceConformance (Context.getProtocol (KnownProtocolKind::Hashable));
2546- forceConformance (Context.getProtocol (KnownProtocolKind::Differentiable));
2547-
2548- // If the class conforms to Encodable or Decodable, even via an extension,
2537+ // If the type conforms to Encodable or Decodable, even via an extension,
25492538 // the CodingKeys enum is synthesized as a member of the type itself.
25502539 // Force it into existence.
2551- (void ) evaluateOrDefault (Context.evaluator ,
2552- ResolveImplicitMemberRequest{CD,
2553- ImplicitMemberAction::ResolveCodingKeys},
2554- {});
2540+ if (nominal) {
2541+ (void ) evaluateOrDefault (Context.evaluator ,
2542+ ResolveImplicitMemberRequest{nominal,
2543+ ImplicitMemberAction::ResolveCodingKeys},
2544+ {});
2545+ }
25552546
2556- // If the class has a @main attribute, we need to force synthesis of the
2547+ // If the decl has a @main attribute, we need to force synthesis of the
25572548 // $main function.
2558- (void ) evaluateOrDefault (Context.evaluator ,
2559- SynthesizeMainFunctionRequest{CD},
2560- nullptr );
2549+ (void ) evaluateOrDefault (
2550+ Context.evaluator ,
2551+ SynthesizeMainFunctionRequest{const_cast <Decl *>(idc->getDecl ())},
2552+ nullptr );
25612553
2562- for (auto *member : CD ->getMembers ()) {
2554+ for (auto *member : idc ->getMembers ()) {
25632555 if (auto *var = dyn_cast<VarDecl>(member)) {
25642556 // The projected storage wrapper ($foo) might have dynamically-dispatched
25652557 // accessors, so force them to be synthesized.
@@ -2570,7 +2562,7 @@ EmittedMembersRequest::evaluate(Evaluator &evaluator,
25702562
25712563 SortedFuncList synthesizedMembers;
25722564
2573- for (auto *member : CD ->getMembers ()) {
2565+ for (auto *member : idc ->getMembers ()) {
25742566 if (auto *afd = dyn_cast<AbstractFunctionDecl>(member)) {
25752567 // Add synthesized members to a side table and sort them by their mangled
25762568 // name, since they could have been added to the class in any order.
0 commit comments