Skip to content

Commit e9dedf3

Browse files
committed
[cxx-interop][SwiftCompilerSources] Use swift::DiagnosticEngine instead of BridgedDiagnosticEngine
This also removes `BridgedOptionalDiagnosticEngine`. rdar://83361087
1 parent dceed56 commit e9dedf3

File tree

10 files changed

+25
-84
lines changed

10 files changed

+25
-84
lines changed

SwiftCompilerSources/Sources/AST/DiagnosticEngine.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,11 @@ public struct DiagnosticFixIt {
5353
}
5454

5555
public struct DiagnosticEngine {
56-
private let bridged: BridgedDiagnosticEngine
56+
private let bridged: swift.DiagnosticEngine
5757

58-
public init(bridged: BridgedDiagnosticEngine) {
58+
public init(bridged: swift.DiagnosticEngine) {
5959
self.bridged = bridged
6060
}
61-
public init?(bridged: BridgedOptionalDiagnosticEngine) {
62-
guard let object = bridged.object else {
63-
return nil
64-
}
65-
self.bridged = BridgedDiagnosticEngine(object: object)
66-
}
6761

6862
public func diagnose(_ position: SourceLoc?,
6963
_ id: DiagID,

SwiftCompilerSources/Sources/Parse/Regex.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private func _RegexLiteralLexingFn(
4646
_ curPtrPtr: UnsafeMutablePointer<UnsafePointer<CChar>>,
4747
_ bufferEndPtr: UnsafePointer<CChar>,
4848
_ mustBeRegex: CBool,
49-
_ bridgedDiagnosticEngine: BridgedOptionalDiagnosticEngine
49+
_ bridgedDiagnosticEngine: swift.DiagnosticEngine?
5050
) -> /*CompletelyErroneous*/ CBool {
5151
let inputPtr = curPtrPtr.pointee
5252

@@ -62,7 +62,8 @@ private func _RegexLiteralLexingFn(
6262

6363
if let error = error {
6464
// Emit diagnostic if diagnostics are enabled.
65-
if let diagEngine = DiagnosticEngine(bridged: bridgedDiagnosticEngine) {
65+
if let bridged = bridgedDiagnosticEngine {
66+
let diagEngine = DiagnosticEngine(bridged: bridged)
6667
let startLoc = SourceLoc(
6768
locationInFile: error.location.assumingMemoryBound(to: UInt8.self))!
6869
diagEngine.diagnose(startLoc, .regex_literal_parsing_error, error.message)
@@ -93,7 +94,7 @@ public func _RegexLiteralParsingFn(
9394
_ captureStructureOut: UnsafeMutableRawPointer,
9495
_ captureStructureSize: CUnsignedInt,
9596
_ bridgedDiagnosticBaseLoc: swift.SourceLoc,
96-
_ bridgedDiagnosticEngine: BridgedDiagnosticEngine
97+
_ bridgedDiagnosticEngine: swift.DiagnosticEngine
9798
) -> Bool {
9899
let str = String(cString: inputPtr)
99100
let captureBuffer = UnsafeMutableRawBufferPointer(

include/swift/AST/ASTBridging.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,12 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagID : uint32_t {
3939
#include "swift/AST/DiagnosticsAll.def"
4040
} BridgedDiagID;
4141

42-
typedef struct {
43-
void * _Nonnull object;
44-
} BridgedDiagnosticEngine;
45-
46-
typedef struct {
47-
void *_Nullable object;
48-
} BridgedOptionalDiagnosticEngine;
49-
5042
// FIXME: Can we bridge InFlightDiagnostic?
51-
void DiagnosticEngine_diagnose(BridgedDiagnosticEngine, swift::SourceLoc loc,
43+
void DiagnosticEngine_diagnose(swift::DiagnosticEngine &, swift::SourceLoc loc,
5244
BridgedDiagID diagID, BridgedArrayRef arguments,
5345
swift::CharSourceRange highlight,
5446
BridgedArrayRef fixIts);
5547

56-
bool DiagnosticEngine_hadAnyError(BridgedDiagnosticEngine);
57-
5848
SWIFT_END_NULLABILITY_ANNOTATIONS
5949

6050
#endif // SWIFT_AST_ASTBRIDGING_H

include/swift/AST/BridgingUtils.h

Lines changed: 0 additions & 32 deletions
This file was deleted.

include/swift/AST/DiagnosticEngine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ namespace swift {
781781

782782
/// Class responsible for formatting diagnostics and presenting them
783783
/// to the user.
784-
class DiagnosticEngine {
784+
class SWIFT_IMPORT_REFERENCE DiagnosticEngine {
785785
public:
786786
/// The source manager used to interpret source locations and
787787
/// display diagnostics.

include/swift/Basic/Compiler.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,11 @@
178178
#define SWIFT_VFORMAT(fmt)
179179
#endif
180180

181+
// Tells Swift's ClangImporter to import a C++ type as a foreign reference type.
182+
#if __has_attribute(swift_attr)
183+
#define SWIFT_IMPORT_REFERENCE __attribute__((swift_attr("import_as_ref")))
184+
#else
185+
#define SWIFT_IMPORT_REFERENCE
186+
#endif
187+
181188
#endif // SWIFT_BASIC_COMPILER_H

include/swift/Parse/RegexParserBridging.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
/// past.
2828
/// - MustBeRegex: whether an error during lexing should be considered a regex
2929
/// literal, or some thing else.
30-
/// - BridgedOptionalDiagnosticEngine: RegexLiteralLexingFn should diagnose the
31-
/// token using this engine.
30+
/// - OptionalDiagnosticEngine: RegexLiteralLexingFn should diagnose the
31+
/// token using this engine.
3232
///
3333
/// Returns: A bool indicating whether lexing was completely erroneous, and
3434
/// cannot be recovered from, or false if there either was no error,
3535
/// or there was a recoverable error.
3636
typedef bool (*RegexLiteralLexingFn)(
3737
/*CurPtrPtr*/ const char *_Nonnull *_Nonnull,
3838
/*BufferEnd*/ const char *_Nonnull,
39-
/*MustBeRegex*/ bool, BridgedOptionalDiagnosticEngine);
39+
/*MustBeRegex*/ bool, swift::DiagnosticEngine *_Nullable);
4040
void Parser_registerRegexLiteralLexingFn(RegexLiteralLexingFn _Nullable fn);
4141

4242
/// Parse a regex literal string. Takes the following arguments:
@@ -48,16 +48,16 @@ void Parser_registerRegexLiteralLexingFn(RegexLiteralLexingFn _Nullable fn);
4848
/// - CaptureStructureSize: The size of the capture structure buffer. Must be
4949
/// greater than or equal to `strlen(InputPtr) + 3`.
5050
/// - DiagnosticBaseLoc: Start location of the regex literal.
51-
/// - BridgedDiagnosticEngine: RegexLiteralParsingFn should diagnose the
52-
/// parsing errors using this engine.
51+
/// - DiagnosticEngine: RegexLiteralParsingFn should diagnose the
52+
/// parsing errors using this engine.
5353
///
5454
/// Returns: A bool value indicating if there was an error while parsing.
5555
typedef bool (*RegexLiteralParsingFn)(/*InputPtr*/ const char *_Nonnull,
5656
/*VersionOut*/ unsigned *_Nonnull,
5757
/*CaptureStructureOut*/ void *_Nonnull,
5858
/*CaptureStructureSize*/ unsigned,
5959
/*DiagnosticBaseLoc*/ swift::SourceLoc,
60-
BridgedDiagnosticEngine);
60+
swift::DiagnosticEngine &);
6161
void Parser_registerRegexLiteralParsingFn(RegexLiteralParsingFn _Nullable fn);
6262

6363
#endif // REGEX_PARSER_BRIDGING

lib/AST/ASTBridging.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,18 @@
1717

1818
using namespace swift;
1919

20-
namespace {
21-
/// BridgedDiagnosticEngine -> DiagnosticEngine *.
22-
DiagnosticEngine *getDiagnosticEngine(const BridgedDiagnosticEngine &bridged) {
23-
return static_cast<DiagnosticEngine *>(bridged.object);
24-
}
25-
26-
} // namespace
27-
2820
void DiagnosticEngine_diagnose(
29-
BridgedDiagnosticEngine bridgedEngine, SourceLoc loc,
30-
BridgedDiagID bridgedDiagID,
21+
DiagnosticEngine &engine, SourceLoc loc, BridgedDiagID bridgedDiagID,
3122
BridgedArrayRef /*DiagnosticArgument*/ bridgedArguments,
3223
CharSourceRange highlight,
3324
BridgedArrayRef /*DiagnosticInfo::FixIt*/ bridgedFixIts) {
34-
auto *D = getDiagnosticEngine(bridgedEngine);
3525

3626
auto diagID = static_cast<DiagID>(bridgedDiagID);
3727
SmallVector<DiagnosticArgument, 2> arguments;
3828
for (auto arg : getArrayRef<DiagnosticArgument>(bridgedArguments)) {
3929
arguments.push_back(arg);
4030
}
41-
auto inflight = D->diagnose(loc, diagID, arguments);
31+
auto inflight = engine.diagnose(loc, diagID, arguments);
4232

4333
// Add highlight.
4434
if (highlight.isValid()) {
@@ -52,8 +42,3 @@ void DiagnosticEngine_diagnose(
5242
inflight.fixItReplaceChars(range.getStart(), range.getEnd(), text);
5343
}
5444
}
55-
56-
bool DiagnosticEngine_hadAnyError(BridgedDiagnosticEngine bridgedEngine) {
57-
auto *D = getDiagnosticEngine(bridgedEngine);
58-
return D->hadAnyError();
59-
}

lib/Parse/Lexer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
//===----------------------------------------------------------------------===//
1616

1717
#include "swift/Parse/Lexer.h"
18-
#include "swift/AST/BridgingUtils.h"
1918
#include "swift/AST/DiagnosticsParse.h"
2019
#include "swift/AST/Identifier.h"
2120
#include "swift/Basic/LangOptions.h"
@@ -2091,7 +2090,7 @@ const char *Lexer::tryScanRegexLiteral(const char *TokStart, bool MustBeRegex,
20912090
// recovered from.
20922091
auto *Ptr = TokStart;
20932092
CompletelyErroneous = regexLiteralLexingFn(
2094-
&Ptr, BufferEnd, MustBeRegex, getBridgedOptionalDiagnosticEngine(Diags));
2093+
&Ptr, BufferEnd, MustBeRegex, Diags);
20952094

20962095
// If we didn't make any lexing progress, this isn't a regex literal and we
20972096
// should fallback to lexing as something else.

lib/Parse/ParseRegex.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
#include "swift/AST/BridgingUtils.h"
18-
#include "swift/AST/DiagnosticsParse.h"
1917
#include "swift/Basic/BridgingUtils.h"
2018
#include "swift/Parse/ParsedSyntaxRecorder.h"
2119
#include "swift/Parse/Parser.h"
@@ -51,8 +49,7 @@ ParserResult<Expr> Parser::parseExprRegexLiteral() {
5149
regexLiteralParsingFn(regexText.str().c_str(), &version,
5250
/*captureStructureOut*/ capturesBuf.data(),
5351
/*captureStructureSize*/ capturesBuf.size(),
54-
/*diagBaseLoc*/ Tok.getLoc(),
55-
getBridgedDiagnosticEngine(&Diags));
52+
/*diagBaseLoc*/ Tok.getLoc(), Diags);
5653
auto loc = consumeToken();
5754
SourceMgr.recordRegexLiteralStartLoc(loc);
5855

0 commit comments

Comments
 (0)