Check and lowering support for for loops. (#5698)

Add check support for `for` loops following #1885. This also adds a
basic `Optional` type to the prelude, as that's necessary to support the
new `Iterate` interface.

Depends on #5688, #5697. Those PRs aren't stacked here, but this change
will crash until they land.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
Richard Smith
2025-06-25 23:45:14 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent a556cf41fc
commit 866794b82a
24 changed files with 1640 additions and 77 deletions
+4 -4
View File
@@ -419,10 +419,10 @@ class NodeStack {
case Parse::NodeKind::WhereOperand:
return Id::KindFor<SemIR::InstId>();
case Parse::NodeKind::ExplicitParamList:
case Parse::NodeKind::ForIn:
case Parse::NodeKind::IfCondition:
case Parse::NodeKind::IfExprIf:
case Parse::NodeKind::ImplicitParamList:
case Parse::NodeKind::WhileCondition:
case Parse::NodeKind::WhileConditionStart:
return Id::KindFor<SemIR::InstBlockId>();
case Parse::NodeKind::FunctionDefinitionStart:
@@ -449,6 +449,7 @@ class NodeStack {
case Parse::NodeKind::ExplicitParamListStart:
case Parse::NodeKind::FieldInitializer:
case Parse::NodeKind::FieldIntroducer:
case Parse::NodeKind::ForHeaderStart:
case Parse::NodeKind::FunctionIntroducer:
case Parse::NodeKind::IfStatementElse:
case Parse::NodeKind::ImplicitParamListStart:
@@ -483,10 +484,8 @@ class NodeStack {
case Parse::NodeKind::ExportIntroducer:
case Parse::NodeKind::FileEnd:
case Parse::NodeKind::FileStart:
case Parse::NodeKind::Forall:
case Parse::NodeKind::ForHeader:
case Parse::NodeKind::ForHeaderStart:
case Parse::NodeKind::ForIn:
case Parse::NodeKind::Forall:
case Parse::NodeKind::IdentifierNameQualifierWithParams:
case Parse::NodeKind::IdentifierNameQualifierWithoutParams:
case Parse::NodeKind::IdentifierPackageName:
@@ -528,6 +527,7 @@ class NodeStack {
case Parse::NodeKind::StructFieldDesignator:
case Parse::NodeKind::StructTypeLiteralComma:
case Parse::NodeKind::TupleLiteralComma:
case Parse::NodeKind::WhileCondition:
return Id::Kind::Invalid;
default:
// In this case, the kind must be determinable from the category, or we