@@ -56,8 +56,8 @@ static bool isSubstitutableFor(Type type, ArchetypeType *archetype,
56
56
return true ;
57
57
}
58
58
59
- UncurriedCandidate::UncurriedCandidate (ValueDecl *decl, unsigned level )
60
- : declOrExpr(decl), level(level ), substituted(false ) {
59
+ UncurriedCandidate::UncurriedCandidate (ValueDecl *decl, bool skipCurriedSelf )
60
+ : declOrExpr(decl), skipCurriedSelf(skipCurriedSelf ), substituted(false ) {
61
61
62
62
if (auto *PD = dyn_cast<ParamDecl>(decl)) {
63
63
if (PD->hasValidSignature ())
@@ -95,15 +95,15 @@ ArrayRef<Identifier> UncurriedCandidate::getArgumentLabels(
95
95
if (auto decl = getDecl ()) {
96
96
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
97
97
if (func->hasImplicitSelfDecl ()) {
98
- if (level == 0 ) {
98
+ if (!skipCurriedSelf ) {
99
99
scratch.push_back (Identifier ());
100
100
return scratch;
101
101
}
102
102
103
- --level ;
103
+ skipCurriedSelf = false ;
104
104
}
105
105
106
- if (level == 0 ) {
106
+ if (!skipCurriedSelf ) {
107
107
// Retrieve the argument labels of the corresponding parameter list.
108
108
for (auto param : *func->getParameters ()) {
109
109
scratch.push_back (param->getArgumentName ());
@@ -112,20 +112,18 @@ ArrayRef<Identifier> UncurriedCandidate::getArgumentLabels(
112
112
}
113
113
} else if (auto enumElt = dyn_cast<EnumElementDecl>(decl)) {
114
114
// 'self'
115
- if (level == 0 ) {
115
+ if (!skipCurriedSelf ) {
116
116
scratch.push_back (Identifier ());
117
117
return scratch;
118
118
}
119
119
120
120
// The associated data of the case.
121
- if (level == 1 ) {
122
- auto *paramList = enumElt->getParameterList ();
123
- if (!paramList) return { };
124
- for (auto param : *paramList) {
125
- scratch.push_back (param->getArgumentName ());
126
- }
127
- return scratch;
121
+ auto *paramList = enumElt->getParameterList ();
122
+ if (!paramList) return { };
123
+ for (auto param : *paramList) {
124
+ scratch.push_back (param->getArgumentName ());
128
125
}
126
+ return scratch;
129
127
}
130
128
}
131
129
@@ -143,7 +141,8 @@ void UncurriedCandidate::dump() const {
143
141
decl->dumpRef (llvm::errs ());
144
142
else
145
143
llvm::errs () << " <<EXPR>>" ;
146
- llvm::errs () << " - uncurry level " << level;
144
+ llvm::errs () << " - ignore curried self = " << (skipCurriedSelf ? " yes"
145
+ : " no" );
147
146
148
147
if (auto FT = getUncurriedFunctionType ())
149
148
llvm::errs () << " - type: " << Type (FT) << " \n " ;
@@ -322,7 +321,7 @@ CalleeCandidateInfo::evaluateCloseness(UncurriedCandidate candidate,
322
321
323
322
auto candArgs = candidate.getParameters ();
324
323
SmallBitVector candDefaultMap =
325
- computeDefaultMap (candArgs, candidate.getDecl (), candidate.level );
324
+ computeDefaultMap (candArgs, candidate.getDecl (), candidate.skipCurriedSelf );
326
325
327
326
struct OurListener : public MatchCallArgumentListener {
328
327
CandidateCloseness result = CC_ExactMatch;
@@ -589,28 +588,27 @@ void CalleeCandidateInfo::collectCalleeCandidates(Expr *fn,
589
588
/* implicitDotSyntax=*/ false );
590
589
}
591
590
592
- // Determine the callee level for a "bare" reference to the given
593
- // declaration.
594
- auto getCalleeLevel = [implicitDotSyntax](ValueDecl *decl) -> unsigned {
591
+ // Determine if we need to skip "self" to get to a "bare" reference.
592
+ auto skipCurriedSelf = [implicitDotSyntax](ValueDecl *decl) -> bool {
595
593
if (auto func = dyn_cast<FuncDecl>(decl)) {
596
594
if (func->isOperator () && func->getDeclContext ()->isTypeContext () &&
597
595
!implicitDotSyntax)
598
- return 1 ;
596
+ return true ;
599
597
}
600
598
601
- return 0 ;
599
+ return false ;
602
600
};
603
601
604
602
if (auto declRefExpr = dyn_cast<DeclRefExpr>(fn)) {
605
603
auto decl = declRefExpr->getDecl ();
606
- candidates.push_back ({ decl, getCalleeLevel (decl) });
604
+ candidates.push_back ({ decl, skipCurriedSelf (decl) });
607
605
declName = decl->getBaseName ().userFacingName ();
608
606
return ;
609
607
}
610
608
611
609
if (auto declRefExpr = dyn_cast<OtherConstructorDeclRefExpr>(fn)) {
612
610
auto decl = declRefExpr->getDecl ();
613
- candidates.push_back ({ decl, getCalleeLevel (decl) });
611
+ candidates.push_back ({ decl, skipCurriedSelf (decl) });
614
612
615
613
if (auto selfTy = decl->getDeclContext ()->getSelfInterfaceType ())
616
614
declName = selfTy.getString () + " .init" ;
@@ -621,7 +619,7 @@ void CalleeCandidateInfo::collectCalleeCandidates(Expr *fn,
621
619
622
620
if (auto overloadedDRE = dyn_cast<OverloadedDeclRefExpr>(fn)) {
623
621
for (auto cand : overloadedDRE->getDecls ()) {
624
- candidates.push_back ({ cand, getCalleeLevel (cand) });
622
+ candidates.push_back ({ cand, skipCurriedSelf (cand) });
625
623
}
626
624
627
625
if (!candidates.empty ())
@@ -671,12 +669,13 @@ void CalleeCandidateInfo::collectCalleeCandidates(Expr *fn,
671
669
baseType = CS.getType (AE->getArg ())->getWithoutSpecifierType ();
672
670
673
671
for (auto &C : candidates) {
674
- C. level += 1 ;
672
+ bool hadCurriedSelf = C. skipCurriedSelf ;
675
673
674
+ C.skipCurriedSelf = true ;
676
675
baseType = replaceTypeVariablesWithUnresolved (baseType);
677
676
678
677
// Compute a new substituted type if we have a base type to apply.
679
- if (baseType && C. level == 1 && C.getDecl ()) {
678
+ if (baseType && !hadCurriedSelf && C.getDecl ()) {
680
679
baseType = baseType
681
680
->getWithoutSpecifierType ()
682
681
->getMetatypeInstanceType ();
@@ -691,7 +690,7 @@ void CalleeCandidateInfo::collectCalleeCandidates(Expr *fn,
691
690
}
692
691
}
693
692
}
694
-
693
+
695
694
return ;
696
695
}
697
696
}
@@ -709,36 +708,35 @@ void CalleeCandidateInfo::collectCalleeCandidates(Expr *fn,
709
708
710
709
// Otherwise, we couldn't tell structurally what is going on here, so try to
711
710
// dig something out of the constraint system.
712
- unsigned uncurryLevel = 0 ;
711
+ bool hasCurriedSelf = false ;
713
712
714
713
// The candidate list of an unresolved_dot_expr is the candidate list of the
715
714
// base uncurried by one level, and we refer to the name of the member, not to
716
715
// the name of any base.
717
716
if (auto UDE = dyn_cast<UnresolvedDotExpr>(fn)) {
718
717
declName = UDE->getName ().getBaseName ().userFacingName ();
719
- uncurryLevel = 1 ;
718
+ hasCurriedSelf = true ;
720
719
721
720
// If base is a module or metatype, this is just a simple
722
721
// reference so its curry level should be 0.
723
722
if (auto *DRE = dyn_cast<DeclRefExpr>(UDE->getBase ())) {
724
723
if (auto baseType = DRE->getType ())
725
- uncurryLevel =
726
- (baseType->is <ModuleType>() || baseType->is <AnyMetatypeType>()) ? 0
727
- : 1 ;
724
+ hasCurriedSelf = !(baseType->is <ModuleType>() ||
725
+ baseType->is <AnyMetatypeType>());
728
726
}
729
727
730
728
// If we actually resolved the member to use, return it.
731
729
auto loc = CS.getConstraintLocator (UDE, ConstraintLocator::Member);
732
730
if (auto *member = CS.findResolvedMemberRef (loc)) {
733
- candidates.push_back ({ member, uncurryLevel });
731
+ candidates.push_back ({ member, hasCurriedSelf });
734
732
return ;
735
733
}
736
734
737
735
// If we resolved the constructor member, return it.
738
736
auto ctorLoc =
739
737
CS.getConstraintLocator (UDE, ConstraintLocator::ConstructorMember);
740
738
if (auto *member = CS.findResolvedMemberRef (ctorLoc)) {
741
- candidates.push_back ({ member, uncurryLevel });
739
+ candidates.push_back ({ member, hasCurriedSelf });
742
740
return ;
743
741
}
744
742
@@ -754,7 +752,7 @@ void CalleeCandidateInfo::collectCalleeCandidates(Expr *fn,
754
752
}
755
753
756
754
if (isa<MemberRefExpr>(fn))
757
- uncurryLevel = 1 ;
755
+ hasCurriedSelf = true ;
758
756
759
757
// Scan to see if we have a disjunction constraint for this callee.
760
758
for (auto &constraint : CS.getConstraints ()) {
@@ -768,7 +766,7 @@ void CalleeCandidateInfo::collectCalleeCandidates(Expr *fn,
768
766
continue ;
769
767
auto c = bindOverload->getOverloadChoice ();
770
768
if (c.isDecl ())
771
- candidates.push_back ({ c.getDecl (), uncurryLevel });
769
+ candidates.push_back ({ c.getDecl (), hasCurriedSelf });
772
770
}
773
771
774
772
// If we found some candidates, then we're done.
@@ -865,13 +863,13 @@ CalleeCandidateInfo::CalleeCandidateInfo(Type baseType,
865
863
auto decl = cand.getDecl ();
866
864
867
865
// If this is a method or enum case member (not a var or subscript), then
868
- // the uncurry level is 1 if self has already been applied.
869
- unsigned uncurryLevel = 0 ;
866
+ // we need to skip `self` if it has already been applied.
867
+ bool hasCurriedSelf = false ;
870
868
if (decl->getDeclContext ()->isTypeContext () &&
871
869
selfAlreadyApplied && !isa<SubscriptDecl>(decl))
872
- uncurryLevel = 1 ;
870
+ hasCurriedSelf = true ;
873
871
874
- candidates.push_back ({ decl, uncurryLevel });
872
+ candidates.push_back ({ decl, hasCurriedSelf });
875
873
876
874
// If we have a base type for this member, try to perform substitutions into
877
875
// it to get a simpler and more concrete type.
0 commit comments