Skip to content

Commit 722bc0f

Browse files
committed
ASTBridging: Bridge swift::DiagID directly
1 parent 3e9923f commit 722bc0f

File tree

9 files changed

+32
-28
lines changed

9 files changed

+32
-28
lines changed

SwiftCompilerSources/Sources/AST/DiagnosticEngine.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2022 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2022 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -11,10 +11,9 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import ASTBridging
14-
1514
import Basic
1615

17-
public typealias DiagID = BridgedDiagID
16+
public typealias DiagID = swift.DiagID
1817

1918
public protocol DiagnosticArgument {
2019
func _withBridgedDiagnosticArgument(_ fn: (BridgedDiagnosticArgument) -> Void)
@@ -130,6 +129,17 @@ public struct DiagnosticEngine {
130129
closure()
131130
}
132131

132+
// FIXME: Remove this overload once https://github.com/swiftlang/swift/issues/82318 is fixed.
133+
public func diagnose(
134+
_ id: DiagID,
135+
arguments args: [DiagnosticArgument],
136+
at position: SourceLoc?,
137+
highlight: CharSourceRange? = nil,
138+
fixIts: [DiagnosticFixIt] = []
139+
) {
140+
diagnose(id, args, at: position, highlight: highlight, fixIts: fixIts)
141+
}
142+
133143
public func diagnose(_ id: DiagID,
134144
_ args: DiagnosticArgument...,
135145
at position: SourceLoc?,

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceDiagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private struct DiagnoseDependence {
139139

140140
func diagnose(_ position: SourceLoc?, _ id: DiagID,
141141
_ args: DiagnosticArgument...) {
142-
context.diagnosticEngine.diagnose(id, args, at: position)
142+
context.diagnosticEngine.diagnose(id, arguments: args, at: position)
143143
}
144144

145145
/// Check that this use is inside the dependence scope.

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceInsertion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private func insertResultDependencies(for apply: LifetimeDependentApply, _ conte
263263
}
264264

265265
private func diagnoseUnknownDependenceSource(sourceLoc: SourceLoc?, _ context: FunctionPassContext) {
266-
context.diagnosticEngine.diagnose(.lifetime_value_outside_scope, [], at: sourceLoc)
266+
context.diagnosticEngine.diagnose(.lifetime_value_outside_scope, at: sourceLoc)
267267
}
268268

269269
private func insertParameterDependencies(apply: LifetimeDependentApply, target: Operand,

SwiftCompilerSources/Sources/SIL/ASTExtensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information

include/swift/AST/ASTBridging.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "swift/AST/AccessorKind.h"
2424
#include "swift/AST/DiagnosticKind.h"
25+
#include "swift/AST/DiagnosticList.h"
2526
#include "swift/Basic/BasicBridging.h"
2627

2728
#ifdef USED_IN_CPP_SOURCE
@@ -530,13 +531,6 @@ struct BridgedPatternBindingEntry {
530531
// MARK: Diagnostic Engine
531532
//===----------------------------------------------------------------------===//
532533

533-
// NOTE: This must be the same underlying value as C++ 'swift::DiagID' defined
534-
// in 'DiagnosticList.cpp'.
535-
enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagID : uint32_t {
536-
#define DIAG(KIND, ID, Group, Options, Text, Signature) BridgedDiagID_##ID,
537-
#include "swift/AST/DiagnosticsAll.def"
538-
};
539-
540534
class BridgedDiagnosticArgument {
541535
int64_t storage[3];
542536

@@ -579,7 +573,7 @@ class BridgedDiagnostic {
579573
SWIFT_NAME("BridgedDiagnosticEngine.diagnose(self:at:_:_:highlightAt:"
580574
"highlightLength:fixIts:)")
581575
void BridgedDiagnosticEngine_diagnose(
582-
BridgedDiagnosticEngine, BridgedSourceLoc loc, BridgedDiagID diagID,
576+
BridgedDiagnosticEngine, BridgedSourceLoc loc, swift::DiagID diagID,
583577
BridgedArrayRef arguments, BridgedSourceLoc highlightStart,
584578
uint32_t hightlightLength, BridgedArrayRef fixIts);
585579

include/swift/AST/AccessorKind.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ namespace swift {
2323
// diagnostics.
2424
enum class ENUM_EXTENSIBILITY_ATTR(closed) AccessorKind {
2525
#define ACCESSOR(ID, KEYWORD) ID SWIFT_NAME(#KEYWORD),
26+
#define INIT_ACCESSOR(ID, KEYWORD) \
27+
ID, // FIXME: We should be able to remove this once Linux CI host Swift is
28+
// upgraded to 6.0
2629
#define LAST_ACCESSOR(ID) Last = ID
2730
#include "swift/AST/AccessorKinds.def"
28-
#undef ACCESSOR
29-
#undef LAST_ACCESSOR
3031
};
3132

3233
} // namespace swift

include/swift/AST/DiagnosticList.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,28 @@
1717
#ifndef SWIFT_DIAGNOSTICLIST_H
1818
#define SWIFT_DIAGNOSTICLIST_H
1919

20-
#include <cstdint>
21-
#include <type_traits>
20+
/// Be *very* careful with what you include here! See include caveats in
21+
/// `ASTBridging.h`.
22+
#include "swift/Basic/SwiftBridging.h"
23+
#include <stdint.h>
2224

2325
namespace swift {
2426

2527
/// Enumeration describing all of possible diagnostics.
2628
///
2729
/// Each of the diagnostics described in Diagnostics.def has an entry in
2830
/// this enumeration type that uniquely identifies it.
29-
enum class DiagID : uint32_t {
31+
enum class ENUM_EXTENSIBILITY_ATTR(open) DiagID : uint32_t {
3032
#define DIAG(KIND, ID, Group, Options, Text, Signature) ID,
3133
#include "swift/AST/DiagnosticsAll.def"
3234
NumDiagsHandle
3335
};
3436
static_assert(static_cast<uint32_t>(swift::DiagID::invalid_diagnostic) == 0,
3537
"0 is not the invalid diagnostic ID");
3638

37-
constexpr auto NumDiagIDs =
38-
static_cast<std::underlying_type_t<DiagID>>(DiagID::NumDiagsHandle);
39+
constexpr auto NumDiagIDs = static_cast<uint32_t>(DiagID::NumDiagsHandle);
3940

40-
enum class FixItID : uint32_t {
41+
enum class ENUM_EXTENSIBILITY_ATTR(open) FixItID : uint32_t {
4142
#define DIAG(KIND, ID, Group, Options, Text, Signature)
4243
#define FIXIT(ID, Text, Signature) ID,
4344
#include "swift/AST/DiagnosticsAll.def"

lib/AST/Bridging/DiagnosticsBridging.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//===--- Bridging/DiagnosticsBridging.cpp.cpp -----------------------------===//
1+
//===--- Bridging/DiagnosticsBridging.cpp -----------------------*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2022-2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -49,14 +49,12 @@ BridgedDiagnosticFixIt::BridgedDiagnosticFixIt(BridgedSourceLoc start,
4949
}
5050

5151
void BridgedDiagnosticEngine_diagnose(
52-
BridgedDiagnosticEngine bridgedEngine, BridgedSourceLoc loc,
53-
BridgedDiagID bridgedDiagID,
52+
BridgedDiagnosticEngine bridgedEngine, BridgedSourceLoc loc, DiagID diagID,
5453
BridgedArrayRef /*BridgedDiagnosticArgument*/ bridgedArguments,
5554
BridgedSourceLoc highlightStart, uint32_t hightlightLength,
5655
BridgedArrayRef /*BridgedDiagnosticFixIt*/ bridgedFixIts) {
5756
auto *D = bridgedEngine.unbridged();
5857

59-
auto diagID = static_cast<DiagID>(bridgedDiagID);
6058
SmallVector<DiagnosticArgument, 2> arguments;
6159
for (auto arg : bridgedArguments.unbridged<BridgedDiagnosticArgument>()) {
6260
arguments.push_back(arg.unbridged());

lib/ASTGen/Sources/ASTGen/Decls.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ extension ASTGenVisitor {
394394
case ._modify:
395395
return ._modify
396396
case .`init`:
397-
return .`init`
397+
return .Init
398398
case .read:
399399
precondition(ctx.langOptsHasFeature(.CoroutineAccessors), "(compiler bug) 'read' accessor should only be parsed with 'CoroutineAccessors' feature")
400400
return .read

0 commit comments

Comments
 (0)