Skip to content

Commit faa7f67

Browse files
Merge pull request #82165 from AnthonyLatsis/jepa
{AST,Basic}Bridging: Use `<swift/bridging>` and try directly bridging one of our enums
2 parents bf558a3 + b40b192 commit faa7f67

17 files changed

+235
-272
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 36 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// Pure bridging mode does not permit including any C++/llvm/swift headers.
2020
// See also the comments for `BRIDGING_MODE` in the top-level CMakeLists.txt file.
2121
//
22+
#include "swift/AST/DiagnosticKind.h"
2223
#include "swift/Basic/BasicBridging.h"
2324

2425
#ifdef USED_IN_CPP_SOURCE
@@ -118,17 +119,15 @@ class BridgedIdentifier {
118119
BridgedIdentifier(const void *_Nullable raw) : Raw(raw) {}
119120

120121
BRIDGED_INLINE BridgedIdentifier(swift::Identifier ident);
121-
122122
BRIDGED_INLINE swift::Identifier unbridged() const;
123-
};
124123

125-
SWIFT_NAME("getter:BridgedIdentifier.raw(self:)")
126-
inline const void *_Nullable BridgedIdentifier_raw(BridgedIdentifier ident) {
127-
return ident.Raw;
128-
}
124+
SWIFT_COMPUTED_PROPERTY
125+
const void *_Nullable getRaw() const { return Raw; }
129126

130-
SWIFT_NAME("getter:BridgedIdentifier.isOperator(self:)")
131-
BRIDGED_INLINE bool BridgedIdentifier_isOperator(const BridgedIdentifier);
127+
BRIDGED_INLINE
128+
SWIFT_COMPUTED_PROPERTY
129+
bool getIsOperator() const;
130+
};
132131

133132
struct BridgedLocatedIdentifier {
134133
SWIFT_NAME("name")
@@ -236,6 +235,11 @@ BridgedDeclNameLoc_createParsed(
236235
// MARK: ASTContext
237236
//===----------------------------------------------------------------------===//
238237

238+
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedEndianness : size_t {
239+
EndianLittle,
240+
EndianBig,
241+
};
242+
239243
class BridgedASTContext {
240244
swift::ASTContext * _Nonnull Ctx;
241245

@@ -245,17 +249,31 @@ class BridgedASTContext {
245249

246250
SWIFT_UNAVAILABLE("Use '.raw' instead")
247251
BRIDGED_INLINE swift::ASTContext &unbridged() const;
252+
253+
SWIFT_COMPUTED_PROPERTY
254+
void *_Nonnull getRaw() const { return Ctx; }
255+
256+
SWIFT_COMPUTED_PROPERTY
257+
unsigned getMajorLanguageVersion() const;
258+
259+
SWIFT_COMPUTED_PROPERTY
260+
unsigned getLangOptsTargetPointerBitWidth() const;
261+
262+
SWIFT_COMPUTED_PROPERTY
263+
bool getLangOptsAttachCommentsToDecls() const;
264+
265+
SWIFT_COMPUTED_PROPERTY
266+
BridgedEndianness getLangOptsTargetEndianness() const;
267+
268+
SWIFT_COMPUTED_PROPERTY
269+
BridgedAvailabilityMacroMap getAvailabilityMacroMap() const;
248270
};
249271

250272
#define IDENTIFIER_WITH_NAME(Name, _) \
251273
SWIFT_NAME("getter:BridgedASTContext.id_" #Name "(self:)") \
252274
BRIDGED_INLINE BridgedIdentifier BridgedASTContext_id_##Name(BridgedASTContext bridged);
253275
#include "swift/AST/KnownIdentifiers.def"
254276

255-
SWIFT_NAME("getter:BridgedASTContext.raw(self:)")
256-
BRIDGED_INLINE
257-
void * _Nonnull BridgedASTContext_raw(BridgedASTContext bridged);
258-
259277
SWIFT_NAME("BridgedASTContext.init(raw:)")
260278
BRIDGED_INLINE
261279
BridgedASTContext BridgedASTContext_fromRaw(void * _Nonnull ptr);
@@ -283,9 +301,6 @@ SWIFT_NAME("BridgedASTContext.langOptsHasFeature(self:_:)")
283301
bool BridgedASTContext_langOptsHasFeature(BridgedASTContext cContext,
284302
BridgedFeature feature);
285303

286-
SWIFT_NAME("getter:BridgedASTContext.majorLanguageVersion(self:)")
287-
unsigned BridgedASTContext_majorLanguageVersion(BridgedASTContext cContext);
288-
289304
SWIFT_NAME("BridgedASTContext.langOptsCustomConditionSet(self:_:)")
290305
bool BridgedASTContext_langOptsCustomConditionSet(BridgedASTContext cContext,
291306
BridgedStringRef cName);
@@ -318,25 +333,10 @@ SWIFT_NAME("BridgedASTContext.langOptsIsActiveTargetPtrAuth(self:_:)")
318333
bool BridgedASTContext_langOptsIsActiveTargetPtrAuth(BridgedASTContext cContext,
319334
BridgedStringRef cName);
320335

321-
SWIFT_NAME("getter:BridgedASTContext.langOptsTargetPointerBitWidth(self:)")
322-
unsigned BridgedASTContext_langOptsTargetPointerBitWidth(BridgedASTContext cContext);
323-
324336
SWIFT_NAME("BridgedASTContext.langOptsGetTargetAtomicBitWidths(self:_:)")
325337
SwiftInt BridgedASTContext_langOptsGetTargetAtomicBitWidths(BridgedASTContext cContext,
326338
SwiftInt* _Nullable * _Nonnull cComponents);
327339

328-
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedEndianness : size_t {
329-
EndianLittle,
330-
EndianBig,
331-
};
332-
333-
SWIFT_NAME("getter:BridgedASTContext.langOptsAttachCommentsToDecls(self:)")
334-
bool BridgedASTContext_langOptsAttachCommentsToDecls(
335-
BridgedASTContext cContext);
336-
337-
SWIFT_NAME("getter:BridgedASTContext.langOptsTargetEndianness(self:)")
338-
BridgedEndianness BridgedASTContext_langOptsTargetEndianness(BridgedASTContext cContext);
339-
340340
SWIFT_NAME("BridgedASTContext.langOptsGetLanguageVersion(self:_:)")
341341
SwiftInt BridgedASTContext_langOptsGetLanguageVersion(BridgedASTContext cContext,
342342
SwiftInt* _Nullable * _Nonnull cComponents);
@@ -345,10 +345,6 @@ SWIFT_NAME("BridgedASTContext.langOptsGetCompilerVersion(self:_:)")
345345
SwiftInt BridgedASTContext_langOptsGetCompilerVersion(BridgedASTContext cContext,
346346
SwiftInt* _Nullable * _Nonnull cComponents);
347347

348-
SWIFT_NAME("getter:BridgedASTContext.availabilityMacroMap(self:)")
349-
BridgedAvailabilityMacroMap
350-
BridgedASTContext_getAvailabilityMacroMap(BridgedASTContext cContext);
351-
352348
/* Deallocate an array of Swift int values that was allocated in C++. */
353349
void deallocateIntBuffer(SwiftInt * _Nullable cComponents);
354350

@@ -442,7 +438,7 @@ class BridgedASTNode {
442438
return BridgedASTNode(e.unbridged(), BridgedASTNodeKindExpr);
443439
}
444440

445-
SWIFT_UNAVAILABLE("use .kind")
441+
SWIFT_COMPUTED_PROPERTY
446442
BridgedASTNodeKind getKind() const {
447443
return static_cast<BridgedASTNodeKind>(opaque & 0x7);
448444
}
@@ -454,11 +450,6 @@ class BridgedASTNode {
454450
BRIDGED_INLINE swift::ASTNode unbridged() const;
455451
};
456452

457-
SWIFT_NAME("getter:BridgedASTNode.kind(self:)")
458-
inline BridgedASTNodeKind BridgedASTNode_getKind(BridgedASTNode node) {
459-
return node.getKind();
460-
}
461-
462453
// Declare `.asDecl` on each BridgedXXXDecl type, which upcasts a wrapper for
463454
// a Decl subclass to a BridgedDecl.
464455
#define DECL(Id, Parent) \
@@ -575,15 +566,6 @@ class BridgedDiagnosticFixIt {
575566
BridgedDiagnosticFixIt(BridgedSourceLoc start, uint32_t length, BridgedStringRef text);
576567
};
577568

578-
/// Diagnostic severity when reporting diagnostics.
579-
enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : size_t {
580-
BridgedFatalError,
581-
BridgedError,
582-
BridgedWarning,
583-
BridgedRemark,
584-
BridgedNote,
585-
};
586-
587569
class BridgedDiagnostic {
588570
public:
589571
struct Impl;
@@ -622,7 +604,7 @@ bool BridgedDiagnosticEngine_hadAnyError(BridgedDiagnosticEngine);
622604
SWIFT_NAME("BridgedDiagnostic.init(at:message:severity:engine:)")
623605
BridgedDiagnostic BridgedDiagnostic_create(BridgedSourceLoc cLoc,
624606
BridgedStringRef cText,
625-
BridgedDiagnosticSeverity severity,
607+
swift::DiagnosticKind severity,
626608
BridgedDiagnosticEngine cDiags);
627609

628610
/// Highlight a source range as part of the diagnostic.
@@ -1930,8 +1912,11 @@ class BridgedCaptureListEntry {
19301912

19311913
public:
19321914
BRIDGED_INLINE BridgedCaptureListEntry(swift::CaptureListEntry CLE);
1933-
19341915
BRIDGED_INLINE swift::CaptureListEntry unbridged() const;
1916+
1917+
BRIDGED_INLINE
1918+
SWIFT_COMPUTED_PROPERTY
1919+
BridgedVarDecl getVarDecl() const;
19351920
};
19361921

19371922
SWIFT_NAME("BridgedCaptureListEntry.createParsed(_:declContext:ownership:"
@@ -1943,10 +1928,6 @@ BridgedCaptureListEntry BridegedCaptureListEntry_createParsed(
19431928
BridgedSourceLoc cNameLoc, BridgedSourceLoc cEqualLoc,
19441929
BridgedExpr cInitializer);
19451930

1946-
SWIFT_NAME("getter:BridgedCaptureListEntry.varDecl(self:)")
1947-
BRIDGED_INLINE BridgedVarDecl
1948-
BridegedCaptureListEntry_getVar(BridgedCaptureListEntry entry);
1949-
19501931
SWIFT_NAME("BridgedCaptureListExpr.createParsed(_:captureList:closure:)")
19511932
BridgedCaptureListExpr BridgedCaptureListExpr_createParsed(BridgedASTContext cContext,
19521933
BridgedArrayRef cCaptureList,

include/swift/AST/ASTBridgingImpl.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ swift::Identifier BridgedIdentifier::unbridged() const {
4343
return swift::Identifier::getFromOpaquePointer(Raw);
4444
}
4545

46-
bool BridgedIdentifier_isOperator(const BridgedIdentifier ident) {
47-
return ident.unbridged().isOperator();
46+
bool BridgedIdentifier::getIsOperator() const {
47+
return unbridged().isOperator();
4848
}
4949

5050
//===----------------------------------------------------------------------===//
@@ -101,10 +101,6 @@ BridgedASTContext::BridgedASTContext(swift::ASTContext &ctx) : Ctx(&ctx) {}
101101

102102
swift::ASTContext &BridgedASTContext::unbridged() const { return *Ctx; }
103103

104-
void * _Nonnull BridgedASTContext_raw(BridgedASTContext bridged) {
105-
return &bridged.unbridged();
106-
}
107-
108104
BridgedASTContext BridgedASTContext_fromRaw(void * _Nonnull ptr) {
109105
return *static_cast<swift::ASTContext *>(ptr);
110106
}
@@ -938,8 +934,8 @@ swift::CaptureListEntry BridgedCaptureListEntry::unbridged() const {
938934
return swift::CaptureListEntry(PBD);
939935
}
940936

941-
BridgedVarDecl BridegedCaptureListEntry_getVar(BridgedCaptureListEntry entry) {
942-
return entry.unbridged().getVar();
937+
BridgedVarDecl BridgedCaptureListEntry::getVarDecl() const {
938+
return unbridged().getVar();
943939
}
944940

945941
//===----------------------------------------------------------------------===//

include/swift/AST/DiagnosticConsumer.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef SWIFT_BASIC_DIAGNOSTICCONSUMER_H
2020
#define SWIFT_BASIC_DIAGNOSTICCONSUMER_H
2121

22+
#include "swift/AST/DiagnosticKind.h"
2223
#include "swift/Basic/LLVM.h"
2324
#include "swift/Basic/SourceLoc.h"
2425
#include "llvm/Support/SourceMgr.h"
@@ -30,15 +31,6 @@ namespace swift {
3031
class SourceManager;
3132
enum class DiagID : uint32_t;
3233

33-
/// Describes the kind of diagnostic.
34-
///
35-
enum class DiagnosticKind : uint8_t {
36-
Error,
37-
Warning,
38-
Remark,
39-
Note
40-
};
41-
4234
/// Information about a diagnostic passed to DiagnosticConsumers.
4335
struct DiagnosticInfo {
4436
DiagID ID = DiagID(0);

include/swift/AST/DiagnosticKind.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===-- AST/DiagnosticKind.h ------------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_AST_DIAGNOSTIC_KIND_H
14+
#define SWIFT_AST_DIAGNOSTIC_KIND_H
15+
16+
/// This header is included in a bridging header. Be *very* careful with what
17+
/// you include here! See include caveats in `ASTBridging.h`.
18+
#include "swift/Basic/SwiftBridging.h"
19+
#include <stdint.h>
20+
21+
namespace swift {
22+
23+
/// Describes the kind of diagnostic.
24+
enum class ENUM_EXTENSIBILITY_ATTR(open) DiagnosticKind : uint8_t {
25+
Error SWIFT_NAME("error"),
26+
Warning SWIFT_NAME("warning"),
27+
Remark SWIFT_NAME("remark"),
28+
Note SWIFT_NAME("note")
29+
};
30+
31+
} // namespace swift
32+
33+
#endif // SWIFT_AST_DIAGNOSTIC_KIND_H

0 commit comments

Comments
 (0)