Skip to content

Commit c09c9a1

Browse files
authored
Merge pull request #2769 from DougGregor/ifconfig-versioned-to-syntaxerrorsallowed
[SwiftIfConfig] Rename "versioned" to "syntaxErrorsAllowed" throughout
2 parents 829e487 + 831261b commit c09c9a1

5 files changed

+50
-49
lines changed

Sources/SwiftIfConfig/ConfiguredRegions.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,19 @@ fileprivate class ConfiguredRegionVisitor<Configuration: BuildConfiguration>: Sy
7878
}
7979

8080
// For inactive clauses, distinguish between inactive and unparsed.
81-
let isVersioned = clause.isVersioned(
81+
let syntaxErrorsAllowed = clause.syntaxErrorsAllowed(
8282
configuration: configuration
83-
).versioned
83+
).syntaxErrorsAllowed
8484

8585
// If this is within an active region, or this is an unparsed region,
8686
// record it.
87-
if inActiveRegion || isVersioned {
88-
regions.append((clause, isVersioned ? .unparsed : .inactive))
87+
if inActiveRegion || syntaxErrorsAllowed {
88+
regions.append((clause, syntaxErrorsAllowed ? .unparsed : .inactive))
8989
}
9090

9191
// Recurse into inactive (but not unparsed) regions to find any
9292
// unparsed regions below.
93-
if !isVersioned, let elements = clause.elements {
93+
if !syntaxErrorsAllowed, let elements = clause.elements {
9494
let priorInActiveRegion = inActiveRegion
9595
inActiveRegion = false
9696
defer {

Sources/SwiftIfConfig/IfConfigEvaluation.swift

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ import SwiftSyntax
2525
/// - Returns: A pair of Boolean values and any diagnostics produced during the
2626
/// evaluation. The first Boolean describes whether the condition holds with
2727
/// the given build configuration. The second Boolean described whether
28-
/// the build condition is a "versioned" check that implies that we shouldn't
28+
/// the build condition's failure implies that we shouldn't
2929
/// diagnose syntax errors in blocks where the check fails.
3030
func evaluateIfConfig(
3131
condition: ExprSyntax,
3232
configuration: some BuildConfiguration
33-
) -> (active: Bool, versioned: Bool, diagnostics: [Diagnostic]) {
33+
) -> (active: Bool, syntaxErrorsAllowed: Bool, diagnostics: [Diagnostic]) {
3434
var extraDiagnostics: [Diagnostic] = []
3535

3636
/// Record the error before returning the given value.
3737
func recordError(
3838
_ error: any Error,
3939
at node: some SyntaxProtocol
40-
) -> (active: Bool, versioned: Bool, diagnostics: [Diagnostic]) {
40+
) -> (active: Bool, syntaxErrorsAllowed: Bool, diagnostics: [Diagnostic]) {
4141
return (
4242
active: false,
43-
versioned: true,
43+
syntaxErrorsAllowed: true,
4444
diagnostics: extraDiagnostics + error.asDiagnostics(at: node)
4545
)
4646
}
@@ -49,7 +49,7 @@ func evaluateIfConfig(
4949
/// every 'throw' site in this evaluation.
5050
func recordError(
5151
_ error: IfConfigError
52-
) -> (active: Bool, versioned: Bool, diagnostics: [Diagnostic]) {
52+
) -> (active: Bool, syntaxErrorsAllowed: Bool, diagnostics: [Diagnostic]) {
5353
return recordError(error, at: error.syntax)
5454
}
5555

@@ -58,10 +58,10 @@ func evaluateIfConfig(
5858
func checkConfiguration(
5959
at node: some SyntaxProtocol,
6060
body: () throws -> (Bool, Bool)
61-
) -> (active: Bool, versioned: Bool, diagnostics: [Diagnostic]) {
61+
) -> (active: Bool, syntaxErrorsAllowed: Bool, diagnostics: [Diagnostic]) {
6262
do {
63-
let (active, versioned) = try body()
64-
return (active, versioned, extraDiagnostics)
63+
let (active, syntaxErrorsAllowed) = try body()
64+
return (active, syntaxErrorsAllowed, extraDiagnostics)
6565
} catch let error {
6666
return recordError(error, at: node)
6767
}
@@ -71,7 +71,7 @@ func evaluateIfConfig(
7171
if let boolLiteral = condition.as(BooleanLiteralExprSyntax.self) {
7272
return (
7373
active: boolLiteral.literalValue,
74-
versioned: false,
74+
syntaxErrorsAllowed: false,
7575
diagnostics: extraDiagnostics
7676
)
7777
}
@@ -84,7 +84,7 @@ func evaluateIfConfig(
8484

8585
return (
8686
active: result,
87-
versioned: false,
87+
syntaxErrorsAllowed: false,
8888
diagnostics: [
8989
IfConfigError.integerLiteralCondition(
9090
syntax: condition,
@@ -101,20 +101,20 @@ func evaluateIfConfig(
101101

102102
// Evaluate the custom condition. If the build configuration cannot answer this query, fail.
103103
return checkConfiguration(at: identExpr) {
104-
(active: try configuration.isCustomConditionSet(name: ident), versioned: false)
104+
(active: try configuration.isCustomConditionSet(name: ident), syntaxErrorsAllowed: false)
105105
}
106106
}
107107

108108
// Logical '!'.
109109
if let prefixOp = condition.as(PrefixOperatorExprSyntax.self),
110110
prefixOp.operator.text == "!"
111111
{
112-
let (innerActive, innerVersioned, innerDiagnostics) = evaluateIfConfig(
112+
let (innerActive, innersyntaxErrorsAllowed, innerDiagnostics) = evaluateIfConfig(
113113
condition: prefixOp.expression,
114114
configuration: configuration
115115
)
116116

117-
return (active: !innerActive, versioned: innerVersioned, diagnostics: innerDiagnostics)
117+
return (active: !innerActive, syntaxErrorsAllowed: innersyntaxErrorsAllowed, diagnostics: innerDiagnostics)
118118
}
119119

120120
// Logical '&&' and '||'.
@@ -123,26 +123,26 @@ func evaluateIfConfig(
123123
(op.operator.text == "&&" || op.operator.text == "||")
124124
{
125125
// Evaluate the left-hand side.
126-
let (lhsActive, lhsVersioned, lhsDiagnostics) = evaluateIfConfig(
126+
let (lhsActive, lhssyntaxErrorsAllowed, lhsDiagnostics) = evaluateIfConfig(
127127
condition: binOp.leftOperand,
128128
configuration: configuration
129129
)
130130

131131
// Short-circuit evaluation if we know the answer and the left-hand side
132-
// was versioned.
133-
if lhsVersioned {
132+
// was syntaxErrorsAllowed.
133+
if lhssyntaxErrorsAllowed {
134134
switch (lhsActive, op.operator.text) {
135135
case (true, "||"):
136-
return (active: true, versioned: lhsVersioned, diagnostics: lhsDiagnostics)
136+
return (active: true, syntaxErrorsAllowed: lhssyntaxErrorsAllowed, diagnostics: lhsDiagnostics)
137137
case (false, "&&"):
138-
return (active: false, versioned: lhsVersioned, diagnostics: lhsDiagnostics)
138+
return (active: false, syntaxErrorsAllowed: lhssyntaxErrorsAllowed, diagnostics: lhsDiagnostics)
139139
default:
140140
break
141141
}
142142
}
143143

144144
// Evaluate the right-hand side.
145-
let (rhsActive, rhsVersioned, rhsDiagnostics) = evaluateIfConfig(
145+
let (rhsActive, rhssyntaxErrorsAllowed, rhsDiagnostics) = evaluateIfConfig(
146146
condition: binOp.rightOperand,
147147
configuration: configuration
148148
)
@@ -151,14 +151,14 @@ func evaluateIfConfig(
151151
case "||":
152152
return (
153153
active: lhsActive || rhsActive,
154-
versioned: lhsVersioned && rhsVersioned,
154+
syntaxErrorsAllowed: lhssyntaxErrorsAllowed && rhssyntaxErrorsAllowed,
155155
diagnostics: lhsDiagnostics + rhsDiagnostics
156156
)
157157

158158
case "&&":
159159
return (
160160
active: lhsActive && rhsActive,
161-
versioned: lhsVersioned || rhsVersioned,
161+
syntaxErrorsAllowed: lhssyntaxErrorsAllowed || rhssyntaxErrorsAllowed,
162162
diagnostics: lhsDiagnostics + rhsDiagnostics
163163
)
164164

@@ -186,7 +186,7 @@ func evaluateIfConfig(
186186
func doSingleIdentifierArgumentCheck(
187187
_ body: (String) throws -> Bool,
188188
role: String
189-
) -> (active: Bool, versioned: Bool, diagnostics: [Diagnostic]) {
189+
) -> (active: Bool, syntaxErrorsAllowed: Bool, diagnostics: [Diagnostic]) {
190190
// Ensure that we have a single argument that is a simple identifier.
191191
guard let argExpr = call.arguments.singleUnlabeledExpression,
192192
let arg = argExpr.simpleIdentifierExpr
@@ -197,14 +197,14 @@ func evaluateIfConfig(
197197
}
198198

199199
return checkConfiguration(at: argExpr) {
200-
(active: try body(arg), versioned: fn.isVersioned)
200+
(active: try body(arg), syntaxErrorsAllowed: fn.syntaxErrorsAllowed)
201201
}
202202
}
203203

204204
/// Perform a check for a version constraint as used in the "swift" or "compiler" version checks.
205205
func doVersionComparisonCheck(
206206
_ actualVersion: VersionTuple
207-
) -> (active: Bool, versioned: Bool, diagnostics: [Diagnostic]) {
207+
) -> (active: Bool, syntaxErrorsAllowed: Bool, diagnostics: [Diagnostic]) {
208208
// Ensure that we have a single unlabeled argument that is either >= or < as a prefix
209209
// operator applied to a version.
210210
guard let argExpr = call.arguments.singleUnlabeledExpression,
@@ -229,13 +229,13 @@ func evaluateIfConfig(
229229
case ">=":
230230
return (
231231
active: actualVersion >= version,
232-
versioned: fn.isVersioned,
232+
syntaxErrorsAllowed: fn.syntaxErrorsAllowed,
233233
diagnostics: extraDiagnostics
234234
)
235235
case "<":
236236
return (
237237
active: actualVersion < version,
238-
versioned: fn.isVersioned,
238+
syntaxErrorsAllowed: fn.syntaxErrorsAllowed,
239239
diagnostics: extraDiagnostics
240240
)
241241
default:
@@ -286,7 +286,7 @@ func evaluateIfConfig(
286286

287287
return (
288288
active: configuration.endianness == expectedEndianness,
289-
versioned: fn.isVersioned,
289+
syntaxErrorsAllowed: fn.syntaxErrorsAllowed,
290290
diagnostics: extraDiagnostics
291291
)
292292

@@ -317,7 +317,7 @@ func evaluateIfConfig(
317317
fatalError("extraneous case above not handled")
318318
}
319319

320-
return (active: active, versioned: fn.isVersioned, diagnostics: extraDiagnostics)
320+
return (active: active, syntaxErrorsAllowed: fn.syntaxErrorsAllowed, diagnostics: extraDiagnostics)
321321

322322
case .swift:
323323
return doVersionComparisonCheck(configuration.languageVersion)
@@ -353,7 +353,7 @@ func evaluateIfConfig(
353353

354354
return (
355355
active: configuration.compilerVersion >= expectedVersion,
356-
versioned: fn.isVersioned,
356+
syntaxErrorsAllowed: fn.syntaxErrorsAllowed,
357357
diagnostics: extraDiagnostics
358358
)
359359

@@ -429,7 +429,7 @@ func evaluateIfConfig(
429429
importPath: importPath.map { String($0) },
430430
version: version
431431
),
432-
versioned: fn.isVersioned
432+
syntaxErrorsAllowed: fn.syntaxErrorsAllowed
433433
)
434434
}
435435
}
@@ -439,20 +439,20 @@ func evaluateIfConfig(
439439
}
440440

441441
extension IfConfigClauseSyntax {
442-
/// Determine whether this condition is "versioned".
443-
func isVersioned(
442+
/// Determine whether this condition is "syntaxErrorsAllowed".
443+
func syntaxErrorsAllowed(
444444
configuration: some BuildConfiguration
445-
) -> (versioned: Bool, diagnostics: [Diagnostic]) {
445+
) -> (syntaxErrorsAllowed: Bool, diagnostics: [Diagnostic]) {
446446
guard let condition else {
447-
return (versioned: false, diagnostics: [])
447+
return (syntaxErrorsAllowed: false, diagnostics: [])
448448
}
449449

450450
// Evaluate this condition against the build configuration.
451-
let (_, versioned, diagnostics) = evaluateIfConfig(
451+
let (_, syntaxErrorsAllowed, diagnostics) = evaluateIfConfig(
452452
condition: condition,
453453
configuration: configuration
454454
)
455455

456-
return (versioned, diagnostics)
456+
return (syntaxErrorsAllowed, diagnostics)
457457
}
458458
}

Sources/SwiftIfConfig/IfConfigFunctions.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ enum IfConfigFunctions: String {
5757
/// via `_ptrauth(<name>)`.
5858
case _ptrauth
5959

60-
/// Whether uses of this function consistute a "versioned" check. Such checks
61-
/// suppress parser diagnostics if the block failed.
62-
var isVersioned: Bool {
60+
/// Whether uses of this function consitutes a check that guards new syntax.
61+
/// When such a check fails, the compiler should not diagnose syntax errors
62+
/// within the covered block.
63+
var syntaxErrorsAllowed: Bool {
6364
switch self {
6465
case .swift, .compiler, ._compiler_version:
6566
return true

Sources/SwiftIfConfig/IfConfigRegionState.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public enum IfConfigRegionState {
3737
foldingDiagnostics.append(contentsOf: error.asDiagnostics(at: condition))
3838
}.cast(ExprSyntax.self)
3939

40-
let (active, versioned, evalDiagnostics) = evaluateIfConfig(
40+
let (active, syntaxErrorsAllowed, evalDiagnostics) = evaluateIfConfig(
4141
condition: foldedCondition,
4242
configuration: configuration
4343
)
4444

4545
let diagnostics = foldingDiagnostics + evalDiagnostics
46-
switch (active, versioned) {
46+
switch (active, syntaxErrorsAllowed) {
4747
case (true, _): return (.active, diagnostics)
4848
case (false, false): return (.inactive, diagnostics)
4949
case (false, true): return (.unparsed, diagnostics)

Sources/SwiftIfConfig/SyntaxProtocol+IfConfig.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ extension SyntaxProtocol {
4949

5050
if activeClause != ifConfigClause {
5151
// This was not the active clause, so we know that we're in an
52-
// inactive block. However, if the condition is versioned, this is an
52+
// inactive block. If syntax errors aren't allowable, this is an
5353
// unparsed region.
54-
let (isVersioned, localDiagnostics) = ifConfigClause.isVersioned(
54+
let (syntaxErrorsAllowed, localDiagnostics) = ifConfigClause.syntaxErrorsAllowed(
5555
configuration: configuration
5656
)
5757
diagnostics.append(contentsOf: localDiagnostics)
5858

59-
if isVersioned {
59+
if syntaxErrorsAllowed {
6060
return (.unparsed, diagnostics)
6161
}
6262

0 commit comments

Comments
 (0)