File tree Expand file tree Collapse file tree 4 files changed +13
-25
lines changed Expand file tree Collapse file tree 4 files changed +13
-25
lines changed Original file line number Diff line number Diff line change @@ -808,7 +808,6 @@ class ForEachStmt : public LabeledStmt {
808
808
809
809
// Set by Sema:
810
810
ProtocolConformanceRef sequenceConformance = ProtocolConformanceRef();
811
- ConcreteDeclRef makeIterator;
812
811
ConcreteDeclRef iteratorNext;
813
812
VarDecl *iteratorVar = nullptr ;
814
813
Expr *iteratorVarRef = nullptr ;
@@ -838,9 +837,6 @@ class ForEachStmt : public LabeledStmt {
838
837
void setConvertElementExpr (Expr *expr) { convertElementExpr = expr; }
839
838
Expr *getConvertElementExpr () const { return convertElementExpr; }
840
839
841
- void setMakeIterator (ConcreteDeclRef declRef) { makeIterator = declRef; }
842
- ConcreteDeclRef getMakeIterator () const { return makeIterator; }
843
-
844
840
void setIteratorNext (ConcreteDeclRef declRef) { iteratorNext = declRef; }
845
841
ConcreteDeclRef getIteratorNext () const { return iteratorNext; }
846
842
Original file line number Diff line number Diff line change @@ -1593,9 +1593,6 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
1593
1593
}
1594
1594
void visitForEachStmt (ForEachStmt *S) {
1595
1595
printCommon (S, " for_each_stmt" );
1596
- PrintWithColorRAII (OS, LiteralValueColor) << " make_generator=" ;
1597
- S->getMakeIterator ().dump (
1598
- PrintWithColorRAII (OS, LiteralValueColor).getOS ());
1599
1596
PrintWithColorRAII (OS, LiteralValueColor) << " next=" ;
1600
1597
S->getIteratorNext ().dump (
1601
1598
PrintWithColorRAII (OS, LiteralValueColor).getOS ());
Original file line number Diff line number Diff line change @@ -909,8 +909,20 @@ void StmtEmitter::visitForEachStmt(ForEachStmt *S) {
909
909
auto initialization =
910
910
SGF.emitInitializationForVarDecl (S->getIteratorVar (), false );
911
911
SILLocation loc = SILLocation (S->getSequence ());
912
+
913
+ // Compute the reference to the Sequence's makeIterator().
914
+ FuncDecl *makeIteratorReq = SGF.getASTContext ().getSequenceMakeIterator ();
915
+ auto sequenceProto =
916
+ SGF.getASTContext ().getProtocol (KnownProtocolKind::Sequence);
917
+ auto sequenceConformance = S->getSequenceConformance ();
918
+ Type sequenceType = S->getSequence ()->getType ();
919
+ auto sequenceSubs = SubstitutionMap::getProtocolSubstitutions (
920
+ sequenceProto, sequenceType, sequenceConformance);
921
+ ConcreteDeclRef makeIteratorRef (makeIteratorReq, sequenceSubs);
922
+
923
+ // Call makeIterator().
912
924
RValue result = SGF.emitApplyMethod (
913
- loc, S-> getMakeIterator () , ArgumentSource (S->getSequence ()),
925
+ loc, makeIteratorRef , ArgumentSource (S->getSequence ()),
914
926
PreparedArguments (ArrayRef<AnyFunctionType::Param>({})),
915
927
SGFContext (initialization.get ()));
916
928
if (!result.isInContext ()) {
Original file line number Diff line number Diff line change @@ -3013,17 +3013,8 @@ auto TypeChecker::typeCheckForEachBinding(
3013
3013
3014
3014
// Perform any necessary conversions of the sequence (e.g. [T]! -> [T]).
3015
3015
expr = solution.coerceToType (expr, SequenceType, Locator);
3016
-
3017
3016
if (!expr) return nullptr ;
3018
3017
3019
- // Convert the sequence as appropriate for the makeIterator() call.
3020
- auto makeIteratorOverload = solution.getOverloadChoice (ContextualLocator);
3021
- auto makeIteratorSelfType = solution.simplifyType (
3022
- makeIteratorOverload.openedFullType
3023
- )->castTo <AnyFunctionType>()->getParams ()[0 ].getPlainType ();
3024
- expr = solution.coerceToType (expr, makeIteratorSelfType,
3025
- ContextualLocator);
3026
-
3027
3018
cs.cacheExprTypes (expr);
3028
3019
Stmt->setSequence (expr);
3029
3020
@@ -3054,14 +3045,6 @@ auto TypeChecker::typeCheckForEachBinding(
3054
3045
ConformanceCheckFlags::InExpression,
3055
3046
expr->getLoc ());
3056
3047
3057
- // Record the makeIterator declaration we used.
3058
- auto makeIteratorDecl = makeIteratorOverload.choice .getDecl ();
3059
- auto makeIteratorSubs = SequenceType->getMemberSubstitutionMap (
3060
- cs.DC ->getParentModule (), makeIteratorDecl);
3061
- auto makeIteratorDeclRef =
3062
- ConcreteDeclRef (makeIteratorDecl, makeIteratorSubs);
3063
- Stmt->setMakeIterator (makeIteratorDeclRef);
3064
-
3065
3048
solution.setExprTypes (expr);
3066
3049
return expr;
3067
3050
}
You can’t perform that action at this time.
0 commit comments