Skip to content

Commit

Permalink
Merge pull request #964 from hylo-lang/avoid-foreach
Browse files Browse the repository at this point in the history
Avoid needless use of 'Sequence.forEach' (#930)
  • Loading branch information
kyouko-taiga authored Sep 7, 2023
2 parents f73cfec + 9318ee0 commit 55a6769
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Sources/Core/AST/AST+Walk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Utils
/// }
/// }
/// var v = V()
/// ast.modules.forEach({ ast.walk($0, notifying: &v) })
/// for m in ast.modules { ast.walk(m, notifying: &v) }
/// print(v.outermostFunctions)
///
/// This program prints the IDs of the outermost function declarations in `ast`.
Expand Down Expand Up @@ -222,7 +222,7 @@ extension AST {
/// Visits all nodes in `roots` and their children in pre-order, notifying `o` when a node is
/// entered or left.
public func walk<T: NodeIDProtocol, O: ASTWalkObserver>(roots: [T], notifying o: inout O) {
roots.forEach({ walk(AnyNodeID($0), notifying: &o) })
for r in roots { walk(AnyNodeID(r), notifying: &o) }
}

/// Visits all condition items in `i` and their children in pre-order, notifying `o` when a node
Expand Down Expand Up @@ -806,7 +806,7 @@ extension AST {

/// Visits the children of `c` in pre-order, notifying `o` when a node is entered or left.
public func traverse<O: ASTWalkObserver>(whereClause c: WhereClause, notifying o: inout O) {
c.constraints.forEach({ traverse(constraintExpr: $0.value, notifying: &o) })
for k in c.constraints { traverse(constraintExpr: k.value, notifying: &o) }
}

/// Visits the children of `c` in pre-order, notifying `o` when a node is entered or left.
Expand All @@ -816,7 +816,7 @@ extension AST {
switch c {
case .conformance(let lhs, let traits):
walk(lhs, notifying: &o)
traits.forEach({ walk($0, notifying: &o) })
for t in traits { walk(t, notifying: &o) }
case .equality(let lhs, let rhs):
walk(lhs, notifying: &o)
walk(rhs, notifying: &o)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/Types/LambdaType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct LambdaType: TypeProtocol {
self.output = output

var fs = environment.flags
inputs.forEach({ fs.merge($0.type.flags) })
for i in inputs { fs.merge(i.type.flags) }
fs.merge(output.flags)
flags = fs
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/Types/MethodType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct MethodType: TypeProtocol {
self.output = output

var fs = receiver.flags
inputs.forEach({ fs.merge($0.type.flags) })
for i in inputs { fs.merge(i.type.flags) }
fs.merge(output.flags)
flags = fs
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/Types/SubscriptImplType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public struct SubscriptImplType: TypeProtocol {
self.output = output

var fs = environment.flags
inputs.forEach({ fs.merge($0.type.flags) })
for i in inputs { fs.merge(i.type.flags) }
fs.merge(output.flags)
flags = fs
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/Types/SubscriptType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public struct SubscriptType: TypeProtocol {
self.output = output

var fs = environment.flags
inputs.forEach({ fs.merge($0.type.flags) })
for i in inputs { fs.merge(i.type.flags) }
fs.merge(output.flags)
flags = fs
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/FrontEnd/TypeChecking/TypeChecker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ struct TypeChecker {

/// Type checks the sources in `batch`.
mutating func check<S: Sequence<TranslationUnit.ID>>(_ batch: S) {
batch.forEach({ check($0) })
for u in batch { check(u) }
}

/// Type checks `u` and all declarations nested in `d`.
Expand All @@ -386,7 +386,7 @@ struct TypeChecker {
private mutating func check<S: Sequence<T>, T: DeclID>(
_ batch: S, ignoringSharedCache ignoreSharedCache: Bool = false
) {
batch.forEach({ check($0, ignoringSharedCache: ignoreSharedCache) })
for d in batch { check(d, ignoringSharedCache: ignoreSharedCache) }
}

/// Type checks `d` and all declarations nested in `d`.
Expand Down Expand Up @@ -565,7 +565,7 @@ struct TypeChecker {

/// Type checks `d` and all declarations nested in `d`.
private mutating func _check(_ d: ModuleDecl.ID) {
program[d].sources.forEach({ check($0) })
check(program[d].sources)
}

/// Type checks `d` and all declarations nested in `d`.
Expand Down Expand Up @@ -785,7 +785,7 @@ struct TypeChecker {

/// Type checks `s`.
private mutating func check(_ s: BraceStmt.ID) {
program[s].stmts.forEach({ check($0) })
for t in program[s].stmts { check(t) }
}

/// Type checks `s`.
Expand Down Expand Up @@ -1097,7 +1097,7 @@ struct TypeChecker {

/// Appends each variant of `c` to `candidates` that is has type `t`.
func appendDefinitions(of d: MethodDecl.ID, matching t: AnyType, in s: inout [AnyDeclID]) {
program[d].impls.forEach({ appendIfDefinition($0, matching: t, in: &s) })
for v in program[d].impls { appendIfDefinition(v, matching: t, in: &s) }
}

/// Appends `d` to `s` iff it's a a definition with type `t`.
Expand Down

0 comments on commit 55a6769

Please sign in to comment.