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 {
private let bridged: BridgedDiagnosticEngine
private let bridged: swift.DiagnosticEngine
public init(bridged: BridgedDiagnosticEngine) {
public init(bridged: swift.DiagnosticEngine) {
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?,
_ id: DiagID,

View File

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

View File

@@ -39,22 +39,12 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagID : uint32_t {
#include "swift/AST/DiagnosticsAll.def"
} BridgedDiagID;
typedef struct {
void * _Nonnull object;
} BridgedDiagnosticEngine;
typedef struct {
void *_Nullable object;
} BridgedOptionalDiagnosticEngine;
// FIXME: Can we bridge InFlightDiagnostic?
void DiagnosticEngine_diagnose(BridgedDiagnosticEngine, swift::SourceLoc loc,
void DiagnosticEngine_diagnose(swift::DiagnosticEngine &, swift::SourceLoc loc,
BridgedDiagID diagID, BridgedArrayRef arguments,
swift::CharSourceRange highlight,
BridgedArrayRef fixIts);
bool DiagnosticEngine_hadAnyError(BridgedDiagnosticEngine);
SWIFT_END_NULLABILITY_ANNOTATIONS
#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
/// to the user.
class DiagnosticEngine {
class SWIFT_IMPORT_REFERENCE DiagnosticEngine {
public:
/// The source manager used to interpret source locations and
/// display diagnostics.

View File

@@ -178,4 +178,11 @@
#define SWIFT_VFORMAT(fmt)
#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

View File

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

View File

@@ -17,28 +17,18 @@
using namespace swift;
namespace {
/// BridgedDiagnosticEngine -> DiagnosticEngine *.
DiagnosticEngine *getDiagnosticEngine(const BridgedDiagnosticEngine &bridged) {
return static_cast<DiagnosticEngine *>(bridged.object);
}
} // namespace
void DiagnosticEngine_diagnose(
BridgedDiagnosticEngine bridgedEngine, SourceLoc loc,
BridgedDiagID bridgedDiagID,
DiagnosticEngine &engine, SourceLoc loc, BridgedDiagID bridgedDiagID,
BridgedArrayRef /*DiagnosticArgument*/ bridgedArguments,
CharSourceRange highlight,
BridgedArrayRef /*DiagnosticInfo::FixIt*/ bridgedFixIts) {
auto *D = getDiagnosticEngine(bridgedEngine);
auto diagID = static_cast<DiagID>(bridgedDiagID);
SmallVector<DiagnosticArgument, 2> arguments;
for (auto arg : getArrayRef<DiagnosticArgument>(bridgedArguments)) {
arguments.push_back(arg);
}
auto inflight = D->diagnose(loc, diagID, arguments);
auto inflight = engine.diagnose(loc, diagID, arguments);
// Add highlight.
if (highlight.isValid()) {
@@ -52,8 +42,3 @@ void DiagnosticEngine_diagnose(
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/AST/BridgingUtils.h"
#include "swift/AST/DiagnosticsParse.h"
#include "swift/AST/Identifier.h"
#include "swift/Basic/LangOptions.h"
@@ -2091,7 +2090,7 @@ const char *Lexer::tryScanRegexLiteral(const char *TokStart, bool MustBeRegex,
// recovered from.
auto *Ptr = TokStart;
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
// 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/Parse/ParsedSyntaxRecorder.h"
#include "swift/Parse/Parser.h"
@@ -51,8 +49,7 @@ ParserResult<Expr> Parser::parseExprRegexLiteral() {
regexLiteralParsingFn(regexText.str().c_str(), &version,
/*captureStructureOut*/ capturesBuf.data(),
/*captureStructureSize*/ capturesBuf.size(),
/*diagBaseLoc*/ Tok.getLoc(),
getBridgedDiagnosticEngine(&Diags));
/*diagBaseLoc*/ Tok.getLoc(), Diags);
auto loc = consumeToken();
SourceMgr.recordRegexLiteralStartLoc(loc);