From dadb863c08cde9a8723237aa4ebd470dfd5d02e6 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 1 Sep 2023 12:13:35 -0700 Subject: [PATCH 1/7] [Swift bridging] Use Swift(U)Int consistently for bridging --- include/swift/AST/CASTBridging.h | 23 ++++++++++------------- include/swift/Basic/CBasicBridging.h | 5 ++++- lib/AST/CASTBridging.cpp | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/swift/AST/CASTBridging.h b/include/swift/AST/CASTBridging.h index 2d6a5a7409113..0f798f961db94 100644 --- a/include/swift/AST/CASTBridging.h +++ b/include/swift/AST/CASTBridging.h @@ -25,17 +25,14 @@ SWIFT_BEGIN_NULLABILITY_ANNOTATIONS SWIFT_BEGIN_ASSUME_NONNULL -typedef long SwiftInt; -typedef unsigned long SwiftUInt; - typedef struct { const unsigned char *_Nullable data; - long length; + SwiftInt length; } BridgedString; typedef struct { const void *_Nullable data; - long numElements; + SwiftInt numElements; } BridgedArrayRef; typedef struct BridgedASTContext { @@ -70,7 +67,7 @@ typedef struct { BridgedSourceLoc TrailingCommaLoc; } BridgedTupleTypeElement; -typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedRequirementReprKind : long { +typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedRequirementReprKind : SwiftInt { /// A type bound T : P, where T is a type that depends on a generic /// parameter and P is some type that should bound T, either as a concrete /// supertype or a protocol to which T must conform. @@ -97,7 +94,7 @@ typedef struct { } BridgedRequirementRepr; /// Diagnostic severity when reporting diagnostics. -typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : long { +typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : SwiftInt { BridgedFatalError, BridgedError, BridgedWarning, @@ -113,7 +110,7 @@ typedef struct BridgedDiagnosticEngine { void *raw; } BridgedDiagnosticEngine; -typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedMacroDefinitionKind : long { +typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedMacroDefinitionKind : SwiftInt { /// An expanded macro. BridgedExpandedMacro = 0, /// An external macro, spelled with either the old spelling (Module.Type) @@ -124,7 +121,7 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedMacroDefinitionKind : long { } BridgedMacroDefinitionKind; /// Bridged parameter specifiers -typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedAttributedTypeSpecifier : long { +typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedAttributedTypeSpecifier : SwiftInt { BridgedAttributedTypeSpecifierInOut, BridgedAttributedTypeSpecifierBorrowing, BridgedAttributedTypeSpecifierConsuming, @@ -135,7 +132,7 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedAttributedTypeSpecifier : long } BridgedAttributedTypeSpecifier; // Bridged type attribute kinds, which mirror TypeAttrKind exactly. -typedef enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedTypeAttrKind : long { +typedef enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedTypeAttrKind : SwiftInt { BridgedTypeAttrKind_autoclosure, BridgedTypeAttrKind_convention, BridgedTypeAttrKind_noescape, @@ -187,7 +184,7 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedTypeAttrKind : long { BridgedTypeAttrKind_Count } BridgedTypeAttrKind; -typedef enum ENUM_EXTENSIBILITY_ATTR(open) ASTNodeKind : long { +typedef enum ENUM_EXTENSIBILITY_ATTR(open) ASTNodeKind : SwiftInt { ASTNodeKindExpr, ASTNodeKindStmt, ASTNodeKindDecl @@ -307,7 +304,7 @@ void *IfStmt_create(BridgedASTContext cContext, BridgedSourceLoc cIfLoc, void *BraceStmt_create(BridgedASTContext cContext, BridgedSourceLoc cLBLoc, BridgedArrayRef elements, BridgedSourceLoc cRBLoc); -BridgedSourceLoc SourceLoc_advanced(BridgedSourceLoc cLoc, long len); +BridgedSourceLoc SourceLoc_advanced(BridgedSourceLoc cLoc, SwiftInt len); void *ParamDecl_create(BridgedASTContext cContext, BridgedSourceLoc cLoc, BridgedSourceLoc cArgLoc, BridgedIdentifier argName, @@ -357,7 +354,7 @@ void *GenericTypeParamDecl_create(BridgedASTContext cContext, BridgedDeclContext cDeclContext, BridgedIdentifier name, BridgedSourceLoc cNameLoc, - BridgedSourceLoc cEachLoc, long index, + BridgedSourceLoc cEachLoc, SwiftInt index, _Bool isParameterPack); void GenericTypeParamDecl_setInheritedType(BridgedASTContext cContext, void *Param, void *ty); diff --git a/include/swift/Basic/CBasicBridging.h b/include/swift/Basic/CBasicBridging.h index 1a99b83c703c2..6dd6189692677 100644 --- a/include/swift/Basic/CBasicBridging.h +++ b/include/swift/Basic/CBasicBridging.h @@ -38,9 +38,12 @@ FeatureName, SWIFT_BEGIN_ASSUME_NONNULL +typedef long SwiftInt; +typedef unsigned long SwiftUInt; + typedef struct BridgedData { const char *_Nullable baseAddress; - unsigned long size; + SwiftUInt size; } BridgedData; void BridgedData_free(BridgedData data); diff --git a/lib/AST/CASTBridging.cpp b/lib/AST/CASTBridging.cpp index e629b4057b0e9..f68e02daccd6d 100644 --- a/lib/AST/CASTBridging.cpp +++ b/lib/AST/CASTBridging.cpp @@ -204,7 +204,7 @@ void *ImportDecl_create(BridgedASTContext cContext, std::move(importPath).get()); } -BridgedSourceLoc SourceLoc_advanced(BridgedSourceLoc cLoc, long len) { +BridgedSourceLoc SourceLoc_advanced(BridgedSourceLoc cLoc, SwiftInt len) { SourceLoc loc = convertSourceLoc(cLoc).getAdvancedLoc(len); return {loc.getOpaquePointerValue()}; } @@ -764,7 +764,7 @@ void *GenericTypeParamDecl_create(BridgedASTContext cContext, BridgedDeclContext cDeclContext, BridgedIdentifier name, BridgedSourceLoc cNameLoc, - BridgedSourceLoc cEachLoc, long index, + BridgedSourceLoc cEachLoc, SwiftInt index, bool isParameterPack) { return GenericTypeParamDecl::createParsed( convertDeclContext(cDeclContext), convertIdentifier(name), @@ -881,6 +881,6 @@ bool Plugin_waitForNextMessage(PluginHandle handle, BridgedData *out) { auto size = message.size(); auto outPtr = malloc(size); memcpy(outPtr, message.data(), size); - *out = BridgedData{(const char *)outPtr, (unsigned long)size}; + *out = BridgedData{(const char *)outPtr, (SwiftUInt)size}; return false; } From e0232742ce930ae8fd4513246c4fb2a9be66c8b2 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 1 Sep 2023 12:18:33 -0700 Subject: [PATCH 2/7] Define the C++ Swift(U)Int types using the same logic as SwiftShims The C type tha corresponds to Swift's pointer-sized `Int` and `UInt` types varies from one platform to the next. The canonical C types are `ptrdiff_t` and `size_t`, but we're in the depths of the compiler we can't include the C library headers that provide them because they introduce cyclic module dependencies. Sigh. SwiftShims has some logic to compute these types. However, SwiftShims is part of the Swift runtime, not the compiler, so those headers cannot be included here. So, we clone the logic and simplify it somewhat for our use case. This fixes truncation issues on Windows, where the uses of `unsigned long` and `long` for Swift(U)Int are incorrect. --- include/swift/Basic/CBasicBridging.h | 61 ++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/include/swift/Basic/CBasicBridging.h b/include/swift/Basic/CBasicBridging.h index 6dd6189692677..6771d446778ce 100644 --- a/include/swift/Basic/CBasicBridging.h +++ b/include/swift/Basic/CBasicBridging.h @@ -21,6 +21,64 @@ // it causes importing the "Darwin"/"Glibc" overlay module. That violates // layering. i.e. Darwin overlay is created by Swift compiler. +// NOTE: Partially ported from SwiftShim's SwiftStdint.h. We cannot include +// that header here because it belongs to the runtime, but we need the same +// logic for interoperability with Swift code in the compiler itself. +// stdint.h is provided by Clang, but it dispatches to libc's stdint.h. As a +// result, using stdint.h here would pull in Darwin module (which includes +// libc). This creates a dependency cycle, so we can't use stdint.h in +// SwiftShims. +// On Linux, the story is different. We get the error message +// "/usr/include/x86_64-linux-gnu/sys/types.h:146:10: error: 'stddef.h' file not +// found" +// This is a known Clang/Ubuntu bug. + +// Clang has been defining __INTxx_TYPE__ macros for a long time. +// __UINTxx_TYPE__ are defined only since Clang 3.5. +#if !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__wasi__) +#include +typedef int64_t __swiftc_int64_t; +typedef uint64_t __swiftc_uint64_t; +typedef int32_t __swiftc_int32_t; +typedef uint32_t __swiftc_uint32_t; +typedef intptr_t __swiftc_intptr_t; +typedef uintptr_t __swiftc_uintptr_t; +#else +typedef __INT64_TYPE__ __swiftc_int64_t; +#ifdef __UINT64_TYPE__ +typedef __UINT64_TYPE__ __swiftc_uint64_t; +#else +typedef unsigned __INT64_TYPE__ __swiftc_uint64_t; +#endif + +typedef __INT32_TYPE__ __swiftc_int32_t; +#ifdef __UINT32_TYPE__ +typedef __UINT32_TYPE__ __swiftc_uint32_t; +#else +typedef unsigned __INT32_TYPE__ __swiftc_uint32_t; +#endif + +#define __swiftc_join3(a,b,c) a ## b ## c + +#define __swiftc_intn_t(n) __swiftc_join3(__swiftc_int, n, _t) +#define __swiftc_uintn_t(n) __swiftc_join3(__swiftc_uint, n, _t) + +#if defined(_MSC_VER) && !defined(__clang__) +#if defined(_WIN32) +typedef __swiftc_int32_t SwiftInt; +typedef __swiftc_uint32_t SwiftUInt; +#elif defined(_WIN64) +typedef __swiftc_int64_t SwiftInt; +typedef __swiftc_uint64_t SwiftUInt; +#else +#error unknown windows pointer width +#endif +#else +typedef __swiftc_intn_t(__INTPTR_WIDTH__) SwiftInt; +typedef __swiftc_uintn_t(__INTPTR_WIDTH__) SwiftUInt; +#endif +#endif + SWIFT_BEGIN_NULLABILITY_ANNOTATIONS #ifdef __cplusplus @@ -38,9 +96,6 @@ FeatureName, SWIFT_BEGIN_ASSUME_NONNULL -typedef long SwiftInt; -typedef unsigned long SwiftUInt; - typedef struct BridgedData { const char *_Nullable baseAddress; SwiftUInt size; From 592752741917c0ff76e382646f6d3e8a0bdd30c1 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 1 Sep 2023 12:40:46 -0700 Subject: [PATCH 3/7] Switch order of _WIN64/_WIN32 checks in computation of C types for Int/UInt 64-bit Windows defines both _WIN64 and _WIN32, so the logic here would always end up defining 32-bit C types for Swift's `Int` and `UInt`. Fix the ordering to check for 64-bit first, then 32-bit second. Note that the SwiftShims version of this code has always been wrong, but it's completely benign because SwiftShims is only used in the Swift runtime itself, which is built with Clang (on all platforms), and doesn't need to go through this code path. Still, we fix it in both places, so we don't get a nasty surprise if the SwiftShims version of the header later gets included in a non-Clang C++ compiler. --- include/swift/Basic/CBasicBridging.h | 8 ++++---- stdlib/public/SwiftShims/swift/shims/SwiftStdint.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/swift/Basic/CBasicBridging.h b/include/swift/Basic/CBasicBridging.h index 6771d446778ce..f1fbbae861bf7 100644 --- a/include/swift/Basic/CBasicBridging.h +++ b/include/swift/Basic/CBasicBridging.h @@ -64,12 +64,12 @@ typedef unsigned __INT32_TYPE__ __swiftc_uint32_t; #define __swiftc_uintn_t(n) __swiftc_join3(__swiftc_uint, n, _t) #if defined(_MSC_VER) && !defined(__clang__) -#if defined(_WIN32) -typedef __swiftc_int32_t SwiftInt; -typedef __swiftc_uint32_t SwiftUInt; -#elif defined(_WIN64) +#if defined(_WIN64) typedef __swiftc_int64_t SwiftInt; typedef __swiftc_uint64_t SwiftUInt; +#elif defined(_WIN32) +typedef __swiftc_int32_t SwiftInt; +typedef __swiftc_uint32_t SwiftUInt; #else #error unknown windows pointer width #endif diff --git a/stdlib/public/SwiftShims/swift/shims/SwiftStdint.h b/stdlib/public/SwiftShims/swift/shims/SwiftStdint.h index 117677e497af3..386186df0962c 100644 --- a/stdlib/public/SwiftShims/swift/shims/SwiftStdint.h +++ b/stdlib/public/SwiftShims/swift/shims/SwiftStdint.h @@ -71,12 +71,12 @@ typedef unsigned __INT8_TYPE__ __swift_uint8_t; #define __swift_uintn_t(n) __swift_join3(__swift_uint, n, _t) #if defined(_MSC_VER) && !defined(__clang__) -#if defined(_WIN32) -typedef __swift_int32_t __swift_intptr_t; -typedef __swift_uint32_t __swift_uintptr_t; -#elif defined(_WIN64) +#if defined(_WIN64) typedef __swift_int64_t __swift_intptr_t; typedef __swift_uint64_t __swift_uintptr_t; +#elif defined(_WIN32) +typedef __swift_int32_t __swift_intptr_t; +typedef __swift_uint32_t __swift_uintptr_t; #else #error unknown windows pointer width #endif From 566c71ff30702d2f909d3e7cacade3257bb26f60 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 1 Sep 2023 14:47:58 -0700 Subject: [PATCH 4/7] Fix handling of Swift(U)Int for Windows --- include/swift/Basic/CBasicBridging.h | 7 ++++++- lib/ASTGen/Sources/LLVMJSON/LLVMJSON.swift | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/swift/Basic/CBasicBridging.h b/include/swift/Basic/CBasicBridging.h index f1fbbae861bf7..130ca4f04190b 100644 --- a/include/swift/Basic/CBasicBridging.h +++ b/include/swift/Basic/CBasicBridging.h @@ -35,7 +35,12 @@ // Clang has been defining __INTxx_TYPE__ macros for a long time. // __UINTxx_TYPE__ are defined only since Clang 3.5. -#if !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__wasi__) +#if defined(_MSC_VER) && !defined(__clang__) +typedef __int64 __swiftc_int64_t; +typedef unsigned __int64 __swiftc_uint64_t; +typedef int __swiftc_int32_t; +typedef unsigned int __swiftc_uint32_t; +#elif !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__wasi__) #include typedef int64_t __swiftc_int64_t; typedef uint64_t __swiftc_uint64_t; diff --git a/lib/ASTGen/Sources/LLVMJSON/LLVMJSON.swift b/lib/ASTGen/Sources/LLVMJSON/LLVMJSON.swift index c0b98123881d9..1ab7a991c5e43 100644 --- a/lib/ASTGen/Sources/LLVMJSON/LLVMJSON.swift +++ b/lib/ASTGen/Sources/LLVMJSON/LLVMJSON.swift @@ -41,7 +41,7 @@ public struct LLVMJSON { /// Decode a JSON data to a Swift value. public static func decode(_ type: T.Type, from json: UnsafeBufferPointer) throws -> T { - let data = BridgedData(baseAddress: json.baseAddress, size: UInt(json.count)) + let data = BridgedData(baseAddress: json.baseAddress, size: SwiftUInt(json.count)) let valuePtr = JSON_deserializedValue(data) defer { JSON_value_delete(valuePtr) } From 8a8fa2d778395ad4a08396588168c8c826558182 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 1 Sep 2023 15:16:23 -0700 Subject: [PATCH 5/7] Apply suggestions from code review Co-authored-by: Saleem Abdulrasool --- include/swift/Basic/CBasicBridging.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/swift/Basic/CBasicBridging.h b/include/swift/Basic/CBasicBridging.h index 130ca4f04190b..ca1b90754582a 100644 --- a/include/swift/Basic/CBasicBridging.h +++ b/include/swift/Basic/CBasicBridging.h @@ -55,6 +55,7 @@ typedef __UINT64_TYPE__ __swiftc_uint64_t; #else typedef unsigned __INT64_TYPE__ __swiftc_uint64_t; #endif +#endif typedef __INT32_TYPE__ __swiftc_int32_t; #ifdef __UINT32_TYPE__ @@ -82,7 +83,6 @@ typedef __swiftc_uint32_t SwiftUInt; typedef __swiftc_intn_t(__INTPTR_WIDTH__) SwiftInt; typedef __swiftc_uintn_t(__INTPTR_WIDTH__) SwiftUInt; #endif -#endif SWIFT_BEGIN_NULLABILITY_ANNOTATIONS From 45533851bc012a12b04e20f0fa3a8cf3727e1eeb Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 1 Sep 2023 18:27:15 -0700 Subject: [PATCH 6/7] Apply suggestions from code review Co-authored-by: Saleem Abdulrasool --- include/swift/Basic/CBasicBridging.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/swift/Basic/CBasicBridging.h b/include/swift/Basic/CBasicBridging.h index ca1b90754582a..2e13a2135e331 100644 --- a/include/swift/Basic/CBasicBridging.h +++ b/include/swift/Basic/CBasicBridging.h @@ -55,7 +55,6 @@ typedef __UINT64_TYPE__ __swiftc_uint64_t; #else typedef unsigned __INT64_TYPE__ __swiftc_uint64_t; #endif -#endif typedef __INT32_TYPE__ __swiftc_int32_t; #ifdef __UINT32_TYPE__ @@ -63,6 +62,7 @@ typedef __UINT32_TYPE__ __swiftc_uint32_t; #else typedef unsigned __INT32_TYPE__ __swiftc_uint32_t; #endif +#endif #define __swiftc_join3(a,b,c) a ## b ## c From eaa856d123d3057b494f7320285ad1b4c746357f Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 1 Sep 2023 20:50:36 -0700 Subject: [PATCH 7/7] ASTGen: adjust for type changes The type definitions do not uniformly import as `Swift.Int` and `Swift.UInt`. Add some casts to accommodate the type conversions. --- lib/ASTGen/Sources/ASTGen/ASTGen.swift | 3 ++- lib/ASTGen/Sources/ASTGen/Generics.swift | 3 ++- lib/ASTGen/Sources/ASTGen/Macros.swift | 10 +++++----- lib/ASTGen/Sources/ASTGen/Misc.swift | 5 +++-- lib/ASTGen/Sources/ASTGen/PluginHost.swift | 4 ++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/ASTGen/Sources/ASTGen/ASTGen.swift b/lib/ASTGen/Sources/ASTGen/ASTGen.swift index 7d726f002b081..7d40032fb62aa 100644 --- a/lib/ASTGen/Sources/ASTGen/ASTGen.swift +++ b/lib/ASTGen/Sources/ASTGen/ASTGen.swift @@ -1,4 +1,5 @@ import CASTBridging +import CBasicBridging import SwiftParser // Needed to use SyntaxTransformVisitor's visit method. @@ -8,7 +9,7 @@ import SwiftSyntax extension Array { public func withBridgedArrayRef(_ c: (BridgedArrayRef) -> T) -> T { withUnsafeBytes { buf in - c(BridgedArrayRef(data: buf.baseAddress!, numElements: count)) + c(BridgedArrayRef(data: buf.baseAddress!, numElements: SwiftInt(count))) } } } diff --git a/lib/ASTGen/Sources/ASTGen/Generics.swift b/lib/ASTGen/Sources/ASTGen/Generics.swift index cba550688b75e..e5feb22ceea94 100644 --- a/lib/ASTGen/Sources/ASTGen/Generics.swift +++ b/lib/ASTGen/Sources/ASTGen/Generics.swift @@ -1,4 +1,5 @@ import CASTBridging +import CBasicBridging import SwiftParser // Needed to use SyntaxTransformVisitor's visit method. @@ -37,7 +38,7 @@ extension ASTGenVisitor { return .decl( GenericTypeParamDecl_create( - self.ctx, self.declContext, name, nameLoc, eachLoc, genericParameterIndex, + self.ctx, self.declContext, name, nameLoc, eachLoc, SwiftInt(genericParameterIndex), eachLoc.raw != nil)) } } diff --git a/lib/ASTGen/Sources/ASTGen/Macros.swift b/lib/ASTGen/Sources/ASTGen/Macros.swift index 96205f1d149e9..e9929cd84a809 100644 --- a/lib/ASTGen/Sources/ASTGen/Macros.swift +++ b/lib/ASTGen/Sources/ASTGen/Macros.swift @@ -281,7 +281,7 @@ func checkMacroDefinition( if module == "Builtin" { switch type { case "ExternalMacro": - return BridgedMacroDefinitionKind.builtinExternalMacro.rawValue + return Int(BridgedMacroDefinitionKind.builtinExternalMacro.rawValue) default: // Warn about the unknown builtin. @@ -326,7 +326,7 @@ func checkMacroDefinition( ] ) ) - return BridgedMacroDefinitionKind.externalMacro.rawValue + return Int(BridgedMacroDefinitionKind.externalMacro.rawValue) case let .expansion(expansionSyntax, replacements: _) where expansionSyntax.macroName.text == "externalMacro": @@ -365,7 +365,7 @@ func checkMacroDefinition( // Form the "ModuleName.TypeName" result string. (externalMacroPointer.pointee, externalMacroLength.pointee) = allocateUTF8String("\(module).\(type)", nullTerminated: true) - return BridgedMacroDefinitionKind.externalMacro.rawValue + return Int(BridgedMacroDefinitionKind.externalMacro.rawValue) case let .expansion(expansionSyntax, replacements: replacements): // Provide the expansion syntax. @@ -376,7 +376,7 @@ func checkMacroDefinition( // If there are no replacements, we're done. if replacements.isEmpty { - return BridgedMacroDefinitionKind.expandedMacro.rawValue + return Int(BridgedMacroDefinitionKind.expandedMacro.rawValue) } // The replacements are triples: (startOffset, endOffset, parameter index). @@ -391,7 +391,7 @@ func checkMacroDefinition( replacementsPtr.pointee = replacementBuffer.baseAddress numReplacementsPtr.pointee = replacements.count - return BridgedMacroDefinitionKind.expandedMacro.rawValue + return Int(BridgedMacroDefinitionKind.expandedMacro.rawValue) } } catch let errDiags as DiagnosticsError { let srcMgr = SourceManager(cxxDiagnosticEngine: diagEnginePtr) diff --git a/lib/ASTGen/Sources/ASTGen/Misc.swift b/lib/ASTGen/Sources/ASTGen/Misc.swift index acc15c8b8bca5..a4532bfa43672 100644 --- a/lib/ASTGen/Sources/ASTGen/Misc.swift +++ b/lib/ASTGen/Sources/ASTGen/Misc.swift @@ -1,4 +1,5 @@ import CASTBridging +import CBasicBridging import SwiftParser // Needed to use SyntaxTransformVisitor's visit method. @@ -65,7 +66,7 @@ extension BridgedSourceLoc { ) { if let start = buffer.baseAddress, position.utf8Offset >= 0 && position.utf8Offset < buffer.count { - self = SourceLoc_advanced(BridgedSourceLoc(raw: start), position.utf8Offset) + self = SourceLoc_advanced(BridgedSourceLoc(raw: start), SwiftInt(position.utf8Offset)) } else { self = nil } @@ -75,7 +76,7 @@ extension BridgedSourceLoc { extension String { mutating func withBridgedString(_ body: (BridgedString) throws -> R) rethrows -> R { try withUTF8 { buffer in - try body(BridgedString(data: buffer.baseAddress, length: buffer.count)) + try body(BridgedString(data: buffer.baseAddress, length: SwiftInt(buffer.count))) } } } diff --git a/lib/ASTGen/Sources/ASTGen/PluginHost.swift b/lib/ASTGen/Sources/ASTGen/PluginHost.swift index ece9dde4d92ae..16a4065d29bb4 100644 --- a/lib/ASTGen/Sources/ASTGen/PluginHost.swift +++ b/lib/ASTGen/Sources/ASTGen/PluginHost.swift @@ -121,7 +121,7 @@ struct CompilerPlugin { private func sendMessage(_ message: HostToPluginMessage) throws { let hadError = try LLVMJSON.encoding(message) { (data) -> Bool in - return Plugin_sendMessage(opaqueHandle, BridgedData(baseAddress: data.baseAddress, size: UInt(data.count))) + return Plugin_sendMessage(opaqueHandle, BridgedData(baseAddress: data.baseAddress, size: SwiftUInt(data.count))) } if hadError { throw PluginError.failedToSendMessage @@ -339,7 +339,7 @@ class PluginDiagnosticsEngine { guard let bufferBaseAddress = exportedSourceFile.pointee.buffer.baseAddress else { return nil } - return SourceLoc_advanced(BridgedSourceLoc(raw: bufferBaseAddress), offset) + return SourceLoc_advanced(BridgedSourceLoc(raw: bufferBaseAddress), SwiftInt(offset)) } /// C++ source location from a position value from a plugin.