"The compiler" is actually several different libraries whose headers are in the include/swift directory and whose implementations are in the lib directory. Each library is responsible for a different function, such as parsing, semantic analysis, or optimizing SIL. Some parts are more closely related to other tools; for instance, the IDE library is essentially a set of APIs for SourceKit to talk to the compiler.
For your task, the most important type will be
ForEachStmt, the abstract syntax tree node representing a for-in loop. You can search for uses in the repository, but here are a few of the most important landmarks:
Like all AST nodes,
ForEachStmt is declared in the AST library, and specifically in include/swift/AST/Stmt.h.
Type-checking is part of semantic analysis, which is the job of the Sema library; specifically,
ForEachStmt is typechecked in lib/Sema/TypeCheckConstraints.cpp.
AST nodes are lowered into SIL (a sort of pseudo-assembly language which still expresses many Swift behaviors) in the SILGen library. Specifically, the instructions for
ForEachStmt are emitted in lib/SILGen/SILGenStmt.cpp. At this point, the code ceases to be a for-in loop and becomes just a set of instructions which happen to loop until
Although not strictly part of the compiler, the standard library is in the stdlib/public/core directory. Types interface with for-in loops through the
IteratorProtocol protocols, which are in stdlib/public/core/Sequence.swift.
If you do try to tackle this project, your next question will probably be "How do I get started working on Swift?" I recommend watching this talk by @harlanhaskins and @codafi, which explains how to build, navigate, and work on the compiler.