Merge remote-tracking branch 'origin/main' into rebranch

This commit is contained in:
swift-ci
2022-07-15 07:14:24 -07:00
10 changed files with 25 additions and 84 deletions

View File

@@ -53,17 +53,11 @@ public struct DiagnosticFixIt {
} }
public struct DiagnosticEngine { public struct DiagnosticEngine {
private let bridged: BridgedDiagnosticEngine private let bridged: swift.DiagnosticEngine
public init(bridged: BridgedDiagnosticEngine) { public init(bridged: swift.DiagnosticEngine) {
self.bridged = bridged self.bridged = bridged
} }
public init?(bridged: BridgedOptionalDiagnosticEngine) {
guard let object = bridged.object else {
return nil
}
self.bridged = BridgedDiagnosticEngine(object: object)
}
public func diagnose(_ position: SourceLoc?, public func diagnose(_ position: SourceLoc?,
_ id: DiagID, _ id: DiagID,

View File

@@ -46,7 +46,7 @@ private func _RegexLiteralLexingFn(
_ curPtrPtr: UnsafeMutablePointer<UnsafePointer<CChar>>, _ curPtrPtr: UnsafeMutablePointer<UnsafePointer<CChar>>,
_ bufferEndPtr: UnsafePointer<CChar>, _ bufferEndPtr: UnsafePointer<CChar>,
_ mustBeRegex: CBool, _ mustBeRegex: CBool,
_ bridgedDiagnosticEngine: BridgedOptionalDiagnosticEngine _ bridgedDiagnosticEngine: swift.DiagnosticEngine?
) -> /*CompletelyErroneous*/ CBool { ) -> /*CompletelyErroneous*/ CBool {
let inputPtr = curPtrPtr.pointee let inputPtr = curPtrPtr.pointee
@@ -62,7 +62,8 @@ private func _RegexLiteralLexingFn(
if let error = error { if let error = error {
// Emit diagnostic if diagnostics are enabled. // Emit diagnostic if diagnostics are enabled.
if let diagEngine = DiagnosticEngine(bridged: bridgedDiagnosticEngine) { if let bridged = bridgedDiagnosticEngine {
let diagEngine = DiagnosticEngine(bridged: bridged)
let startLoc = SourceLoc( let startLoc = SourceLoc(
locationInFile: error.location.assumingMemoryBound(to: UInt8.self))! locationInFile: error.location.assumingMemoryBound(to: UInt8.self))!
diagEngine.diagnose(startLoc, .regex_literal_parsing_error, error.message) diagEngine.diagnose(startLoc, .regex_literal_parsing_error, error.message)
@@ -93,7 +94,7 @@ public func _RegexLiteralParsingFn(
_ captureStructureOut: UnsafeMutableRawPointer, _ captureStructureOut: UnsafeMutableRawPointer,
_ captureStructureSize: CUnsignedInt, _ captureStructureSize: CUnsignedInt,
_ bridgedDiagnosticBaseLoc: swift.SourceLoc, _ bridgedDiagnosticBaseLoc: swift.SourceLoc,
_ bridgedDiagnosticEngine: BridgedDiagnosticEngine _ bridgedDiagnosticEngine: swift.DiagnosticEngine
) -> Bool { ) -> Bool {
let str = String(cString: inputPtr) let str = String(cString: inputPtr)
let captureBuffer = UnsafeMutableRawBufferPointer( let captureBuffer = UnsafeMutableRawBufferPointer(

View File

@@ -39,22 +39,12 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagID : uint32_t {
#include "swift/AST/DiagnosticsAll.def" #include "swift/AST/DiagnosticsAll.def"
} BridgedDiagID; } BridgedDiagID;
typedef struct {
void * _Nonnull object;
} BridgedDiagnosticEngine;
typedef struct {
void *_Nullable object;
} BridgedOptionalDiagnosticEngine;
// FIXME: Can we bridge InFlightDiagnostic? // FIXME: Can we bridge InFlightDiagnostic?
void DiagnosticEngine_diagnose(BridgedDiagnosticEngine, swift::SourceLoc loc, void DiagnosticEngine_diagnose(swift::DiagnosticEngine &, swift::SourceLoc loc,
BridgedDiagID diagID, BridgedArrayRef arguments, BridgedDiagID diagID, BridgedArrayRef arguments,
swift::CharSourceRange highlight, swift::CharSourceRange highlight,
BridgedArrayRef fixIts); BridgedArrayRef fixIts);
bool DiagnosticEngine_hadAnyError(BridgedDiagnosticEngine);
SWIFT_END_NULLABILITY_ANNOTATIONS SWIFT_END_NULLABILITY_ANNOTATIONS
#endif // SWIFT_AST_ASTBRIDGING_H #endif // SWIFT_AST_ASTBRIDGING_H

View File

@@ -1,32 +0,0 @@
//===--- BridgingUtils.h - utilities for swift bridging -------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_AST_BRIDGINGUTILS_H
#define SWIFT_AST_BRIDGINGUTILS_H
#include "swift/AST/ASTBridging.h"
#include "swift/AST/DiagnosticEngine.h"
namespace swift {
inline BridgedDiagnosticEngine getBridgedDiagnosticEngine(DiagnosticEngine *D) {
return {(void *)D};
}
inline BridgedOptionalDiagnosticEngine
getBridgedOptionalDiagnosticEngine(DiagnosticEngine *D) {
return {(void *)D};
}
} // namespace swift
#endif

View File

@@ -781,7 +781,7 @@ namespace swift {
/// Class responsible for formatting diagnostics and presenting them /// Class responsible for formatting diagnostics and presenting them
/// to the user. /// to the user.
class DiagnosticEngine { class SWIFT_IMPORT_REFERENCE DiagnosticEngine {
public: public:
/// The source manager used to interpret source locations and /// The source manager used to interpret source locations and
/// display diagnostics. /// display diagnostics.

View File

@@ -178,4 +178,11 @@
#define SWIFT_VFORMAT(fmt) #define SWIFT_VFORMAT(fmt)
#endif #endif
// Tells Swift's ClangImporter to import a C++ type as a foreign reference type.
#if __has_attribute(swift_attr)
#define SWIFT_IMPORT_REFERENCE __attribute__((swift_attr("import_as_ref")))
#else
#define SWIFT_IMPORT_REFERENCE
#endif
#endif // SWIFT_BASIC_COMPILER_H #endif // SWIFT_BASIC_COMPILER_H

View File

@@ -27,8 +27,8 @@
/// past. /// past.
/// - MustBeRegex: whether an error during lexing should be considered a regex /// - MustBeRegex: whether an error during lexing should be considered a regex
/// literal, or some thing else. /// literal, or some thing else.
/// - BridgedOptionalDiagnosticEngine: RegexLiteralLexingFn should diagnose the /// - OptionalDiagnosticEngine: RegexLiteralLexingFn should diagnose the
/// token using this engine. /// token using this engine.
/// ///
/// Returns: A bool indicating whether lexing was completely erroneous, and /// Returns: A bool indicating whether lexing was completely erroneous, and
/// cannot be recovered from, or false if there either was no error, /// cannot be recovered from, or false if there either was no error,
@@ -36,7 +36,7 @@
typedef bool (*RegexLiteralLexingFn)( typedef bool (*RegexLiteralLexingFn)(
/*CurPtrPtr*/ const char *_Nonnull *_Nonnull, /*CurPtrPtr*/ const char *_Nonnull *_Nonnull,
/*BufferEnd*/ const char *_Nonnull, /*BufferEnd*/ const char *_Nonnull,
/*MustBeRegex*/ bool, BridgedOptionalDiagnosticEngine); /*MustBeRegex*/ bool, swift::DiagnosticEngine *_Nullable);
void Parser_registerRegexLiteralLexingFn(RegexLiteralLexingFn _Nullable fn); void Parser_registerRegexLiteralLexingFn(RegexLiteralLexingFn _Nullable fn);
/// Parse a regex literal string. Takes the following arguments: /// Parse a regex literal string. Takes the following arguments:
@@ -48,8 +48,8 @@ void Parser_registerRegexLiteralLexingFn(RegexLiteralLexingFn _Nullable fn);
/// - CaptureStructureSize: The size of the capture structure buffer. Must be /// - CaptureStructureSize: The size of the capture structure buffer. Must be
/// greater than or equal to `strlen(InputPtr) + 3`. /// greater than or equal to `strlen(InputPtr) + 3`.
/// - DiagnosticBaseLoc: Start location of the regex literal. /// - DiagnosticBaseLoc: Start location of the regex literal.
/// - BridgedDiagnosticEngine: RegexLiteralParsingFn should diagnose the /// - DiagnosticEngine: RegexLiteralParsingFn should diagnose the
/// parsing errors using this engine. /// parsing errors using this engine.
/// ///
/// Returns: A bool value indicating if there was an error while parsing. /// Returns: A bool value indicating if there was an error while parsing.
typedef bool (*RegexLiteralParsingFn)(/*InputPtr*/ const char *_Nonnull, typedef bool (*RegexLiteralParsingFn)(/*InputPtr*/ const char *_Nonnull,
@@ -57,7 +57,7 @@ typedef bool (*RegexLiteralParsingFn)(/*InputPtr*/ const char *_Nonnull,
/*CaptureStructureOut*/ void *_Nonnull, /*CaptureStructureOut*/ void *_Nonnull,
/*CaptureStructureSize*/ unsigned, /*CaptureStructureSize*/ unsigned,
/*DiagnosticBaseLoc*/ swift::SourceLoc, /*DiagnosticBaseLoc*/ swift::SourceLoc,
BridgedDiagnosticEngine); swift::DiagnosticEngine &);
void Parser_registerRegexLiteralParsingFn(RegexLiteralParsingFn _Nullable fn); void Parser_registerRegexLiteralParsingFn(RegexLiteralParsingFn _Nullable fn);
#endif // REGEX_PARSER_BRIDGING #endif // REGEX_PARSER_BRIDGING

View File

@@ -17,28 +17,18 @@
using namespace swift; using namespace swift;
namespace {
/// BridgedDiagnosticEngine -> DiagnosticEngine *.
DiagnosticEngine *getDiagnosticEngine(const BridgedDiagnosticEngine &bridged) {
return static_cast<DiagnosticEngine *>(bridged.object);
}
} // namespace
void DiagnosticEngine_diagnose( void DiagnosticEngine_diagnose(
BridgedDiagnosticEngine bridgedEngine, SourceLoc loc, DiagnosticEngine &engine, SourceLoc loc, BridgedDiagID bridgedDiagID,
BridgedDiagID bridgedDiagID,
BridgedArrayRef /*DiagnosticArgument*/ bridgedArguments, BridgedArrayRef /*DiagnosticArgument*/ bridgedArguments,
CharSourceRange highlight, CharSourceRange highlight,
BridgedArrayRef /*DiagnosticInfo::FixIt*/ bridgedFixIts) { BridgedArrayRef /*DiagnosticInfo::FixIt*/ bridgedFixIts) {
auto *D = getDiagnosticEngine(bridgedEngine);
auto diagID = static_cast<DiagID>(bridgedDiagID); auto diagID = static_cast<DiagID>(bridgedDiagID);
SmallVector<DiagnosticArgument, 2> arguments; SmallVector<DiagnosticArgument, 2> arguments;
for (auto arg : getArrayRef<DiagnosticArgument>(bridgedArguments)) { for (auto arg : getArrayRef<DiagnosticArgument>(bridgedArguments)) {
arguments.push_back(arg); arguments.push_back(arg);
} }
auto inflight = D->diagnose(loc, diagID, arguments); auto inflight = engine.diagnose(loc, diagID, arguments);
// Add highlight. // Add highlight.
if (highlight.isValid()) { if (highlight.isValid()) {
@@ -52,8 +42,3 @@ void DiagnosticEngine_diagnose(
inflight.fixItReplaceChars(range.getStart(), range.getEnd(), text); inflight.fixItReplaceChars(range.getStart(), range.getEnd(), text);
} }
} }
bool DiagnosticEngine_hadAnyError(BridgedDiagnosticEngine bridgedEngine) {
auto *D = getDiagnosticEngine(bridgedEngine);
return D->hadAnyError();
}

View File

@@ -15,7 +15,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "swift/Parse/Lexer.h" #include "swift/Parse/Lexer.h"
#include "swift/AST/BridgingUtils.h"
#include "swift/AST/DiagnosticsParse.h" #include "swift/AST/DiagnosticsParse.h"
#include "swift/AST/Identifier.h" #include "swift/AST/Identifier.h"
#include "swift/Basic/LangOptions.h" #include "swift/Basic/LangOptions.h"
@@ -2091,7 +2090,7 @@ const char *Lexer::tryScanRegexLiteral(const char *TokStart, bool MustBeRegex,
// recovered from. // recovered from.
auto *Ptr = TokStart; auto *Ptr = TokStart;
CompletelyErroneous = regexLiteralLexingFn( CompletelyErroneous = regexLiteralLexingFn(
&Ptr, BufferEnd, MustBeRegex, getBridgedOptionalDiagnosticEngine(Diags)); &Ptr, BufferEnd, MustBeRegex, Diags);
// If we didn't make any lexing progress, this isn't a regex literal and we // If we didn't make any lexing progress, this isn't a regex literal and we
// should fallback to lexing as something else. // should fallback to lexing as something else.

View File

@@ -14,8 +14,6 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "swift/AST/BridgingUtils.h"
#include "swift/AST/DiagnosticsParse.h"
#include "swift/Basic/BridgingUtils.h" #include "swift/Basic/BridgingUtils.h"
#include "swift/Parse/ParsedSyntaxRecorder.h" #include "swift/Parse/ParsedSyntaxRecorder.h"
#include "swift/Parse/Parser.h" #include "swift/Parse/Parser.h"
@@ -51,8 +49,7 @@ ParserResult<Expr> Parser::parseExprRegexLiteral() {
regexLiteralParsingFn(regexText.str().c_str(), &version, regexLiteralParsingFn(regexText.str().c_str(), &version,
/*captureStructureOut*/ capturesBuf.data(), /*captureStructureOut*/ capturesBuf.data(),
/*captureStructureSize*/ capturesBuf.size(), /*captureStructureSize*/ capturesBuf.size(),
/*diagBaseLoc*/ Tok.getLoc(), /*diagBaseLoc*/ Tok.getLoc(), Diags);
getBridgedDiagnosticEngine(&Diags));
auto loc = consumeToken(); auto loc = consumeToken();
SourceMgr.recordRegexLiteralStartLoc(loc); SourceMgr.recordRegexLiteralStartLoc(loc);