Skip to content

Commit 9f421e5

Browse files
committed
Improve comments for the short-circuit evaluation of #ifs
1 parent 4f0f172 commit 9f421e5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Sources/SwiftIfConfig/IfConfigEvaluation.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ func evaluateIfConfig(
146146
outermostCondition: false
147147
)
148148

149-
// Short-circuit evaluation if we know the answer. We still recurse into
150-
// the right-hand side, but with a dummy configuration that won't have
151-
// side effects, so we only get validation-related errors.
149+
// Determine whether we already know the result. We might short-circuit the
150+
// evaluation, depending on whether we need to produce validation
151+
// diagnostics for the right-hand side.
152152
let shortCircuitResult: Bool?
153153
switch (lhsActive, op.operator.text) {
154154
case (true, "||"): shortCircuitResult = true
@@ -157,8 +157,8 @@ func evaluateIfConfig(
157157
}
158158

159159
// If we are supposed to short-circuit and the left-hand side of this
160-
// operator with inactive &&, stop now: we shouldn't evaluate the right-
161-
// hand side at all.
160+
// operator permits syntax errors when it fails, stop now: we shouldn't
161+
// process the right-hand side at all.
162162
if let isActive = shortCircuitResult, lhsSyntaxErrorsAllowed {
163163
return (
164164
active: isActive,
@@ -167,7 +167,9 @@ func evaluateIfConfig(
167167
)
168168
}
169169

170-
// Evaluate the right-hand side.
170+
// Process the right-hand side. If we already know the answer, then
171+
// avoid performing any build configuration queries that might cause
172+
// side effects.
171173
let rhsActive: Bool
172174
let rhsSyntaxErrorsAllowed: Bool
173175
let rhsDiagnostics: [Diagnostic]

0 commit comments

Comments
 (0)