@@ -609,24 +609,6 @@ SILGenModule::getWitnessTable(ProtocolConformance *conformance) {
609
609
return table;
610
610
}
611
611
612
- static bool maybeOpenCodeProtocolWitness (
613
- SILGenFunction &SGF, ProtocolConformanceRef conformance, SILLinkage linkage,
614
- Type selfInterfaceType, Type selfType, GenericEnvironment *genericEnv,
615
- SILDeclRef requirement, SILDeclRef witness, SubstitutionList witnessSubs) {
616
- if (auto witnessFn = dyn_cast<FuncDecl>(witness.getDecl ())) {
617
- if (witnessFn->getAccessorKind () == AccessorKind::IsMaterializeForSet) {
618
- auto reqFn = cast<FuncDecl>(requirement.getDecl ());
619
- assert (reqFn->getAccessorKind () == AccessorKind::IsMaterializeForSet);
620
- return SGF.maybeEmitMaterializeForSetThunk (conformance, linkage,
621
- selfInterfaceType, selfType,
622
- genericEnv, reqFn, witnessFn,
623
- witnessSubs);
624
- }
625
- }
626
-
627
- return false ;
628
- }
629
-
630
612
SILFunction *SILGenModule::emitProtocolWitness (
631
613
ProtocolConformanceRef conformance, SILLinkage linkage,
632
614
IsSerialized_t isSerialized, SILDeclRef requirement, SILDeclRef witnessRef,
@@ -695,34 +677,36 @@ SILFunction *SILGenModule::emitProtocolWitness(
695
677
PrettyStackTraceSILFunction trace (" generating protocol witness thunk" , f);
696
678
697
679
// Create the witness.
698
- Type selfInterfaceType;
699
- Type selfType;
700
-
701
- // If the witness is a free function, there is no Self type.
702
- if (!isFree) {
703
- auto *proto = cast<ProtocolDecl>(requirement.getDecl ()->getDeclContext ());
704
- selfInterfaceType = proto->getSelfInterfaceType ().subst (reqtSubMap);
705
- selfType = GenericEnvironment::mapTypeIntoContext (
706
- genericEnv, selfInterfaceType);
707
- }
708
-
709
680
SILGenFunction SGF (*this , *f);
710
681
711
682
// Substitutions mapping the generic parameters of the witness to
712
683
// archetypes of the witness thunk generic environment.
713
684
auto witnessSubs = witness.getSubstitutions ();
714
685
715
- // Open-code certain protocol witness "thunks".
716
- if (maybeOpenCodeProtocolWitness (SGF, conformance, linkage,
717
- selfInterfaceType, selfType, genericEnv,
718
- requirement, witnessRef, witnessSubs)) {
719
- assert (!isFree);
720
- return f;
686
+ // Open-code protocol witness thunks for materializeForSet.
687
+ if (auto witnessFn = dyn_cast<FuncDecl>(witnessRef.getDecl ())) {
688
+ if (witnessFn->getAccessorKind () == AccessorKind::IsMaterializeForSet) {
689
+ assert (!isFree);
690
+
691
+ auto *proto = cast<ProtocolDecl>(requirement.getDecl ()->getDeclContext ());
692
+ auto selfInterfaceType = proto->getSelfInterfaceType ().subst (reqtSubMap);
693
+ auto selfType = GenericEnvironment::mapTypeIntoContext (
694
+ genericEnv, selfInterfaceType);
695
+
696
+ auto reqFn = cast<FuncDecl>(requirement.getDecl ());
697
+ assert (reqFn->getAccessorKind () == AccessorKind::IsMaterializeForSet);
698
+
699
+ if (SGF.maybeEmitMaterializeForSetThunk (conformance, linkage,
700
+ selfInterfaceType, selfType,
701
+ genericEnv, reqFn, witnessFn,
702
+ witnessSubs))
703
+ return f;
704
+
705
+ // Proceed down the normal path.
706
+ }
721
707
}
722
708
723
- SGF.emitProtocolWitness (selfType,
724
- AbstractionPattern (reqtOrigTy),
725
- reqtSubstTy,
709
+ SGF.emitProtocolWitness (AbstractionPattern (reqtOrigTy), reqtSubstTy,
726
710
requirement, witnessRef,
727
711
witnessSubs, isFree);
728
712
0 commit comments