Skip to content

Commit ee17ef1

Browse files
authored
Merge pull request #76040 from DougGregor/revert-if-config-in-parser-diag
Revert "Use SwiftIfConfig to determine where to emit new parser diagnostics
2 parents 8139450 + fc5ba4c commit ee17ef1

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

include/swift/Bridging/ASTGen.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ int swift_ASTGen_roundTripCheck(void *_Nonnull sourceFile);
4848
/// Emit parser diagnostics for given source file.. Returns non-zero if any
4949
/// diagnostics were emitted.
5050
int swift_ASTGen_emitParserDiagnostics(
51-
BridgedASTContext astContext,
5251
void *_Nonnull diagEngine, void *_Nonnull sourceFile, int emitOnlyErrors,
5352
int downgradePlaceholderErrorsToWarnings);
5453

lib/ASTGen/Sources/ASTGen/SourceFile.swift

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import ASTBridging
1414
import SwiftDiagnostics
15-
import SwiftIfConfig
1615
@_spi(ExperimentalLanguageFeatures) import SwiftParser
1716
import SwiftParserDiagnostics
1817
import SwiftSyntax
@@ -143,10 +142,20 @@ public func roundTripCheck(
143142
}
144143
}
145144

145+
extension Syntax {
146+
/// Whether this syntax node is or is enclosed within a #if.
147+
fileprivate var isInIfConfig: Bool {
148+
if self.is(IfConfigDeclSyntax.self) {
149+
return true
150+
}
151+
152+
return parent?.isInIfConfig ?? false
153+
}
154+
}
155+
146156
/// Emit diagnostics within the given source file.
147157
@_cdecl("swift_ASTGen_emitParserDiagnostics")
148158
public func emitParserDiagnostics(
149-
ctx: BridgedASTContext,
150159
diagEnginePtr: UnsafeMutableRawPointer,
151160
sourceFilePtr: UnsafeMutablePointer<UInt8>,
152161
emitOnlyErrors: CInt,
@@ -163,18 +172,11 @@ public func emitParserDiagnostics(
163172
)
164173

165174
let diagnosticEngine = BridgedDiagnosticEngine(raw: diagEnginePtr)
166-
let buildConfiguration = CompilerBuildConfiguration(
167-
ctx: ctx,
168-
conditionLoc:
169-
BridgedSourceLoc(
170-
at: AbsolutePosition(utf8Offset: 0),
171-
in: sourceFile.pointee.buffer
172-
)
173-
)
174-
175175
for diag in diags {
176-
// If the diagnostic is in an unparsed #if region, don't emit it.
177-
if diag.node.isActive(in: buildConfiguration).state == .unparsed {
176+
// Skip over diagnostics within #if, because we don't know whether
177+
// we are in an active region or not.
178+
// FIXME: This heuristic could be improved.
179+
if diag.node.isInIfConfig {
178180
continue
179181
}
180182

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &items) {
267267
if (parsingOpts.contains(ParsingFlags::ValidateNewParserDiagnostics) &&
268268
!Context.Diags.hadAnyError()) {
269269
auto hadSyntaxError = swift_ASTGen_emitParserDiagnostics(
270-
Context, &Context.Diags, exportedSourceFile,
270+
&Context.Diags, exportedSourceFile,
271271
/*emitOnlyErrors=*/true,
272272
/*downgradePlaceholderErrorsToWarnings=*/
273273
Context.LangOpts.Playground ||
@@ -346,7 +346,7 @@ void Parser::parseSourceFileViaASTGen(
346346
// If we're supposed to emit diagnostics from the parser, do so now.
347347
if (!suppressDiagnostics) {
348348
auto hadSyntaxError = swift_ASTGen_emitParserDiagnostics(
349-
Context, &Context.Diags, exportedSourceFile, /*emitOnlyErrors=*/false,
349+
&Context.Diags, exportedSourceFile, /*emitOnlyErrors=*/false,
350350
/*downgradePlaceholderErrorsToWarnings=*/langOpts.Playground ||
351351
langOpts.WarnOnEditorPlaceholder);
352352
if (hadSyntaxError && Context.Diags.hadAnyError() &&

test/ASTGen/if_config.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// REQUIRES: asserts
44

55
#if NOT_SET
6-
func f { } // expected-error{{expected parameter clause in function signature}}
7-
// expected-note@-1{{insert parameter clause}}{{7-8=}}{{8-8=(}}{{8-8=) }}
6+
func f { } // FIXME: Error once the parser diagnostics generator knows to
7+
// evaluate the active clause.
88
#endif
99

1010
#if compiler(>=10.0)

0 commit comments

Comments
 (0)